- Bugfix to make dupli particles for hair respect render amount.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 10 Jan 2008 21:44:16 +0000 (21:44 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 10 Jan 2008 21:44:16 +0000 (21:44 +0000)
- Allow Random and Even distribution settings to be set after hair
  is made editable, since they also affect children.

source/blender/blenkernel/BKE_anim.h
source/blender/blenkernel/intern/anim.c
source/blender/render/intern/source/convertblender.c
source/blender/src/buttons_object.c

index 7b7bd7f87046d770ce27f6e4e1ed1179fc2d206c..30392523439bbeeae41366ed11f79fd5f9088c59 100644 (file)
@@ -34,6 +34,8 @@
 #ifndef BKE_ANIM_H
 #define BKE_ANIM_H
 
+#define MAX_DUPLI_RECUR 4
+
 struct Path;
 struct Object;
 struct PartEff;
index d20031179bf20ebb7113b284fe64017d0cd5b35e..933cf1f2e3bffb171d32d98f9f85fd16adb2f49e 100644 (file)
@@ -75,8 +75,6 @@
 #include <config.h>
 #endif
 
-#define MAX_DUPLI_RECUR 4
-
 static void object_duplilist_recursive(ID *id, Object *ob, ListBase *duplilist, float par_space_mat[][4], int level);
 
 void free_path(Path *path)
index d9dcd9b251ddbdfc1751dda20d9bb5e04252d6bf..fa60a891ce191a46e3ab6362c3c39004f8b489bd 100644 (file)
@@ -4090,6 +4090,39 @@ static int allow_render_dupli_instance(Render *re, DupliObject *dob, Object *obd
                !(re->r.mode & R_RADIO));
 }
 
+static void dupli_render_particle_set(Render *re, Object *ob, int level, int enable)
+{
+       /* ugly function, but we need to set particle systems to their render
+        * settings before calling object_duplilist, to get render level duplis */
+       Group *group;
+       GroupObject *go;
+       ParticleSystem *psys;
+
+       if(level >= MAX_DUPLI_RECUR)
+               return;
+       
+       if(ob->transflag & OB_DUPLIPARTS) {
+               DerivedMesh *dm;
+
+               for(psys=ob->particlesystem.first; psys; psys=psys->next)
+                       if(enable)
+                               psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy);
+                       else
+                               psys_render_restore(ob, psys);
+
+               if(enable) {
+                       dm = mesh_create_derived_render(ob,     CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
+                       dm->release(dm);
+               }
+       }
+
+       if(ob->dup_group==NULL) return;
+       group= ob->dup_group;
+
+       for(go= group->gobject.first; go; go= go->next)
+               dupli_render_particle_set(re, go->ob, level+1, enable);
+}
+
 static void database_init_objects(Render *re, unsigned int lay, int nolamps, int onlyselected, Object *actob, int only_verts)
 {
        Base *base;
@@ -4125,7 +4158,10 @@ static void database_init_objects(Render *re, unsigned int lay, int nolamps, int
                                DupliObject *dob;
                                ListBase *lb;
 
+                               dupli_render_particle_set(re, ob, 0, 1);
                                lb= object_duplilist(sce, ob);
+                               dupli_render_particle_set(re, ob, 0, 0);
+
                                for(dob= lb->first; dob; dob= dob->next) {
                                        Object *obd= dob->ob;
                                        
index 4ce57419b69e5d060d177a1ea8367e72c48e2a14..18b9ac92ec03435841be4a907e7d0648a5ba9d59 100644 (file)
@@ -4280,7 +4280,7 @@ static void object_panel_particle_system(Object *ob)
        short butx=0, buty=160, butw=150, buth=20;
        char str[30];
        static short partact;
-       short totpart;
+       short totpart, lock;
 
        block= uiNewBlock(&curarea->uiblocks, "object_panel_particle_system", UI_EMBOSS, UI_HELV, curarea->win);
        if(uiNewPanel(curarea, block, "Particle System", "Particle", 0, 0, 318, 204)==0) return;
@@ -4340,9 +4340,9 @@ static void object_panel_particle_system(Object *ob)
                uiBlockEndAlign(block);
        }
 
-       if(psys->flag & PSYS_EDITED || psys->flag & PSYS_PROTECT_CACHE) {
+       lock= (psys->flag & PSYS_EDITED || psys->flag & PSYS_PROTECT_CACHE);
+       if(lock)
                uiSetButLock(1, "Hair is edited or cache is protected!");
-       }
 
        uiDefButS(block, MENU, B_PARTTYPE, "Type%t|Hair%x2|Reactor%x1|Emitter%x0", 210,buty,100,buth, &part->type, 14.0, 0.0, 0, 0, "Type of particle system");
 
@@ -4388,15 +4388,20 @@ static void object_panel_particle_system(Object *ob)
 
        uiDefBut(block, LABEL, 0, "Emit From:",                                                 butx,buty,butw,buth, NULL, 0.0, 0, 0, 0, "");
        uiBlockBeginAlign(block);
+
+       if(lock) uiClearButLock();
        uiDefButBitI(block, TOG, PART_TRAND, B_PART_DISTR, "Random",    butx,(buty-=buth),butw/2,buth, &part->flag, 0, 0, 0, 0, "Emit in random order of elements");
-       
+       if(lock) uiSetButLock(1, "Hair is edited or cache is protected!");
+
        if(part->type==PART_REACTOR)
                uiDefButS(block, MENU, B_PART_DISTR, "Particle %x3|Volume %x2|Faces %x1|Verts %x0", butx+butw/2,buty,butw/2,buth, &part->from, 14.0, 0.0, 0, 0, "Where to emit particles from");
        else
                uiDefButS(block, MENU, B_PART_DISTR, "Volume %x2|Faces %x1|Verts%x0", butx+butw/2,buty,butw/2,buth, &part->from, 14.0, 0.0, 0, 0, "Where to emit particles from");
 
        if(ELEM(part->from,PART_FROM_FACE,PART_FROM_VOLUME)) {
+               if(lock) uiClearButLock();
                uiDefButBitI(block, TOG, PART_EDISTR, B_PART_DISTR, "Even",butx,(buty-=buth),butw/2,buth, &part->flag, 0, 0, 0, 0, "Use even distribution from faces based on face areas or edge lengths");
+               if(lock) uiSetButLock(1, "Hair is edited or cache is protected!");
                uiDefButS(block, MENU, B_PART_DISTR, "Distribution %t|Grid%x2|Random%x1|Jittered%x0", butx+butw/2,buty,butw/2,buth, &part->distr, 14.0, 0.0, 0, 0, "How to distribute particles on selected element");
                if(part->distr==PART_DISTR_JIT) {
                        uiDefButF(block, NUM, B_PART_DISTR, "Amount:",          butx,(buty-=buth),butw,buth, &part->jitfac, 0, 2.0, 1, 1, "Amount of jitter applied to the sampling");