Page MenuHome

patch-texchannel-v0.1.txt

Authored By
Ken Hughes (khughes)
Nov 13 2013, 1:03 PM
Size
11 KB
Subscribers
None

patch-texchannel-v0.1.txt

Index: blender/source/blender/python/api2_2x/Ipo.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipo.c,v
retrieving revision 1.40
diff -u -u -r1.40 Ipo.c
--- blender/source/blender/python/api2_2x/Ipo.c 24 May 2005 15:14:32 -0000 1.40
+++ blender/source/blender/python/api2_2x/Ipo.c 1 Jun 2005 05:22:11 -0000
@@ -158,6 +158,7 @@
static int IpoSetAttr( BPy_Ipo * self, char *name, PyObject * v );
static PyObject *IpoGetAttr( BPy_Ipo * self, char *name );
static PyObject *IpoRepr( BPy_Ipo * self );
+static PyObject *generate_ModuleIntConstant(char *name, int value);
/*****************************************************************************/
/* Python Ipo_Type structure definition: */
@@ -185,6 +186,7 @@
0, /* tp_members */
};
+
/*****************************************************************************/
/* Function: M_Ipo_New */
/* Python equivalent: Blender.Ipo.New */
@@ -339,6 +341,37 @@
}
+extern char* ma_ic_names[];
+extern char* mtex_ic_names[];
+extern int ma_ar[];
+
+static PyObject * IpoMa_Dict;
+
+static void Ipo_dictInit()
+{
+ int i, j, len;
+ char tmpname[128];
+
+ IpoMa_Dict = PyDict_New();
+ BLI_strncpy ( tmpname, "MatIpo_", sizeof(tmpname) );
+ len = strlen (tmpname);
+ for ( i = 0 ; i < MA_TOTNAM; ++i ) {
+ BLI_strncpy ( tmpname+len, ma_ic_names[i], sizeof(tmpname)-len);
+ for ( j = len; tmpname[j]; ++j )
+ tmpname[j] = toupper( tmpname[j] );
+ PyDict_SetItemString( IpoMa_Dict, tmpname+len,
+ generate_ModuleIntConstant(tmpname, ma_ar[i] ));
+ }
+ for ( i = 0 ; i < TEX_TOTNAM; ++i )
+ {
+ BLI_strncpy ( tmpname+len, mtex_ic_names[i], sizeof(tmpname)-len);
+ for ( j = len; tmpname[j]; ++j )
+ tmpname[j] = toupper( tmpname[j] );
+ PyDict_SetItemString( IpoMa_Dict, tmpname+len,
+ generate_ModuleIntConstant(tmpname, ma_ar[MA_TOTNAM+i] ));
+ }
+}
+
/*****************************************************************************/
/* Function: Ipo_Init */
/*****************************************************************************/
@@ -349,8 +382,9 @@
Ipo_Type.ob_type = &PyType_Type;
submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
+ Ipo_dictInit();
- return ( submodule );
+ return submodule;
}
/*****************************************************************************/
@@ -824,10 +858,9 @@
return ok;
}
-
/*
Function: Ipo_addCurve
- Bpy: Blender.Ipo.addCurve( 'curname')
+ Bpy: Blender.Ipo.addCurve( curname, texchannel=0)
add a new curve to an existing IPO.
example:
@@ -840,15 +873,19 @@
int param = 0; /* numeric curve name constant */
int ok = 0;
int ipofound = 0;
+ int texchannel = 0;
char *cur_name = 0; /* input arg: curve name */
Ipo *ipo = 0;
IpoCurve *icu = 0;
Link *link;
- if( !PyArg_ParseTuple( args, "s", &cur_name ) )
+ if( !PyArg_ParseTuple( args, "s|i", &cur_name, &texchannel ) )
return ( EXPP_ReturnPyObjError
( PyExc_TypeError, "expected string argument" ) );
+ if ( texchannel < 0 || texchannel > 9 )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_ValueError, "texture channel value must be in rrange 0 to 9" ) );
/* chase down the ipo list looking for ours */
link = G.main->ipo.first;
@@ -917,6 +954,12 @@
return EXPP_ReturnPyObjError
( PyExc_NameError, "curve name was invalid" );
+ /* if texture channel, set correct channel */
+ if ( param & MA_MAP1 ) {
+ param -= MA_MAP1;
+ param |= texchannel_to_adrcode(texchannel);
+ }
+
/* ask blender to create the new ipo curve */
icu = get_ipocurve( NULL, ipo->blocktype, param, self->ipo );
@@ -968,21 +1011,44 @@
( PyExc_RuntimeError, "IpoCurve not found" ) );
}
+/*
+ Function: Ipo_getCurve
+ Bpy: Blender.Ipo.delCurve(curtype, texchannel=0)
+ delete an existing curve from IPO.
+ example:
+ ipo = Blender.Ipo.New('Object','ObIpo')
+ cu = ipo.delCurve('LocX')
+*/
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
{
char *str, *str1;
IpoCurve *icu = 0;
+ int texchannel = 0;
+ int map = 0;
- if( !PyArg_ParseTuple( args, "s", &str ) )
+ if( !PyArg_ParseTuple( args, "s|i", &str, &texchannel ) )
return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ ( PyExc_TypeError, "expected string argument, or string and integer" ) );
+
+ if ( texchannel < 0 || texchannel > 9 )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_ValueError, "texture channel value must be in rrange 0 to 9" ) );
+ map = texchannel_to_adrcode ( texchannel );
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
str1 = getIpoCurveName( icu );
- if( !strcmp( str1, str ) )
- return IpoCurve_CreatePyObject( icu );
+ if( !strcmp( str1, str ) ) { /* names match */
+ if ( icu->adrcode < MA_MAP1 ) { /* not texture channel */
+ if ( texchannel == 0 ) /* no channel specified */
+ return IpoCurve_CreatePyObject( icu );
+ else
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_ValueError, "texture channel value specified for non-texchannel curve" ) );
+ } else if ( map & icu->adrcode ) /* texture channel matches */
+ return IpoCurve_CreatePyObject( icu );
+ }
}
Py_INCREF( Py_None );
@@ -1249,6 +1315,53 @@
return Py_None;
}
+static PyObject * Ipo_listCurveTypes ( int blocktype )
+{
+ PyObject *obj = NULL;
+ char tmpname[128];
+ int i, j;
+
+ switch ( blocktype ) {
+ case ID_MA:
+ obj = PyList_New( 0 );
+ if ( obj == NULL )
+ return NULL;
+ for ( i = 0 ; i < MA_TOTNAM; ++i ) {
+ strcpy (tmpname, ma_ic_names[i]);
+ for ( j = 0; tmpname[j]; ++j )
+ tmpname[j] = toupper( tmpname[j] );
+ if ( PyList_Append ( obj, Py_BuildValue("s", tmpname ) ) == -1 )
+ return NULL;
+ }
+ for ( i = 0 ; i < TEX_TOTNAM; ++i ) {
+ strcpy (tmpname, mtex_ic_names[i]);
+ for ( j = 0; tmpname[j]; ++j )
+ tmpname[j] = toupper( tmpname[j] );
+ if ( PyList_Append ( obj, Py_BuildValue("s", tmpname ) ) == -1 )
+ return NULL;
+ }
+ return obj;
+ default:
+ Py_INCREF( Py_None );
+ return Py_None;
+ }
+}
+
+static PyObject * Ipo_checkCurveTypes ( int blocktype, char * name )
+{
+ PyObject *obj = NULL;
+
+ switch ( blocktype ) {
+ case ID_MA:
+ obj = PyDict_GetItemString( IpoMa_Dict, name );
+ if ( obj != NULL )
+ Py_INCREF( obj );
+ return obj;
+ default:
+ break;
+ }
+ return NULL;
+}
/*****************************************************************************/
/* Function: IpoDeAlloc */
@@ -1268,8 +1381,24 @@
/*****************************************************************************/
static PyObject *IpoGetAttr( BPy_Ipo * self, char *name )
{
+ PyObject *obj;
+
if( strcmp( name, "curves" ) == 0 )
return Ipo_getCurves( self );
+
+ if ( strcmp( name, "__members__" ) == 0 ) {
+ obj = Ipo_listCurveTypes ( self->ipo->blocktype );
+ PyList_Insert( obj, 0, Py_BuildValue("s","curves") );
+ return obj;
+ }
+
+ if( strcmp( name, "types" ) == 0 )
+ return Ipo_listCurveTypes ( self->ipo->blocktype );
+
+ obj = Ipo_checkCurveTypes ( self->ipo->blocktype, name );
+ if ( obj != NULL )
+ return obj;
+
return Py_FindMethod( BPy_Ipo_methods, ( PyObject * ) self, name );
}
@@ -1331,3 +1460,17 @@
{
return ( ( BPy_Ipo * ) pyobj )->ipo;
}
+
+static PyObject *generate_ModuleIntConstant(char *name, int value)
+{
+ PyObject *constant = M_constant_New();
+
+ constant_insert((BPy_constant*)constant,
+ "value", PyInt_FromLong(value));
+ constant_insert((BPy_constant*)constant,
+ "name", PyString_FromString(name));
+
+ Py_INCREF(constant);
+ return constant;
+}
+
Index: blender/source/blender/python/api2_2x/Ipocurve.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipocurve.c,v
retrieving revision 1.24
diff -u -u -r1.24 Ipocurve.c
--- blender/source/blender/python/api2_2x/Ipocurve.c 24 May 2005 15:14:32 -0000 1.24
+++ blender/source/blender/python/api2_2x/Ipocurve.c 1 Jun 2005 05:22:11 -0000
@@ -89,6 +89,7 @@
static PyObject *IpoCurve_getPoints( C_IpoCurve * self );
static int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value );
static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args );
+static PyObject *IpoCurve_getTexChannel ( C_IpoCurve * self );
/*****************************************************************************/
/* Python C_IpoCurve methods table: */
@@ -119,6 +120,8 @@
"() - Returns list of all bezTriples of the curve"},
{"evaluate", ( PyCFunction ) IpoCurve_evaluate, METH_VARARGS,
"(float) - Evaluate curve at given time"},
+ {"getTexChannel", ( PyCFunction ) IpoCurve_getTexChannel, METH_NOARGS,
+ "() - Get IpoCurve texture channel info"},
{NULL, NULL, 0, NULL}
};
@@ -158,6 +161,8 @@
0, /* tp_members */
};
+static int IpoCurve_CurveType ( C_IpoCurve * self );
+
/*****************************************************************************/
/* Function: M_IpoCurve_New */
/* Python equivalent: Blender.IpoCurve.New */
@@ -179,7 +184,6 @@
submodule =
Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
M_IpoCurve_doc );
-
return ( submodule );
}
@@ -449,6 +453,64 @@
return PyString_FromString( "" );
}
+static int adrcode_to_texchannel ( int adrcode )
+{
+ if ( adrcode & MA_MAP1 ) return 0;
+ if ( adrcode & MA_MAP2 ) return 1;
+ if ( adrcode & MA_MAP3 ) return 2;
+ if ( adrcode & MA_MAP4 ) return 3;
+ if ( adrcode & MA_MAP5 ) return 4;
+ if ( adrcode & MA_MAP6 ) return 5;
+ if ( adrcode & MA_MAP7 ) return 6;
+ if ( adrcode & MA_MAP8 ) return 7;
+ if ( adrcode & MA_MAP9 ) return 8;
+ if ( adrcode & MA_MAP10 ) return 9;
+ return -1;
+}
+
+/*
+ Function: IpoCurve_getTexChannel
+ Bpy: Blender.Ipocurve.getTexChannel()
+
+ returns value of texture channel, or None is not a texture channel IPO
+ example:
+ ipo = Blender.Ipo.Get('MatIpo')
+ cu = ipo.getCurve('Col',6)
+ if cu != None: channel = cu.getTexChannel()
+*/
+
+static PyObject *IpoCurve_getTexChannel ( C_IpoCurve * self )
+{
+ switch ( self->ipocurve->blocktype ) {
+ case ID_OB:
+ case ID_TE:
+ case ID_CA:
+ case ID_AC:
+ case ID_CU:
+ case ID_KE:
+ case ID_SEQ:
+ case IPO_CO:
+ Py_INCREF( Py_None ); /* curves without texture channels */
+ return Py_None;
+ case ID_LA:
+ case ID_MA:
+ case ID_WO:
+ if ( self->ipocurve->adrcode >= MA_MAP1 ) {
+ int texchannel = adrcode_to_texchannel ( self->ipocurve->adrcode );
+ if ( texchannel != 0 ) /* if we get a valid value */
+ return PyInt_FromLong ( texchannel );
+ else
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "unknown texture channel value found" );
+ }
+ Py_INCREF( Py_None ); /* non-texchannel curve */
+ return Py_None;
+ default:
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "This function doesn't support this ipocurve type yet" );
+ }
+}
+
static void IpoCurveDeAlloc( C_IpoCurve * self )
{
PyObject_DEL( self );
@@ -505,6 +567,8 @@
return IpoCurve_getPoints( self );
if( strcmp( name, "name" ) == 0 )
return IpoCurve_getName( self );
+ if( strcmp( name, "texChannel" ) == 0 )
+ return IpoCurve_getTexChannel ( self );
return Py_FindMethod( C_IpoCurve_methods, ( PyObject * ) self, name );
}
@@ -548,7 +612,6 @@
if( !pyipo )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create C_IpoCurve object" );
-
pyipo->ipocurve = ipo;
return ( PyObject * ) pyipo;

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
19/41/983971e7eb95f13841c30ddf99a3

Event Timeline