[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11034] branches/pyapi_devel/source/ blender/python/api2_2x: made the list subtype material_list into a generic list subtupe to be used for small lists such as materials , textures, scriptlinks, colorbands and renderlayers.

Campbell Barton cbarton at metavr.com
Sun Jun 24 03:58:59 CEST 2007


Revision: 11034
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11034
Author:   campbellbarton
Date:     2007-06-24 03:58:51 +0200 (Sun, 24 Jun 2007)

Log Message:
-----------
made the list subtype material_list into a generic list subtupe to be used for small lists such as materials, textures, scriptlinks, colorbands and renderlayers.
currently works for materials and scriptlinks.

scriptlinks are a list of tuples [(Text, Event)...]

removed previous implimentation of scriptlink sequence.

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
    branches/pyapi_devel/source/blender/python/api2_2x/Camera.c
    branches/pyapi_devel/source/blender/python/api2_2x/Curve.c
    branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
    branches/pyapi_devel/source/blender/python/api2_2x/Material.c
    branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
    branches/pyapi_devel/source/blender/python/api2_2x/Metaball.c
    branches/pyapi_devel/source/blender/python/api2_2x/Object.c
    branches/pyapi_devel/source/blender/python/api2_2x/Scene.c
    branches/pyapi_devel/source/blender/python/api2_2x/Text3d.c
    branches/pyapi_devel/source/blender/python/api2_2x/Texture.c
    branches/pyapi_devel/source/blender/python/api2_2x/World.c
    branches/pyapi_devel/source/blender/python/api2_2x/gen_library.c
    branches/pyapi_devel/source/blender/python/api2_2x/gen_library.h

Added Paths:
-----------
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_list.c
    branches/pyapi_devel/source/blender/python/api2_2x/bpy_list.h

Removed Paths:
-------------
    branches/pyapi_devel/source/blender/python/api2_2x/material_list.c
    branches/pyapi_devel/source/blender/python/api2_2x/material_list.h
    branches/pyapi_devel/source/blender/python/api2_2x/object_scriptlink.c
    branches/pyapi_devel/source/blender/python/api2_2x/object_scriptlink.h

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Blender.c	2007-06-23 21:12:14 UTC (rev 11033)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Blender.c	2007-06-24 01:58:51 UTC (rev 11034)
@@ -94,8 +94,7 @@
 #include "Window.h"
 #include "World.h"
 #include "Types.h"
-#include "object_scriptlink.h"
-#include "material_list.h"
+#include "bpy_list.h"
 #include "layer_set.h"
 
 /**********************************************************/
@@ -942,8 +941,6 @@
 	PyDict_SetItemString(dict, "link", Py_None);
 	EXPP_dict_set_item_str(dict, "event", PyString_FromString(""));
 	EXPP_dict_set_item_str(dict, "mode", smode);
-
-	ScriptLink_Init(); /*PyDict_SetItemString(dict, "Camera", Camera_Init());*/
 	
 	PyDict_SetItemString(dict, "Armature", Armature_Init());
 	PyDict_SetItemString(dict, "BezTriple", BezTriple_Init());
@@ -983,6 +980,6 @@
 	PyDict_SetItemString(dict, "Window", Window_Init());
 	PyDict_SetItemString(dict, "World", World_Init());
 	
-	MaterialList_Init();
+	BPyList_Init();
 	LayerSet_Init();
 }

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Camera.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Camera.c	2007-06-23 21:12:14 UTC (rev 11033)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Camera.c	2007-06-24 01:58:51 UTC (rev 11034)
@@ -44,6 +44,7 @@
 #include "gen_utils.h"
 #include "gen_library.h"
 #include "Ipo.h"
+#include "bpy_list.h"
 
 
 #define IPOKEY_LENS 0
@@ -540,4 +541,4 @@
 {
 	return PyString_FromFormat( "[Camera \"%s\"]",
 				    self->camera->id.name + 2 );
-}
\ No newline at end of file
+}

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Curve.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Curve.c	2007-06-23 21:12:14 UTC (rev 11033)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Curve.c	2007-06-24 01:58:51 UTC (rev 11034)
@@ -46,6 +46,7 @@
 #include "gen_utils.h"
 #include "gen_library.h"
 #include "mydevice.h"
+#include "bpy_list.h"
 
 
 /*****************************************************************************/

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c	2007-06-23 21:12:14 UTC (rev 11033)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c	2007-06-24 01:58:51 UTC (rev 11034)
@@ -45,6 +45,7 @@
 #include "constant.h"
 #include "gen_utils.h"
 #include "gen_library.h"
+#include "bpy_list.h"
 
 /*****************************************************************************/
 /* Python BPy_Lamp defaults:                                                 */

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Material.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Material.c	2007-06-23 21:12:14 UTC (rev 11033)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Material.c	2007-06-24 01:58:51 UTC (rev 11034)
@@ -55,7 +55,7 @@
 #include "gen_utils.h"
 #include "gen_library.h"
 #include "IDProp.h"
-
+#include "bpy_list.h"
 /* closure values for getColorComponent()/setColorComponent() */
 
 #define IPOKEY_RGB          0
@@ -294,14 +294,8 @@
 static PyObject *Material_getSssCol( BPy_Material * self );
 
 static PyObject *Material_getSssEnable( BPy_Material * self );
-static PyObject *Material_getTextures( BPy_Material * self );
 
-static PyObject *Material_setTexture( BPy_Material * self, PyObject * args );
-static PyObject *Material_clearTexture( BPy_Material * self, PyObject * args );
-
 static PyObject *Material_insertIpoKey( BPy_Material * self, PyObject * args );
-static PyObject *Material_getColorband( BPy_Material * self, void * type);
-int Material_setColorband( BPy_Material * self, PyObject * value, void * type);
 static PyObject *Material_copy( BPy_Material * self );
 
 static PyObject *getFloatAttr( BPy_Material *self, void *type );
@@ -315,11 +309,7 @@
 static PyMethodDef BPy_Material_methods[] = {
 	/* name, method, flags, doc */
 	{"insertIpoKey", ( PyCFunction ) Material_insertIpoKey, METH_VARARGS,
-	 "(Material Ipo Constant) - Insert IPO Key at current frame"},	 
-	{"setTexture", ( PyCFunction ) Material_setTexture, METH_VARARGS,
-	 "(n,tex,texco=0,mapto=0) - Set numbered texture to tex"},
-	{"clearTexture", ( PyCFunction ) Material_clearTexture, METH_VARARGS,
-	 "(n) - Remove texture from numbered slot"},
+	 "(Material Ipo Constant) - Insert IPO Key at current frame"},
 	{"__copy__", ( PyCFunction ) Material_copy, METH_NOARGS,
 	 "() - Return a copy of the material."},
 	{"copy", ( PyCFunction ) Material_copy, METH_NOARGS,
@@ -337,21 +327,21 @@
 	
 	/* custom types */
 	{"textures", /* TODO - set textures - was not in 2.44 though */
-	 (getter)Material_getTextures, (setter)NULL,
+	 (getter)BPyList_get, (setter)BPyList_set,
 	 "Back scattering weight",
-	 NULL},
+	 (void *)BPY_LIST_TYPE_TEXTURE},
 	{"ipo",
 	 (getter)Material_getIpo, (setter)Material_setIpo,
 	 "Material Ipo data",
 	 NULL},
 	{"colorbandDiffuse",
-	 (getter)Material_getColorband, (setter)Material_setColorband,
+	 (getter)BPyList_get, (setter)BPyList_set,
 	 "Set the light group for this material",
-	 (void *) 0},
+	 (void *) BPY_LIST_TYPE_COLORBAND},
 	{"colorbandSpecular",
-	 (getter)Material_getColorband, (setter)Material_setColorband,
+	 (getter)BPyList_get, (setter)BPyList_set,
 	 "Set the light group for this material",
-	 (void *) 1},
+	 (void *) BPY_LIST_TYPE_COLORBAND_SPEC},
 	{"enableSSS",
 	 (getter)Material_getSssEnable, (setter)Material_setSssEnable,
 	 "if true, SSS will be rendered for this material",
@@ -883,35 +873,6 @@
 	return EXPP_getBitfield( &self->material->sss_flag, MA_DIFF_SSS, 'h' );
 }
 
-static PyObject *Material_getTextures( BPy_Material * self )
-{
-	int i;
-	struct MTex *mtex;
-	PyObject *t[MAX_MTEX];
-	PyObject *tuple;
-
-	/* build a texture list */
-	for( i = 0; i < MAX_MTEX; ++i ) {
-		mtex = self->material->mtex[i];
-
-		if( mtex ) {
-			t[i] = MTex_CreatePyObject( mtex );
-		} else {
-			Py_INCREF( Py_None );
-			t[i] = Py_None;
-		}
-	}
-
-	/* turn the array into a tuple */
-	tuple = Py_BuildValue( "NNNNNNNNNN", t[0], t[1], t[2], t[3],
-			       t[4], t[5], t[6], t[7], t[8], t[9] );
-	if( !tuple )
-		return EXPP_ReturnPyObjError( PyExc_MemoryError,
-					      "Material_getTextures: couldn't create PyTuple" );
-
-	return tuple;
-}
-
 /*
  * this should accept a Py_None argument and just delete the Ipo link
  * (as Lamp_clearIpo() does)
@@ -1665,62 +1626,6 @@
 	return EXPP_setBitfield( value, &self->material->sss_flag, MA_DIFF_SSS, 'h' );
 }
 
-static PyObject *Material_setTexture( BPy_Material * self, PyObject * args )
-{
-	int texnum;
-	PyObject *pytex;
-	Tex *bltex;
-	int texco = TEXCO_ORCO, mapto = MAP_COL;
-
-	if( !PyArg_ParseTuple( args, "iO!|ii", &texnum, &Texture_Type, &pytex,
-			       &texco, &mapto ) )
-		return EXPP_ReturnPyObjError( PyExc_TypeError,
-					      "expected int in [0,9] and Texture" );
-	if( ( texnum < 0 ) || ( texnum >= MAX_MTEX ) )
-		return EXPP_ReturnPyObjError( PyExc_TypeError,
-					      "expected int in [0,9] and Texture" );
-
-	bltex = Texture_FromPyObject( pytex );
-
-	if( !self->material->mtex[texnum] ) {
-		/* there isn't an mtex for this slot so we need to make one */
-		self->material->mtex[texnum] = add_mtex(  );
-	} else {
-		/* we already had a texture here so deal with the old one first */
-		self->material->mtex[texnum]->tex->id.us--;
-	}
-
-	self->material->mtex[texnum]->tex = bltex;
-	id_us_plus( &bltex->id );
-	self->material->mtex[texnum]->texco = (short)texco;
-	self->material->mtex[texnum]->mapto = (short)mapto;
-
-	Py_RETURN_NONE;
-}
-
-static PyObject *Material_clearTexture( BPy_Material * self, PyObject * args )
-{
-	int texnum;
-	struct MTex *mtex;
-
-	if( !PyArg_ParseTuple( args, "i", &texnum ) )
-		return EXPP_ReturnPyObjError( PyExc_TypeError,
-					      "expected int in [0,9]" );
-	if( ( texnum < 0 ) || ( texnum >= MAX_MTEX ) )
-		return EXPP_ReturnPyObjError( PyExc_TypeError,
-					      "expected int in [0,9]" );
-
-	mtex = self->material->mtex[texnum];
-	if( mtex ) {
-		if( mtex->tex )
-			mtex->tex->id.us--;
-		MEM_freeN( mtex );
-		self->material->mtex[texnum] = NULL;
-	}
-
-	Py_RETURN_NONE;
-}
-
 /* mat.__copy__ */
 static PyObject *Material_copy( BPy_Material * self )
 {
@@ -1762,119 +1667,6 @@
 }
 
 /*****************************************************************************/
-/* These functions are used here and in in Texture.c						*/
-/*****************************************************************************/
-PyObject *EXPP_PyList_fromColorband( ColorBand *coba )
-{
-	short i;
-	PyObject *cbls;
-	PyObject *colls;
-	
-	if (!coba)
-		return PyList_New( 0 );
-	
-	cbls = PyList_New( coba->tot );
-	
-	for (i=0; i < coba->tot; i++) {
-		colls = PyList_New( 5 );
-		PyList_SET_ITEM( colls, 0, PyFloat_FromDouble(coba->data[i].r) );
-		PyList_SET_ITEM( colls, 1, PyFloat_FromDouble(coba->data[i].g) );
-		PyList_SET_ITEM( colls, 2, PyFloat_FromDouble(coba->data[i].b) );
-		PyList_SET_ITEM( colls, 3, PyFloat_FromDouble(coba->data[i].a) );
-		PyList_SET_ITEM( colls, 4, PyFloat_FromDouble(coba->data[i].pos) );
-		PyList_SET_ITEM(cbls, i, colls);
-	}
-	return cbls;
-}
-
-/* make sure you coba is not none before calling this */
-int EXPP_Colorband_fromPyList( ColorBand **coba, PyObject * value )
-{
-	short totcol, i;
-	PyObject *colseq;
-	PyObject *pyflt;
-	float f;
-	
-	if ( !PySequence_Check( value )  )
-		return ( EXPP_ReturnIntError( PyExc_TypeError,
-				"Colorband must be a sequence" ) );
-	
-	totcol = PySequence_Size(value);
-	if ( totcol > 31)
-		return ( EXPP_ReturnIntError( PyExc_ValueError,
-				"Colorband must be between 1 and 31 in length" ) );
-	
-	if (totcol==0) {
-		MEM_freeN(*coba);
-		*coba = NULL;
-		return 0;
-	}
-	
-	if (!*coba)
-		*coba = MEM_callocN( sizeof(ColorBand), "colorband");
-	
-	for (i=0; i<totcol; i++) {
-		colseq = PySequence_GetItem( value, i );
-		if ( !PySequence_Check( colseq ) || PySequence_Size( colseq ) != 5) {
-			Py_DECREF ( colseq );
-			return ( EXPP_ReturnIntError( PyExc_ValueError,
-				"Colorband colors must be sequences of 5 floats" ) );
-		}
-		for (i=0; i<5; i++) {
-			pyflt = PySequence_GetItem( colseq, i );

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list