Initial commit for BPy Particle patch #8557 from Cedric Paille

Thanks, Cedric!

*** WARNING ****   This is a Work In Progress   *** Warning ****
This commit is contained in:
Stephen Swaney 2008-05-11 04:15:21 +00:00
parent 33568c3f24
commit a2c10ff1e7
7 changed files with 2190 additions and 870 deletions

@ -96,6 +96,7 @@ struct ID; /*keep me up here */
#include "Window.h"
#include "World.h"
#include "Types.h"
#include "Particle.h"
/**********************************************************/
/* Python API function prototypes for the Blender module. */
@ -1074,6 +1075,7 @@ void M_Blender_Init(void)
PyDict_SetItemString(dict, "Node", Node_Init());
PyDict_SetItemString(dict, "Noise", Noise_Init());
PyDict_SetItemString(dict, "Object", Object_Init());
PyDict_SetItemString(dict, "Particle", ParticleSys_Init());
PyDict_SetItemString(dict, "Group", Group_Init());
PyDict_SetItemString(dict, "Registry", Registry_Init());
PyDict_SetItemString(dict, "Scene", Scene_Init());

@ -27,7 +27,7 @@
*
* Contributor(s): Michel Selten, Willian Germano, Jacques Guignot,
* Joseph Gilbert, Stephen Swaney, Bala Gi, Campbell Barton, Johnny Matthews,
* Ken Hughes, Alex Mole, Jean-Michel Soler
* Ken Hughes, Alex Mole, Jean-Michel Soler, Cedric Paille
*
* ***** END GPL LICENSE BLOCK *****
*/
@ -117,6 +117,7 @@ struct rctf;
#include "EXPP_interface.h"
#include "BIF_editkey.h"
#include "IDProp.h"
#include "Particle.h"
/* Defines for insertIpoKey */
@ -336,6 +337,9 @@ struct PyMethodDef M_Object_methods[] = {
static int setupSB(Object* ob); /*Make sure Softbody Pointer is initialized */
static int setupPI(Object* ob);
static PyObject *Object_getParticleSys( BPy_Object * self );
/* fixme Object_newParticleSys( self, default-partsys-name ) */
static PyObject *Object_newParticleSys( BPy_Object * self );
static PyObject *Object_buildParts( BPy_Object * self );
static PyObject *Object_clearIpo( BPy_Object * self );
static PyObject *Object_clrParent( BPy_Object * self, PyObject * args );
@ -465,6 +469,10 @@ static PyObject *Object_upAxis(BPy_Object * self);
/*****************************************************************************/
static PyMethodDef BPy_Object_methods[] = {
/* name, method, flags, doc */
{"getParticleSystems", ( PyCFunction ) Object_getParticleSys, METH_NOARGS,
"Return a list of particle systems"},
{"newParticleSystem", ( PyCFunction ) Object_newParticleSys, METH_NOARGS,
"Create and link a new particle system"},
{"buildParts", ( PyCFunction ) Object_buildParts, METH_NOARGS,
"Recalcs particle system (if any), (depricated, will always return an empty list in version 2.46)"},
{"getIpo", ( PyCFunction ) Object_getIpo, METH_NOARGS,
@ -1026,6 +1034,78 @@ static PyObject *M_Object_Duplicate( PyObject * self_unused,
/* Python BPy_Object methods: */
/*****************************************************************************/
PyObject *Object_getParticleSys( BPy_Object * self ){
ParticleSystem *blparticlesys = 0;
Object *ob = self->object;
PyObject *partsyslist,*current;
blparticlesys = ob->particlesystem.first;
partsyslist = PyList_New( 0 );
if (!blparticlesys)
return partsyslist;
current = ParticleSys_CreatePyObject( blparticlesys, ob );
PyList_Append(partsyslist,current);
while(blparticlesys = blparticlesys->next){
current = ParticleSys_CreatePyObject( blparticlesys, ob );
PyList_Append(partsyslist,current);
}
return partsyslist;
}
PyObject *Object_newParticleSys( BPy_Object * self ){
ParticleSystem *psys = 0;
ParticleSystem *rpsys = 0;
ModifierData *md;
ParticleSystemModifierData *psmd;
Object *ob = self->object;
char *name = NULL;
ID *id;
int nr;
id = (ID *)psys_new_settings("PSys", G.main);
psys = MEM_callocN(sizeof(ParticleSystem), "particle_system");
psys->pointcache = BKE_ptcache_add();
psys->flag |= PSYS_ENABLED;
BLI_addtail(&ob->particlesystem,psys);
md = modifier_new(eModifierType_ParticleSystem);
sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
psmd = (ParticleSystemModifierData*) md;
psmd->psys=psys;
BLI_addtail(&ob->modifiers, md);
psys->part=(ParticleSettings*)id;
psys->totpart=0;
psys->flag=PSYS_ENABLED|PSYS_CURRENT;
psys->cfra=bsystem_time(ob,(float)G.scene->r.cfra+1,0.0);
rpsys = psys;
/* check need for dupliobjects */
nr=0;
for(psys=ob->particlesystem.first; psys; psys=psys->next){
if(ELEM(psys->part->draw_as,PART_DRAW_OB,PART_DRAW_GR))
nr++;
}
if(nr)
ob->transflag |= OB_DUPLIPARTS;
else
ob->transflag &= ~OB_DUPLIPARTS;
BIF_undo_push("Browse Particle System");
DAG_scene_sort(G.scene);
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
return ParticleSys_CreatePyObject(rpsys,ob);
}
static PyObject *Object_buildParts( BPy_Object * self )
{
/* This is now handles by modifiers */

File diff suppressed because it is too large Load Diff

@ -22,43 +22,32 @@
*
* This is a new part of Blender.
*
* Contributor(s): Jacques Guignot
* Contributor(s): Jacques Guignot, Cedric Paille
*
* ***** END GPL LICENSE BLOCK *****
*/
*/
#ifndef EXPP_PARTICLE_H
#define EXPP_PARTICLE_H
#ifndef EXPP_PARTICLESYS_H
#define EXPP_PARTICLESYS_H
#include <Python.h>
#include "DNA_effect_types.h"
#include "DNA_particle_types.h"
#include "DNA_object_types.h"
extern PyTypeObject Particle_Type;
extern PyTypeObject ParticleSys_Type;
#define BPy_Particle_Check(v) ((v)->ob_type==&Particle_Type)
#define BPy_ParticleSys_Check(v) \
((v)->ob_type == &ParticleSys_Type) /* for type checking */
/* Python BPy_Particle structure definition */
/* Python BPy_Effect structure definition */
typedef struct {
PyObject_HEAD /* required py macro */
Effect * particle;
} BPy_Particle;
ParticleSystem *psys;
Object *object; /* fixeme: if this points back to the parent object,it is wrong */
} BPy_PartSys;
#include "Effect.h"
/*****************************************************************************/
/* Python Particle_Type callback function prototypes: */
/*****************************************************************************/
#if 0
void ParticleDeAlloc( BPy_Particle * msh );
//int ParticlePrint (BPy_Particle *msh, FILE *fp, int flags);
int ParticleSetAttr( BPy_Particle * msh, char *name, PyObject * v );
PyObject *ParticleGetAttr( BPy_Particle * msh, char *name );
PyObject *ParticleRepr( void );
PyObject *ParticleCreatePyObject( struct Effect *particle );
int ParticleCheckPyObject( PyObject * py_obj );
struct Particle *ParticleFromPyObject( PyObject * py_obj );
#endif
PyObject *ParticleSys_Init( void );
PyObject *ParticleSys_CreatePyObject( ParticleSystem * psystem, Object *ob );
#endif /* EXPP_PARTICLE_H */
#endif /* EXPP_EFFECT_H */

@ -46,6 +46,7 @@ The Blender Python API Reference
- L{Pose} (*)
- L{Constraint} (*)
- L{ActionStrips<NLA>} (*)
- L{Particle}
- L{Registry}
- L{Scene} (*)
- L{Radio}

@ -641,6 +641,15 @@ class Object:
@ivar upAxis: Up axis. Return string 'Y' | 'Y' | 'Z' (readonly)
@type upAxis: string
"""
def getParticleSystems():
"""
Return a list of particle systems linked to this object (see Blender.Particle).
"""
def newParticleSystem():
"""
Link a new particle system (see Blender.Particle).
"""
def buildParts():
"""

@ -0,0 +1,367 @@
# Blender.Object module and the Object PyType object
"""
The Blender.Particle submodule
Particle
========
This module provides access to the B{Particle} in Blender.
@type TYPE: readonly dictionary
@var TYPE: Constant dict used for with L{Particle.TYPE}
- HAIR: set particle system to hair mode.
- REACTOR: set particle system to reactor mode.
- EMITTER: set particle system to emitter mode.
@type DISTRIBUTION: readonly dictionary
@var DISTRIBUTION: Constant dict used for with L{Particle.DISTRIBUTION}
- GRID: set grid distribution.
- RANDOM: set random distribution.
- JITTERED: set jittered distribution.
@type EMITFROM: readonly dictionary
@var EMITFROM: Constant dict used for with L{Particle.EMITFROM}
- VERTS: set particles emit from vertices
- FACES: set particles emit from faces
- VOLUME: set particles emit from volume
- PARTICLE: set particles emit from particles
@type REACTON: readonly dictionary
@var REACTON: Constant dict used for with L{Particle.REACTON}
- NEAR: react on near
- COLLISION: react on collision
- DEATH: react on death
@type DRAWAS: readonly dictionary
@var DRAWAS: Constant dict used for with L{Particle.DRAWAS}
- NONE: Don't draw
- POINT: Draw as point
- CIRCLE: Draw as circles
- CROSS: Draw as crosses
- AXIS: Draw as axis
- LINE: Draw as lines
- PATH: Draw pathes
- OBJECT: Draw object
- GROUP: Draw goup
- BILLBOARD: Draw as billboard
"""
class Particle:
"""
The Particle object
===================
This object gives access to paticles data.
@ivar seed: Set an offset in the random table.
@type seed: int
@ivar type: Type of particle system ( Particle.TYPE[ 'HAIR' | 'REACTOR' | 'EMITTER' ] ).
@type type: int
@ivar resolutionGrid: The resolution of the particle grid.
@type resolutionGrid: int
@ivar startFrame: Frame # to start emitting particles.
@type startFrame: float
@ivar endFrame: Frame # to stop emitting particles.
@type endFrame: float
@ivar editable: Finalize hair to enable editing in particle mode.
@type editable: int
@ivar amount: The total number of particles.
@type amount: int
@ivar multireact: React multiple times ( Paricle.REACTON[ 'NEAR' | 'COLLISION' | 'DEATH' ] ).
@type multireact: int
@ivar reactshape: Power of reaction strength dependence on distance to target.
@type reactshape: float
@ivar hairSegments: Amount of hair segments.
@type hairSegments: int
@ivar lifetime: Specify the life span of the particles.
@type lifetime: float
@ivar randlife: Give the particle life a random variation.
@type randlife: float
@ivar randemission: Give the particle life a random variation
@type randemission: int
@ivar particleDistribution: Where to emit particles from Paricle.EMITFROM[ 'PARTICLE' | 'VOLUME' | 'FACES' | 'VERTS' ] )
@type particleDistribution: int
@ivar evenDistribution: Use even distribution from faces based on face areas or edge lengths.
@type evenDistribution: int
@ivar distribution: How to distribute particles on selected element Paricle.DISTRIBUTION[ 'GRID' | 'RANDOM' | 'JITTERED' ] ).
@type distribution: int
@ivar jitterAmount: Amount of jitter applied to the sampling.
@type jitterAmount: float
@ivar pf: Emission locations / face (0 = automatic).
@type pf:int
@ivar invert: Invert what is considered object and what is not.
@type invert: int
@ivar targetObject: The object that has the target particle system (empty if same object).
@type targetObject: Blender object
@ivar targetpsys: The target particle system number in the object.
@type targetpsys: int
@ivar 2d: Constrain boids to a surface.
@type 2d: float
@ivar maxvel: Maximum velocity.
@type maxvel: float
@ivar avvel: The usual speed % of max velocity.
@type avvel: float
@ivar latacc: Lateral acceleration % of max velocity
@type latacc: float
@ivar tanacc: Tangential acceleration % of max velocity
@type tanacc: float
@ivar groundz: Default Z value.
@type groundz: float
@ivar object: Constrain boids to object's surface.
@type object: Blender Object
@ivar renderEmitter: Render emitter object.
@type renderEmitter: int
@ivar displayPercentage: Particle display percentage.
@type displayPercentage: int
@ivar hairDisplayStep: How many steps paths are drawn with (power of 2) in visu mode.
@type hairDisplayStep: int
@ivar hairRenderStep: How many steps paths are rendered with (power of 2) in render mode."
@type hairRenderStep: int
@ivar duplicateObject: Get the duplicate object.
@type duplicateObject: Blender Object
@ivar drawAs: Get draw type Particle.DRAWAS([ 'NONE' | 'OBJECT' | 'POINT' | ... ]).
@type drawAs: int
"""
def freeEdit():
"""
Free edit mode.
@return: None
"""
def getLoc(all=0,id=0):
"""
Get the particles locations.
A list of tuple is returned in particle mode.
A list of list of tuple is returned in hair mode.
The tuple is a vector list of 3 or 4 floats in world space (x,y,z, optionnaly the particle's id).
@type all: int
@param all: if not 0 export all particles (uninitialized (unborn or died)particles exported as None).
@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)
"""
def getRot(all=0,id=0):
"""
Get the particles rotations as quaternion.
A list of tuple is returned in particle mode.
The tuple is a vector list of 4 or 5 floats (x,y,z,w, optionnaly the id of the particle).
@type all: int
@param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None).
@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
"""
def getMat():
"""
Get the particles material.
@rtype: Blender Material
@return: The marterial assigned to particles
"""
def getSize(all=0,id=0):
"""
Get the particles size.
A list of float or list of tuple (particle's size,particle's id).
@type all: int
@param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None).
@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).
"""
def getAge(all=0,id=0):
"""
Get the particles age.
A list of float or list of tuple (particle's age,particle's id).
@type all: int
@param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None).
@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).
"""
# Blender.Object module and the Object PyType object
"""
The Blender.Particle submodule
Particle
========
This module provides access to the B{Particle} in Blender.
@type TYPE: readonly dictionary
@var TYPE: Constant dict used for with L{Particle.TYPE}
- HAIR: set particle system to hair mode.
- REACTOR: set particle system to reactor mode.
- EMITTER: set particle system to emitter mode.
@type DISTRIBUTION: readonly dictionary
@var DISTRIBUTION: Constant dict used for with L{Particle.DISTRIBUTION}
- GRID: set grid distribution.
- RANDOM: set random distribution.
- JITTERED: set jittered distribution.
@type EMITFROM: readonly dictionary
@var EMITFROM: Constant dict used for with L{Particle.EMITFROM}
- VERTS: set particles emit from vertices
- FACES: set particles emit from faces
- VOLUME: set particles emit from volume
- PARTICLE: set particles emit from particles
@type REACTON: readonly dictionary
@var REACTON: Constant dict used for with L{Particle.REACTON}
- NEAR: react on near
- COLLISION: react on collision
- DEATH: react on death
@type DRAWAS: readonly dictionary
@var DRAWAS: Constant dict used for with L{Particle.DRAWAS}
- NONE: Don't draw
- POINT: Draw as point
- CIRCLE: Draw as circles
- CROSS: Draw as crosses
- AXIS: Draw as axis
- LINE: Draw as lines
- PATH: Draw pathes
- OBJECT: Draw object
- GROUP: Draw goup
- BILLBOARD: Draw as billboard
"""
def Get(name):
"""
Get the particle system of the object "name".
@type name: string
@return: The particle system of the object.
"""
def New(name):
"""
Assign a new particle system to the object "name".
@type name: string
@return: The newly created particle system.
"""
class Particle:
"""
The Particle object
===================
This object gives access to paticles data.
@ivar seed: Set an offset in the random table.
@type seed: int
@ivar type: Type of particle system ( Particle.TYPE[ 'HAIR' | 'REACTOR' | 'EMITTER' ] ).
@type type: int
@ivar resolutionGrid: The resolution of the particle grid.
@type resolutionGrid: int
@ivar startFrame: Frame # to start emitting particles.
@type startFrame: float
@ivar endFrame: Frame # to stop emitting particles.
@type endFrame: float
@ivar editable: Finalize hair to enable editing in particle mode.
@type editable: int
@ivar amount: The total number of particles.
@type amount: int
@ivar multireact: React multiple times ( Paricle.REACTON[ 'NEAR' | 'COLLISION' | 'DEATH' ] ).
@type multireact: int
@ivar reactshape: Power of reaction strength dependence on distance to target.
@type reactshape: float
@ivar hairSegments: Amount of hair segments.
@type hairSegments: int
@ivar lifetime: Specify the life span of the particles.
@type lifetime: float
@ivar randlife: Give the particle life a random variation.
@type randlife: float
@ivar randemission: Give the particle life a random variation
@type randemission: int
@ivar particleDistribution: Where to emit particles from Paricle.EMITFROM[ 'PARTICLE' | 'VOLUME' | 'FACES' | 'VERTS' ] )
@type particleDistribution: int
@ivar evenDistribution: Use even distribution from faces based on face areas or edge lengths.
@type evenDistribution: int
@ivar distribution: How to distribute particles on selected element Paricle.DISTRIBUTION[ 'GRID' | 'RANDOM' | 'JITTERED' ] ).
@type distribution: int
@ivar jitterAmount: Amount of jitter applied to the sampling.
@type jitterAmount: float
@ivar pf: Emission locations / face (0 = automatic).
@type pf:int
@ivar invert: Invert what is considered object and what is not.
@type invert: int
@ivar targetObject: The object that has the target particle system (empty if same object).
@type targetObject: Blender object
@ivar targetpsys: The target particle system number in the object.
@type targetpsys: int
@ivar 2d: Constrain boids to a surface.
@type 2d: float
@ivar maxvel: Maximum velocity.
@type maxvel: float
@ivar avvel: The usual speed % of max velocity.
@type avvel: float
@ivar latacc: Lateral acceleration % of max velocity
@type latacc: float
@ivar tanacc: Tangential acceleration % of max velocity
@type tanacc: float
@ivar groundz: Default Z value.
@type groundz: float
@ivar object: Constrain boids to object's surface.
@type object: Blender Object
@ivar renderEmitter: Render emitter object.
@type renderEmitter: int
@ivar displayPercentage: Particle display percentage.
@type displayPercentage: int
@ivar hairDisplayStep: How many steps paths are drawn with (power of 2) in visu mode.
@type hairDisplayStep: int
@ivar hairRenderStep: How many steps paths are rendered with (power of 2) in render mode."
@type hairRenderStep: int
@ivar duplicateObject: Get the duplicate object.
@type duplicateObject: Blender Object
@ivar drawAs: Get draw type Particle.DRAWAS([ 'NONE' | 'OBJECT' | 'POINT' | ... ]).
@type drawAs: int
"""
def freeEdit():
"""
Free edit mode.
@return: None
"""
def getLoc(all=0,id=0):
"""
Get the particles locations.
A list of tuple is returned in particle mode.
A list of list of tuple is returned in hair mode.
The tuple is a vector list of 3 floats in world space.
@type all: int
@param all: if not 0 export all particles (uninitialized (unborn or died)particles exported as None).
@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)
"""
def getRot(all=0,id=0):
"""
Get the particles rotations as quaternion.
A list of tuple is returned in particle mode.
The tuple is a vector list of 4 floats (quaternion).
@type all: int
@param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None).
@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
"""
def getMat():
"""
Get the particles material.
@rtype: Blender Material
@return: The marterial assigned to particles
"""
def getSize(all=0,id=0):
"""
Get the particles size.
A list of float.
@type all: int
@param all: if not 0 export all particles (uninitialized (unborn or died) particles exported as None).
@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).
"""