From 7b3b3ae432f692ed32f57aa70bdab5b89a05be21 Mon Sep 17 00:00:00 2001 From: Willian Padovani Germano Date: Tue, 20 Jul 2004 08:16:46 +0000 Subject: Trying to fix bug reported by Peter den Bak and Meino Christian Cramer (thanks!): -- splash screen disappeared (duh, I did that!) and Blender quits upon exiting from some 225 games: It was troublesome to find how to run demos in general with the screen correctly redrawn before they started, etc. Ended up making the above error in screenmain(). About the games, I don't have them and will need some time to get the files for testing, but I'll do it, though only on linux. BPython: -- Window: added GetScreens, SetScreen and improved GetScreenInfo. -- Object, NMesh: updated (added in NMesh) method getMaterials to return either only valid materials as before or also empty slots (as None). This previous omission can be considered a bug, since it made info about materials incomplete / incompatible with face mat indices. Thanks Yann Vernier for bringing this up and sending/proposing a patch that also fixed a bug related to assigning lists of materials with different lengths to obj and its mesh. setMaterials also accepts Py_None entries now, which become empty slots in Blender. -- doc updates. --- source/blender/python/api2_2x/Material.c | 54 +++---- source/blender/python/api2_2x/Material.h | 2 +- source/blender/python/api2_2x/NMesh.c | 216 ++++++++++++++++++++++++++- source/blender/python/api2_2x/NMesh.h | 146 ------------------ source/blender/python/api2_2x/Object.c | 31 ++-- source/blender/python/api2_2x/Window.c | 100 ++++++++++++- source/blender/python/api2_2x/doc/Blender.py | 11 +- source/blender/python/api2_2x/doc/NMesh.py | 34 ++++- source/blender/python/api2_2x/doc/Object.py | 9 +- source/blender/python/api2_2x/doc/Window.py | 22 ++- source/blender/python/api2_2x/gen_utils.c | 7 +- source/blender/python/api2_2x/modules.h | 4 +- 12 files changed, 422 insertions(+), 214 deletions(-) (limited to 'source/blender/python/api2_2x') diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c index 81ea0dbba0f..f5f22948fec 100644 --- a/source/blender/python/api2_2x/Material.c +++ b/source/blender/python/api2_2x/Material.c @@ -209,11 +209,11 @@ static PyObject *M_Material_Get(PyObject *self, PyObject *args) BPy_Material *wanted_mat = NULL; - while ((mat_iter) && (wanted_mat == NULL)) { - - if (strcmp (name, mat_iter->id.name+2) == 0) + while (mat_iter) { + if (strcmp (name, mat_iter->id.name+2) == 0) { wanted_mat = (BPy_Material *)Material_CreatePyObject (mat_iter); - + break; + } mat_iter = mat_iter->id.next; } @@ -221,7 +221,7 @@ static PyObject *M_Material_Get(PyObject *self, PyObject *args) char error_msg[64]; PyOS_snprintf(error_msg, sizeof(error_msg), "Material \"%s\" not found", name); - return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); + return EXPP_ReturnPyObjError (PyExc_NameError, error_msg); } return (PyObject *)wanted_mat; @@ -1714,11 +1714,10 @@ static PyObject *Material_repr (BPy_Material *self) return PyString_FromFormat ("[Material \"%s\"]", self->material->id.name+2); } - /*****************************************************************************/ /* These functions are used in NMesh.c and Object.c */ /*****************************************************************************/ -PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len) +PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len, int all) { PyObject *list; int i; @@ -1735,6 +1734,9 @@ PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len) PyList_Append (list, ob); Py_DECREF (ob); /* because Append increfs */ } + else if (all) { /* return NULL mats (empty slots) as Py_None */ + PyList_Append (list, Py_None); + } } return list; @@ -1752,7 +1754,7 @@ Material **EXPP_newMaterialList_fromPyList (PyObject *list) matlist = EXPP_newMaterialList (len); - for (i= 0; i < len; i++) { + for (i = 0; i < len; i++) { pymat = (BPy_Material *)PySequence_GetItem (list, i); @@ -1760,7 +1762,9 @@ Material **EXPP_newMaterialList_fromPyList (PyObject *list) mat = pymat->material; matlist[i] = mat; } - + else if ((PyObject *)pymat == Py_None) { + matlist[i] = NULL; + } else { /* error; illegal type in material list */ Py_DECREF(pymat); MEM_freeN(matlist); @@ -1783,26 +1787,26 @@ Material **EXPP_newMaterialList(int len) int EXPP_releaseMaterialList (Material **matlist, int len) { - int i; - Material * mat; + int i; + Material *mat; if ((len < 0) || (len > MAXMAT)) { - printf ("illegal matindex!\n"); - return 0; + printf ("illegal matindex!\n"); + return 0; } for (i=0 ; ius > 0) - ((ID *)mat)->us--; - else - printf ("FATAL: material usage=0: %s", ((ID *)mat)->name); - } + mat = matlist[i]; + if (mat) { + if (((ID *)mat)->us > 0) + ((ID *)mat)->us--; + else + printf ("FATAL: material usage=0: %s", ((ID *)mat)->name); + } } - MEM_freeN (matlist); + MEM_freeN (matlist); - return 1; + return 1; } /** expands pointer array of length 'oldsize' to length 'newsize'. @@ -1818,16 +1822,16 @@ static int expandPtrArray(void **p, int oldsize, int newsize) if (newsize < oldsize) { return 0; } - newarray = MEM_callocN(newsize * sizeof(void *), "PtrArray"); + newarray = MEM_callocN(sizeof(void *)*newsize, "PtrArray"); if (*p) { - memcpy(newarray, *p, oldsize); + memcpy(newarray, *p, sizeof(void *)*oldsize); MEM_freeN(*p); } *p = newarray; return 1; } -int EXPP_synchronizeMaterialLists (Object *object, void *data) +int EXPP_synchronizeMaterialLists (Object *object) { Material *** p_dataMaterials = give_matarar (object); short * nmaterials = give_totcolp (object); diff --git a/source/blender/python/api2_2x/Material.h b/source/blender/python/api2_2x/Material.h index d53c04a9cca..5345cc0c90e 100644 --- a/source/blender/python/api2_2x/Material.h +++ b/source/blender/python/api2_2x/Material.h @@ -62,7 +62,7 @@ Material *Material_FromPyObject (PyObject *pyobj); int Material_CheckPyObject (PyObject *pyobj); /* Some functions needed by NMesh.c */ -PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len); +PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len, int all); Material **EXPP_newMaterialList_fromPyList (PyObject *list); Material **EXPP_newMaterialList(int len); diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index ca8cc46ebc0..db32a964443 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -48,6 +48,165 @@ #define NMESH_SUBDIV_MIN 1 #define NMESH_SUBDIV_MAX 6 +static char NMesh_addVertGroup_doc[] = +"add a named and empty vertex(deform) Group to a mesh that has been linked\n\ +to an object. "; + +static char NMesh_removeVertGroup_doc[] = +"remove a named vertex(deform) Group from a mesh that has been linked\n\ +to an object. Will remove all verts assigned to group."; + +static char NMesh_assignVertsToGroup_doc[] = +"Adds an array (a python list) of vertex points (by index) to a named\n\ +vertex group. The list will have an associated wieght assigned to them.\n\ +The weight represents the amount of influence this group has over these\n\ +vertex points. Weights should be in the range of 0.0 - 1.0.\n\ +The assignmode can be either 'add', 'subtract', or 'replace'. If this vertex\n\ +is not assigned to the group 'add' creates a new association with the weight\n\ +specified, otherwise the weight given is added to the current weight of the\n\ +vertex.\n\ +'subtract' will attempt to subtract the weight passed from a vertex already\n\ +associated with a group, else it does nothing. 'replace' attempts to replace\n\ +the weight with the new weight value for an already associated vertex/group,\n\ +else it does nothing. The mesh must have all it's vertex points set before\n\ +attempting to assign any vertex points to a vertex group."; + +static char NMesh_removeVertsFromGroup_doc[] = +"Remove an array (a python list) of vertex points from a named group in a\n\ +mesh that has been linked to an object. If no list is given this will remove\n\ +all vertex point associations with the group passed"; + +static char NMesh_getVertsFromGroup_doc[] = +"By passing a python list of vertex indices and a named group, this will\n\ +return a python list representing the indeces that are a part of this vertex.\n\ +group. If no association was found for the index passed nothing will be\n\ +return for the index. An optional flag will also return the weights as well"; + +static char NMesh_renameVertGroup_doc[] = +"Renames a vertex group"; + +static char NMesh_getVertGroupNames_doc[] = +"Returns a list of all the vertex group names"; + +static char M_NMesh_doc[] = +"The Blender.NMesh submodule"; + +static char M_NMesh_Col_doc[]= +"([r, g, b, a]) - Get a new mesh color\n\n\ +[r=255, g=255, b=255, a=255] Specify the color components"; + +static char M_NMesh_Face_doc[] = +"(vertexlist = None) - Get a new face, and pass optional vertex list"; + +static char NMFace_append_doc[] = +"(vert) - appends Vertex 'vert' to face vertex list"; + +static char M_NMesh_Vert_doc[] = +"([x, y, z]) - Get a new vertice\n\n\ +[x, y, z] Specify new coordinates"; + +static char NMesh_getMaterials_doc[] = +"(i = -1) - Get this mesh's list of materials.\n\ +(i = -1) - int: determines the list's contents:\n\ +-1: return the current list, possibly modified by the script (default);\n\ + 0: get a fresh list from the Blender mesh -- modifications not included,\n\ + unless the script called mesh.update() first;\n\ + 1: like 0, but does not ignore empty slots, returns them as 'None'."; + +static char NMesh_setMaterials_doc[] = +"(matlist) - Set this mesh's list of materials. This method makes sure\n\ +the passed matlist is valid (can only include up to 16 materials and None's)."; + +static char NMesh_addMaterial_doc[] = +"(material) - add a new Blender Material 'material' to this Mesh's materials\n\ +list."; + +static char NMesh_insertKey_doc[] = +"(frame = None, type = 'relative') - inserts a Mesh key at the given frame\n\ +if called without arguments, it inserts the key at the current Scene frame.\n\ +(type) - 'relative' or 'absolute'. Only relevant on the first call to this\n\ +function for each nmesh."; + +static char NMesh_removeAllKeys_doc[] = +"() - removes all keys from this mesh\n\ +returns True if successful or False if this NMesh wasn't linked to a real\n\ +Blender Mesh yet or the Mesh had no keys"; + +static char NMesh_getSelectedFaces_doc[] = +"(flag = None) - returns list of selected Faces\n\ +If flag = 1, return indices instead"; + +static char NMesh_getActiveFace_doc[] = +"returns the index of the active face "; + +static char NMesh_hasVertexUV_doc[] = +"(flag = None) - returns 1 if Mesh has per vertex UVs ('Sticky')\n\ +The optional argument sets the Sticky flag"; + +static char NMesh_hasFaceUV_doc[] = +"(flag = None) - returns 1 if Mesh has textured faces\n\ +The optional argument sets the textured faces flag"; + +static char NMesh_hasVertexColours_doc[] = +"(flag = None) - returns 1 if Mesh has vertex colours.\n\ +The optional argument sets the vertex colour flag"; + +static char NMesh_getVertexInfluences_doc[] = +"Return a list of the influences of bones in the vertex \n\ +specified by index. The list contains pairs with the \n\ +bone name and the weight."; + + +static char NMesh_update_doc[] = "(recalc_normals = 0) - updates the Mesh.\n\ +if recalc_normals is given and is equal to 1, normal vectors are recalculated."; + +static char NMesh_getMode_doc[] = +"() - get the mode flags of this nmesh as an or'ed int value."; + +static char NMesh_setMode_doc[] = +"(none to 5 strings) - set the mode flags of this nmesh.\n\ +() - unset all flags."; + +static char NMesh_getMaxSmoothAngle_doc[] = +"() - get the max smooth angle for mesh auto smoothing."; + +static char NMesh_setMaxSmoothAngle_doc[] = +"(int) - set the max smooth angle for mesh auto smoothing in the range\n\ +[1,80] in degrees."; + +static char NMesh_getSubDivLevels_doc[] = +"() - get the subdivision levels for display and rendering: [display, render]"; + +static char NMesh_setSubDivLevels_doc[] = +"([int, int]) - set the subdivision levels for [display, render] -- they are\n\ +clamped to the range [1,6]."; + +static char M_NMesh_New_doc[] = +"() - returns a new, empty NMesh mesh object\n"; + +static char M_NMesh_GetRaw_doc[] = +"([name]) - Get a raw mesh from Blender\n\n\ +[name] Name of the mesh to be returned\n\n\ +If name is not specified a new empty mesh is\n\ +returned, otherwise Blender returns an existing\n\ +mesh."; + +static char M_NMesh_GetRawFromObject_doc[] = +"(name) - Get the raw mesh used by a Blender object\n\n\ +(name) Name of the object to get the mesh from\n\n\ +This returns the mesh as used by the object, which\n\ +means it contains all deformations and modifications."; + +static char M_NMesh_PutRaw_doc[] = +"(mesh, [name, renormal]) - Return a raw mesh to Blender\n\n\ +(mesh) The NMesh object to store\n\ +[name] The mesh to replace\n\ +[renormal=1] Flag to control vertex normal recalculation\n\n\ +If the name of a mesh to replace is not given a new\n\ +object is created and returned."; + + + void mesh_update(Mesh *mesh) { edge_drawflags_mesh(mesh); @@ -273,7 +432,7 @@ static PyObject *NMFace_getattr(PyObject *self, char *name) else if ((strcmp(name, "normal") == 0) || (strcmp(name, "no") == 0)) { - if (EXPP_check_sequence_consistency(mf->v, &NMVert_Type)) { + if (EXPP_check_sequence_consistency(mf->v, &NMVert_Type) == 1) { float fNormal[3] = {0.0,0.0,0.0}; float *vco[4] = {NULL, NULL, NULL, NULL}; @@ -632,6 +791,51 @@ static void NMesh_dealloc(PyObject *self) PyObject_DEL(self); } +static PyObject *NMesh_getMaterials (PyObject *self, PyObject *args) +{ + BPy_NMesh *nm = (BPy_NMesh *)self; + PyObject *list = NULL; + Mesh *me = nm->mesh; + int all = -1; + + if (!PyArg_ParseTuple (args, "|i", &all)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected nothing or an int (bool) as argument"); + + if (all >= 0) { + list = EXPP_PyList_fromMaterialList (me->mat, me->totcol, all); + Py_DECREF (nm->materials); /* update nmesh.materials attribute */ + nm->materials = EXPP_incr_ret(list); + } + else + list = EXPP_incr_ret (nm->materials); + + return list; +} + +static PyObject *NMesh_setMaterials (PyObject *self, PyObject *args) +{ + BPy_NMesh *me = (BPy_NMesh *)self; + PyObject *pymats = NULL; + + if (!PyArg_ParseTuple (args, "O!", &PyList_Type, pymats)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected a list of materials (None's also accepted) as argument"); + + if (!EXPP_check_sequence_consistency (pymats, &Material_Type)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "list should only contain materials (None's also accepted)"); + + if (PyList_Size(pymats) > 16) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "list can't have more than 16 materials"); + + Py_DECREF (me->materials); + me->materials = EXPP_incr_ret (pymats); + + return EXPP_incr_ret (Py_None); +} + static PyObject *NMesh_addMaterial (PyObject *self, PyObject *args) { BPy_NMesh *me = (BPy_NMesh *)self; @@ -1076,6 +1280,8 @@ static struct PyMethodDef NMesh_methods[] = MethodDef(getActiveFace), MethodDef(getSelectedFaces), MethodDef(getVertexInfluences), + MethodDef(getMaterials), + MethodDef(setMaterials), MethodDef(addMaterial), MethodDef(insertKey), MethodDef(removeAllKeys), @@ -1434,7 +1640,7 @@ static PyObject *new_NMesh_internal(Mesh *oldmesh, PyList_SetItem (me->faces, i, (PyObject *)nmface_from_data(me, vidxs, oldmf->mat_nr, oldmf->flag, oldtf, oldmc)); } - me->materials = EXPP_PyList_fromMaterialList(oldmesh->mat, oldmesh->totcol); + me->materials = EXPP_PyList_fromMaterialList(oldmesh->mat, oldmesh->totcol, 0); } return (PyObject *)me; @@ -1959,10 +2165,10 @@ static PyObject *M_NMesh_PutRaw(PyObject *self, PyObject *args) return EXPP_ReturnPyObjError (PyExc_AttributeError, "nmesh materials are not a sequence"); - if (!EXPP_check_sequence_consistency(nmesh->verts, &NMVert_Type)) + if (EXPP_check_sequence_consistency(nmesh->verts, &NMVert_Type) != 1) return EXPP_ReturnPyObjError (PyExc_AttributeError, "nmesh vertices must be NMVerts"); - if (!EXPP_check_sequence_consistency(nmesh->faces, &NMFace_Type)) + if (EXPP_check_sequence_consistency(nmesh->faces, &NMFace_Type) != 1) return EXPP_ReturnPyObjError (PyExc_AttributeError, "nmesh faces must be NMFaces"); @@ -2021,7 +2227,7 @@ static PyObject *M_NMesh_PutRaw(PyObject *self, PyObject *args) if (ob) { // we created a new object nmesh->object = ob; // linking so vgrouping methods know which obj to work on NMesh_assignMaterials_toObject(nmesh, ob); - EXPP_synchronizeMaterialLists (ob, ob->data); + EXPP_synchronizeMaterialLists (ob); return Object_CreatePyObject(ob); } else { diff --git a/source/blender/python/api2_2x/NMesh.h b/source/blender/python/api2_2x/NMesh.h index efaba2a9e17..93c2031c17a 100644 --- a/source/blender/python/api2_2x/NMesh.h +++ b/source/blender/python/api2_2x/NMesh.h @@ -101,152 +101,6 @@ static PyObject *g_nmeshmodule = NULL; #define BPy_NMVert_Check(v) ((v)->ob_type == &NMVert_Type) #define BPy_NMCol_Check(v) ((v)->ob_type == &NMCol_Type) - -static char NMesh_addVertGroup_doc[] = -"add a named and empty vertex(deform) Group to a mesh that has been linked\n\ -to an object. "; - -static char NMesh_removeVertGroup_doc[] = -"remove a named vertex(deform) Group from a mesh that has been linked\n\ -to an object. Will remove all verts assigned to group."; - -static char NMesh_assignVertsToGroup_doc[] = -"Adds an array (a python list) of vertex points (by index) to a named\n\ -vertex group. The list will have an associated wieght assigned to them.\n\ -The weight represents the amount of influence this group has over these\n\ -vertex points. Weights should be in the range of 0.0 - 1.0.\n\ -The assignmode can be either 'add', 'subtract', or 'replace'. If this vertex\n\ -is not assigned to the group 'add' creates a new association with the weight\n\ -specified, otherwise the weight given is added to the current weight of the\n\ -vertex.\n\ -'subtract' will attempt to subtract the weight passed from a vertex already\n\ -associated with a group, else it does nothing. 'replace' attempts to replace\n\ -the weight with the new weight value for an already associated vertex/group,\n\ -else it does nothing. The mesh must have all it's vertex points set before\n\ -attempting to assign any vertex points to a vertex group."; - -static char NMesh_removeVertsFromGroup_doc[] = -"Remove an array (a python list) of vertex points from a named group in a\n\ -mesh that has been linked to an object. If no list is given this will remove\n\ -all vertex point associations with the group passed"; - -static char NMesh_getVertsFromGroup_doc[] = -"By passing a python list of vertex indices and a named group, this will\n\ -return a python list representing the indeces that are a part of this vertex.\n\ -group. If no association was found for the index passed nothing will be\n\ -return for the index. An optional flag will also return the weights as well"; - -static char NMesh_renameVertGroup_doc[] = -"Renames a vertex group"; - -static char NMesh_getVertGroupNames_doc[] = -"Returns a list of all the vertex group names"; - -static char M_NMesh_doc[] = -"The Blender.NMesh submodule"; - -static char M_NMesh_Col_doc[]= -"([r, g, b, a]) - Get a new mesh color\n\n\ -[r=255, g=255, b=255, a=255] Specify the color components"; - -static char M_NMesh_Face_doc[] = -"(vertexlist = None) - Get a new face, and pass optional vertex list"; - -static char NMFace_append_doc[] = -"(vert) - appends Vertex 'vert' to face vertex list"; - -static char M_NMesh_Vert_doc[] = -"([x, y, z]) - Get a new vertice\n\n\ -[x, y, z] Specify new coordinates"; - -static char NMesh_addMaterial_doc[] = -"(material) - add a new Blender Material 'material' to this Mesh's materials\n\ -list."; - -static char NMesh_insertKey_doc[] = -"(frame = None, type = 'relative') - inserts a Mesh key at the given frame\n\ -if called without arguments, it inserts the key at the current Scene frame.\n\ -(type) - 'relative' or 'absolute'. Only relevant on the first call to this\n\ -function for each nmesh."; - -static char NMesh_removeAllKeys_doc[] = -"() - removes all keys from this mesh\n\ -returns True if successful or False if this NMesh wasn't linked to a real\n\ -Blender Mesh yet or the Mesh had no keys"; - -static char NMesh_getSelectedFaces_doc[] = -"(flag = None) - returns list of selected Faces\n\ -If flag = 1, return indices instead"; - -static char NMesh_getActiveFace_doc[] = -"returns the index of the active face "; - -static char NMesh_hasVertexUV_doc[] = -"(flag = None) - returns 1 if Mesh has per vertex UVs ('Sticky')\n\ -The optional argument sets the Sticky flag"; - -static char NMesh_hasFaceUV_doc[] = -"(flag = None) - returns 1 if Mesh has textured faces\n\ -The optional argument sets the textured faces flag"; - -static char NMesh_hasVertexColours_doc[] = -"(flag = None) - returns 1 if Mesh has vertex colours.\n\ -The optional argument sets the vertex colour flag"; - -static char NMesh_getVertexInfluences_doc[] = -"Return a list of the influences of bones in the vertex \n\ -specified by index. The list contains pairs with the \n\ -bone name and the weight."; - - -static char NMesh_update_doc[] = "(recalc_normals = 0) - updates the Mesh.\n\ -if recalc_normals is given and is equal to 1, normal vectors are recalculated."; - -static char NMesh_getMode_doc[] = -"() - get the mode flags of this nmesh as an or'ed int value."; - -static char NMesh_setMode_doc[] = -"(none to 5 strings) - set the mode flags of this nmesh.\n\ -() - unset all flags."; - -static char NMesh_getMaxSmoothAngle_doc[] = -"() - get the max smooth angle for mesh auto smoothing."; - -static char NMesh_setMaxSmoothAngle_doc[] = -"(int) - set the max smooth angle for mesh auto smoothing in the range\n\ -[1,80] in degrees."; - -static char NMesh_getSubDivLevels_doc[] = -"() - get the subdivision levels for display and rendering: [display, render]"; - -static char NMesh_setSubDivLevels_doc[] = -"([int, int]) - set the subdivision levels for [display, render] -- they are\n\ -clamped to the range [1,6]."; - -static char M_NMesh_New_doc[] = -"() - returns a new, empty NMesh mesh object\n"; - -static char M_NMesh_GetRaw_doc[] = -"([name]) - Get a raw mesh from Blender\n\n\ -[name] Name of the mesh to be returned\n\n\ -If name is not specified a new empty mesh is\n\ -returned, otherwise Blender returns an existing\n\ -mesh."; - -static char M_NMesh_GetRawFromObject_doc[] = -"(name) - Get the raw mesh used by a Blender object\n\n\ -(name) Name of the object to get the mesh from\n\n\ -This returns the mesh as used by the object, which\n\ -means it contains all deformations and modifications."; - -static char M_NMesh_PutRaw_doc[] = -"(mesh, [name, renormal]) - Return a raw mesh to Blender\n\n\ -(mesh) The NMesh object to store\n\ -[name] The mesh to replace\n\ -[renormal=1] Flag to control vertex normal recalculation\n\n\ -If the name of a mesh to replace is not given a new\n\ -object is created and returned."; - /* Typedefs for the new types */ typedef struct { diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 0830184d941..784b832f968 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -108,7 +108,7 @@ static PyObject *Object_getEuler (BPy_Object *self); static PyObject *Object_getInverseMatrix (BPy_Object *self); static PyObject *Object_getIpo (BPy_Object *self); static PyObject *Object_getLocation (BPy_Object *self, PyObject *args); -static PyObject *Object_getMaterials (BPy_Object *self); +static PyObject *Object_getMaterials (BPy_Object *self, PyObject *args); static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args); static PyObject *Object_getName (BPy_Object *self); static PyObject *Object_getParent (BPy_Object *self); @@ -183,8 +183,9 @@ hierarchy (faster)"}, "Returns the object's inverse matrix"}, {"getLocation", (PyCFunction)Object_getLocation, METH_VARARGS, "Returns the object's location (x, y, z)"}, - {"getMaterials", (PyCFunction)Object_getMaterials, METH_NOARGS, - "Returns list of materials assigned to the object"}, + {"getMaterials", (PyCFunction)Object_getMaterials, METH_VARARGS, + "(i = 0) - Returns list of materials assigned to the object.\n\ +if i is nonzero, empty slots are not ignored: they are returned as None's."}, {"getMatrix", (PyCFunction)Object_getMatrix, METH_VARARGS, "Returns the object matrix - worlspace or localspace (default)"}, {"getName", (PyCFunction)Object_getName, METH_NOARGS, @@ -919,10 +920,17 @@ static PyObject *Object_getLocation (BPy_Object *self, PyObject *args) "couldn't get Object.loc attributes")); } -static PyObject *Object_getMaterials (BPy_Object *self) +static PyObject *Object_getMaterials (BPy_Object *self, PyObject *args) { + int all = 0; + + if (!PyArg_ParseTuple(args, "|i", &all)){ + return (EXPP_ReturnPyObjError (PyExc_AttributeError, + "expected an int or nothing")); + } + return (EXPP_PyList_fromMaterialList (self->object->mat, - self->object->totcol)); + self->object->totcol, all)); } static PyObject *Object_getMatrix (BPy_Object *self, PyObject *args) @@ -1258,7 +1266,7 @@ static PyObject *Object_link (BPy_Object *self, PyObject *args) if ( self->object->type == OB_MESH) { self->object->totcol = 0; - EXPP_synchronizeMaterialLists(self->object, id); + EXPP_synchronizeMaterialLists(self->object); } id_us_plus (id); @@ -1585,8 +1593,7 @@ static PyObject *Object_setMaterials (BPy_Object *self, PyObject *args) case OB_MESH: /* fall through */ case OB_MBALL: /* fall through */ case OB_SURF: - EXPP_synchronizeMaterialLists (self->object, - self->object->data); + EXPP_synchronizeMaterialLists (self->object); break; default: break; @@ -1679,13 +1686,13 @@ static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args) if (!PyArg_ParseTuple (args, "O", &object)) { - return EXPP_ReturnPyObjError (PyExc_AttributeError, + return EXPP_ReturnPyObjError (PyExc_TypeError, "expected an object argument"); } if (!Object_CheckPyObject ((PyObject*)object)) { return EXPP_ReturnPyObjError (PyExc_TypeError, - "argument 1 is not of type 'Object'"); + "first argument is not of type 'Object'"); } if (self->object->type != object->object->type) @@ -1708,9 +1715,9 @@ static PyObject *Object_shareFrom (BPy_Object *self, PyObject *args) if ( self->object->type == OB_MESH && id ){ self->object->totcol = 0; - EXPP_synchronizeMaterialLists(self->object, id); + EXPP_synchronizeMaterialLists(self->object); } - + id_us_plus (id); if (oldid) { diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c index fd48c5adfad..73ae020acbf 100644 --- a/source/blender/python/api2_2x/Window.c +++ b/source/blender/python/api2_2x/Window.c @@ -96,6 +96,8 @@ static PyObject *M_Window_GetKeyQualifiers (PyObject *self); static PyObject *M_Window_SetKeyQualifiers (PyObject *self, PyObject *args); static PyObject *M_Window_GetAreaSize (PyObject *self); static PyObject *M_Window_GetAreaID (PyObject *self); +static PyObject *M_Window_GetScreens (PyObject *self); +static PyObject *M_Window_SetScreen (PyObject *self, PyObject *args); static PyObject *M_Window_GetScreenInfo (PyObject *self, PyObject *args, PyObject *kwords); @@ -232,20 +234,28 @@ static char M_Window_GetAreaID_doc[] = static char M_Window_GetAreaSize_doc[] = "() - Get the current window's (area) size as [x,y]."; +static char M_Window_GetScreens_doc[] = +"() - Get a list with the names of all available screens."; + +static char M_Window_SetScreen_doc[] = +"(name) - Set current screen to the one with the given 'name'."; + static char M_Window_GetScreenInfo_doc[] = -"(type = -1, rect = 'win') - Get info about the current screen setup.\n\ +"(type = -1, rect = 'win', screen = None)\n\ +- Get info about the the areas in the current screen setup.\n\ (type = -1) - int: the space type (Blender.Window.Types) to restrict the\n\ results to, all if -1;\n\ -(rect = 'win') - the rectangle of interest. This defines if the corner\n\ +(rect = 'win') - str: the rectangle of interest. This defines if the corner\n\ coordinates returned will refer to:\n\ - the whole area: 'total';\n\ - only the header: 'header';\n\ - - only the window content (default): 'win'.\n\n\ + - only the window content (default): 'win'.\n\ +(screen = None) - str: the screen name, current if not given.\n\n\ A list of dictionaries (one for each area) is returned.\n\ Each dictionary has keys:\n\ 'vertices': [xmin, ymin, xmax, ymax] area corners;\n\ 'win': window type, see Blender.Window.Types dict;\n\ -'id': this area's id."; +'id': area's id."; /*****************************************************************************/ /* Python method structure definition for Blender.Window module: */ @@ -304,6 +314,10 @@ struct PyMethodDef M_Window_methods[] = { M_Window_GetAreaSize_doc}, {"GetAreaID", (PyCFunction)M_Window_GetAreaID, METH_NOARGS, M_Window_GetAreaID_doc}, + {"GetScreens", (PyCFunction)M_Window_GetScreens, METH_NOARGS, + M_Window_GetScreens_doc}, + {"SetScreen", (PyCFunction)M_Window_SetScreen, METH_VARARGS, + M_Window_SetScreen_doc}, {"GetScreenInfo", (PyCFunction)M_Window_GetScreenInfo, METH_VARARGS | METH_KEYWORDS, M_Window_GetScreenInfo_doc}, {NULL, NULL, 0, NULL} @@ -958,21 +972,75 @@ static PyObject *M_Window_GetAreaID(PyObject *self) return Py_BuildValue("h", sa->win); } +static PyObject *M_Window_SetScreen(PyObject *self, PyObject *args) +{ + bScreen *scr = G.main->screen.first; + char *name = NULL; + + if (!PyArg_ParseTuple(args, "s", &name)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "expected string as argument"); + + while (scr) { + if (!strcmp(scr->id.name+2, name)) { + setscreen(scr); + break; + } + scr = scr->id.next; + } + + if (!scr) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "no such screen, check Window.GetScreens() for valid names."); + + return EXPP_incr_ret(Py_None); +} + +static PyObject *M_Window_GetScreens(PyObject *self) +{ + bScreen *scr = G.main->screen.first; + PyObject *list = PyList_New(0); + PyObject *str = NULL; + + if (!list) + return EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create py list!"); + + while (scr) { + str = PyString_FromString(scr->id.name+2); + + if (!str) { + Py_DECREF(list); + return EXPP_ReturnPyObjError (PyExc_MemoryError, + "couldn't create py string!"); + } + + PyList_Append(list, str); /* incref's str */ + Py_DECREF(str); + + scr = scr->id.next; + } + + return list; +} + static PyObject *M_Window_GetScreenInfo(PyObject *self, PyObject *args, PyObject *kwords) { ScrArea *sa = G.curscreen->areabase.first; + bScreen *scr = G.main->screen.first; PyObject *item, *list; rcti *rct; int type = -1; char *rect = "win"; - static char *kwlist[] = {"type", "rect", NULL}; + char *screen = ""; + static char *kwlist[] = {"type", "rect", "screen", NULL}; int rctype = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwords, "|is", kwlist, &type, - &rect)) + if (!PyArg_ParseTupleAndKeywords(args, kwords, "|iss", kwlist, &type, + &rect, &screen)) return EXPP_ReturnPyObjError (PyExc_TypeError, - "expected nothing or an int and a string as arguments"); + "expected nothing or an int and two strings as arguments"); if (!strcmp(rect, "win")) rctype = 0; @@ -986,6 +1054,22 @@ static PyObject *M_Window_GetScreenInfo(PyObject *self, PyObject *args, list = PyList_New(0); + if (screen && screen[0] != '\0') { + while (scr) { + if (!strcmp(scr->id.name+2, screen)) { + sa = scr->areabase.first; + break; + } + scr = scr->id.next; + } + } + + if (!scr) { + Py_DECREF(list); + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "no such screen, see existing ones with Window.GetScreens."); + } + while (sa) { if (type != -1 && sa->spacetype != type) { sa = sa->next; diff --git a/source/blender/python/api2_2x/doc/Blender.py b/source/blender/python/api2_2x/doc/Blender.py index 985608b53b4..38a3cbc67bc 100644 --- a/source/blender/python/api2_2x/doc/Blender.py +++ b/source/blender/python/api2_2x/doc/Blender.py @@ -53,11 +53,11 @@ The Blender Python API Reference Introduction: ------------- - This Reference documents the Blender Python API, a growing collection of - Python modules (libs) that give access to part of the program's internal data - and functions. + This reference documents the Blender Python API, a growing collection of + Python modules (libraries) that give access to part of the program's internal + data and functions. - Through scripting, Blender can be extended in realtime. Possibilities range + Through scripting Blender can be extended in realtime. Possibilities range from simple functionality to importers / exporters and even more complex "applications". Blender scripts are written in U{Python }, an impressive high level, multi-paradigm, @@ -66,7 +66,8 @@ The Blender Python API Reference @author: The Blender Python Team @requires: Blender 2.34 or newer. @version: 2.34 -@see: U{www.blender.org} +@see: U{www.blender.org}: documentation and forum +@see: U{www.elysiun.com}: user forum @see: U{projects.blender.org} @see: U{www.python.org} @see: U{www.python.org/doc} diff --git a/source/blender/python/api2_2x/doc/NMesh.py b/source/blender/python/api2_2x/doc/NMesh.py index a1f9e9434bb..992ed27a4bf 100644 --- a/source/blender/python/api2_2x/doc/NMesh.py +++ b/source/blender/python/api2_2x/doc/NMesh.py @@ -3,7 +3,7 @@ """ The Blender.NMesh submodule. -B{New}: vertex selection. +B{New}: L{NMesh.getMaterials}, L{NMesh.setMaterials}. Mesh Data ========= @@ -235,7 +235,8 @@ class NMesh: object in Blender and NMesh as its Python counterpart. @cvar name: The NMesh name. It's common to use this field to store extra data about the mesh (to be exported to another program, for example). - @cvar materials: The list of materials used by this NMesh. + @cvar materials: The list of materials used by this NMesh. See + L{NMesh.getMaterials} for important details. @cvar verts: The list of NMesh vertices (NMVerts). @cvar users: The number of Objects using (linked to) this mesh. @cvar faces: The list of NMesh faces (NMFaces). @@ -254,6 +255,35 @@ class NMesh: @param material: A Blender Material. """ + def getMaterials(what = -1): + """ + Get this NMesh's list of materials. + @type what: int + @param what: determines the list's contents: + - -1: return the current nmesh's list; + - 0: retrieve a fresh list from the Blender mesh -- eventual + modifications made by the script not included, unless + L{NMesh.update}d is called before this method; + - 1: like 0, but empty slots are not ignored, they are returned as + None's. + @note: what >= 0 also updates nmesh.materials attribute. + @rtype: list of materials + @return: the requested list of materials. + @note: if a user goes to the material buttons window and removes some + mesh's link to a material, that material slot becomes empty. + Previously such materials were ignored. + """ + + def setMaterials(matlist): + """ + Set this NMesh's list of materials. This method checks the consistency of + the passed list: must only have materials or None's and can't contain more + than 16 entries. + @type matlist: list of materials + @param matlist: a list with materials, None's also accepted (they become + empty material slots in Blender. + """ + def hasVertexColours(flag = None): """ Get (and optionally set) if this NMesh has vertex colours. diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 4ddb576d05b..2cea8d90f75 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -277,9 +277,12 @@ class Object: @return: a python action. """ - def getMaterials(): + def getMaterials(what = 0): """ Returns a list of materials assigned to the object. + @type what: int + @param what: if nonzero, empty slots will be returned as None's instead + of being ignored (default way). See L{NMesh.NMesh.getMaterials}. @rtype: list of Material Objects @return: list of Material Objects assigned to the object. """ @@ -492,7 +495,7 @@ class Object: def shareFrom(object): """ - Link data of self with object specified in the argument. This works only + Link data of object specified in the argument with self. This works only if self and the object specified are of the same type. @type object: Blender Object @param object: A Blender Object of the same type. @@ -710,4 +713,4 @@ class Property: """ Get the type for this property. @rtype: string - """ \ No newline at end of file + """ diff --git a/source/blender/python/api2_2x/doc/Window.py b/source/blender/python/api2_2x/doc/Window.py index 941bc0df564..3626e38bc09 100644 --- a/source/blender/python/api2_2x/doc/Window.py +++ b/source/blender/python/api2_2x/doc/Window.py @@ -8,7 +8,7 @@ Window This module provides access to B{Window} functions in Blender. -B{New}: L{EditMode}, L{ViewLayer}, functions related to input events, etc. +B{New}: many new functions related to screens and events. Example: -------- @@ -360,7 +360,22 @@ def GetAreaSize (): returns for the 'vertices' of the same area. """ -def GetScreenInfo (type = -1, rect = 'win'): +def GetScreens (): + """ + Get the names of all available screens. + @rtype: list of strings + @return: a list of names that can be passed to L{SetScreen}. + """ + +def SetScreen (name): + """ + Set as current screen the one with the given name. + @type name: string + @param name: the name of an existing screen. Use L{GetScreens} to get + a list with all screen names. + """ + +def GetScreenInfo (type = -1, rect = 'win', screen = ''): """ Get info about the current screen setup. @type type: int @@ -373,6 +388,9 @@ def GetScreenInfo (type = -1, rect = 'win'): - the whole area: 'total' - only the header: 'header' - only the window content part (default): 'win' + @type screen: string + @param screen: the name of an available screen. The current one is used by + default. @rtype: list of dictionaries @return: a list of dictionaries, one for each area in the screen. Each dictionary has these keys (all values are ints): diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c index 20a6e92d9d2..3f8ff62cee2 100644 --- a/source/blender/python/api2_2x/gen_utils.c +++ b/source/blender/python/api2_2x/gen_utils.c @@ -145,17 +145,18 @@ int EXPP_check_sequence_consistency(PyObject *seq, PyTypeObject *against) { PyObject *ob; int len = PySequence_Length(seq); - int i; + int i, result = 1; for (i = 0; i < len; i++) { ob = PySequence_GetItem(seq, i); - if (ob->ob_type != against) { + if (ob == Py_None) result = 2; + else if (ob->ob_type != against) { Py_DECREF(ob); return 0; } Py_DECREF(ob); } - return 1; + return result; /* 1 if all of 'against' type, 2 if there are (also) Nones */ } PyObject *EXPP_tuple_repr(PyObject *self, int size) diff --git a/source/blender/python/api2_2x/modules.h b/source/blender/python/api2_2x/modules.h index b78da5595eb..f284184199f 100644 --- a/source/blender/python/api2_2x/modules.h +++ b/source/blender/python/api2_2x/modules.h @@ -100,9 +100,9 @@ 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); +int EXPP_synchronizeMaterialLists (Object *object); void EXPP_incr_mats_us (Material **matlist, int len); -PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len); +PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len, int all); Material * GetMaterialByName (char * name); /* Texture */ -- cgit v1.2.3