From 46f6cdcdcc68917bf54926a72aae34a061c4ec7f Mon Sep 17 00:00:00 2001 From: Janne Karhu Date: Sun, 5 Jul 2009 12:36:20 +0000 Subject: [PATCH] Added a particle instance modifier option to use particle size. --- release/ui/buttons_data_modifier.py | 2 ++ source/blender/blenkernel/intern/modifier.c | 33 ++++++++++++++++--- source/blender/makesdna/DNA_modifier_types.h | 1 + source/blender/makesrna/intern/rna_modifier.c | 5 +++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/release/ui/buttons_data_modifier.py b/release/ui/buttons_data_modifier.py index 477be27e820..10f3efa1ed4 100644 --- a/release/ui/buttons_data_modifier.py +++ b/release/ui/buttons_data_modifier.py @@ -299,12 +299,14 @@ class DATA_PT_modifiers(DataButtonsPanel): col = layout.column_flow() col.itemR(md, "normal") col.itemR(md, "children") + col.itemR(md, "size") col.itemR(md, "path") if md.path: col.itemR(md, "keep_shape") col.itemR(md, "unborn") col.itemR(md, "alive") col.itemR(md, "dead") + col.itemL(md, "") if md.path: col.itemR(md, "axis", text="") diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 71428a9e947..046dfcc9f87 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -6477,6 +6477,7 @@ static DerivedMesh * particleInstanceModifier_applyModifier( int i,totvert, totpart=0, totface, maxvert, maxface, first_particle=0; short track=ob->trackflag%3, trackneg, axis = pimd->axis; float max_co=0.0, min_co=0.0, temp_co[3], cross[3]; + float *size=NULL; trackneg=((ob->trackflag>2)?1:0); @@ -6503,6 +6504,25 @@ static DerivedMesh * particleInstanceModifier_applyModifier( if(totpart==0) return derivedData; + if(pimd->flag & eParticleInstanceFlag_UseSize) { + int p; + float *si; + si = size = MEM_callocN(totpart * sizeof(float), "particle size array"); + + if(pimd->flag & eParticleInstanceFlag_Parents) { + for(p=0, pa= psys->particles; ptotpart; p++, pa++, si++) + *si = pa->size; + } + + if(pimd->flag & eParticleInstanceFlag_Children) { + ChildParticle *cpa = psys->child; + + for(p=0; ptotchild; p++, cpa++, si++) { + *si = psys_get_child_size(psys, cpa, 0.0f, NULL); + } + } + } + pars=psys->particles; totvert=dm->getNumVerts(dm); @@ -6585,10 +6605,12 @@ static DerivedMesh * particleInstanceModifier_applyModifier( } else{ state.time=-1.0; - psys_get_particle_state(md->scene, pimd->ob, psys, i/totvert, &state,1); + psys_get_particle_state(md->scene, pimd->ob, psys, first_particle + i/totvert, &state,1); } QuatMulVecf(state.rot,mv->co); + if(pimd->flag & eParticleInstanceFlag_UseSize) + VecMulf(mv->co, size[i/totvert]); VECADD(mv->co,mv->co,state.co); } @@ -6641,6 +6663,9 @@ static DerivedMesh * particleInstanceModifier_applyModifier( psys->lattice= NULL; } + if(size) + MEM_freeN(size); + return result; } static DerivedMesh *particleInstanceModifier_applyModifierEM( @@ -7279,10 +7304,10 @@ static DerivedMesh * explodeModifier_explodeMesh(ExplodeModifierData *emd, timestep= psys_get_timestep(part); - if(part->flag & PART_GLOB_TIME) + //if(part->flag & PART_GLOB_TIME) cfra=bsystem_time(scene, 0,(float)scene->r.cfra,0.0); - else - cfra=bsystem_time(scene, ob,(float)scene->r.cfra,0.0); + //else + // cfra=bsystem_time(scene, ob,(float)scene->r.cfra,0.0); /* hash table for vertice <-> particle relations */ vertpahash= BLI_edgehash_new(); diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 1fa17760e8d..49a6fd4daf0 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -504,6 +504,7 @@ typedef enum { eParticleInstanceFlag_Alive = (1<<4), eParticleInstanceFlag_Dead = (1<<5), eParticleInstanceFlag_KeepShape = (1<<6), + eParticleInstanceFlag_UseSize = (1<<7), } ParticleInstanceModifierFlag; typedef struct ParticleInstanceModifierData { diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index f4c14a51b13..30e9346a961 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1365,6 +1365,11 @@ static void rna_def_modifier_particleinstance(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Keep Shape", "Don't stretch the object."); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_update"); + prop= RNA_def_property(srna, "size", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", eParticleInstanceFlag_UseSize); + RNA_def_property_ui_text(prop, "Size", "Use particle size to scale the instances."); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Modifier_update"); + prop= RNA_def_property(srna, "position", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "position"); RNA_def_property_range(prop, 0.0, 1.0);