Page Menu
Home
Search
Configure Global Search
Log In
Files
F2643
stage5-patch-MTex.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:05 PM
Size
19 KB
Subscribers
None
stage5-patch-MTex.txt
View Options
Index: source/blender/python/api2_2x/Material.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Material.c,v
retrieving revision 1.33
diff -u -r1.33 Material.c
--- source/blender/python/api2_2x/Material.c 27 May 2005 05:39:40 -0000 1.33
+++ source/blender/python/api2_2x/Material.c 11 Jul 2005 22:49:34 -0000
@@ -1181,29 +1181,27 @@
static PyObject *Material_getTextures( BPy_Material * self )
{
int i;
- struct MTex *mtex;
- PyObject *t[MAX_MTEX];
- PyObject *tuple;
+ struct MTex **mtex = self->material->mtex;
+ PyObject *tuple = PyTuple_New (MAX_MTEX);
+
+ /* check for creation error */
+ if( !tuple )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "Material_getTextures: couldn't create PyTuple" );
/* build a texture list */
- for( i = 0; i < MAX_MTEX; ++i ) {
- mtex = self->material->mtex[i];
+ for( i = 0; i < MAX_MTEX; ++i, ++mtex ) {
+ PyObject *obj;
- if( mtex ) {
- t[i] = MTex_CreatePyObject( mtex );
+ if( *mtex ) {
+ obj = MTex_CreatePyObject( *mtex, self->material->ipo, i );
} else {
Py_INCREF( Py_None );
- t[i] = Py_None;
+ obj = Py_None;
}
+ PyTuple_SET_ITEM( tuple, i, obj );
}
- /* turn the array into a tuple */
- tuple = Py_BuildValue( "NNNNNNNN", t[0], t[1], t[2], t[3],
- t[4], t[5], t[6], t[7] );
- if( !tuple )
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "Material_getTextures: couldn't create PyTuple" );
-
return tuple;
}
@@ -2126,6 +2124,8 @@
else if( strcmp( name, "fresnelTransFac" ) == 0 )
attr = PyFloat_FromDouble( ( double ) self->material->
fresnel_tra_i );
+ else if( strcmp( name, "textures" ) == 0 )
+ attr = Material_getTextures( self );
else if( strcmp( name, "users" ) == 0 )
attr = PyInt_FromLong( ( double ) self->material->
id.us );
Index: source/blender/python/api2_2x/MTex.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/MTex.c,v
retrieving revision 1.5
diff -u -r1.5 MTex.c
--- source/blender/python/api2_2x/MTex.c 7 Oct 2004 19:25:39 -0000 1.5
+++ source/blender/python/api2_2x/MTex.c 11 Jul 2005 22:49:34 -0000
@@ -37,13 +37,14 @@
#include <BLI_blenlib.h>
#include <BKE_texture.h>
#include <BKE_utildefines.h>
+#include <BSE_editipo.h>
#include "MTex.h"
#include "Texture.h"
+#include "Ipocurve.h"
#include "constant.h"
#include "gen_utils.h"
-
/*****************************************************************************/
/* Python BPy_MTex methods declarations: */
/*****************************************************************************/
@@ -74,7 +75,7 @@
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 );
-
+static PyObject *MTex_getIpo ( BPy_MTex * self );
/*****************************************************************************/
/* Python MTex_Type structure definition: */
@@ -115,7 +116,7 @@
return submodule;
}
-PyObject *MTex_CreatePyObject( MTex * mtex )
+PyObject *MTex_CreatePyObject( MTex * mtex, Ipo * ipo, int channel )
{
BPy_MTex *pymtex;
@@ -125,6 +126,15 @@
"couldn't create BPy_MTex PyObject" );
pymtex->mtex = mtex;
+
+ /*
+ * store the Ipo this tex channel belong to, and convert the
+ * channel number to its MA_MAP value (see <DNA_ipo_types.h>)
+ */
+
+ pymtex->ipo = ipo;
+ pymtex->map = texchannel_to_adrcode(channel);
+
return ( PyObject * ) pymtex;
}
@@ -133,7 +143,6 @@
return ( ( BPy_MTex * ) pyobj )->mtex;
}
-
int MTex_CheckPyObject( PyObject * pyobj )
{
return ( pyobj->ob_type == &MTex_Type );
@@ -178,6 +187,8 @@
return PyInt_FromLong( self->mtex->texco );
else if( STREQ( name, "mapto" ) )
return PyInt_FromLong( self->mtex->mapto );
+ else if( STREQ( name, "ipo" ) )
+ return MTex_getIpo ( self );
else if( STREQ( name, "__members__" ) )
return Py_BuildValue( "[s,s,s]", "tex", "texco", "mapto" );
@@ -186,6 +197,43 @@
return Py_FindMethod( BPy_MTex_methods, ( PyObject * ) self, name );
}
+/*
+ * build a dictionary of the texture channel curves which correspond to
+ * this MTex.
+ */
+
+static
+PyObject * MTex_getIpo ( BPy_MTex * self )
+{
+#if 0
+ IpoCurve *icu;
+ PyObject * dict = PyDict_New();
+
+ /* double-check allocation */
+
+ if (!dict )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "MTex_getIpos: couldn't create PyDict" );
+
+ /*
+ * find curve in the IPO with matching tex channels
+ */
+
+ for ( icu = self->ipo->curve.first; icu ; icu = icu->next ) {
+ if ( icu->adrcode & self->map ) {
+ PyObject *obj = IpoCurve_CreatePyObject( icu, self->ipo );
+ PyDict_SetItemString( dict, getIpoCurveName( icu ), obj );
+ Py_DECREF ( obj );
+ }
+ }
+ return dict;
+#else
+ extern PyObject *Ipo_CreatePyObjectChannel ( Ipo * ipo, int channel );
+
+ return Ipo_CreatePyObjectChannel( self->ipo, self->map );
+#endif
+}
+
static int MTex_setAttr( BPy_MTex * self, char *name, PyObject * value )
{
PyObject *valtuple;
@@ -216,6 +264,10 @@
Py_INCREF( Py_None ); /* because we decref it below */
error = Py_None;
}
+ }
+ else if( STREQ( name, "ipo" ) ) {
+ return EXPP_ReturnIntError( PyExc_KeyError,
+ "attribute \"ipo\" is read-only" );
}
else {
Index: source/blender/python/api2_2x/MTex.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/MTex.h,v
retrieving revision 1.2
diff -u -r1.2 MTex.h
--- source/blender/python/api2_2x/MTex.h 25 Sep 2004 20:30:39 -0000 1.2
+++ source/blender/python/api2_2x/MTex.h 11 Jul 2005 22:49:34 -0000
@@ -34,8 +34,8 @@
#define EXPP_MTEX_H
#include <Python.h>
-
#include <DNA_texture_types.h>
+#include <DNA_ipo_types.h>
/*****************************************************************************/
@@ -44,6 +44,8 @@
typedef struct {
PyObject_HEAD MTex * mtex;
+ int map; /* texture channel MA_MAP value */
+ Ipo * ipo; /* pointer to IPO of this channel */
} BPy_MTex;
extern PyTypeObject MTex_Type;
@@ -56,7 +58,7 @@
/*****************************************************************************/
PyObject *MTex_Init( void );
-PyObject *MTex_CreatePyObject( struct MTex *obj );
+PyObject *MTex_CreatePyObject( MTex * mtex, Ipo * ipo, int channel );
int MTex_CheckPyObject( PyObject * py_obj );
MTex *MTex_FromPyObject( PyObject * py_obj );
Index: source/blender/python/api2_2x/Lamp.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Lamp.c,v
retrieving revision 1.33
diff -u -r1.33 Lamp.c
--- source/blender/python/api2_2x/Lamp.c 10 Jun 2005 12:33:09 -0000 1.33
+++ source/blender/python/api2_2x/Lamp.c 11 Jul 2005 22:49:34 -0000
@@ -42,6 +42,7 @@
#include <BSE_editipo.h>
#include <mydevice.h>
+#include "MTex.h"
#include "Lamp.h"
#include "Ipo.h"
@@ -217,6 +218,7 @@
static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * args );
static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args );
static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args );
+static PyObject *Lamp_getTextures( BPy_Lamp * self );
/*****************************************************************************/
/* Python BPy_Lamp methods table: */
@@ -1329,7 +1331,9 @@
attr = PyFloat_FromDouble( self->lamp->att2 );
else if( strcmp( name, "users" ) == 0 )
attr = PyInt_FromLong( self->lamp->id.us );
-
+ else if( strcmp( name, "textures" ) == 0 )
+ attr = Lamp_getTextures( self );
+
else if( strcmp( name, "Types" ) == 0 ) {
attr = Py_BuildValue( "{s:h,s:h,s:h,s:h,s:h,s:h}",
"Lamp", EXPP_LAMP_TYPE_LAMP,
@@ -1593,4 +1597,31 @@
EXPP_allqueue(REDRAWNLA, 0);
return EXPP_incr_ret( Py_None );
+}
+
+static PyObject *Lamp_getTextures( BPy_Lamp * self )
+{
+ int i;
+ struct MTex **mtex = self->lamp->mtex;
+ PyObject *tuple = PyTuple_New (MAX_MTEX);
+
+ /* check for creation error */
+ if( !tuple )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "Lamp_getTextures: couldn't create PyTuple" );
+
+ /* build a texture list */
+ for( i = 0; i < MAX_MTEX; ++i, ++mtex ) {
+ PyObject *obj;
+
+ if( *mtex ) {
+ obj = MTex_CreatePyObject( *mtex, self->lamp->ipo, i );
+ } else {
+ Py_INCREF( Py_None );
+ obj = Py_None;
+ }
+ PyTuple_SET_ITEM( tuple, i, obj );
+ }
+
+ return tuple;
}
Index: source/blender/python/api2_2x/World.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/World.c,v
retrieving revision 1.30
diff -u -r1.30 World.c
--- source/blender/python/api2_2x/World.c 17 Jun 2005 05:10:14 -0000 1.30
+++ source/blender/python/api2_2x/World.c 11 Jul 2005 22:49:34 -0000
@@ -54,10 +54,10 @@
#include <DNA_scene_types.h> /* for G.scene */
+#include "MTex.h"
#include "World.h"
#include "Ipo.h"
-
#include "constant.h"
#include "rgbTuple.h"
#include "gen_utils.h"
@@ -99,7 +99,7 @@
static PyObject *World_addScriptLink( BPy_World * self, PyObject * args );
static PyObject *World_clearScriptLinks( BPy_World * self, PyObject * args );
static PyObject *World_setCurrent( BPy_World * self );
-
+static PyObject *World_getTextures( BPy_World * self );
/*****************************************************************************/
/* Python API function prototypes for the World module. */
@@ -945,6 +945,8 @@
return World_getMist( self );
if( strcmp( name, "users" ) == 0 )
return PyInt_FromLong( self->world->id.us );
+ if( strcmp( name, "textures" ) == 0 )
+ return World_getTextures( self );
return Py_FindMethod( BPy_World_methods, ( PyObject * ) self, name );
}
@@ -1157,4 +1159,31 @@
EXPP_allqueue(REDRAWNLA, 0);
return EXPP_incr_ret( Py_None );
+}
+
+static PyObject *World_getTextures( BPy_World * self )
+{
+ int i;
+ struct MTex **mtex = self->world->mtex;
+ PyObject *tuple = PyTuple_New (MAX_MTEX);
+
+ /* check for creation error */
+ if( !tuple )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "World_getTextures: couldn't create PyTuple" );
+
+ /* build a texture list */
+ for( i = 0; i < MAX_MTEX; ++i, ++mtex ) {
+ PyObject *obj;
+
+ if( *mtex ) {
+ obj = MTex_CreatePyObject( *mtex, self->world->ipo, i );
+ } else {
+ Py_INCREF( Py_None );
+ obj = Py_None;
+ }
+ PyTuple_SET_ITEM( tuple, i, obj );
+ }
+
+ return tuple;
}
--- source/blender/python/api2_2x/Ipo.c 2005-07-11 09:33:51.000000000 -0700
+++ source/blender/python/api2_2x/Ipo.c 2005-07-11 12:44:05.000000000 -0700
@@ -51,6 +51,24 @@
#include "Types.h"
#include "gen_utils.h"
+#define TEXCHANNELS
+
+/*
+ * check for a curve match, including in texture channels
+ */
+
+#ifdef TEXCHANNELS
+#define CURVEMATCH(self,adrcode,param) \
+ ( ( !self->channel && adrcode == param ) || \
+ ( self->channel && ( self->channel | ( param & (MA_MAP1-1) ) ) == adrcode ) )
+
+#define CURVETYPE(self,adrcode) \
+ ( self->ipo->blocktype==ID_KE || \
+ (!self->channel && adrcode < MA_MAP1) || \
+ (self->channel & adrcode) )
+
+#endif
+
/*****************************************************************************/
/* Python API function prototypes for the Ipo module. */
/*****************************************************************************/
@@ -609,7 +627,7 @@
*/
#if BLENDER_VERSION < 241
-static PyObject *Ipo_oldAppend( Ipo * ipo, char *cur_name );
+static int Ipo_oldAppend( int block, char *cur_name, int *param );
#endif
static PyObject *Ipo_append( BPy_Ipo * self, PyObject * args )
@@ -656,8 +674,22 @@
"Ipo not found" );
#if BLENDER_VERSION < 241
- if ( cur_name ) /* if passed a string, handle the old way */
- return Ipo_oldAppend( ipo, cur_name );
+ /*
+ * if a string argument, search for its adrcode
+ */
+
+ if ( cur_name && !Ipo_oldAppend( ipo->blocktype, cur_name, ¶m ) )
+ return EXPP_ReturnPyObjError
+ ( PyExc_NameError, "curve name was invalid" );
+#endif
+
+#ifdef TEXCHANNELS
+ /*
+ * if tex channel, set parameter for the actual channel
+ */
+
+ if ( self->channel )
+ param = (param & (MA_MAP1-1)) | self->channel;
#endif
/*
@@ -666,7 +698,12 @@
icu= ipo->curve.first;
while (icu) {
- if( icu->adrcode == param ) {
+#ifdef TEXCHANNELS
+ if ( CURVEMATCH (self, icu->adrcode, param) )
+#else
+ if ( icu->adrcode == param )
+#endif
+ {
#if BLENDER_VERSION < 241
if ( depcount ) {
printf ( "Calling Ipo.append() with an existing curve is deprecated;\n");
@@ -705,6 +742,7 @@
if (!list)
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create PyList object" );
+
/*
* if IpoCurve_CreatePyObject returns NULL, it already threw an
* exception and things are messed up, so just give up
@@ -718,9 +756,8 @@
* but curve not in the correct channel, skip
*/
- if ( ( !self->channel && icu->adrcode >= MA_MAP1 ) ||
- !(self->channel & icu->adrcode) )
- continue;
+ if ( !CURVETYPE( self, icu->adrcode ) )
+ continue;
#endif
obj = IpoCurve_CreatePyObject( icu );
if (!obj) {
@@ -744,7 +781,10 @@
IpoCurve *icu;
for ( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- ++length;
+#ifdef TEXCHANNELS
+ if ( CURVETYPE( self, icu->adrcode ) )
+#endif
+ ++length;
}
return length;
}
@@ -760,7 +800,6 @@
{
IpoCurve *icu = NULL;
int param = 0; /* numeric curve name constant */
- int mask = MA_MAP1-1; /* used to figure out range for adr_code */
#if BLENDER_VERSION < 241
char *str = NULL;
@@ -805,30 +844,18 @@
#endif
/*
- * since largest curve for Keys is larger than MA_MAP1,
- * adjust the mask if this is a Key IPO
- */
-
- if ( self->ipo->blocktype == ID_KE )
- mask = 127;
-
- /*
- * look through the curve list for a matching adrcode
+ * look through the curve list for a matching adrcode. If not a
+ * texchannel, then look for an exact match; otherwise, look for
+ * a channel match and parameter match
*/
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- if ( ( icu->adrcode & mask ) == param ) {
#ifdef TEXCHANNELS
- if ( icu->adrcode <= mask ) { /* not texture channel */
- if ( !self->channel ) /* no channel specified */
- return IpoCurve_CreatePyObject( icu );
- else
- return ( EXPP_ReturnPyObjError
- ( PyExc_ValueError, "texture channel value specified for non-texchannel curve" ) );
- } else if ( self->channel & icu->adrcode ) /* texture channel matches */
+ if ( CURVEMATCH (self, icu->adrcode, param) )
+#else
+ if ( icu->adrcode == param )
#endif
- return IpoCurve_CreatePyObject( icu );
- }
+ return IpoCurve_CreatePyObject( icu );
}
return EXPP_incr_ret ( Py_None );
}
@@ -843,7 +870,6 @@
{
IpoCurve *icu;
int param = 0;
- int mask = MA_MAP1-1; /* used to figure out range for adr_code */
#if BLENDER_VERSION < 241
static int depcount=2;
@@ -897,30 +923,16 @@
"cannot set IPO curves" );
/*
- * since largest curve for Keys is larger than MA_MAP1,
- * adjust the mask if this is a Key IPO
- */
-
- if ( self->ipo->blocktype == ID_KE )
- mask = 127;
-
- /*
* search curve list for a match
*/
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
- if ( ( icu->adrcode & mask ) == param ) {
#ifdef TEXCHANNELS
- if ( icu->adrcode <= mask ) { /* not texture channel */
- if ( !self->channel ) /* no channel specified */
- break;
- else
- return EXPP_ReturnIntError ( PyExc_ValueError,
- "texture channel value specified for non-texchannel curve" );
- } else if ( self->channel & icu->adrcode ) /* texture channel matches */
+ if ( CURVEMATCH (self, icu->adrcode, param) )
+#else
+ if ( icu->adrcode == param )
#endif
- break;
- }
+ break;
}
/*
@@ -1095,13 +1107,17 @@
int minadr = 0x7fffffff;
/*
- * search for the next largest (relative to current iterator) adrcode
+ * look for the next largest curve (based on adrcode)
*/
for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
if ( icu->adrcode < minadr && icu->adrcode > self->iter ) {
- minadr = icu->adrcode;
- ptr = icu;
+#ifdef TEXCHANNELS
+ if ( !CURVETYPE( self, icu->adrcode ) )
+ continue;
+#endif
+ minadr = icu->adrcode;
+ ptr = icu;
}
}
@@ -2201,98 +2217,50 @@
return ok;
}
-static PyObject *Ipo_oldAppend( Ipo * ipo, char *cur_name )
+static int Ipo_oldAppend( int blocktype, char *cur_name, int *param)
{
- int param = 0; /* numeric curve name constant */
- int ok = 0;
- IpoCurve *icu = 0;
static int depcount=2;
- static int depcount2=2;
+
+ if ( depcount ) {
+ printf ("Calling Ipo.append() with a string argument is deprecated by module constants.\n");
+ printf (" This will throw an exception after version 2.40.\n");
+ --depcount;
+ }
/*
depending on the block type,
check if the input arg curve name is valid
and set param to numeric value.
*/
- if ( depcount2 ) {
- printf ("Calling Ipo.append() with a string argument is deprecated by module constants.\n");
- printf (" This will throw an exception after version 2.40.\n");
- --depcount2;
- }
- switch ( ipo->blocktype ) {
+ switch ( blocktype ) {
case ID_OB:
- ok = Ipo_obIcuName( cur_name, ¶m );
- break;
+ return Ipo_obIcuName( cur_name, param );
case ID_CA:
- ok = Ipo_caIcuName( cur_name, ¶m );
- break;
+ return Ipo_caIcuName( cur_name, param );
case ID_LA:
- ok = Ipo_laIcuName( cur_name, ¶m );
- break;
+ return Ipo_laIcuName( cur_name, param );
case ID_TE:
- ok = Ipo_texIcuName( cur_name, ¶m );
- break;
+ return Ipo_texIcuName( cur_name, param );
case ID_WO:
- ok = Ipo_woIcuName( cur_name, ¶m );
- break;
+ return Ipo_woIcuName( cur_name, param );
case ID_MA:
- ok = Ipo_maIcuName( cur_name, ¶m );
- break;
+ return Ipo_maIcuName( cur_name, param );
case ID_AC:
- ok = Ipo_acIcuName( cur_name, ¶m );
- break;
+ return Ipo_acIcuName( cur_name, param );
case IPO_CO:
- ok = Ipo_coIcuName( cur_name, ¶m );
- break;
+ return Ipo_coIcuName( cur_name, param );
case ID_CU:
- ok = Ipo_cuIcuName( cur_name, ¶m );
- break;
+ return Ipo_cuIcuName( cur_name, param );
case ID_KE:
- ok = Ipo_keIcuName( cur_name, ¶m );
- break;
+ return Ipo_keIcuName( cur_name, param );
case ID_SEQ:
- ok = Ipo_seqIcuName( cur_name, ¶m );
- break;
+ return Ipo_seqIcuName( cur_name, param );
default:
- ok = 0;
- }
-
- if( !ok ) /* curve type was invalid */
- return EXPP_ReturnPyObjError
- ( PyExc_NameError, "curve name was invalid" );
-
- /*
- * see if the curve already exists
- */
-
- icu= ipo->curve.first;
- while (icu) {
- if( icu->adrcode == param ) {
- if ( depcount ) {
- printf ( "Calling Ipo.append() with an existing curve is deprecated;\n");
- printf ( " this will throw a ValueError exception after V2.40.\n" );
- --depcount;
- }
- }
- icu= icu->next;
+ return 0;
}
-
- /* ask blender to create the new ipo curve */
- icu = get_ipocurve( NULL, ipo->blocktype, param, ipo );
-
- if( !icu ) /* could not create curve */
- return EXPP_ReturnPyObjError ( PyExc_RuntimeError,
- "blender could not create ipo curve" );
-
- allspace( REMAKEIPO, 0 );
- EXPP_allqueue( REDRAWIPO, 0 );
-
- /* create a bpy wrapper for the new ipo curve */
- return IpoCurve_CreatePyObject( icu );
}
#endif
-
#endif
--- source/blender/python/api2_2x/Ipo.h 2005-07-05 23:39:07.000000000 -0700
+++ source/blender/python/api2_2x/Ipo.h 2005-07-11 16:20:32.000000000 -0700
@@ -48,6 +48,7 @@
#else
int iter; /* pointer used by iterator */
#endif
+ int channel; /* texture channel */
} BPy_Ipo;
extern PyTypeObject Ipo_Type;
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
87/2a/6b7aebc4eace49124974fc461c7a
Event Timeline
Log In to Comment