Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorKen Hughes <khughes@pacific.edu>2008-08-19 02:39:55 +0400
committerKen Hughes <khughes@pacific.edu>2008-08-19 02:39:55 +0400
commitdeadd5ee011aed52138f8110369ca8848239d890 (patch)
treeac942aa8f29976f7c8bd289337a78d00be3f0e00 /source
parent17e42222306e8671fb8937594200d350abd127f4 (diff)
Python API
---------- Add Material.enabledTextures attribute; this allows users to enable and disable textures assigned to a material.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/api2_2x/Material.c92
-rw-r--r--source/blender/python/api2_2x/doc/Material.py19
2 files changed, 105 insertions, 6 deletions
diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c
index ccd24a437b5..20747a167e6 100644
--- a/source/blender/python/api2_2x/Material.c
+++ b/source/blender/python/api2_2x/Material.c
@@ -554,6 +554,7 @@ static int Material_setSssTexScatter( BPy_Material * self, PyObject * value );
static int Material_setSssFront( BPy_Material * self, PyObject * value );
static int Material_setSssBack( BPy_Material * self, PyObject * value );
static int Material_setSssBack( BPy_Material * self, PyObject * value );
+static int Material_setTexChannel( BPy_Material * self, PyObject * value );
static PyObject *Material_getColorComponent( BPy_Material * self,
void * closure );
@@ -633,6 +634,7 @@ static PyObject *Material_getSssBack( BPy_Material * self );
static PyObject *Material_getFilter( BPy_Material * self );
static PyObject *Material_getTranslucency( BPy_Material * self );
static PyObject *Material_getTextures( BPy_Material * self );
+static PyObject *Material_getTexChannel( BPy_Material * self );
static PyObject *Material_clearIpo( BPy_Material * self );
static PyObject *Material_setTexture( BPy_Material * self, PyObject * args );
@@ -1140,7 +1142,11 @@ static PyGetSetDef BPy_Material_getseters[] = {
NULL},
{"lightGroup",
(getter)Material_getLightGroup, (setter)Material_setLightGroup,
- "Set the light group for this material",
+ "The light group for this material",
+ NULL},
+ {"enabledTextures",
+ (getter)Material_getTexChannel, (setter)Material_setTexChannel,
+ "Enabled texture channels for this material",
NULL},
{"R",
(getter)Material_getColorComponent, (setter)Material_setColorComponent,
@@ -1517,6 +1523,36 @@ static PyObject *Material_getLightGroup( BPy_Material * self )
return Group_CreatePyObject( self->material->group );
}
+static PyObject *Material_getTexChannel( BPy_Material * self )
+{
+ int i;
+ short mask = 1;
+ PyObject *list = PyList_New(0);
+ if( !list )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "PyList_New() failed" );
+
+ for( i = 0, mask = 1; i < MAX_MTEX ; ++i, mask <<= 1 ) {
+ if( self->material->mtex[i] && (mask & self->material->septex) == 0 ) {
+ PyObject * val = PyInt_FromLong(i);
+ if( !val ) {
+ Py_DECREF( list );
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "PyInt_FromLong() failed" );
+ }
+ if( PyList_Append( list, val ) < 0 ) {
+ Py_DECREF( val );
+ Py_DECREF( list );
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "PyList_Append() failed" );
+ }
+ Py_DECREF( val );
+ }
+ }
+
+ return list;
+}
+
static PyObject *Material_getHaloSize( BPy_Material * self )
{
return PyFloat_FromDouble( ( double ) self->material->hasize );
@@ -1982,6 +2018,57 @@ static int Material_setLightGroup( BPy_Material * self, PyObject * value )
return GenericLib_assignData(value, (void **) &self->material->group, NULL, 1, ID_GR, 0);
}
+static int Material_setTexChannel( BPy_Material * self, PyObject * value )
+{
+ int i, mask;
+ short septex = 0;
+ int result = 1;
+
+ /* fail if input is not a standard sequence */
+ if( !PyList_Check( value ) && !PyTuple_Check( value ) )
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected tuple or list of integers" );
+
+ /* get a fast sequence; in Python 2.5, this just return the original
+ * list or tuple and INCREFs it, so we must DECREF */
+ value = PySequence_Fast( value, "" );
+
+ /* set the disable bit for each existing texture */
+ for( i= 0, mask= 1; i < MAX_MTEX; ++i, mask <<= 1 )
+ if( self->material->mtex[i] != NULL )
+ septex |= mask;
+
+ /* check the list, and build new septex value */
+ for( i= PySequence_Size(value)-1; i >= 0; --i ) {
+ long ival;
+ PyObject *item = PySequence_Fast_GET_ITEM( value, i );
+ if( !PyInt_Check( item ) ) {
+ PyErr_SetString ( PyExc_TypeError,
+ "expected tuple or list of integers" );
+ goto exit;
+ }
+ ival= PyInt_AsLong( item );
+ if(ival < 0 || ival > MAX_MTEX) {
+ PyErr_SetString( PyExc_ValueError,
+ "channel value out of range" );
+ goto exit;
+ }
+ ival&= (1<<MAX_MTEX)-1;
+ if( self->material->mtex[(int)ival] == NULL ) {
+ PyErr_SetString( PyExc_ValueError,
+ "channels must have a texture assigned" );
+ goto exit;
+ }
+ septex&= ~(1<<ival);
+ }
+ self->material->septex= septex;
+ result = 0;
+
+exit:
+ Py_DECREF(value);
+ return result;
+}
+
static int Material_setAdd( BPy_Material * self, PyObject * value )
{
return EXPP_setFloatClamped ( value, &self->material->add,
@@ -2313,9 +2400,6 @@ static int Material_setSssBack( BPy_Material * self, PyObject * value )
EXPP_MAT_SSS_BACK_MAX);
}
-
-
-
static PyObject *Material_setTexture( BPy_Material * self, PyObject * args )
{
int texnum;
diff --git a/source/blender/python/api2_2x/doc/Material.py b/source/blender/python/api2_2x/doc/Material.py
index a3496164cd1..02f7edd77f5 100644
--- a/source/blender/python/api2_2x/doc/Material.py
+++ b/source/blender/python/api2_2x/doc/Material.py
@@ -323,6 +323,21 @@ class Material:
each color a list of 5 floats [0 - 1], [r,g,b,a,pos].
The colorband can have between 1 and 31 colors.
@type colorbandSpecular: list
+ @type enabledTextures: list of integers
+ @ivar enabledTextures: The texture channels enabled in this material.
+ The attribute returns is list of integers in the range [0, 9], each
+ number representing the respective enabled MTex entry (see
+ L{getTextures()<getTextures>}). Enabling is done by assigning
+ a list of ints or an empty list. Attempting to enable a channel
+ which does not have a texture assigned to it will result in a
+ ValueError exception.
+ Example::
+ mat.enabledTextures = [] # no texture channels are enabled
+ mat.enabledTextures = [0, 6] # texture channels 0 and 6 are enabled
+ ch = mat.enabledTextures
+ ch.append(4)
+ mat.enabledTextures = ch
+ print mat.enabledTextures # will print: [0, 4, 6]
@ivar enableSSS: If True, subsurface scattering will be rendered on this material.
@type enableSSS: bool
@@ -1010,7 +1025,7 @@ class Material:
def setTexture(index, texture, texco, mapto):
"""
- Assign a Blender Texture object to slot number 'number'.
+ Assign a Blender Texture object to channel number 'number'.
@type index: int
@param index: material's texture index in [0, 9].
@type texture: Blender Texture
@@ -1033,7 +1048,7 @@ class Material:
Get this Material's Texture list.
@rtype: list of MTex
@return: a list of Blender MTex objects. None is returned for each empty
- texture slot.
+ texture channel.
"""
def getScriptLinks (event):