Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenkernel/intern/texture.c6
-rw-r--r--source/blender/makesdna/DNA_texture_types.h13
-rw-r--r--source/blender/render/intern/source/pointdensity.c32
-rw-r--r--source/blender/src/buttons_shading.c48
4 files changed, 71 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index 62bab45dd50..45fd11faa32 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -43,6 +43,7 @@
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "BLI_rand.h"
+#include "BLI_kdtree.h"
#include "DNA_texture_types.h"
#include "DNA_key_types.h"
@@ -874,7 +875,7 @@ PointDensity *BKE_add_pointdensity(void)
pd= MEM_callocN(sizeof(PointDensity), "pointdensity");
pd->radius = 0.3f;
pd->nearest = 5;
- pd->type = TEX_PD_PSYS;
+ pd->source = TEX_PD_PSYS;
pd->point_tree = NULL;
return pd;
@@ -883,8 +884,7 @@ PointDensity *BKE_add_pointdensity(void)
PointDensity *BKE_copy_pointdensity(PointDensity *pd)
{
PointDensity *pdn;
- int a;
-
+
pdn= MEM_dupallocN(pd);
pdn->point_tree = NULL;
diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h
index ed172c24474..aef8bd95ee4 100644
--- a/source/blender/makesdna/DNA_texture_types.h
+++ b/source/blender/makesdna/DNA_texture_types.h
@@ -133,12 +133,14 @@ typedef struct PointDensity {
short nearest;
float radius;
- short type;
+ short source;
short pdpad[3];
struct Object *object; /* for 'Particle system' type - source object */
short psysindex; /* and object's psys number */
- short pdpad2[3];
+ short psys_cache_space; /* cache particles in worldspace, object space, ... ? */
+
+ short pdpad2[2];
void *point_tree; /* the kd-tree containing points */
} PointDensity;
@@ -406,14 +408,15 @@ typedef struct TexMapping {
/* **************** PointDensity ********************* */
-/* type */
+/* source */
#define TEX_PD_PSYS 0
#define TEX_PD_OBJECT 1
#define TEX_PD_FILE 2
-/* psys_space */
-#define TEX_PD_PSYS_WORLDSPACE 0
+/* psys_cache_space */
+#define TEX_PD_PSYS_OBJECTLOC 0
#define TEX_PD_PSYS_OBJECTSPACE 1
+#define TEX_PD_PSYS_WORLDSPACE 2
#endif
diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c
index 00dbbd34f96..e589e579565 100644
--- a/source/blender/render/intern/source/pointdensity.c
+++ b/source/blender/render/intern/source/pointdensity.c
@@ -26,11 +26,14 @@
#include <stdlib.h>
#include <stdio.h>
+#include "BLI_arithb.h"
#include "BLI_kdtree.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_main.h"
+#include "BKE_object.h"
+#include "BKE_particle.h"
#include "DNA_texture_types.h"
#include "DNA_particle_types.h"
@@ -45,10 +48,15 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
ParticleKey state;
float cfra=bsystem_time(ob,(float)G.scene->r.cfra,0.0);
int i, childexists;
-
+ float partco[3];
+ float obview[4][4];
+
/* init crap */
if (!psys || !ob || !pd) return;
+ //Mat4CpyMat4(obview, ob->obmat);
+ Mat4MulMat4(obview, re->viewinv, ob->obmat);
+
/* Just to create a valid rendering context */
psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, 0);
@@ -60,6 +68,9 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
return;
}
+ /* in case ob->imat isn't up-to-date */
+ Mat4Invert(ob->imat, ob->obmat);
+
/* finally do something */
pd->point_tree = BLI_kdtree_new(psys->totpart+psys->totchild);
@@ -70,7 +81,20 @@ static void pointdensity_cache_psys(Render *re, PointDensity *pd, Object *ob, Pa
state.time = cfra;
if(psys_get_particle_state(ob, psys, i, &state, 0)) {
- BLI_kdtree_insert(pd->point_tree, 0, state.co, NULL);
+
+ VECCOPY(partco, state.co);
+
+ if (pd->psys_cache_space == TEX_PD_PSYS_OBJECTSPACE)
+ Mat4MulVecfl(ob->imat, partco);
+ else if (pd->psys_cache_space == TEX_PD_PSYS_OBJECTLOC) {
+ float obloc[3];
+ VECCOPY(obloc, ob->loc);
+ VecSubf(partco, partco, obloc);
+ } else {
+ /* TEX_PD_PSYS_WORLDSPACE */
+ }
+
+ BLI_kdtree_insert(pd->point_tree, 0, partco, NULL);
}
}
@@ -88,7 +112,7 @@ static void cache_pointdensity(Render *re, Tex *tex)
pd->point_tree = NULL;
}
- if (pd->type == TEX_PD_PSYS) {
+ if (pd->source == TEX_PD_PSYS) {
ParticleSystem *psys;
Object *ob = pd->object;
int i;
@@ -192,4 +216,4 @@ int pointdensitytex(Tex *tex, float *texvec, TexResult *texres)
BRICONT;
return rv;
-} \ No newline at end of file
+}
diff --git a/source/blender/src/buttons_shading.c b/source/blender/src/buttons_shading.c
index 002c62c1a17..5397ab84f1c 100644
--- a/source/blender/src/buttons_shading.c
+++ b/source/blender/src/buttons_shading.c
@@ -748,18 +748,9 @@ static void texture_panel_pointdensity(Tex *tex)
if(tex->pd) {
pd= tex->pd;
- uiBlockBeginAlign(block);
- uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Ob:",
- X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->object), "Object that has the particle system");
-
- if (pd->object->particlesystem.first) {
- uiDefButS(block, NUM, B_REDR, "PSys:",
- X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->psysindex), 1, 10, 10, 3, "Particle system number in the object");
- }
- uiBlockEndAlign(block);
-
- yco -= YSPACE;
-
+ uiDefBut(block, LABEL, B_NOP, "Density estimation:",
+ X2CLM1, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+
uiBlockBeginAlign(block);
uiDefButF(block, NUM, B_REDR, "Radius: ",
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->radius), 0.001, 100.0, 10, 2, "Radius to look for nearby particles within");
@@ -767,11 +758,36 @@ static void texture_panel_pointdensity(Tex *tex)
X2CLM1, yco-=BUTH, BUTW2, BUTH, &(pd->nearest), 2.0, 30.0, 10, 2, "The number of nearby particles to check for density");
uiBlockEndAlign(block);
- uiDefBut(block, LABEL, B_NOP, " ",
- X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+ yco = PANEL_YMAX;
+
+ uiDefBut(block, LABEL, B_NOP, "Point data source:",
+ X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+
+ uiDefButS(block, MENU, B_TEXREDR_PRV, "Particle System %x0",
+ X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->source, 0.0, 0.0, 0, 0, "Source");
+
+ yco -= YSPACE;
+
+ if (pd->source == TEX_PD_PSYS) {
+ uiBlockBeginAlign(block);
+ uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Ob:",
+ X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->object), "Object that has the particle system");
+
+ if (pd->object->particlesystem.first) {
+ uiDefButS(block, NUM, B_REDR, "PSys:",
+ X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->psysindex), 1, 10, 10, 3, "Particle system number in the object");
+ }
+ uiBlockEndAlign(block);
+
+ yco -= YSPACE;
+
+ uiDefBut(block, LABEL, B_NOP, "Cache particles in:",
+ X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+ uiDefButS(block, MENU, B_TEXREDR_PRV, "Emit Object Location %x0|Emit Object Space %x1|Global Space %x2",
+ X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->psys_cache_space, 0.0, 0.0, 0, 0, "Co-ordinate system to cache particles in");
+ }
}
-
-
+
}