patch #2869 MTex module additions

contributed by Yehoshua Sapir (sapir)

adds attributes to MTex module.  adds module constants.
Uses new style tp_getset.
This commit is contained in:
Stephen Swaney
2005-11-26 02:10:42 +00:00
parent 8128835ada
commit 51e70835cc
4 changed files with 866 additions and 94 deletions

View File

@@ -25,7 +25,7 @@
*
* This is a new part of Blender.
*
* Contributor(s): Alex Mole
* Contributor(s): Alex Mole, Yehoshua Sapir
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -33,13 +33,15 @@
#include "BKE_utildefines.h"
#include "Texture.h"
#include "Object.h"
#include "gen_utils.h"
#include <DNA_material_types.h>
/*****************************************************************************/
/* Python BPy_MTex methods declarations: */
/*****************************************************************************/
static PyObject *MTex_setTex( BPy_MTex * self, PyObject * args );
static PyObject *MTex_setTexMethod( BPy_MTex * self, PyObject * args );
/*****************************************************************************/
/* Python method structure definition for Blender.Texture.MTex module: */
@@ -53,7 +55,7 @@ struct PyMethodDef M_MTex_methods[] = {
/*****************************************************************************/
static PyMethodDef BPy_MTex_methods[] = {
/* name, method, flags, doc */
{"setTex", ( PyCFunction ) MTex_setTex, METH_VARARGS,
{"setTex", ( PyCFunction ) MTex_setTexMethod, METH_VARARGS,
"(i) - Set MTex Texture"},
{NULL, NULL, 0, NULL}
};
@@ -62,15 +64,126 @@ static PyMethodDef BPy_MTex_methods[] = {
/* Python MTex_Type callback function prototypes: */
/*****************************************************************************/
static void MTex_dealloc( BPy_MTex * self );
static int MTex_setAttr( BPy_MTex * self, char *name, PyObject * v );
static int MTex_compare( BPy_MTex * a, BPy_MTex * b );
static PyObject *MTex_getAttr( BPy_MTex * self, char *name );
static PyObject *MTex_repr( BPy_MTex * self );
#define MTEXGET(x) \
static PyObject *MTex_get##x( BPy_MTex *self, void *closure );
#define MTEXSET(x) \
static int MTex_set##x( BPy_MTex *self, PyObject *value, void *closure);
#define MTEXGETSET(x) \
MTEXGET(x) \
MTEXSET(x)
MTEXGETSET(Tex)
MTEXGETSET(TexCo)
MTEXGETSET(Object)
MTEXGETSET(MapTo)
MTEXGETSET(Col)
MTEXGETSET(DVar)
MTEXGETSET(BlendMode)
MTEXGETSET(ColFac)
MTEXGETSET(NorFac)
MTEXGETSET(VarFac)
MTEXGETSET(DispFac)
MTEXGETSET(WarpFac)
MTEXGETSET(Ofs)
MTEXGETSET(Size)
MTEXGETSET(Mapping)
MTEXGETSET(Flag)
MTEXGETSET(ProjX)
MTEXGETSET(ProjY)
MTEXGETSET(ProjZ)
MTEXGETSET(MapToFlag)
/*****************************************************************************/
/* Python get/set methods table */
/*****************************************************************************/
static PyGetSetDef MTex_getseters[] = {
{ "tex", (getter) MTex_getTex, (setter) MTex_setTex,
"Texture whose mapping this MTex describes", NULL },
{ "texco", (getter) MTex_getTexCo, (setter) MTex_setTexCo,
"Texture coordinate space (UV, Global, etc.)", NULL },
{ "object", (getter) MTex_getObject, (setter) MTex_setObject,
"Object whose space to use when texco is Object", NULL },
{ "mapto", (getter) MTex_getMapTo, (setter) MTex_setMapTo,
"What values the texture affects", NULL },
{ "col", (getter) MTex_getCol, (setter) MTex_setCol,
"Color that the texture blends with", NULL },
{ "dvar", (getter) MTex_getDVar, (setter) MTex_setDVar,
"Value that the texture blends with when not blending colors", NULL },
{ "blendmode", (getter) MTex_getBlendMode, (setter) MTex_setBlendMode,
"Texture blending mode", NULL },
{ "colfac", (getter) MTex_getColFac, (setter) MTex_setColFac,
"Factor by which texture affects color", NULL },
{ "norfac", (getter) MTex_getNorFac, (setter) MTex_setNorFac,
"Factor by which texture affects normal", NULL },
{ "varfac", (getter) MTex_getVarFac, (setter) MTex_setVarFac,
"Factor by which texture affects most variables", NULL },
{ "dispfac", (getter) MTex_getDispFac, (setter) MTex_setDispFac,
"Factor by which texture affects displacement", NULL },
{ "warpfac", (getter) MTex_getWarpFac, (setter) MTex_setWarpFac,
"Factor by which texture affects warp", NULL },
{ "ofs", (getter) MTex_getOfs, (setter) MTex_setOfs,
"Offset to adjust texture space", NULL },
{ "size", (getter) MTex_getSize, (setter) MTex_setSize,
"Size to scale texture space", NULL },
{ "mapping", (getter) MTex_getMapping, (setter) MTex_setMapping,
"Mapping of texture coordinates (flat, cube, etc.)", NULL },
{ "stencil", (getter) MTex_getFlag, (setter) MTex_setFlag,
"Stencil mode", (void*) MTEX_STENCIL },
{ "neg", (getter) MTex_getFlag, (setter) MTex_setFlag,
"Negate texture values mode", (void*) MTEX_NEGATIVE },
{ "noRGB", (getter) MTex_getFlag, (setter) MTex_setFlag,
"Convert texture RGB values to intensity values",
(void*) MTEX_RGBTOINT },
{ "correctNor", (getter) MTex_getFlag, (setter) MTex_setFlag,
"Correct normal mapping for Texture space and Object space",
(void*) MTEX_VIEWSPACE },
{ "xproj", (getter) MTex_getProjX, (setter) MTex_setProjX,
"Projection of X axis to Texture space", NULL },
{ "yproj", (getter) MTex_getProjY, (setter) MTex_setProjY,
"Projection of Y axis to Texture space", NULL },
{ "zproj", (getter) MTex_getProjZ, (setter) MTex_setProjZ,
"Projection of Z axis to Texture space", NULL },
{ "mtCol", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to color", (void*) MAP_COL },
{ "mtNor", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to normals", (void*) MAP_NORM },
{ "mtCsp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to specularity color", (void*) MAP_COLSPEC },
{ "mtCmir", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to mirror color", (void*) MAP_COLMIR },
{ "mtRef", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to reflectivity", (void*) MAP_REF },
{ "mtSpec", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to specularity", (void*) MAP_SPEC },
{ "mtEmit", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to emit value", (void*) MAP_EMIT },
{ "mtAlpha", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to alpha value", (void*) MAP_ALPHA },
{ "mtHard", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to hardness", (void*) MAP_HAR },
{ "mtRayMir", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to RayMir value", (void*) MAP_RAYMIRR },
{ "mtTranslu", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to translucency", (void*) MAP_TRANSLU },
{ "mtAmb", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to ambient value", (void*) MAP_AMB },
{ "mtDisp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to displacement", (void*) MAP_DISPLACE },
{ "mtWarp", (getter) MTex_getMapToFlag, (setter) MTex_setMapToFlag,
"How texture maps to warp", (void*) MAP_WARP },
{ NULL, NULL, NULL, NULL, NULL }
};
/*****************************************************************************/
/* Python MTex_Type structure definition: */
/*****************************************************************************/
PyTypeObject MTex_Type = {
PyObject_HEAD_INIT( NULL )
0, /* ob_size */
@@ -80,27 +193,55 @@ PyTypeObject MTex_Type = {
/* methods */
( destructor ) MTex_dealloc, /* tp_dealloc */
0, /* tp_print */
( getattrfunc ) MTex_getAttr, /* tp_getattr */
( setattrfunc ) MTex_setAttr, /* tp_setattr */
0, /* tp_getattr */
0, /* tp_setattr */
( cmpfunc ) MTex_compare, /* tp_compare */
( reprfunc ) MTex_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_hash */
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
0, /* tp_doc */
0, 0, 0, 0, 0, 0,
0, /* tp_methods */
BPy_MTex_methods, /* tp_methods */
0, /* tp_members */
MTex_getseters, /* struct PyGetSetDef *tp_getset; */
0, /* struct _typeobject *tp_base; */
0, /* PyObject *tp_dict; */
0, /* descrgetfunc tp_descr_get; */
0, /* descrsetfunc tp_descr_set; */
0, /* long tp_dictoffset; */
0, /* initproc tp_init; */
0, /* allocfunc tp_alloc; */
0, /* newfunc tp_new; */
/* Low-level free-memory routine */
0, /* freefunc tp_free; */
/* For PyObject_IS_GC */
0, /* inquiry tp_is_gc; */
0, /* PyObject *tp_bases; */
/* method resolution order */
0, /* PyObject *tp_mro; */
0, /* PyObject *tp_cache; */
0, /* PyObject *tp_subclasses; */
0, /* PyObject *tp_weaklist; */
0
};
PyObject *MTex_Init( void )
{
PyObject *submodule;
/* PyObject *dict; */
MTex_Type.ob_type = &PyType_Type;
/* call PyType_Ready() to init dictionaries & such */
if( PyType_Ready( &MTex_Type) < 0)
return NULL;
/* So do we need this? */
/* MTex_Type.ob_type = &PyType_Type;*/
submodule = Py_InitModule( "Blender.Texture.MTex", M_MTex_methods );
@@ -136,17 +277,27 @@ int MTex_CheckPyObject( PyObject * pyobj )
/* Python BPy_MTex methods: */
/*****************************************************************************/
static PyObject *MTex_setTex( BPy_MTex * self, PyObject * args )
static PyObject *MTex_setTexMethod( BPy_MTex * self, PyObject * args )
{
BPy_Texture *pytex = NULL;
if( !PyArg_ParseTuple( args, "O!", &Texture_Type, &pytex ) )
Tex *tex;
if( args == Py_None )
{
tex = NULL;
} else if( Texture_CheckPyObject( args ) ) {
tex = Texture_FromPyObject( args );
} else {
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected Texture argument" );
}
if( self->mtex->tex )
self->mtex->tex->id.us--;
self->mtex->tex = Texture_FromPyObject( ( PyObject * ) pytex );
self->mtex->tex = tex;
if( self->mtex->tex )
self->mtex->tex->id.us++;
Py_INCREF( Py_None );
return Py_None;
@@ -157,77 +308,6 @@ static void MTex_dealloc( BPy_MTex * self )
PyObject_DEL( self );
}
static PyObject *MTex_getAttr( BPy_MTex * self, char *name )
{
if( STREQ( name, "tex" ) ) {
if( self->mtex->tex )
return Texture_CreatePyObject( self->mtex->tex );
else {
Py_INCREF( Py_None );
return Py_None;
}
} else if( STREQ( name, "texco" ) )
return PyInt_FromLong( self->mtex->texco );
else if( STREQ( name, "mapto" ) )
return PyInt_FromLong( self->mtex->mapto );
else if( STREQ( name, "__members__" ) )
return Py_BuildValue( "[s,s,s]", "tex", "texco", "mapto" );
/* not an attribute, search the methods table */
return Py_FindMethod( BPy_MTex_methods, ( PyObject * ) self, name );
}
static int MTex_setAttr( BPy_MTex * self, char *name, PyObject * value )
{
PyObject *valtuple;
PyObject *error = NULL;
/* Put "value" in a tuple, because we want to pass it to functions *
* that only accept PyTuples. */
valtuple = Py_BuildValue( "(O)", value );
if( !valtuple )
return EXPP_ReturnIntError( PyExc_MemoryError,
"MTex_setAttr: couldn't create PyTuple" );
if( STREQ( name, "tex" ) )
error = MTex_setTex( self, valtuple );
else if( STREQ( name, "texco" ) ) {
if( PyInt_Check( value ) ) {
int texco = PyInt_AsLong( value );
/* TODO: sanity-check this input! */
self->mtex->texco = (short)texco;
Py_INCREF( Py_None ); /* because we decref it below */
error = Py_None;
}
} else if( STREQ( name, "mapto" ) ) {
if( PyInt_Check( value ) ) {
int mapto = PyInt_AsLong( value );
/* TODO: sanity-check this input! */
self->mtex->mapto = (short)mapto;
Py_INCREF( Py_None ); /* because we decref it below */
error = Py_None;
}
}
else {
/* Error */
Py_DECREF( valtuple );
return EXPP_ReturnIntError( PyExc_KeyError,
"attribute not found" );
}
Py_DECREF( valtuple );
if( error != Py_None )
return -1;
/* Py_None was INCREF'd by the set*() function, so we need to DECREF it */
Py_DECREF( Py_None );
return 0;
}
static int MTex_compare( BPy_MTex * a, BPy_MTex * b )
{
return ( a->mtex == b->mtex ) ? 0 : -1;
@@ -237,3 +317,572 @@ static PyObject *MTex_repr( BPy_MTex * self )
{
return PyString_FromFormat( "[MTex]" );
}
/*****************************************************************************/
/* Python BPy_MTex get and set functions: */
/*****************************************************************************/
static PyObject *MTex_getTex( BPy_MTex *self, void *closure )
{
if( self->mtex->tex )
return Texture_CreatePyObject( self->mtex->tex );
else {
Py_INCREF( Py_None );
return Py_None;
}
}
static int MTex_setTex( BPy_MTex *self, PyObject *value, void *closure)
{
Tex *tex;
if( value == Py_None )
{
tex = NULL;
} else if( Texture_CheckPyObject( value ) ) {
tex = Texture_FromPyObject( value );
} else {
return EXPP_ReturnIntError( PyExc_TypeError,
"expected Texture argument" );
}
if( self->mtex->tex )
self->mtex->tex->id.us--;
self->mtex->tex = tex;
if( self->mtex->tex )
self->mtex->tex->id.us++;
return 0;
}
static PyObject *MTex_getTexCo( BPy_MTex *self, void *closure )
{
return PyInt_FromLong( self->mtex->texco );
}
static int MTex_setTexCo( BPy_MTex *self, PyObject *value, void *closure)
{
int texco;
if( !PyInt_Check( value ) ) {
return EXPP_ReturnIntError( PyExc_TypeError,
"Value must be a member of Texture.TexCo dictionary" );
}
texco = PyInt_AsLong( value ) ;
if (texco != TEXCO_ORCO && texco != TEXCO_REFL && texco != TEXCO_NORM &&
texco != TEXCO_GLOB && texco != TEXCO_UV && texco != TEXCO_OBJECT &&
texco != TEXCO_WINDOW && texco != TEXCO_VIEW && texco != TEXCO_STICKY )
return EXPP_ReturnIntError( PyExc_ValueError,
"Value must be a member of Texture.TexCo dictionary" );
self->mtex->texco = texco;
return 0;
}
static PyObject *MTex_getObject( BPy_MTex *self, void *closure )
{
if( self->mtex->object )
return Object_CreatePyObject( self->mtex->object );
else {
Py_INCREF( Py_None );
return Py_None;
}
}
static int MTex_setObject( BPy_MTex *self, PyObject *value, void *closure)
{
Object *obj;
if( value == Py_None )
{
obj = NULL;
} else if( Object_CheckPyObject( value ) ) {
obj = Object_FromPyObject( value );
} else {
return EXPP_ReturnIntError( PyExc_TypeError,
"expected Object argument" );
}
if( self->mtex->object )
self->mtex->object->id.us--;
self->mtex->object = obj;
if( self->mtex->object )
self->mtex->object->id.us++;
return 0;
}
static PyObject *MTex_getMapTo( BPy_MTex *self, void *closure )
{
return PyInt_FromLong( self->mtex->mapto );
}
static int MTex_setMapTo( BPy_MTex *self, PyObject *value, void *closure)
{
int mapto;
if( !PyInt_Check( value ) ) {
return EXPP_ReturnIntError( PyExc_TypeError,
"expected an int" );
}
mapto = PyInt_AsLong( value );
/* This method is deprecated anyway. */
if ( mapto < 0 || mapto > 16383 ) {
return EXPP_ReturnIntError( PyExc_ValueError,
"Value must be a sum of values from Texture.MapTo dictionary" );
}
self->mtex->mapto = mapto;
return 0;
}
static PyObject *MTex_getCol( BPy_MTex *self, void *closure )
{
return Py_BuildValue( "(f,f,f)", self->mtex->r, self->mtex->g,
self->mtex->b );
}
static int MTex_setCol( BPy_MTex *self, PyObject *value, void *closure)
{
float rgb[3];
int i;
if( !PyArg_ParseTuple( value, "fff",
&rgb[0], &rgb[1], &rgb[2] ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected tuple of 3 floats" );
for( i = 0; i < 3; ++i )
if( rgb[i] < 0 || rgb[i] > 1 )
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [0,1]" );
self->mtex->r = rgb[0];
self->mtex->g = rgb[1];
self->mtex->b = rgb[2];
return 0;
}
static PyObject *MTex_getDVar( BPy_MTex *self, void *closure )
{
return PyFloat_FromDouble(self->mtex->def_var);
}
static int MTex_setDVar( BPy_MTex *self, PyObject *value, void *closure)
{
float f;
if ( !PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a float" );
f = PyFloat_AsDouble(value);
if (f < 0 || f > 1)
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [0,1]" );
self->mtex->def_var = f;
return 0;
}
static PyObject *MTex_getBlendMode( BPy_MTex *self, void *closure )
{
return PyInt_FromLong(self->mtex->blendtype);
}
static int MTex_setBlendMode( BPy_MTex *self, PyObject *value, void *closure)
{
int n;
if ( !PyInt_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"Value must be member of Texture.BlendModes dictionary" );
n = PyInt_AsLong(value);
/* if (n != MTEX_BLEND && n != MTEX_MUL && n != MTEX_ADD &&
n != MTEX_SUB && n != MTEX_DIV && n != MTEX_DARK &&
n != MTEX_DIFF && n != MTEX_LIGHT && n != MTEX_SCREEN)*/
if (n < 0 || n > 8)
{
return EXPP_ReturnIntError( PyExc_ValueError,
"Value must be member of Texture.BlendModes dictionary" );
}
self->mtex->blendtype = n;
return 0;
}
static PyObject *MTex_getColFac( BPy_MTex *self, void *closure )
{
return PyFloat_FromDouble(self->mtex->colfac);
}
static int MTex_setColFac( BPy_MTex *self, PyObject *value, void *closure)
{
float f;
if ( !PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a float" );
f = PyFloat_AsDouble(value);
if (f < 0 || f > 1)
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [0,1]" );
self->mtex->colfac = f;
return 0;
}
static PyObject *MTex_getNorFac( BPy_MTex *self, void *closure )
{
return PyFloat_FromDouble(self->mtex->norfac);
}
static int MTex_setNorFac( BPy_MTex *self, PyObject *value, void *closure)
{
float f;
if ( !PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a float" );
f = PyFloat_AsDouble(value);
if (f < 0 || f > 25)
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [0,25]" );
self->mtex->norfac = f;
return 0;
}
static PyObject *MTex_getVarFac( BPy_MTex *self, void *closure )
{
return PyFloat_FromDouble(self->mtex->varfac);
}
static int MTex_setVarFac( BPy_MTex *self, PyObject *value, void *closure)
{
float f;
if ( !PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a float" );
f = PyFloat_AsDouble(value);
if (f < 0 || f > 1)
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [0,1]" );
self->mtex->varfac = f;
return 0;
}
static PyObject *MTex_getDispFac( BPy_MTex *self, void *closure )
{
return PyFloat_FromDouble(self->mtex->dispfac);
}
static int MTex_setDispFac( BPy_MTex *self, PyObject *value, void *closure)
{
float f;
if ( !PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a float" );
f = PyFloat_AsDouble(value);
if (f < 0 || f > 1)
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [0,1]" );
self->mtex->dispfac = f;
return 0;
}
static PyObject *MTex_getWarpFac( BPy_MTex *self, void *closure )
{
return PyFloat_FromDouble(self->mtex->warpfac);
}
static int MTex_setWarpFac( BPy_MTex *self, PyObject *value, void *closure)
{
float f;
if ( !PyFloat_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a float" );
f = PyFloat_AsDouble(value);
if (f < 0 || f > 1)
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [0,1]" );
self->mtex->warpfac = f;
return 0;
}
static PyObject *MTex_getOfs( BPy_MTex *self, void *closure )
{
return Py_BuildValue( "(f,f,f)", self->mtex->ofs[0], self->mtex->ofs[1],
self->mtex->ofs[2] );
}
static int MTex_setOfs( BPy_MTex *self, PyObject *value, void *closure)
{
float f[3];
int i;
if( !PyArg_ParseTuple( value, "fff", &f[0], &f[1], &f[2] ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected tuple of 3 floats" );
for( i = 0; i < 3; ++i )
if( f[i] < -10 || f[i] > 10 )
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [-10,10]" );
self->mtex->ofs[0] = f[0];
self->mtex->ofs[1] = f[1];
self->mtex->ofs[2] = f[2];
return 0;
}
static PyObject *MTex_getSize( BPy_MTex *self, void *closure )
{
return Py_BuildValue( "(f,f,f)", self->mtex->size[0], self->mtex->size[1],
self->mtex->size[2] );
}
static int MTex_setSize( BPy_MTex *self, PyObject *value, void *closure)
{
float f[3];
int i;
if( !PyArg_ParseTuple( value, "fff", &f[0], &f[1], &f[2] ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected tuple of 3 floats" );
for( i = 0; i < 3; ++i )
if( f[i] < -100 || f[i] > 100 )
return EXPP_ReturnIntError( PyExc_ValueError,
"values must be in range [-100,100]" );
self->mtex->size[0] = f[0];
self->mtex->size[1] = f[1];
self->mtex->size[2] = f[2];
return 0;
}
static PyObject *MTex_getMapping( BPy_MTex *self, void *closure )
{
return PyInt_FromLong( self->mtex->mapping );
}
static int MTex_setMapping( BPy_MTex *self, PyObject *value, void *closure)
{
int n;
if ( !PyInt_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"Value must be member of Texture.Mappings dictionary" );
n = PyInt_AsLong(value);
/* if (n != MTEX_FLAT && n != MTEX_TUBE && n != MTEX_CUBE &&
n != MTEX_SPHERE) */
if (n < 0 || n > 3)
{
return EXPP_ReturnIntError( PyExc_ValueError,
"Value must be member of Texture.Mappings dictionary" );
}
self->mtex->mapping = n;
return 0;
}
static PyObject *MTex_getFlag( BPy_MTex *self, void *closure )
{
return PyBool_FromLong( self->mtex->texflag & ((int) closure) );
}
static int MTex_setFlag( BPy_MTex *self, PyObject *value, void *closure)
{
if ( !PyBool_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a bool");
if ( value == Py_True )
self->mtex->texflag |= (int)closure;
else
self->mtex->texflag &= ~((int) closure);
return 0;
}
static PyObject *MTex_getProjX( BPy_MTex *self, void *closure )
{
return PyInt_FromLong( self->mtex->projx );
}
static int MTex_setProjX( BPy_MTex *self, PyObject *value, void *closure)
{
int proj;
if( !PyInt_Check( value ) ) {
return EXPP_ReturnIntError( PyExc_TypeError,
"Value must be a member of Texture.Proj dictionary" );
}
proj = PyInt_AsLong( value ) ;
/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */
if (proj < 0 || proj > 3)
return EXPP_ReturnIntError( PyExc_ValueError,
"Value must be a member of Texture.Proj dictionary" );
self->mtex->projx = proj;
return 0;
}
static PyObject *MTex_getProjY( BPy_MTex *self, void *closure )
{
return PyInt_FromLong( self->mtex->projy );
}
static int MTex_setProjY( BPy_MTex *self, PyObject *value, void *closure )
{
int proj;
if( !PyInt_Check( value ) ) {
return EXPP_ReturnIntError( PyExc_TypeError,
"Value must be a member of Texture.Proj dictionary" );
}
proj = PyInt_AsLong( value ) ;
/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */
if (proj < 0 || proj > 3)
return EXPP_ReturnIntError( PyExc_ValueError,
"Value must be a member of Texture.Proj dictionary" );
self->mtex->projy = proj;
return 0;
}
static PyObject *MTex_getProjZ( BPy_MTex *self, void *closure )
{
return PyInt_FromLong( self->mtex->projz );
}
static int MTex_setProjZ( BPy_MTex *self, PyObject *value, void *closure)
{
int proj;
if( !PyInt_Check( value ) ) {
return EXPP_ReturnIntError( PyExc_TypeError,
"Value must be a member of Texture.Proj dictionary" );
}
proj = PyInt_AsLong( value ) ;
/* valid values are from PROJ_N to PROJ_Z = 0 to 3 */
if (proj < 0 || proj > 3)
return EXPP_ReturnIntError( PyExc_ValueError,
"Value must be a member of Texture.Proj dictionary" );
self->mtex->projz = proj;
return 0;
}
static PyObject *MTex_getMapToFlag( BPy_MTex *self, void *closure )
{
int flag = (int) closure;
if ( self->mtex->mapto & flag )
{
return PyInt_FromLong( ( self->mtex->maptoneg & flag ) ? -1 : 1 );
} else {
return PyInt_FromLong( 0 );
}
}
static int MTex_setMapToFlag( BPy_MTex *self, PyObject *value, void *closure)
{
int flag = (int) closure;
int intVal;
if ( !PyInt_Check( value ) )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected an int");
intVal = PyInt_AsLong( value );
if (flag == MAP_COL || flag == MAP_COLSPEC || flag == MAP_COLMIR ||
flag == MAP_WARP) {
if (intVal < 0 || intVal > 1) {
return EXPP_ReturnIntError( PyExc_ValueError,
"value for that mapping must be 0 or 1" );
}
} else {
if (intVal < -1 || intVal > 1) {
return EXPP_ReturnIntError( PyExc_ValueError,
"value for that mapping must be -1, 0 or 1" );
}
}
switch (intVal)
{
case 0:
self->mtex->mapto &= ~flag;
self->mtex->maptoneg &= ~flag;
break;
case 1:
self->mtex->mapto |= flag;
self->mtex->maptoneg &= ~flag;
break;
case -1:
self->mtex->mapto |= flag;
self->mtex->maptoneg |= flag;
break;
}
return 0;
}

View File

@@ -1044,7 +1044,7 @@ static PyObject *M_Texture_STypesDict( void )
PyInt_FromLong(TEX_BLENDER));
PyConstant_Insert(d, "DN_PERLIN",
PyInt_FromLong(TEX_STDPERLIN));
PyConstant_Insert(d, "DN_IMPROVEPERLIN",
PyConstant_Insert(d, "DN_IMPROVEDPERLIN",
PyInt_FromLong(TEX_NEWPERLIN));
PyConstant_Insert(d, "DN_VORONOIF1",
PyInt_FromLong(TEX_VORONOI_F1));
@@ -1123,6 +1123,7 @@ static PyObject *M_Texture_MapToDict( void )
PyConstant_Insert(d, "AMB", PyInt_FromLong(MAP_AMB));
PyConstant_Insert(d, "TRANSLU", PyInt_FromLong(MAP_TRANSLU));
PyConstant_Insert(d, "DISP", PyInt_FromLong(MAP_DISPLACE));
PyConstant_Insert(d, "WARP", PyInt_FromLong(MAP_WARP));
}
return MapTo;
}
@@ -1183,7 +1184,7 @@ static PyObject *M_Texture_NoiseDict( void )
PyConstant_Insert(d, "TRI", PyInt_FromLong(EXPP_TEX_NOISE_TRI));
PyConstant_Insert(d, "BLENDER", PyInt_FromLong(TEX_BLENDER));
PyConstant_Insert(d, "PERLIN", PyInt_FromLong(TEX_STDPERLIN));
PyConstant_Insert(d, "IMPROVEPERLIN", PyInt_FromLong(TEX_NEWPERLIN));
PyConstant_Insert(d, "IMPROVEDPERLIN", PyInt_FromLong(TEX_NEWPERLIN));
PyConstant_Insert(d, "VORONOIF1", PyInt_FromLong(TEX_VORONOI_F1));
PyConstant_Insert(d, "VORONOIF2", PyInt_FromLong(TEX_VORONOI_F2));
PyConstant_Insert(d, "VORONOIF3", PyInt_FromLong(TEX_VORONOI_F3));
@@ -1196,6 +1197,50 @@ static PyObject *M_Texture_NoiseDict( void )
return Noise;
}
static PyObject *M_Texture_BlendModesDict( void )
{
PyObject *BlendModes = PyConstant_New( );
if( BlendModes ) {
BPy_constant *d = ( BPy_constant * ) BlendModes;
PyConstant_Insert(d, "MIX", PyInt_FromLong(MTEX_BLEND));
PyConstant_Insert(d, "MULTIPLY", PyInt_FromLong(MTEX_MUL));
PyConstant_Insert(d, "ADD", PyInt_FromLong(MTEX_ADD));
PyConstant_Insert(d, "SUBTRACT", PyInt_FromLong(MTEX_SUB));
PyConstant_Insert(d, "DIVIDE", PyInt_FromLong(MTEX_DIV));
PyConstant_Insert(d, "DARKEN", PyInt_FromLong(MTEX_DARK));
PyConstant_Insert(d, "DIFFERENCE", PyInt_FromLong(MTEX_DIFF));
PyConstant_Insert(d, "LIGHTEN", PyInt_FromLong(MTEX_LIGHT));
PyConstant_Insert(d, "SCREEN", PyInt_FromLong(MTEX_SCREEN));
}
return BlendModes;
}
static PyObject *M_Texture_MappingsDict( void )
{
PyObject *Mappings = PyConstant_New( );
if( Mappings ) {
BPy_constant *d = ( BPy_constant * ) Mappings;
PyConstant_Insert(d, "FLAT", PyInt_FromLong(MTEX_FLAT));
PyConstant_Insert(d, "CUBE", PyInt_FromLong(MTEX_CUBE));
PyConstant_Insert(d, "TUBE", PyInt_FromLong(MTEX_TUBE));
PyConstant_Insert(d, "SPHERE", PyInt_FromLong(MTEX_SPHERE));
}
return Mappings;
}
static PyObject *M_Texture_ProjDict( void )
{
PyObject *Proj = PyConstant_New( );
if( Proj ) {
BPy_constant *d = ( BPy_constant * ) Proj;
PyConstant_Insert(d, "NONE", PyInt_FromLong(PROJ_N));
PyConstant_Insert(d, "X", PyInt_FromLong(PROJ_X));
PyConstant_Insert(d, "Y", PyInt_FromLong(PROJ_Y));
PyConstant_Insert(d, "Z", PyInt_FromLong(PROJ_Z));
}
return Proj;
}
PyObject *Texture_Init( void )
{
PyObject *submodule;
@@ -1210,6 +1255,9 @@ PyObject *Texture_Init( void )
PyObject *ExtendModes = M_Texture_ExtendModesDict( );
PyObject *ImageFlags = M_Texture_ImageFlagsDict( );
PyObject *Noise = M_Texture_NoiseDict( );
PyObject *BlendModes = M_Texture_BlendModesDict( );
PyObject *Mappings = M_Texture_MappingsDict( );
PyObject *Proj = M_Texture_ProjDict( );
if( PyType_Ready( &Texture_Type ) < 0)
return NULL;
@@ -1233,6 +1281,12 @@ PyObject *Texture_Init( void )
PyModule_AddObject( submodule, "ImageFlags", ImageFlags );
if( Noise )
PyModule_AddObject( submodule, "Noise", Noise );
if ( BlendModes )
PyModule_AddObject( submodule, "BlendModes", BlendModes );
if ( Mappings )
PyModule_AddObject( submodule, "Mappings", Mappings );
if ( Proj )
PyModule_AddObject( submodule, "Proj", Proj );
/* Add the MTex submodule to this module */
dict = PyModule_GetDict( submodule );

View File

@@ -41,7 +41,7 @@ The Blender Python API Reference
- L{Text}
- L{Text3d}
- L{Font}
- L{Texture}
- L{Texture} (*)
- L{TimeLine}
- L{Types}
- L{Window}

View File

@@ -7,6 +7,10 @@
"""
The Blender.Texture submodule.
B{New}:
- many new attributes in L{MTex} submodule
- new dictionaries (L{Texture.BlendModes}, L{Texture.Mappings}, L{Texture.Proj}) to use for the values of some of the new L{MTex} attributes.
Texture
=======
@@ -88,7 +92,7 @@ Example::
- TRI - Produce bands using triangle wave (marble, wood textures)
- BLENDER - Original Blender algorithm
- PERLIN - Ken Perlin's original (1985) algorithm
- IMPROVEPERLIN - Ken Perlin's newer (2002) algorithm
- IMPROVEDPERLIN - Ken Perlin's newer (2002) algorithm
- VORONOIF1 - none
- VORONOIF2 - none
- VORONOIF3 - none
@@ -97,6 +101,32 @@ Example::
- VORONOICRACKLE - none
- CELLNOISE - Steven Worley's cellular basis algorithm (1996)
@type BlendModes: readonly dictionary
@var BlendModes: The available texture blending modes:
- MIX - mix texture with value
- MULTIPLY - multiply texture with value
- ADD - add texture to value
- SUBTRACT - subtract texture from value
- DIVIDE - divide value by texture
- DARKEN - replace value with texture if texture is darker
- DIFFERENCE - difference of texture from value
- LIGHTEN - replace value with texture if texture is lighter
- SCREEN - 'screen' mode
@type Mappings: readonly dictionary
@var Mappings: The available 2D texture coordinate mappings for images:
- FLAT - flat projection
- CUBE - cube projection
- TUBE - cylindrical projection
- SPHERE - spherical projection
@type Proj: readonly dictionary
@var Proj: The available projections per axis:
- NONE - axis isn't used
- X - axis is used as final x axis
- Y - axis is used as final y axis
- Z - axis is used as final z axis
@type STypes: readonly dictionary
@var STypes: Texture-type specific data. Depending on the value of
Texture.type, certain groups will make sense. For instance, when a texture
@@ -151,7 +181,7 @@ Example::
13. Distorted noise type
- DN_BLENDER - Original Blender algorithm
- DN_PERLIN - Ken Perlin's original (1985) algorithm
- DN_IMPROVEPERLIN - Ken Perlin's newer (2002) algorithm
- DN_IMPROVEDPERLIN - Ken Perlin's newer (2002) algorithm
- DN_VORONOIF1 - none
- DN_VORONOIF2 - none
- DN_VORONOIF3 - none
@@ -177,11 +207,16 @@ Example::
- NOR - Make the texture affect the rendered normal
- CSP - Make the texture affect the specularity colour
- CMIR - Make the texture affect the mirror colour
- REF - Make the texture affect the value of the material's reflectivity
- SPEC - Make the texture affect the value of specularity
- REF - Make the texture affect the diffuse reflectivity value
- SPEC - Make the texture affect the specularity value
- HARD - Make the texture affect the hardness value
- ALPHA - Make the texture affect the alpha value
- EMIT - Make the texture affext the emit value
- EMIT - Make the texture affect the emit value
- RAYMIR - Make the texture affect the mirror reflectivity value
- DISP - Make the texture displace the mesh
- TRANSLU - Make the texture affect the translucency value
- AMB - Make the texture affect the ambient value
- WARP - Make the texture affect texture coordinates for the following textures
@type MapTo: readonly dictionary
"""
@@ -449,6 +484,40 @@ class MTex:
@type tex: Blender Texture
@ivar texco: Texture coordinates ("Map input"). See L{TexCo}
@ivar mapto: "Map to" field of texture. OR'd values of L{MapTo}
@ivar object: Object whose space to use when texco is Object
@type object: Blender Object
@ivar col: Color that the texture blends with
@ivar dvar: Value that the texture blends with when not blending colors
@ivar blendmode: Texture blending mode. L{BlendModes}
@ivar colfac: Factor by which texture affects color
@ivar norfac: Factor by which texture affects normal
@ivar varfac: Factor by which texture affects most variables
@ivar dispfac: Factor by which texture affects displacement
@ivar warpfac: Factor by which texture affects warp
@ivar ofs: Offset to adjust texture space
@ivar size: Size to scale texture space
@ivar mapping: Mapping of texture coordinates (flat, cube, etc.). L{Mappings}
@ivar stencil: Stencil mode
@ivar neg: Negate texture values mode
@ivar noRGB: Convert texture RGB values to intensity values
@ivar correctNor: Correct normal mapping for Texture space and Object space
@ivar xproj: Projection of X axis to Texture space. L{Proj}
@ivar yproj: Projection of Y axis to Texture space. L{Proj}
@ivar zproj: Projection of Z axis to Texture space. L{Proj}
@ivar mtCol: How texture maps to color
@ivar mtNor: How texture maps to normals
@ivar mtCsp: How texture maps to specularity color
@ivar mtCmir: How texture maps to mirror color
@ivar mtRef: How texture maps to reflectivity
@ivar mtSpec: How texture maps to specularity
@ivar mtEmit: How texture maps to emit value
@ivar mtAlpha: How texture maps to alpha value
@ivar mtHard: How texture maps to hardness
@ivar mtRayMir: How texture maps to RayMir value
@ivar mtTranslu: How texture maps to translucency
@ivar mtAmb: How texture maps to ambient value
@ivar mtDisp: How texture maps to displacement
@ivar mtWarp: How texture maps to warp
"""
def getIpo():