diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index 9d9a2cfe25c..beab946306f 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -472,7 +472,7 @@ static void Material_Dealloc (BPy_Material *self) /* Description: This function will create a new BPy_Material from an existing*/ /* Blender material structure. */ /*****************************************************************************/ -PyObject *Material_CreatePyObject (Material *mat) +PyObject *Material_CreatePyObject (struct Material *mat) { BPy_Material *pymat; float *col[3], *amb[3], *spec[3], *mir[3]; @@ -1390,3 +1390,75 @@ Material **EXPP_newMaterialList(int len) return matlist; } + +int EXPP_releaseMaterialList (Material **matlist, int len) +{ + int i; + Material * mat; + + if ((len < 0) || (len > MAXMAT)) { + printf ("illegal matindex!\n"); + return 0; + } + + for (i=0 ; ius > 0) + ((ID *)mat)->us--; + else + printf ("FATAL: material usage=0: %s", ((ID *)mat)->name); + } + } + MEM_freeN (matlist); + + return 1; +} + +/** expands pointer array of length 'oldsize' to length 'newsize'. + * A pointer to the (void *) array must be passed as first argument + * The array pointer content can be NULL, in this case a new array of length + * 'newsize' is created. + */ + +static int expandPtrArray(void **p, int oldsize, int newsize) +{ + void *newarray; + + if (newsize < oldsize) { + return 0; + } + newarray = MEM_callocN(newsize * sizeof(void *), "PtrArray"); + if (*p) { + memcpy(newarray, *p, oldsize); + MEM_freeN(*p); + } + *p = newarray; + return 1; +} + +int EXPP_synchronizeMaterialLists (Object *object, void *data) +{ + Material *** p_dataMaterials = give_matarar (object); + short * nmaterials = give_totcolp (object); + + if (object->totcol > *nmaterials) { + /* More object mats than data mats */ + *nmaterials = object->totcol; + return expandPtrArray ((void *) p_dataMaterials, + *nmaterials, + object->totcol); + } + else { + if (object->totcol < *nmaterials) { + /* More data mats than object mats */ + object->totcol = *nmaterials; + return expandPtrArray ((void *) &object->mat, + object->totcol, + *nmaterials); + } + } + + /* No synchronization is needed; they're of equal length */ + return 1; +} diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index c96b2139cfd..a0ace75b1c9 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -82,7 +82,6 @@ struct PyMethodDef M_Object_methods[] = { /*****************************************************************************/ static PyObject *Object_clrParent (BPy_Object *self, PyObject *args); static PyObject *Object_getData (BPy_Object *self); -static PyObject *Object_getDeformData (BPy_Object *self); static PyObject *Object_getDeltaLocation (BPy_Object *self); static PyObject *Object_getDrawMode (BPy_Object *self); static PyObject *Object_getDrawType (BPy_Object *self); @@ -119,9 +118,6 @@ hierarchy (faster)"}, {"getData", (PyCFunction)Object_getData, METH_NOARGS, "Returns the datablock object containing the object's data, \ e.g. Mesh"}, - {"getDeformData", (PyCFunction)Object_getDeformData, METH_NOARGS, - "Returns the datablock object containing the object's deformed \ -data.\nCurrently, this is only supported for a Mesh"}, {"getDeltaLocation", (PyCFunction)Object_getDeltaLocation, METH_NOARGS, "Returns the object's delta location (x, y, z)"}, {"getDrawMode", (PyCFunction)Object_getDrawMode, METH_NOARGS, @@ -592,6 +588,7 @@ static PyObject *Object_getData (BPy_Object *self) data_object = Image_CreatePyObject (self->object->data); break; case ID_IP: + data_object = Ipo_CreatePyObject (self->object->data); break; case OB_LAMP://#ID_LA: data_object = Lamp_CreatePyObject (self->object->data); @@ -607,6 +604,7 @@ static PyObject *Object_getData (BPy_Object *self) case ID_SCE: break; case ID_TXT: + data_object = Text_CreatePyObject (self->object->data); break; case ID_WO: break; @@ -626,12 +624,6 @@ static PyObject *Object_getData (BPy_Object *self) } } -static PyObject *Object_getDeformData (BPy_Object *self) -{ - return (PythonReturnErrorObject (PyExc_NotImplementedError, - "getDeformData: not yet implemented")); -} - static PyObject *Object_getDeltaLocation (BPy_Object *self) { PyObject *attr = Py_BuildValue ("fff", @@ -704,9 +696,8 @@ static PyObject *Object_getLocation (BPy_Object *self, PyObject *args) static PyObject *Object_getMaterials (BPy_Object *self) { - /* TODO: Implement when the Material module is implemented. */ - return (PythonReturnErrorObject (PyExc_NotImplementedError, - "getMaterials: not yet implemented")); + return (EXPP_PyList_fromMaterialList (self->object->mat, + self->object->totcol)); } static PyObject *Object_getMatrix (BPy_Object *self) @@ -1034,7 +1025,6 @@ static PyObject *Object_setLocation (BPy_Object *self, PyObject *args) static PyObject *Object_setMaterials (BPy_Object *self, PyObject *args) { -#if 0 PyObject * list; int len; int i; @@ -1063,8 +1053,7 @@ static PyObject *Object_setMaterials (BPy_Object *self, PyObject *args) if (self->object->mat) { - /* TODO: create replacement function */ - releaseMaterialList (self->object->mat, len); + EXPP_releaseMaterialList (self->object->mat, len); } /* Increase the user count on all materials */ for (i=0 ; iobject, self->object->data); + case OB_SURF: + EXPP_synchronizeMaterialLists (self->object, + self->object->data); break; default: break; } } return (Py_None); -#endif - - return (PythonReturnErrorObject (PyExc_NotImplementedError, - "setMaterials: not yet implemented")); } static PyObject *Object_setName (BPy_Object *self, PyObject *args) diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 315074aeab5..e89c50d50b0 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -103,10 +103,6 @@ class Object: """ """ - def getDeformData(): - """ - """ - def getDeltaLocation(): """ """ diff --git a/source/blender/python/api2_2x/modules.h b/source/blender/python/api2_2x/modules.h index bae6d0e9cf8..8dc829f2d21 100644 --- a/source/blender/python/api2_2x/modules.h +++ b/source/blender/python/api2_2x/modules.h @@ -84,6 +84,13 @@ int NMesh_CheckPyObject (PyObject *pyobj); /* Material */ PyObject * Material_Init (void); +PyObject * Material_CreatePyObject (struct Material *mat); +int Material_CheckPyObject (PyObject *pyobj); +Material **EXPP_newMaterialList_fromPyList (PyObject *list); +Material **EXPP_newMaterialList(int len); +int EXPP_releaseMaterialList (Material **matlist, int len); +int EXPP_synchronizeMaterialLists (Object *object, void *data); +PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len); /* Camera Data */ PyObject * Camera_Init (void);