Index: source/blender/python/api2_2x/doc/Particle.py =================================================================== --- source/blender/python/api2_2x/doc/Particle.py (revision 15530) +++ source/blender/python/api2_2x/doc/Particle.py (working copy) @@ -137,7 +137,7 @@ @type id: int @param id: add the particle id in the end of the vector tuple @rtype: list of vectors (tuple of 3 floats and optionnaly the id) or list of list of vectors - @return: list of vectors or list of list of vectors (hair mode) + @return: list of vectors or list of list of vectors (hair mode) or None if system is disabled """ def getRot(all=0,id=0): """ @@ -150,7 +150,7 @@ @type id: int @param id: add the particle id in the return tuple @rtype: list of tuple of 4 or 5 elements (if id is not zero) - @return: list of 4-tuples + @return: list of 4-tuples or None if system is disabled """ def getMat(): @@ -169,7 +169,7 @@ @type id: int @param id: add the particle id in the return tuple @rtype: list of floats - @return: list of floats or list of tuples if id is not zero (size,id). + @return: list of floats or list of tuples if id is not zero (size,id) or None if system is disabled. """ def getAge(all=0,id=0): @@ -181,7 +181,7 @@ @type id: int @param id: add the particle id in the return tuple @rtype: list of floats - @return: list of floats or list of tuples if id is not zero (size,id). + @return: list of floats or list of tuples if id is not zero (size,id) or None if system is disabled. """ # Blender.Object module and the Object PyType object Index: source/blender/python/api2_2x/Particle.c =================================================================== --- source/blender/python/api2_2x/Particle.c (revision 15530) +++ source/blender/python/api2_2x/Particle.c (working copy) @@ -40,6 +40,7 @@ #include "BKE_material.h" #include "BKE_utildefines.h" #include "BKE_pointcache.h" +#include "BKE_DerivedMesh.h" #include "BIF_editparticle.h" #include "BIF_space.h" #include "blendef.h" @@ -803,18 +804,20 @@ ParticleSystem *psys = 0L; Object *ob = 0L; PyObject *partlist,*seglist; + ParticleCacheKey **cache,*path; PyObject* loc = 0L; - ParticleCacheKey **cache,*path; ParticleKey state; - float cfra=bsystem_time(ob,(float)CFRA,0.0); + DerivedMesh* dm; + float cfra = bsystem_time(ob,(float)CFRA,0.0); int i,j,k; + float hairstep,l,vm[16],wm[16]; int childexists = 0; int all = 0; int id = 0; if( !PyArg_ParseTuple( args, "|ii", &all,&id ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected one optional integer as argument" ); + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected one optional integer as argument" ); psys = self->psys; ob = self->object; @@ -822,49 +825,63 @@ if (!ob || !psys) Py_RETURN_NONE; - if (psys->part->type == 2){ - cache=psys->pathcache; + G.rendering = 1; + psys_render_set(ob,psys,vm,wm,10,10,0); - /* little hack to calculate hair steps in render mode */ - psys->renderdata = (void*)(int)1; + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); - psys_cache_paths(ob, psys, cfra, 1); + if ( !psys_check_enabled(ob,psys) ){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_INCREF(Py_None); + return Py_None; + } - psys->renderdata = NULL; + if (psys->part->type == 2){ + //hairstep = (float)(1.0/pow(2.0,(float)psys->part->ren_step)); partlist = PyList_New( 0 ); - if( !partlist ) + + if( !partlist ){ + G.rendering = 0; + psys_render_restore(ob,psys); return EXPP_ReturnPyObjError( PyExc_MemoryError, "PyList() failed" ); + } + cache = psys->pathcache; - for(i = 0; i < psys->totpart; i++){ - path=cache[i]; - seglist = PyList_New( 0 ); - k = path->steps+1; - for( j = 0; j < k ; j++){ - loc = PyTuple_New(3); + if ( ((self->psys->part->draw & PART_DRAW_PARENT) && (self->psys->part->childtype != 0)) || (self->psys->part->childtype == 0) ){ - PyTuple_SetItem(loc,0,PyFloat_FromDouble((double)path->co[0])); - PyTuple_SetItem(loc,1,PyFloat_FromDouble((double)path->co[1])); - PyTuple_SetItem(loc,2,PyFloat_FromDouble((double)path->co[2])); + for(i = 0; i < psys->totpart; i++){ + path=cache[i]; + seglist = PyList_New( 0 ); + k = path->steps+1; + for( j = 0; j < k ; j++){ + loc = PyTuple_New(3); - if ( (PyList_Append(seglist,loc) < 0) ){ + PyTuple_SetItem(loc,0,PyFloat_FromDouble((double)path->co[0])); + PyTuple_SetItem(loc,1,PyFloat_FromDouble((double)path->co[1])); + PyTuple_SetItem(loc,2,PyFloat_FromDouble((double)path->co[2])); + + if ( (PyList_Append(seglist,loc) < 0) ){ + Py_DECREF(seglist); + Py_DECREF(partlist); + Py_XDECREF(loc); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + } + Py_DECREF(loc); /* PyList_Append increfs */ + path++; + } + + if ( PyList_Append(partlist,seglist) < 0 ){ Py_DECREF(seglist); Py_DECREF(partlist); - Py_XDECREF(loc); return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "Couldn't append item to PyList" ); + "Couldn't append item to PyList" ); } - Py_DECREF(loc); /* PyList_Append increfs */ - path++; + Py_DECREF(seglist); /* PyList_Append increfs */ } - - if ( PyList_Append(partlist,seglist) < 0 ){ - Py_DECREF(seglist); - Py_DECREF(partlist); - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "Couldn't append item to PyList" ); - } - Py_DECREF(seglist); /* PyList_Append increfs */ } cache=psys->childcache; @@ -898,12 +915,14 @@ } Py_DECREF(seglist); /* PyList_Append increfs */ } - } else { int init; partlist = PyList_New( 0 ); - if( !partlist ) + if( !partlist ){ + G.rendering = 0; + psys_render_restore(ob,psys); return EXPP_ReturnPyObjError( PyExc_MemoryError, "PyList() failed" ); + } if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) childexists = 1; @@ -926,29 +945,37 @@ PyTuple_SetItem(loc,0,PyFloat_FromDouble((double)state.co[0])); PyTuple_SetItem(loc,1,PyFloat_FromDouble((double)state.co[1])); PyTuple_SetItem(loc,2,PyFloat_FromDouble((double)state.co[2])); + if (id) PyTuple_SetItem(loc,3,PyInt_FromLong(i)); if ( PyList_Append(partlist,loc) < 0 ){ + G.rendering = 0; + psys_render_restore(ob,psys); Py_DECREF(partlist); Py_XDECREF(loc); return EXPP_ReturnPyObjError( PyExc_RuntimeError, "Couldn't append item to PyList" ); } - Py_DECREF(loc);/* PyList_Append increfs */ + Py_DECREF(loc); } else { if ( all ){ if ( PyList_Append(partlist,Py_None) < 0 ){ + G.rendering = 0; + psys_render_restore(ob,psys); Py_DECREF(partlist); return EXPP_ReturnPyObjError( PyExc_RuntimeError, "Couldn't append item to PyList" ); } - Py_DECREF(Py_None); /* PyList_Append increfs */ } } } } + + G.rendering = 0; + psys_render_restore(ob,psys); + return partlist; } @@ -958,6 +985,8 @@ PyObject *partlist = 0L; PyObject* loc = 0L; ParticleKey state; + DerivedMesh* dm; + float vm[16],wm[16]; int i; int childexists = 0; int all = 0; @@ -966,8 +995,8 @@ float cfra=bsystem_time(ob,(float)CFRA,0.0); if( !PyArg_ParseTuple( args, "|ii", &all, &id ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected one optional integer as argument" ); + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected one optional integer as argument" ); psys = self->psys; ob = self->object; @@ -975,9 +1004,28 @@ if (!ob || !psys) Py_RETURN_NONE; + G.rendering = 1; + psys_render_set(ob,psys,vm,wm,10,10,0); + + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); + + if ( !psys_check_enabled(ob,psys) ){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_INCREF(Py_None); + return Py_None; + } + if (psys->part->type != 2){ partlist = PyList_New( 0 ); + if( !partlist ){ + G.rendering = 0; + psys_render_restore(ob,psys); + return EXPP_ReturnPyObjError( PyExc_MemoryError, "PyList() failed" ); + } + if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) childexists = 1; @@ -988,8 +1036,12 @@ state.time = cfra; if(psys_get_particle_state(ob,psys,i,&state,0)==0){ if ( all ){ - PyList_Append(partlist,Py_None); - Py_DECREF(Py_None); /* PyList_Append increfs */ + if( PyList_Append(partlist,Py_None) < 0){ + G.rendering = 0; + psys_render_restore(ob,psys); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + } continue; } else { continue; @@ -1005,10 +1057,22 @@ PyTuple_SetItem(loc,3,PyFloat_FromDouble((double)state.rot[3])); if (id) PyTuple_SetItem(loc,4,PyInt_FromLong(i)); - PyList_Append(partlist,loc); + + if (PyList_Append(partlist,loc) < 0){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_DECREF(partlist); + Py_XDECREF(loc); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + } Py_DECREF(loc); /* PyList_Append increfs */ } } + + G.rendering = 0; + psys_render_restore(ob,psys); + return partlist; } @@ -1019,6 +1083,8 @@ Object *ob = 0L; PyObject *partlist,*tuple; PyObject* siz = 0L; + DerivedMesh* dm; + float vm[16],wm[16]; float size; int i; int childexists = 0; @@ -1039,12 +1105,31 @@ if (!ob || !psys) Py_RETURN_NONE; - partlist = PyList_New( 0 ); + G.rendering = 1; + psys_render_set(ob,psys,vm,wm,10,10,0); - if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) - childexists = 1; + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); - for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ + if ( !psys_check_enabled(ob,psys) ){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_INCREF(Py_None); + return Py_None; + } + + partlist = PyList_New( 0 ); + + if( !partlist ){ + G.rendering = 0; + psys_render_restore(ob,psys); + return EXPP_ReturnPyObjError( PyExc_MemoryError, "PyList() failed" ); + } + + if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) + childexists = 1; + + for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ if (psys->part->type != 2){ if (childexists && (i < psys->totpart)) continue; @@ -1061,19 +1146,40 @@ ChildParticle *cpa= &psys->child[i-psys->totpart]; size = psys_get_child_size(psys,cpa,cfra,0); } + if (id){ + tuple = PyTuple_New(2); PyTuple_SetItem(tuple,0,PyFloat_FromDouble((double)size)); PyTuple_SetItem(tuple,1,PyInt_FromLong(i)); - PyList_Append(partlist,tuple); + + if (PyList_Append(partlist,tuple) < 0){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_DECREF(partlist); + Py_XDECREF(tuple); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + } Py_DECREF(tuple); } else { siz = PyFloat_FromDouble((double)size); - PyList_Append(partlist,siz); + if(PyList_Append(partlist,siz) < 0){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_DECREF(partlist); + Py_XDECREF(siz); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + } Py_DECREF(siz); } } } + + G.rendering = 0; + psys_render_restore(ob,psys); + return partlist; } @@ -1085,6 +1191,8 @@ Object *ob = 0L; PyObject *partlist,*tuple; PyObject* lif = 0L; + DerivedMesh* dm; + float vm[16],wm[16]; float life; int i; int childexists = 0; @@ -1105,12 +1213,30 @@ if (!ob || !psys) Py_RETURN_NONE; - partlist = PyList_New( 0 ); + G.rendering = 1; + psys_render_set(ob,psys,vm,wm,10,10,0); - if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) - childexists = 1; + dm = mesh_create_derived_render(ob,CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL); + dm->release(dm); - for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ + if ( !psys_check_enabled(ob,psys) ){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_INCREF(Py_None); + return Py_None; + } + + partlist = PyList_New( 0 ); + if( !partlist ){ + G.rendering = 0; + psys_render_restore(ob,psys); + return EXPP_ReturnPyObjError( PyExc_MemoryError, "PyList() failed" ); + } + + if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT)) + childexists = 1; + + for (i = 0; i < psys->totpart + psys->totchild; i++, data++){ if (psys->part->type != 2){ if (childexists && (i < psys->totpart)) @@ -1129,18 +1255,38 @@ life = psys_get_child_time(psys,cpa,cfra); } if (id){ + tuple = PyTuple_New(2); PyTuple_SetItem(tuple,0,PyFloat_FromDouble((double)life)); + PyTuple_SetItem(tuple,1,PyInt_FromLong(i)); - PyList_Append(partlist,tuple); + if (PyList_Append(partlist,tuple) < 0){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_DECREF(partlist); + Py_XDECREF(tuple); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + } Py_DECREF(tuple); } else { lif = PyFloat_FromDouble((double)life); - PyList_Append(partlist,lif); + if (PyList_Append(partlist,lif) < 0){ + G.rendering = 0; + psys_render_restore(ob,psys); + Py_DECREF(partlist); + Py_XDECREF(lif); + return EXPP_ReturnPyObjError( PyExc_RuntimeError, + "Couldn't append item to PyList" ); + } Py_DECREF(lif); } } } + + G.rendering = 0; + psys_render_restore(ob,psys); + return partlist; }