Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-05-13 01:27:01 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-05-13 01:27:01 +0400
commit3c0f6b65fb5491c73c9fc79889e818f277400bd2 (patch)
tree03594ca794005e1833fe0b3e1b89278a9364364c
parent7d923df2bf524c0155439c2d68cd0f512c93b794 (diff)
[#18711] Particle render API for Python
from Alberto Santos (dnakhain)
-rw-r--r--source/blender/python/api2_2x/Particle.c173
-rw-r--r--source/blender/python/api2_2x/doc/Particle.py19
2 files changed, 192 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Particle.c b/source/blender/python/api2_2x/Particle.c
index ac3e418bb6a..5d40763bb3e 100644
--- a/source/blender/python/api2_2x/Particle.c
+++ b/source/blender/python/api2_2x/Particle.c
@@ -64,6 +64,7 @@ static PyObject *M_ParticleSys_Get( PyObject * self, PyObject * args );
static PyObject *Part_freeEdit( BPy_PartSys * self, PyObject * args );
static PyObject *Part_GetLoc( BPy_PartSys * self, PyObject * args );
static PyObject *Part_GetRot( BPy_PartSys * self, PyObject * args );
+static PyObject *Part_SetMat( BPy_PartSys * self, PyObject * args );
static PyObject *Part_GetMat( BPy_PartSys * self, PyObject * args );
static PyObject *Part_GetSize( BPy_PartSys * self, PyObject * args );
static int Part_setSeed( BPy_PartSys * self, PyObject * args );
@@ -127,6 +128,16 @@ static int Part_setTargetPsys( BPy_PartSys * self, PyObject * args );
static PyObject *Part_getTargetPsys( BPy_PartSys * self );
static int Part_setRenderObject( BPy_PartSys * self, PyObject * args );
static PyObject *Part_getRenderObject( BPy_PartSys * self );
+static int Part_setRenderMaterialColor( BPy_PartSys * self, PyObject * args );
+static PyObject *Part_getRenderMaterialColor( BPy_PartSys * self );
+static int Part_setRenderParents( BPy_PartSys * self, PyObject * args );
+static PyObject *Part_getRenderParents( BPy_PartSys * self );
+static int Part_setRenderUnborn( BPy_PartSys * self, PyObject * args );
+static PyObject *Part_getRenderUnborn( BPy_PartSys * self );
+static int Part_setRenderDied( BPy_PartSys * self, PyObject * args );
+static PyObject *Part_getRenderDied( BPy_PartSys * self );
+static int Part_setRenderMaterialIndex( BPy_PartSys * self, PyObject * args );
+static PyObject *Part_getRenderMaterialIndex( BPy_PartSys * self );
static int Part_setStep( BPy_PartSys * self, PyObject * args );
static PyObject *Part_getStep( BPy_PartSys * self );
static int Part_setRenderStep( BPy_PartSys * self, PyObject * args );
@@ -257,6 +268,8 @@ static PyMethodDef BPy_ParticleSys_methods[] = {
METH_VARARGS, "() - Get particles location"},
{"getRot", ( PyCFunction ) Part_GetRot,
METH_VARARGS, "() - Get particles rotations (list of 4 floats quaternion)"},
+ {"setMat", ( PyCFunction ) Part_SetMat,
+ METH_VARARGS, "() - Set particles material"},
{"getMat", ( PyCFunction ) Part_GetMat,
METH_NOARGS, "() - Get particles material"},
{"getSize", ( PyCFunction ) Part_GetSize,
@@ -390,6 +403,26 @@ static PyGetSetDef BPy_ParticleSys_getseters[] = {
(getter)Part_getRenderObject, (setter)Part_setRenderObject,
"Render emitter object",
NULL},
+ {"renderMatCol",
+ (getter)Part_getRenderMaterialColor, (setter)Part_setRenderMaterialColor,
+ "Draw particles using material's diffuse color",
+ NULL},
+ {"renderParents",
+ (getter)Part_getRenderParents, (setter)Part_setRenderParents,
+ "Render parent particles",
+ NULL},
+ {"renderUnborn",
+ (getter)Part_getRenderUnborn, (setter)Part_setRenderUnborn,
+ "Show particles before they are emitted",
+ NULL},
+ {"renderDied",
+ (getter)Part_getRenderDied, (setter)Part_setRenderDied,
+ "Show particles after they have died",
+ NULL},
+ {"renderMaterial",
+ (getter)Part_getRenderMaterialIndex, (setter)Part_setRenderMaterialIndex,
+ "Specify material index used for the particles",
+ NULL},
{"displayPercentage",
(getter)Part_getParticleDisp, (setter)Part_setParticleDisp,
"Particle display percentage",
@@ -1778,6 +1811,37 @@ error:
return NULL;
}
+static PyObject *Part_SetMat( BPy_PartSys * self, PyObject * args )
+{
+ Object *ob = self->object;
+ BPy_Material *pymat;
+ Material *mat;
+ short index;
+
+ if( !PyArg_ParseTuple( args, "O!", &Material_Type, &pymat ) )
+ return EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected Blender Material PyObject" );
+
+ mat = pymat->material;
+
+ if( ob->totcol >= MAXMAT )
+ return EXPP_ReturnPyObjError( PyExc_RuntimeError,
+ "object data material lists can't have more than 16 materials" );
+
+ index = find_material_index(ob,mat);
+ if (index == 0){ /*Not found*/
+ assign_material(ob,mat,ob->totcol+1);
+ index = find_material_index(ob,mat);
+ }
+
+ if (index>0 && index<MAXMAT)
+ self->psys->part->omat = index;
+
+ /* since we have messed with object, we need to flag for DAG recalc */
+ self->object->recalc |= OB_RECALC_OB;
+
+ Py_RETURN_NONE;
+}
static PyObject *Part_GetMat( BPy_PartSys * self, PyObject * args ){
Material *ma;
@@ -2387,6 +2451,115 @@ static PyObject *Part_getRenderObject( BPy_PartSys * self )
return PyInt_FromLong( ((long)( self->psys->part->draw & PART_DRAW_EMITTER )) > 0 );
}
+static int Part_setRenderMaterialColor( BPy_PartSys * self, PyObject * args )
+{
+ int number;
+
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError( PyExc_TypeError, "expected int argument" );
+
+ number = PyInt_AS_LONG( args );
+
+ if (number){
+ self->psys->part->draw |= PART_DRAW_MAT_COL;
+ }else{
+ self->psys->part->draw &= ~PART_DRAW_MAT_COL;
+ }
+
+ psys_flush_settings( self->psys->part, PSYS_ALLOC, 1 );
+
+ return 0;
+}
+
+static PyObject *Part_getRenderMaterialColor( BPy_PartSys * self )
+{
+ return PyInt_FromLong( ((long)( self->psys->part->draw & PART_DRAW_MAT_COL )) > 0 );
+}
+
+static int Part_setRenderParents( BPy_PartSys * self, PyObject * args )
+{
+ int number;
+
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError( PyExc_TypeError, "expected int argument" );
+
+ number = PyInt_AS_LONG( args );
+
+ if (number){
+ self->psys->part->draw |= PART_DRAW_PARENT;
+ }else{
+ self->psys->part->draw &= ~PART_DRAW_PARENT;
+ }
+
+ return 0;
+}
+
+static PyObject *Part_getRenderParents( BPy_PartSys * self )
+{
+ return PyInt_FromLong( ((long)( self->psys->part->draw & PART_DRAW_PARENT )) > 0 );
+}
+
+static int Part_setRenderUnborn( BPy_PartSys * self, PyObject * args )
+{
+ int number;
+
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError( PyExc_TypeError, "expected int argument" );
+
+ number = PyInt_AS_LONG( args );
+
+ if (number){
+ self->psys->part->flag |= PART_UNBORN;
+ }else{
+ self->psys->part->flag &= ~PART_UNBORN;
+ }
+
+ return 0;
+}
+
+static PyObject *Part_getRenderUnborn( BPy_PartSys * self )
+{
+ return PyInt_FromLong( ((long)( self->psys->part->flag & PART_UNBORN )) > 0 );
+}
+
+static int Part_setRenderDied( BPy_PartSys * self, PyObject * args )
+{
+ int number;
+
+ if( !PyInt_Check( args ) )
+ return EXPP_ReturnIntError( PyExc_TypeError, "expected int argument" );
+
+ number = PyInt_AS_LONG( args );
+
+ if (number){
+ self->psys->part->flag |= PART_DIED;
+ }else{
+ self->psys->part->flag &= ~PART_DIED;
+ }
+
+ return 0;
+}
+
+static int Part_setRenderMaterialIndex( BPy_PartSys * self, PyObject * args )
+{
+ int res = EXPP_setIValueRange( args, &self->psys->part->omat,
+ 1, 16, 'i' );
+
+ psys_flush_settings( self->psys->part, PSYS_ALLOC, 1 );
+
+ return res;
+}
+
+static PyObject *Part_getRenderMaterialIndex( BPy_PartSys * self )
+{
+ return PyInt_FromLong( ((int)( self->psys->part->omat )) );
+}
+
+static PyObject *Part_getRenderDied( BPy_PartSys * self )
+{
+ return PyInt_FromLong( ((long)( self->psys->part->flag & PART_DIED )) > 0 );
+}
+
static int Part_setParticleDisp( BPy_PartSys * self, PyObject * args )
{
int res = EXPP_setIValueRange( args, &self->psys->part->disp,
diff --git a/source/blender/python/api2_2x/doc/Particle.py b/source/blender/python/api2_2x/doc/Particle.py
index 962e8c16249..82d197f71dd 100644
--- a/source/blender/python/api2_2x/doc/Particle.py
+++ b/source/blender/python/api2_2x/doc/Particle.py
@@ -152,6 +152,16 @@ class Particle:
@type object: Blender Object
@ivar renderEmitter: Render emitter object.
@type renderEmitter: int
+ @ivar renderMatCol: Draw particles using material's diffuse color.
+ @type renderMatCol: int
+ @ivar renderParents: Render parent particles.
+ @type renderParents: int
+ @ivar renderUnborn: Show particles before they are emitted.
+ @type renderUnborn: int
+ @ivar renderDied: Show particles after they have died.
+ @type renderDied: int
+ @ivar renderMaterial: Specify material used for the particles.
+ @type renderMaterial: int
@ivar displayPercentage: Particle display percentage.
@type displayPercentage: int
@ivar hairDisplayStep: How many steps paths are drawn with (power of 2) in visu mode.
@@ -291,6 +301,15 @@ class Particle:
@return: list of 4-tuples or None if system is disabled
"""
+ def setMat(mat):
+ """
+ Set the particles' material. This method checks if the argument
+ given is really a material, imposes a limit of 16 materials and adds
+ the material if it wasn't already in the list of the object.
+ @type mat: Blender Material
+ @param mat: The material to be assigned to particles
+ """
+
def getMat():
"""
Get the particles' material.