Index: doc/Particle.py =================================================================== --- doc/Particle.py (revisión: 20159) +++ doc/Particle.py (copia de trabajo) @@ -42,6 +42,20 @@ - OBJECT: Draw object - GROUP: Draw group - BILLBOARD: Draw as billboard +@type VERTEXGROUPS: readonly dictionary +@var VERTEXGROUPS: Constant dict used for with L{Particle.VERTEXGROUP} + - DENSITY: VertexGroup affect to particles density + - VELOCITY: VertexGroup affect to particles velocity + - LENGHT: VertexGroup affect to particles lenght + - CLUMP: VertexGroup affect to particles clump + - KINK: VertexGroup affect to particles kink + - ROUGH1: VertexGroup affect to particles rough1 + - ROUGH2: VertexGroup affect to particles rough2 + - ROUGHE: VertexGroup affect to particles roughE + - SIZE: VertexGroup affect to particles size + - TANVEL: VertexGroup affect to particles tangent velocity + - TANROT: VertexGroup affect to particles tangent rotation + - EFFECTOR: VertexGroup affect to particles effector @type CHILDTYPE: readonly dictionary @var CHILDTYPE: Constant dict used for whith L{Particle.CHILDTYPE} - NONE: set no children @@ -250,3 +264,24 @@ @rtype: list of floats @return: list of floats or list of tuples if id is not zero (size,id) or None if system is disabled. """ + + def getVertGroup(attribute): + """ + Get vertex group name and negation bit assigned to affect parameter attribute. + A list of string and integer (vertex group name, negation bit). + @type attribute: int + @param attribute: Particle.VERTEXGROUPS([ 'DENSITY' | 'VELOCITY' | ... ]) + @rtype: list of objects + @return: first element is the vg name and second the negation bit + """ + def setVertGroup(name,attribute,negated): + """ + Set vertex group and negation bit to affect particles system attribute. + @type name: string + @param name: Name of the vertex group + @type attribute: int + @param attribute: Particle.VERTEXGROUPS([ 'DENSITY' | 'VELOCITY' | ... ]) + @type negated: int + @param negated: Negate the effect of the vertex group + @return: None + """ Index: Particle.c =================================================================== --- Particle.c (revisión: 20159) +++ Particle.c (copia de trabajo) @@ -66,6 +66,8 @@ static PyObject *Part_GetRot( BPy_PartSys * self, PyObject * args ); static PyObject *Part_GetMat( BPy_PartSys * self, PyObject * args ); static PyObject *Part_GetSize( BPy_PartSys * self, PyObject * args ); +static PyObject *Part_GetVertGroup( BPy_PartSys * self, PyObject * args ); +static PyObject *Part_SetVertGroup( BPy_PartSys * self, PyObject * args ); static int Part_setSeed( BPy_PartSys * self, PyObject * args ); static PyObject *Part_getSeed( BPy_PartSys * self ); static int Part_setType( BPy_PartSys * self, PyObject * args ); @@ -219,6 +221,10 @@ METH_VARARGS, "() - Get particles size in a list"}, {"getAge", ( PyCFunction ) Part_GetAge, METH_VARARGS, "() - Get particles life in a list"}, + {"getVertGroup", ( PyCFunction ) Part_GetVertGroup, + METH_VARARGS, "() - Get the vertex group which affects a particles attribute"}, + {"setVertGroup", ( PyCFunction ) Part_SetVertGroup, + METH_VARARGS, "() - Set the vertex group to affect a particles attribute"}, {NULL, NULL, 0, NULL} }; @@ -879,6 +885,43 @@ return ChildTypes; } +/* create the Blender.Particle.VertexGroups constant dict */ + +static PyObject *Particle_VertexGroupsDict( void ) +{ + PyObject *VertexGroups = PyConstant_New( ); + + if( VertexGroups ) { + BPy_constant *c = ( BPy_constant * ) VertexGroups; + + PyConstant_Insert( c, "EFFECTOR", + PyInt_FromLong( 11 ) ); + PyConstant_Insert( c, "TANROT", + PyInt_FromLong( 10 ) ); + PyConstant_Insert( c, "TANVEL", + PyInt_FromLong( 9 ) ); + PyConstant_Insert( c, "SIZE", + PyInt_FromLong( 8 ) ); + PyConstant_Insert( c, "ROUGHE", + PyInt_FromLong( 7 ) ); + PyConstant_Insert( c, "ROUGH2", + PyInt_FromLong( 6 ) ); + PyConstant_Insert( c, "ROUGH1", + PyInt_FromLong( 5 ) ); + PyConstant_Insert( c, "KINK", + PyInt_FromLong( 4 ) ); + PyConstant_Insert( c, "CLUMP", + PyInt_FromLong( 3 ) ); + PyConstant_Insert( c, "LENGHT", + PyInt_FromLong( 2 ) ); + PyConstant_Insert( c, "VELOCITY", + PyInt_FromLong( 1 ) ); + PyConstant_Insert( c, "DENSITY", + PyInt_FromLong( 0 ) ); + } + return VertexGroups; +} + /* create the Blender.Particle.ChildKink constant dict */ static PyObject *Particle_ChildKinkDict( void ) @@ -967,6 +1010,7 @@ PyObject *EmitFrom; PyObject *Dist; PyObject *DrawAs; + PyObject *VertexGroups; PyObject *ChildTypes; PyObject *ChildKinks; PyObject *ChildKinkAxes; @@ -980,6 +1024,7 @@ EmitFrom = Particle_EmitFrom(); DrawAs = Particle_DrawAs(); Dist = Particle_DistrDict(); + VertexGroups = Particle_VertexGroupsDict(); ChildTypes = Particle_ChildTypeDict(); ChildKinks = Particle_ChildKinkDict(); ChildKinkAxes = Particle_ChildKinkAxisDict(); @@ -997,6 +1042,8 @@ PyModule_AddObject( submodule, "DISTRIBUTION", Dist ); if( DrawAs ) PyModule_AddObject( submodule, "DRAWAS", DrawAs ); + if( VertexGroups ) + PyModule_AddObject( submodule, "VERTEXGROUPS", VertexGroups ); if( ChildTypes ) PyModule_AddObject( submodule, "CHILDTYPE", ChildTypes ); if( ChildKinks ) @@ -1552,7 +1599,111 @@ return mat; } +static PyObject *Part_GetVertGroup( BPy_PartSys * self, PyObject * args ){ + PyObject *list; + char errstr[128]; + bDeformGroup *defGroup = NULL; + Object *obj = self->object; + int vg_attribute = 0; + int vg_number = 0; + int count; + PyObject *vg_neg; + PyObject *vg_name; + if( !obj ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "particle system must be linked to an object first" ); + + if( obj->type != OB_MESH ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "linked object is not a mesh" ); + + if( !PyArg_ParseTuple( args, "i", &vg_attribute ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected integer argument" ); + + if( vg_attribute < 0 || vg_attribute > PSYS_TOT_VG-1 ){ + sprintf ( errstr, "expected int argument in [0,%d]", PSYS_TOT_VG-1 ); + return EXPP_ReturnPyObjError( PyExc_TypeError, errstr ); + } + + /*search*/ + vg_number = self->psys->vgroup[vg_attribute]; + count = 1; + defGroup = obj->defbase.first; + while(countnext; + count++; + } + + /*vg_name*/ + if (defGroup && vg_number>0) + vg_name = PyString_FromString( defGroup->name ); + else + vg_name = PyString_FromString( "None" ); + + /*vg_neg*/ + vg_neg = PyInt_FromLong( ((long)( self->psys->vg_neg & (1< 0 ); + + list = PyList_New( 2 ); + PyList_SET_ITEM( list, 0, vg_name ); + PyList_SET_ITEM( list, 1, vg_neg ); + + return list; +} + +static PyObject *Part_SetVertGroup( BPy_PartSys * self, PyObject * args ){ + char errstr[128]; + bDeformGroup *defGroup; + Object *obj = self->object; + char *vg_name = NULL; + int vg_attribute = 0; + int vg_neg = 0; + int vg_number = 0; + int count; + + if( !obj ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "particle system must be linked to an object first" ); + + if( obj->type != OB_MESH ) + return EXPP_ReturnPyObjError( PyExc_AttributeError, + "linked object is not a mesh" ); + + if( !PyArg_ParseTuple( args, "sii", &vg_name, &vg_attribute, &vg_neg ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected one string and two integers arguments" ); + + if( vg_attribute < 0 || vg_attribute > PSYS_TOT_VG-1 ){ + sprintf ( errstr, "expected int argument in [0,%d]", PSYS_TOT_VG-1 ); + return EXPP_ReturnPyObjError( PyExc_TypeError, errstr ); + } + + /*search*/ + count = 1; + defGroup = obj->defbase.first; + while (defGroup){ + if (strcmp(vg_name,defGroup->name)==0) + vg_number = count; + defGroup = defGroup->next; + count++; + } + + /*vgroup*/ + self->psys->vgroup[vg_attribute] = vg_number; + + /*vg_neg*/ + if (vg_neg){ + self->psys->vg_neg |= (1<psys->vg_neg &= ~(1<psys->part, PSYS_ALLOC, 1 ); + + Py_RETURN_NONE; +} + /*****************************************************************************/ /* Function: Set/Get Seed */ /*****************************************************************************/