[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16809] branches/sim_physics/source/ blender: Point Density texture

Matt Ebb matt at mke3.net
Mon Sep 29 06:19:37 CEST 2008


Revision: 16809
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16809
Author:   broken
Date:     2008-09-29 06:19:24 +0200 (Mon, 29 Sep 2008)

Log Message:
-----------
Point Density texture

The Point Density texture now has some additional options for how 
the point locations are cached. Previously it was all relative to 
worldspace, but there are now some other options that make things 
a lot more convenient for mapping the texture to Local (or Orco). 
Thanks to theeth for helping with the space conversions!

The new Object space options allow this sort of thing to be possible
 - a particle system, instanced on a transformed renderable object:
http://mke3.net/blender/devel/rendering/volumetrics/pd_objectspace.mov

It's also a lot easier to use multiple instances, just duplicate
the renderable objects and move them around.


The new particle cache options are:

* Emit Object space
This caches the particles relative to the emitter object's 
coordinate space (i.e. relative to the emitter's object center). 
This makes it possible to map the Texture to Local or Orco 
easily, so you can easily move, rotate or scale the rendering 
object that has the Point Density texture. It's relative to the 
emitter's location, rotation and scale, so if the object you're 
rendering the texture on is aligned differently to the emitter, 
the results will be rotated etc.

* Emit Object Location
This offsets the particles to the emitter object's location in 3D 
space. It's similar to Emit Object Space, however the emitter 
object's rotation and scale are ignored. This is probably the 
easiest to use, since you don't need to worry about the rotation 
and scale of the emitter object (just the rendered object), so 
it's the default.

* Global Space
This is the same as previously, the particles are cached in global space, so to use this effectively you'll need to map the texture to Global, and have the rendered object in the right global location.

Modified Paths:
--------------
    branches/sim_physics/source/blender/blenkernel/intern/texture.c
    branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
    branches/sim_physics/source/blender/render/intern/source/pointdensity.c
    branches/sim_physics/source/blender/src/buttons_shading.c

Modified: branches/sim_physics/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-09-29 04:14:47 UTC (rev 16808)
+++ branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-09-29 04:19:24 UTC (rev 16809)
@@ -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 @@
 	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_copy_pointdensity(PointDensity *pd)
 {
 	PointDensity *pdn;
-	int a;
-	
+
 	pdn= MEM_dupallocN(pd);
 	pdn->point_tree = NULL;
 	

Modified: branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-09-29 04:14:47 UTC (rev 16808)
+++ branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-09-29 04:19:24 UTC (rev 16809)
@@ -133,13 +133,15 @@
 	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 @@
 
 /* **************** 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
 

Modified: branches/sim_physics/source/blender/render/intern/source/pointdensity.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-09-29 04:14:47 UTC (rev 16808)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-09-29 04:19:24 UTC (rev 16809)
@@ -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 @@
 	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 @@
 		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 @@
 
 		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 @@
 		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 @@
 	BRICONT;
 	
 	return rv;
-}
\ No newline at end of file
+}

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-29 04:14:47 UTC (rev 16808)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-29 04:19:24 UTC (rev 16809)
@@ -748,30 +748,46 @@
 	if(tex->pd) {
 		pd= tex->pd;
 
+		uiDefBut(block, LABEL, B_NOP, "Density estimation:",
+			X2CLM1, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+
 		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;
-		
-		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");
 		uiDefButS(block, NUM, B_REDR, "Nearby: ",
 			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");
+		}
 	}
-	
-	
+
 }
 
 





More information about the Bf-blender-cvs mailing list