Added a particle instance modifier option to use particle size.
authorJanne Karhu <jhkarh@gmail.com>
Sun, 5 Jul 2009 12:36:20 +0000 (12:36 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Sun, 5 Jul 2009 12:36:20 +0000 (12:36 +0000)
release/ui/buttons_data_modifier.py
source/blender/blenkernel/intern/modifier.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/makesrna/intern/rna_modifier.c

index 477be27e820956e9631e6f18dedb75fa62d76f0b..10f3efa1ed42d03c21403b1b84de625713844622 100644 (file)
@@ -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="")
                
index 71428a9e9477cc5679f0b4f0e0e270835f88b33a..046dfcc9f87d847077556b6953396674be73197d 100644 (file)
@@ -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; p<psys->totpart; p++, pa++, si++)
+                               *si = pa->size;
+               }
+
+               if(pimd->flag & eParticleInstanceFlag_Children) {
+                       ChildParticle *cpa = psys->child;
+
+                       for(p=0; p<psys->totchild; 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();
index 1fa17760e8d81603bd9970705742332b5efec246..49a6fd4daf0f5039c25efde868a0d116c9a70f40 100644 (file)
@@ -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 {
index f4c14a51b13c73bbe613a2e0ce9a7bf6a8098cb3..30e9346a961ce9f4ed6bf5c31a79ba4fa48b6559 100644 (file)
@@ -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);