Point Density
authorMatt Ebb <matt@mke3.net>
Mon, 10 Nov 2008 00:14:35 +0000 (00:14 +0000)
committerMatt Ebb <matt@mke3.net>
Mon, 10 Nov 2008 00:14:35 +0000 (00:14 +0000)
* Fixed a stupid crash caused by last commit that worked fine on the mac
(but never should have...)

* Fix for using child particles with the new particle age color options

source/blender/blenkernel/intern/texture.c
source/blender/render/intern/source/pointdensity.c
source/blender/src/buttons_shading.c

index 76ef6bdb4e80d4b1c7d8ba18a7ca934b90d84cdd..1bb4ef3eeffc13f458ca244d2dfe2ade5d96a2a7 100644 (file)
@@ -873,6 +873,7 @@ PointDensity *BKE_add_pointdensity(void)
        PointDensity *pd;
        
        pd= MEM_callocN(sizeof(PointDensity), "pointdensity");
+       pd->flag = 0;
        pd->radius = 0.3f;
        pd->falloff_type = TEX_PD_FALLOFF_STD;
        pd->falloff_softness = 2.0;
@@ -886,6 +887,7 @@ PointDensity *BKE_add_pointdensity(void)
        pd->coba = add_colorband(1);
        pd->speed_scale = 1.0f;
        pd->totpoints = 0;
+       pd->coba = add_colorband(1);
        return pd;
 } 
 
index db3e57e0b7936b9fa46cea3f442c8ef8d51d27c8..af2a7edae06da19a27d6e29d330a23f3ece07dcb 100644 (file)
@@ -71,7 +71,7 @@ static int point_data_used(PointDensity *pd)
 /* additional data stored alongside the point density BVH, 
  * accessible by point index number to retrieve other information 
  * such as particle velocity or lifetime */
-static void make_point_data(PointDensity *pd, int total_particles, int point_data_used)
+static void alloc_point_data(PointDensity *pd, int total_particles, int point_data_used)
 {
        int data_size = 0;
        
@@ -123,7 +123,7 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
        psys->lattice=psys_get_lattice(ob,psys);
        
        pd->point_tree = BLI_bvhtree_new(total_particles, 0.0, 4, 6);
-       make_point_data(pd, total_particles, data_used);
+       alloc_point_data(pd, total_particles, data_used);
        pd->totpoints = total_particles;
        if (data_used & POINT_DATA_VEL) offset = pd->totpoints*3;
        
@@ -155,7 +155,15 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
                                pd->point_data[i*3 + 2] = state.vel[2];
                        } 
                        if (data_used & POINT_DATA_LIFE) {
-                               float pa_time = (cfra - pa->time)/pa->lifetime;
+                               float pa_time;
+                               
+                               if (i < psys->totpart) {
+                                       pa_time = (cfra - pa->time)/pa->lifetime;
+                               } else {
+                                       ChildParticle *cpa= (psys->child + i) - psys->totpart;
+                                       pa_time = psys_get_child_time(psys, cpa, cfra);
+                               }
+                               
                                pd->point_data[offset + i] = pa_time;
                        }
                }
index b9ea4ebe9d61008443aa6659dbf00f4a9f8a378e..5ed39764af048e21d9bb699cf5ddcbb47ea670d9 100644 (file)
@@ -840,87 +840,6 @@ static void texture_panel_voronoi(Tex *tex)
        uiDefButF(block, NUMSLI, B_TEXPRV, "W4: ", 10, 10, 150, 19, &tex->vn_w4, -2.0, 2.0, 10, 0, "Sets feature weight 4");
 }
 
-static void texture_panel_pointdensity_modify(Tex *tex)
-{
-       uiBlock *block;
-       PointDensity *pd;
-       short yco=PANEL_YMAX, ymid;
-       
-       block= uiNewBlock(&curarea->uiblocks, "texture_panel_pointdensity_modify", UI_EMBOSS, UI_HELV, curarea->win);
-       if(uiNewPanel(curarea, block, "Modifiers", "Texture", PANELX, PANELY, PANELW, PANELH+20)==0) return;
-       uiSetButLock(tex->id.lib!=0, ERROR_LIBDATA_MESSAGE);
-
-       if(tex->pd==NULL) {
-               tex->pd= BKE_add_pointdensity();
-       }
-       if(!tex->pd) return;
-       
-       if (pd->source == TEX_PD_PSYS) {
-               uiDefBut(block, LABEL, B_NOP, "Color & Intensity By:",
-                       X2CLM1, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
-
-               uiBlockBeginAlign(block);
-               uiDefButS(block, MENU, B_TEXREDR_PRV, "Constant %x0|Particle Age %x1|Particle Speed %x2|Velocity -> RGB %x3|",
-                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &pd->color_source, 0.0, 0.0, 0, 0, "Particle Life: Lifetime mapped as 0.0 - 1.0 intensity, Velocity: XYZ velocity mapped as RGB colours");
-               if (ELEM(pd->color_source, TEX_PD_COLOR_PARTSPEED, TEX_PD_COLOR_PARTVEL)) {
-                       uiDefButF(block, NUM, B_REDR, "Scale: ",
-                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->speed_scale), 0.001, 100.0, 10, 2, "Multipler to bring particle speed within an acceptable range");
-               }
-               uiBlockEndAlign(block);
-               
-               yco-= 2*BUTH;
-               
-               if (ELEM(pd->color_source, TEX_PD_COLOR_PARTAGE, TEX_PD_COLOR_PARTSPEED)) {
-                       rctf rect = {X2CLM1, X2CLM1+BUTW1, yco, yco};
-                       if (tex->pd->coba == NULL) tex->pd->coba = add_colorband(1);
-                       draw_colorband_buts_small(block, tex->pd->coba, &rect, B_TEXREDR_PRV);
-               } else {
-                       /* spacer */
-                       uiDefBut(block, LABEL, B_NOP, "",
-                               X2CLM2, yco, BUTW2, BUTH*2, 0, 0, 0, 0, 0, "");
-               }
-               
-               if (!ELEM(pd->color_source, TEX_PD_COLOR_PARTSPEED, TEX_PD_COLOR_PARTVEL)) yco -= BUTH;
-       }
-       
-       ymid = yco -= YSPACE;
-       
-       uiDefButBitS(block, TOG, TEX_PD_TURBULENCE, B_REDR, "Turbulence",
-               X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->flag), 0, 0, 0, 0, "Add directed turbulence to the density estimation");
-       
-       yco -= YSPACE;
-       
-       uiBlockBeginAlign(block);
-       if (pd->flag & TEX_PD_TURBULENCE) {
-               
-               uiDefButF(block, NUM, B_REDR, "Size: ",
-                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_size), 0.001, 100.0, 10, 2, "Turbulence size");
-               uiDefButS(block, NUM, B_REDR, "Depth: ",
-                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_depth), 0.0, 100.0, 10, 2, "Turbulence depth");
-               uiDefButF(block, NUM, B_REDR, "Strength: ",
-                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_fac), 0.001, 100.0, 10, 2, "");
-               
-               uiBlockEndAlign(block);
-               
-               yco = ymid - BUTH - YSPACE;
-
-               uiDefBut(block, LABEL, B_NOP, "Noise Influence:",
-                       X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
-                       
-               if (pd->source == TEX_PD_PSYS) {
-                       uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Velocity %x1|Particle Age %x2|Time %x3",
-                               X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->noise_influence), 0.0, 0.0, 0, 0, "Noise Influence");
-               } else if (pd->source == TEX_PD_OBJECT) {
-                       uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Time %x3",
-                               X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->noise_influence), 0.0, 0.0, 0, 0, "Noise Influence");
-               }
-       } else {
-               uiDefBut(block, LABEL, B_NOP, "",
-                       X2CLM2, yco-=2*BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
-       }
-
-}
-
 static void texture_panel_pointdensity(Tex *tex)
 {
        uiBlock *block;
@@ -999,6 +918,87 @@ static void texture_panel_pointdensity(Tex *tex)
 
 }
 
+static void texture_panel_pointdensity_modify(Tex *tex)
+{
+       uiBlock *block;
+       PointDensity *pd;
+       short yco=PANEL_YMAX, ymid;
+       
+       block= uiNewBlock(&curarea->uiblocks, "texture_panel_pointdensity_modify", UI_EMBOSS, UI_HELV, curarea->win);
+       if(uiNewPanel(curarea, block, "Modifiers", "Texture", PANELX, PANELY, PANELW, PANELH+20)==0) return;
+       uiSetButLock(tex->id.lib!=0, ERROR_LIBDATA_MESSAGE);
+
+       if(tex->pd==NULL) {
+               tex->pd= BKE_add_pointdensity();
+       }
+       if(!tex->pd) return;
+       pd= tex->pd;
+       
+       if (pd->source == TEX_PD_PSYS) {
+               uiDefBut(block, LABEL, B_NOP, "Color & Intensity By:",
+                       X2CLM1, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+
+               uiBlockBeginAlign(block);
+               uiDefButS(block, MENU, B_TEXREDR_PRV, "Constant %x0|Particle Age %x1|Particle Speed %x2|Velocity -> RGB %x3|",
+                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &pd->color_source, 0.0, 0.0, 0, 0, "Particle Life: Lifetime mapped as 0.0 - 1.0 intensity, Velocity: XYZ velocity mapped as RGB colours");
+               if (ELEM(pd->color_source, TEX_PD_COLOR_PARTSPEED, TEX_PD_COLOR_PARTVEL)) {
+                       uiDefButF(block, NUM, B_REDR, "Scale: ",
+                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->speed_scale), 0.001, 100.0, 10, 2, "Multipler to bring particle speed within an acceptable range");
+               }
+               uiBlockEndAlign(block);
+               
+               yco-= 2*BUTH;
+               
+               
+               if (ELEM(pd->color_source, TEX_PD_COLOR_PARTAGE, TEX_PD_COLOR_PARTSPEED)) {
+                       rctf rect = {X2CLM1, X2CLM1+BUTW1, yco, yco};
+                       if (pd->coba == NULL) pd->coba = add_colorband(1);
+                       draw_colorband_buts_small(block, pd->coba, &rect, B_TEXREDR_PRV);
+               } else {
+                       uiDefBut(block, LABEL, B_NOP, "",
+                               X2CLM2, yco, BUTW2, BUTH*2, 0, 0, 0, 0, 0, "");
+               }
+               
+               if (!ELEM(pd->color_source, TEX_PD_COLOR_PARTSPEED, TEX_PD_COLOR_PARTVEL)) yco -= BUTH;
+       }
+       
+       ymid = yco -= YSPACE;
+       
+       uiDefButBitS(block, TOG, TEX_PD_TURBULENCE, B_REDR, "Turbulence",
+               X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->flag), 0, 0, 0, 0, "Add directed turbulence to the density estimation");
+       
+       yco -= YSPACE;
+       
+       uiBlockBeginAlign(block);
+       if (pd->flag & TEX_PD_TURBULENCE) {
+               
+               uiDefButF(block, NUM, B_REDR, "Size: ",
+                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_size), 0.001, 100.0, 10, 2, "Turbulence size");
+               uiDefButS(block, NUM, B_REDR, "Depth: ",
+                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_depth), 0.0, 100.0, 10, 2, "Turbulence depth");
+               uiDefButF(block, NUM, B_REDR, "Strength: ",
+                       X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->noise_fac), 0.001, 100.0, 10, 2, "");
+               
+               uiBlockEndAlign(block);
+               
+               yco = ymid - BUTH - YSPACE;
+
+               uiDefBut(block, LABEL, B_NOP, "Noise Influence:",
+                       X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+                       
+               if (pd->source == TEX_PD_PSYS) {
+                       uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Velocity %x1|Particle Age %x2|Time %x3",
+                               X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->noise_influence), 0.0, 0.0, 0, 0, "Noise Influence");
+               } else if (pd->source == TEX_PD_OBJECT) {
+                       uiDefButS(block, MENU, B_REDR, "Noise Influence %t|Static %x0|Time %x3",
+                               X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->noise_influence), 0.0, 0.0, 0, 0, "Noise Influence");
+               }
+       } else {
+               uiDefBut(block, LABEL, B_NOP, "",
+                       X2CLM2, yco-=2*BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+       }
+
+}
 
 static char *layer_menu(RenderResult *rr, short *curlay)
 {