[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10965] branches/pyapi_devel/source/ blender/python/api2_2x: Made materials work the same for all types (Objects , Meshes, Metaballs, Curves)

Campbell Barton cbarton at metavr.com
Tue Jun 19 06:12:09 CEST 2007


Revision: 10965
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=10965
Author:   campbellbarton
Date:     2007-06-19 06:12:08 +0200 (Tue, 19 Jun 2007)

Log Message:
-----------
Made materials work the same for all types (Objects, Meshes, Metaballs, Curves)
They use the one datatype that is a real list with its functions wrapped so the blender data stays in sync.

so you can do this for instance..

ls = me.materials
ls[:] = [None, None]
ls.append(bpy.data.materials['Material'])

# ...or
me.materials.append(None)

This isnt finished but Iv tested that basic functionality works- getting and setting works as well as resizing material lists.
ls.extend() and ls[:] = [...] still need type checking.

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/Camera.h
    branches/pyapi_devel/source/blender/python/api2_2x/Curve.c
    branches/pyapi_devel/source/blender/python/api2_2x/Ipo.c
    branches/pyapi_devel/source/blender/python/api2_2x/Lattice.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/NLA.c
    branches/pyapi_devel/source/blender/python/api2_2x/Object.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/bpy_data.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/material_list.c
    branches/pyapi_devel/source/blender/python/api2_2x/material_list.h

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Blender.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Blender.c	2007-06-19 00:55:41 UTC (rev 10964)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Blender.c	2007-06-19 04:12:08 UTC (rev 10965)
@@ -95,6 +95,7 @@
 #include "World.h"
 #include "Types.h"
 #include "object_scriptlink.h"
+#include "material_list.h"
 
 /**********************************************************/
 /* Python API function prototypes for the Blender module.	*/
@@ -980,4 +981,6 @@
 	PyDict_SetItemString(dict, "Texture", Texture_Init());
 	PyDict_SetItemString(dict, "Window", Window_Init());
 	PyDict_SetItemString(dict, "World", World_Init());
+	
+	MaterialList_Init();
 }

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Camera.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Camera.c	2007-06-19 00:55:41 UTC (rev 10964)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Camera.c	2007-06-19 04:12:08 UTC (rev 10965)
@@ -147,12 +147,9 @@
 static int Camera_compare( BPy_Camera * a, BPy_Camera * b );
 static PyObject *Camera_repr( BPy_Camera * self );
 
-PyObject *Camera_Init( void )
-{
-	PyObject *submodule;
-	
-	if( PyType_Ready( &Camera_Type ) < 0 )
-		return NULL;
+void Camera_Init( void )
+{	
+	PyType_Ready( &Camera_Type );
 	/* no Blender.Camera anymore */
 }
 

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Camera.h
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Camera.h	2007-06-19 00:55:41 UTC (rev 10964)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Camera.h	2007-06-19 04:12:08 UTC (rev 10965)
@@ -75,7 +75,7 @@
 #define EXPP_CAM_DRAWSIZE_MIN     0.1f
 #define EXPP_CAM_DRAWSIZE_MAX    10.0
 
-PyObject *Camera_Init( void );
+void Camera_Init( void );
 PyObject *Camera_CreatePyObject( Camera * cam );
 Camera *Camera_FromPyObject( PyObject * pyobj );
 

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Curve.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Curve.c	2007-06-19 00:55:41 UTC (rev 10964)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Curve.c	2007-06-19 04:12:08 UTC (rev 10965)
@@ -83,8 +83,6 @@
 static PyObject *Curve_appendPoint( BPy_Curve * self, PyObject * args );
 static PyObject *Curve_appendNurb( BPy_Curve * self, PyObject * args );
 
-static PyObject *Curve_getMaterials( BPy_Curve * self );
-
 static PyObject *Curve_getBevOb( BPy_Curve * self );
 static int Curve_setBevOb( BPy_Curve * self, PyObject * args );
 
@@ -901,60 +899,6 @@
 	Py_RETURN_NONE;
 }
 
-/*
- * Curve_getMaterials
- *
- */
-
-static PyObject *Curve_getMaterials( BPy_Curve * self )
-{
-	return EXPP_PyList_fromMaterialList( self->curve->mat,
-			self->curve->totcol, 1 );
-}
-
-static int Curve_setMaterials( BPy_Curve *self, PyObject * value )
-{
-	Material **matlist;
-	int len;
-
-	if( !PySequence_Check( value ) ||
-			!EXPP_check_sequence_consistency( value, &Material_Type ) )
-		return EXPP_ReturnIntError( PyExc_TypeError,
-				"sequence should only contain materials or None)" );
-
-	len = PySequence_Size( value );
-	if( len > 16 )
-		return EXPP_ReturnIntError( PyExc_TypeError,
-			"list can't have more than 16 materials" );
-
-	/* free old material list (if it exists) and adjust user counts */
-	if( self->curve->mat ) {
-		Curve *cur = self->curve;
-		int i;
-		for( i = cur->totcol; i-- > 0; )
-			if( cur->mat[i] )
-           		cur->mat[i]->id.us--;
-		MEM_freeN( cur->mat );
-	}
-
-	/* build the new material list, increment user count, store it */
-
-	matlist = EXPP_newMaterialList_fromPyList( value );
-	EXPP_incr_mats_us( matlist, len );
-	self->curve->mat = matlist;
-	self->curve->totcol = (short)len;
-
-/**@ This is another ugly fix due to the weird material handling of blender.
-    * it makes sure that object material lists get updated (by their length)
-    * according to their data material lists, otherwise blender crashes.
-    * It just stupidly runs through all objects...BAD BAD BAD.
-    */
-
-	test_object_materials( ( ID * ) self->curve );
-
-	return 0;
-}
-
 /*****************************************************************************/
 /* Function:    Curve_getBevOb                                               */
 /* Description: Get the bevel object assign to the curve.                    */
@@ -1224,7 +1168,7 @@
 	 "The shape key for the curve (if any)",
 	NULL},
 	{"materials",
-	 (getter)Curve_getMaterials, (setter)Curve_setMaterials,
+	 (getter)GenericLib_getMaterials, (setter)GenericLib_setMaterials,
 	 "The materials associated with the curve",
 	NULL},
 	{NULL,NULL,NULL,NULL,NULL}  /* Sentinel */

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Ipo.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Ipo.c	2007-06-19 00:55:41 UTC (rev 10964)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Ipo.c	2007-06-19 04:12:08 UTC (rev 10965)
@@ -94,10 +94,8 @@
 /* Python BPy_Ipo methods declarations:                                     */
 /*****************************************************************************/
 static PyObject *Ipo_getBlocktype( BPy_Ipo * self );
-static PyObject *Ipo_oldsetBlocktype( BPy_Ipo * self, PyObject * args );
 static int Ipo_setBlocktype( BPy_Ipo * self, PyObject * args );
 static PyObject *Ipo_getRctf( BPy_Ipo * self );
-static PyObject *Ipo_oldsetRctf( BPy_Ipo * self, PyObject * args );
 static int Ipo_setRctf( BPy_Ipo * self, PyObject * args );
 
 static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args );
@@ -130,18 +128,6 @@
 /*****************************************************************************/
 static PyMethodDef BPy_Ipo_methods[] = {
 	/* name, method, flags, doc */
-	{"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
-	 "() - Return Ipo Data name"},
-	{"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
-	 "(str) - Change Ipo Data name"},
-	{"getBlocktype", ( PyCFunction ) Ipo_getBlocktype, METH_NOARGS,
-	 "() - Return Ipo blocktype"},
-	{"setBlocktype", ( PyCFunction ) Ipo_oldsetBlocktype, METH_VARARGS,
-	 "(str) - Change Ipo blocktype"},
-	{"getRctf", ( PyCFunction ) Ipo_getRctf, METH_NOARGS,
-	 "() - Return Ipo rctf"},
-	{"setRctf", ( PyCFunction ) Ipo_oldsetRctf, METH_VARARGS,
-	 "(flt,flt,flt,flt) - Change Ipo rctf"},
 	{"addCurve", ( PyCFunction ) Ipo_addCurve, METH_VARARGS,
 	 "() - Add a curve to Ipo"},
 	{"delCurve", ( PyCFunction ) Ipo_delCurve, METH_VARARGS,
@@ -192,9 +178,8 @@
 	 (getter)Ipo_getChannel, (setter)Ipo_setChannel,
 	 "Ipo texture channel (world, lamp, material Ipos only)",
 	 NULL},
-
 	{"blocktype",
-	 (getter)Ipo_getBlocktype, (setter)NULL,
+	 (getter)Ipo_getBlocktype, (setter)Ipo_setBlocktype,
 	 "Ipo block type",
 	 NULL},
 	{"rctf",
@@ -817,13 +802,13 @@
 		   "couldn't get Ipo.blocktype attribute" );
 }
 
-static int Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
+static int Ipo_setBlocktype( BPy_Ipo * self, PyObject * value )
 {
-	if( !PyInt_CheckExact( args ) )
+	if( !PyInt_CheckExact( value ) )
 		return EXPP_ReturnIntError( PyExc_TypeError,
 				"expected int argument" );
 
-	self->ipo->blocktype = (short)PyInt_AS_LONG( args );
+	self->ipo->blocktype = (short)PyInt_AS_LONG( value );
 
 	return 0;
 }
@@ -1832,19 +1817,3 @@
 		return PyFloat_FromDouble( icu->curval );
 	Py_RETURN_NONE;
 }
-
-/*
- * The following methods should be deprecated when methods are pruned out.
- */
-
-static PyObject *Ipo_oldsetRctf( BPy_Ipo * self, PyObject * args )
-{
-	return EXPP_setterWrapperTuple( (void *)self, args,
-			(setter)Ipo_setRctf );
-}
-
-static PyObject *Ipo_oldsetBlocktype( BPy_Ipo * self, PyObject * args )
-{
-	return EXPP_setterWrapperTuple( (void *)self, args,
-			(setter)Ipo_setBlocktype );
-}

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c	2007-06-19 00:55:41 UTC (rev 10964)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Lattice.c	2007-06-19 04:12:08 UTC (rev 10965)
@@ -89,10 +89,6 @@
 /* In Python these will be written to the console when doing a		 */
 /* Blender.Lattice.__doc__			*/
 /*****************************************************************************/
-static char Lattice_getName_doc[] = "() - Return Lattice Object name";
-
-static char Lattice_setName_doc[] = "(str) - Change Lattice Object name";
-
 static char Lattice_setPartitions_doc[] =
 	"(str) - Set the number of Partitions in x,y,z";
 

Modified: branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c	2007-06-19 00:55:41 UTC (rev 10964)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Mesh.c	2007-06-19 04:12:08 UTC (rev 10965)
@@ -7588,55 +7588,6 @@
 	return MFaceSeq_CreatePyObject( self->mesh );
 }
 
-static PyObject *Mesh_getMaterials( BPy_Mesh *self )
-{
-	return EXPP_PyList_fromMaterialList( self->mesh->mat,
-			self->mesh->totcol, 1 );
-}
-
-static int Mesh_setMaterials( BPy_Mesh *self, PyObject * value )
-{
-    Material **matlist;
-	int len;
-
-    if( !PySequence_Check( value ) ||
-			!EXPP_check_sequence_consistency( value, &Material_Type ) )
-        return EXPP_ReturnIntError( PyExc_TypeError,
-                  "list should only contain materials or None)" );
-
-    len = PyList_Size( value );
-    if( len > 16 )
-        return EXPP_ReturnIntError( PyExc_TypeError,
-                          "list can't have more than 16 materials" );
-
-	/* free old material list (if it exists) and adjust user counts */
-	if( self->mesh->mat ) {
-		Mesh *me = self->mesh;
-		int i;
-		for( i = me->totcol; i-- > 0; )
-			if( me->mat[i] )
-           		me->mat[i]->id.us--;
-		MEM_freeN( me->mat );
-	}
-
-	/* build the new material list, increment user count, store it */
-
-	matlist = EXPP_newMaterialList_fromPyList( value );
-	EXPP_incr_mats_us( matlist, len );
-	self->mesh->mat = matlist;
-    	self->mesh->totcol = (short)len;
-
-/**@ This is another ugly fix due to the weird material handling of blender.

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list