Page Menu
Home
Search
Configure Global Search
Log In
Files
F2270
patch-dictionary-v0.1.txt
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Ken Hughes (khughes)
Nov 13 2013, 1:03 PM
Size
17 KB
Subscribers
None
patch-dictionary-v0.1.txt
View Options
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:30:23 -0000
@@ -1,5 +1,5 @@
/*
- * $Id: Ipo.c,v 1.40 2005/05/24 15:14:32 stiv Exp $
+ * $Id: Ipo.c,v 1.3 2005/06/01 05:30:11 khughes Exp $
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
@@ -47,6 +47,7 @@
#include "Ipocurve.h"
#include "constant.h"
+#include "Types.h"
#include "gen_utils.h"
/*****************************************************************************/
@@ -158,6 +159,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, char *doc);
/*****************************************************************************/
/* Python Ipo_Type structure definition: */
@@ -185,6 +187,7 @@
0, /* tp_members */
};
+
/*****************************************************************************/
/* Function: M_Ipo_New */
/* Python equivalent: Blender.Ipo.New */
@@ -339,6 +342,75 @@
}
+/* in source/blender/src/editipo.c: */
+extern char* ma_ic_names[];
+extern char* ob_ic_names[];
+extern char* mtex_ic_names[];
+
+/* in source/blender/blenkernel/intern/ipo.c: */
+extern int ma_ar[];
+extern int ob_ar[];
+
+/*
+ * Current set of dictionaries of curve types for IPOs.
+ * To save some space, these could be constructed on demand.
+ */
+
+static PyObject *IpoOb_Dict, *IpoMa_Dict;
+
+/*
+ * Build a curve dictionary based on the names and constants provided in
+ * other modules
+ */
+
+static PyObject *Ipo_buildCurveDict ( char *prefix, char *names[],
+ int codes[], unsigned int totnam)
+{
+ unsigned int i, j, len;
+ char tmpname[64];
+ PyObject *obj;
+
+ obj = PyDict_New();
+
+ /* start each constant name with a prefix string identifying IPO type */
+
+ BLI_strncpy ( tmpname, prefix , sizeof(tmpname) );
+ len = strlen (tmpname);
+
+ /*
+ * create a module constant for each string (convert to uppercase), and
+ * insert in the dictionary.
+ */
+
+ for ( i = 0 ; i < totnam; ++i ) {
+ BLI_strncpy ( tmpname+len, names[i], sizeof(tmpname)-len);
+ for ( j = len; tmpname[j]; ++j )
+ tmpname[j] = toupper( tmpname[j] );
+ PyDict_SetItemString( obj, tmpname+len,
+ generate_ModuleIntConstant ( tmpname, codes[i], "no doc" ) );
+ }
+ return obj;
+}
+
+static void Ipo_dictInit()
+{
+ PyObject *obj;
+
+ /* object dictionary */
+
+ IpoOb_Dict = Ipo_buildCurveDict ( "ObIpo_", ob_ic_names, ob_ar, OB_TOTIPO );
+
+ /*
+ * material dictionary; build material and texture channel dictionaries,
+ * then merge them
+ */
+
+ IpoMa_Dict = Ipo_buildCurveDict ( "MatIpo_", ma_ic_names, ma_ar, MA_TOTNAM );
+ obj = Ipo_buildCurveDict ( "MatIpo_", mtex_ic_names, ma_ar+MA_TOTNAM, TEX_TOTNAM );
+ PyDict_Merge( IpoMa_Dict, obj, 0);
+ Py_DECREF( obj );
+}
+
/*****************************************************************************/
/* Function: Ipo_Init */
/*****************************************************************************/
@@ -349,8 +421,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 +897,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 +912,33 @@
int param = 0; /* numeric curve name constant */
int ok = 0;
int ipofound = 0;
+ int texchannel = 0;
char *cur_name = 0; /* input arg: curve name */
+ int oldformat = 0;
+ BPy_constant *constant = NULL;
+
Ipo *ipo = 0;
IpoCurve *icu = 0;
Link *link;
- if( !PyArg_ParseTuple( args, "s", &cur_name ) )
- return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ if ( (PySequence_Size( args ) > 0)
+ && PyString_Check ( PySequence_Fast_GET_ITEM ( args , 0 ) ) ) {
+ static unsigned char depcount=2;
+ if( !PyArg_ParseTuple( args, "s|i", &cur_name, &texchannel ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string (and optional int) argument" ) );
+ if (depcount) {
+ printf ("Ipo.addCurve(): string arguments are deprecated; use module constants instead\n");
+ --depcount;
+ }
+ oldformat = 1;
+ } else if( !PyArg_ParseTuple( args, "O!|i", &constant_Type, &constant, &texchannel ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected module constant (and optional int) 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;
@@ -870,52 +960,62 @@
}
+ if ( oldformat ) {
/*
depending on the block type,
check if the input arg curve name is valid
and set param to numeric value.
*/
- switch ( ipo->blocktype ) {
- case ID_OB:
- ok = Ipo_obIcuName( cur_name, ¶m );
- break;
- case ID_CA:
- ok = Ipo_caIcuName( cur_name, ¶m );
- break;
- case ID_LA:
- ok = Ipo_laIcuName( cur_name, ¶m );
- break;
- case ID_TE:
- ok = Ipo_texIcuName( cur_name, ¶m );
- break;
- case ID_WO:
- ok = Ipo_woIcuName( cur_name, ¶m );
- break;
- case ID_MA:
- ok = Ipo_maIcuName( cur_name, ¶m );
- break;
- case ID_AC:
- ok = Ipo_acIcuName( cur_name, ¶m );
- break;
- case IPO_CO:
- ok = Ipo_coIcuName( cur_name, ¶m );
- break;
- case ID_CU:
- ok = Ipo_cuIcuName( cur_name, ¶m );
- break;
- case ID_KE:
- ok = Ipo_keIcuName( cur_name, ¶m );
- break;
- case ID_SEQ:
- ok = Ipo_seqIcuName( cur_name, ¶m );
- break;
- default:
- ok = 0;
+ switch ( ipo->blocktype ) {
+ case ID_OB:
+ ok = Ipo_obIcuName( cur_name, ¶m );
+ break;
+ case ID_CA:
+ ok = Ipo_caIcuName( cur_name, ¶m );
+ break;
+ case ID_LA:
+ ok = Ipo_laIcuName( cur_name, ¶m );
+ break;
+ case ID_TE:
+ ok = Ipo_texIcuName( cur_name, ¶m );
+ break;
+ case ID_WO:
+ ok = Ipo_woIcuName( cur_name, ¶m );
+ break;
+ case ID_MA:
+ ok = Ipo_maIcuName( cur_name, ¶m );
+ break;
+ case ID_AC:
+ ok = Ipo_acIcuName( cur_name, ¶m );
+ break;
+ case IPO_CO:
+ ok = Ipo_coIcuName( cur_name, ¶m );
+ break;
+ case ID_CU:
+ ok = Ipo_cuIcuName( cur_name, ¶m );
+ break;
+ case ID_KE:
+ ok = Ipo_keIcuName( cur_name, ¶m );
+ break;
+ case ID_SEQ:
+ ok = Ipo_seqIcuName( cur_name, ¶m );
+ break;
+ default:
+ ok = 0;
+ }
+
+ if( !ok ) /* curve type was invalid */
+ return EXPP_ReturnPyObjError
+ ( PyExc_NameError, "curve name was invalid" );
+ } else {
+ param = PyInt_AS_LONG(PyDict_GetItemString(constant->dict, "value"));
}
- if( !ok ) /* curve type was invalid */
- 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 );
@@ -958,7 +1058,10 @@
if( icu->bezt )
MEM_freeN( icu->bezt );
MEM_freeN( icu );
- del_ipoCurve( icu );
+
+ allspace( REMAKEIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
+
Py_INCREF( Py_None );
return Py_None;
}
@@ -968,21 +1071,62 @@
( 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;
+ int oldformat = 0;
+ BPy_constant *constant = NULL;
+ int param = 0;
+
+ if ( (PySequence_Size( args ) > 0)
+ && PyString_Check ( PySequence_Fast_GET_ITEM ( args , 0 ) ) ) {
+ static unsigned char depcount=2;
+ if( !PyArg_ParseTuple( args, "s|i", &str, &texchannel ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected string (and optional int) argument" ) );
+ if (depcount) {
+ printf ("Ipo.getCurve(): string arguments are deprecated; use module constants instead\n");
+ --depcount;
+ }
+ oldformat = 1;
+ } else if( !PyArg_ParseTuple( args, "O!|i", &constant_Type, &constant, &texchannel ) )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected module constant (and optional int) argument" ) );
+ else
+ param = PyInt_AS_LONG(PyDict_GetItemString(constant->dict, "value"));
- if( !PyArg_ParseTuple( args, "s", &str ) )
+ if ( texchannel < 0 || texchannel > 9 )
return ( EXPP_ReturnPyObjError
- ( PyExc_TypeError, "expected string argument" ) );
+ ( 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 ) {
+ if ( oldformat ) str1 = getIpoCurveName( icu );
str1 = getIpoCurveName( icu );
- if( !strcmp( str1, str ) )
- return IpoCurve_CreatePyObject( icu );
+ if ( ( oldformat && !strcmp( str1, str ) ) || /* found curve */
+ ( !oldformat && (icu->adrcode & (MA_MAP1-1)) == param ) ) {
+ 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 +1393,82 @@
return Py_None;
}
+/*
+ * Construct a list of curve types for a particular IPO. This is similar to
+ * the code in Ipo_buildCurveDict() except it puts things in a list. It
+ * might be more efficient to pull things of out the dictionary, but the
+ * items there are no longer in order ( :-( ). Depends if anyone cares.
+ */
+
+static PyObject * Ipo_listCurveTypes ( int blocktype )
+{
+ PyObject *obj = NULL;
+ char tmpname[64];
+ int i, j;
+
+ switch ( blocktype ) {
+ case ID_OB:
+ obj = PyList_New( 0 );
+ if ( obj == NULL )
+ return NULL;
+ for ( i = 0 ; i < OB_TOTNAM; ++i ) {
+ BLI_strncpy ( tmpname, ob_ic_names[i], sizeof(tmpname) );
+ for ( j = 0; tmpname[j]; ++j )
+ tmpname[j] = toupper( tmpname[j] );
+ if ( PyList_Append ( obj, Py_BuildValue("s", tmpname ) ) == -1 )
+ return NULL;
+ }
+ return obj;
+ case ID_MA:
+ obj = PyList_New( 0 );
+ if ( obj == NULL )
+ return NULL;
+ for ( i = 0 ; i < MA_TOTNAM; ++i ) {
+ BLI_strncpy ( tmpname, ma_ic_names[i], sizeof(tmpname) );
+ 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 ) {
+ BLI_strncpy ( tmpname, mtex_ic_names[i], sizeof(tmpname) );
+ 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;
+ }
+}
+
+/*
+ * search specific IPO dictionary for curve name. Return new reference
+ * to PyObject if successful, NULL otherwise.
+ */
+
+static PyObject * Ipo_checkCurveTypes ( int blocktype, char * name )
+{
+ PyObject *obj = NULL;
+
+ switch ( blocktype ) {
+ case ID_OB:
+ obj = PyDict_GetItemString( IpoOb_Dict, name );
+ if ( obj != NULL )
+ Py_INCREF( obj );
+ return obj;
+ 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 +1488,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 +1567,23 @@
{
return ( ( BPy_Ipo * ) pyobj )->ipo;
}
+
+/*
+ * helper to create module constant; this could be put into gen_utils.c
+ * or constant.c
+ */
+
+static PyObject *generate_ModuleIntConstant(char *name, int value, char *doc)
+{
+ PyObject *constant = M_constant_New();
+
+ constant_insert((BPy_constant*)constant, "value", PyInt_FromLong(value));
+ constant_insert((BPy_constant*)constant, "name", PyString_FromString(name));
+#if 0
+ constant_insert((BPy_constant*)constant, "__doc__", PyString_FromString(doc));
+#endif
+
+ 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:30:24 -0000
@@ -1,5 +1,5 @@
/*
- * $Id: Ipocurve.c,v 1.24 2005/05/24 15:14:32 stiv Exp $
+ * $Id: Ipocurve.c,v 1.1 2005/05/30 03:52:27 khughes Exp khughes $
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
@@ -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
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e5/f9/595e5cad70c86fbb9914c3c8a920
Event Timeline
Log In to Comment