[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16814] branches/sim_physics/source/ blender: * New Point Density texture option: 'Object Vertices'

Matt Ebb matt at mke3.net
Mon Sep 29 09:57:25 CEST 2008


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

Log Message:
-----------
* New Point Density texture option: 'Object Vertices'

This works very similarly to particles, it just uses the object's renderable vertices as the points instead.

http://mke3.net/blender/devel/rendering/volumetrics/pd_objectvertices.png

Modified Paths:
--------------
    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/makesdna/DNA_texture_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-09-29 07:17:12 UTC (rev 16813)
+++ branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-09-29 07:56:41 UTC (rev 16814)
@@ -136,12 +136,14 @@
 	short source;
 	short pdpad[3];
 
-	struct Object *object;	/* for 'Particle system' type - source object */
-	short psysindex;		/* and object's psys number */
-	short psys_cache_space;	/* cache particles in worldspace, object space, ... ? */
+	struct Object *object;	/* for 'Object' or 'Particle system' type - source object */
+	short psys_cache_space;		/* cache points in worldspace, object space, ... ? */
+	short psysindex;		/* for 'Particle system' type - object's psys number */
 	
-	short pdpad2[2];
+	short ob_cache_space;		/* cache points in worldspace, object space, ... ? */
 	
+	short pdpad2;
+	
 	void *point_tree;		/* the kd-tree containing points */
 } PointDensity;
 
@@ -414,9 +416,9 @@
 #define TEX_PD_FILE			2
 
 /* psys_cache_space */
-#define TEX_PD_PSYS_OBJECTLOC	0
-#define TEX_PD_PSYS_OBJECTSPACE	1
-#define TEX_PD_PSYS_WORLDSPACE	2
+#define TEX_PD_OBJECTLOC	0
+#define TEX_PD_OBJECTSPACE	1
+#define TEX_PD_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 07:17:12 UTC (rev 16813)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c	2008-09-29 07:56:41 UTC (rev 16814)
@@ -39,6 +39,7 @@
 #include "DNA_particle_types.h"
 
 #include "render_types.h"
+#include "renderdatabase.h"
 #include "texture.h"
 
 
@@ -54,7 +55,6 @@
 	/* init crap */
 	if (!psys || !ob || !pd) return;
 	
-	//Mat4CpyMat4(obview, ob->obmat);
 	Mat4MulMat4(obview, re->viewinv, ob->obmat);
 	
 	/* Just to create a valid rendering context */
@@ -71,7 +71,6 @@
 	/* 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);
 	
 	if (psys->totchild > 0 && !(psys->part->draw & PART_DRAW_PARENT))
@@ -84,17 +83,17 @@
 			
 			VECCOPY(partco, state.co);
 			
-			if (pd->psys_cache_space == TEX_PD_PSYS_OBJECTSPACE)
+			if (pd->psys_cache_space == TEX_PD_OBJECTSPACE)
 				Mat4MulVecfl(ob->imat, partco);
-			else if (pd->psys_cache_space == TEX_PD_PSYS_OBJECTLOC) {
+			else if (pd->psys_cache_space == TEX_PD_OBJECTLOC) {
 				float obloc[3];
 				VECCOPY(obloc, ob->loc);
 				VecSubf(partco, partco, obloc);
 			} else {
-				/* TEX_PD_PSYS_WORLDSPACE */
+				/* TEX_PD_WORLDSPACE */
 			}
 			
-			BLI_kdtree_insert(pd->point_tree, 0, partco, NULL);
+			BLI_kdtree_insert(pd->point_tree, i, partco, NULL);
 		}
 	}
 	
@@ -103,6 +102,38 @@
 }
 
 
+static void pointdensity_cache_object(Render *re, PointDensity *pd, ObjectRen *obr)
+{
+	int i;
+	
+	if (!obr || !pd) return;
+	if(!obr->vertnodes) return;
+	
+	/* in case ob->imat isn't up-to-date */
+	Mat4Invert(obr->ob->imat, obr->ob->obmat);
+	
+	pd->point_tree = BLI_kdtree_new(obr->totvert);
+	
+	for(i=0; i<obr->totvert; i++) {
+		float ver_co[3];
+		VertRen *ver= RE_findOrAddVert(obr, i);
+		
+		VECCOPY(ver_co, ver->co);
+		
+		if (pd->ob_cache_space == TEX_PD_OBJECTSPACE) {
+			Mat4MulVecfl(re->viewinv, ver_co);
+			Mat4MulVecfl(obr->ob->imat, ver_co);
+		} else {
+			/* TEX_PD_WORLDSPACE */
+			Mat4MulVecfl(re->viewinv, ver_co);
+		}
+		
+		BLI_kdtree_insert(pd->point_tree, i, ver_co, NULL);
+	}
+	
+	BLI_kdtree_balance(pd->point_tree);
+
+}
 static void cache_pointdensity(Render *re, Tex *tex)
 {
 	PointDensity *pd = tex->pd;
@@ -124,6 +155,22 @@
 		
 		pointdensity_cache_psys(re, pd, ob, psys);
 	}
+	else if (pd->source == TEX_PD_OBJECT) {
+		Object *ob = pd->object;
+		ObjectRen *obr;
+		int found=0;
+
+		/* find the obren that corresponds to the object */
+		for (obr=re->objecttable.first; obr; obr=obr->next) {
+			if (obr->ob == ob) {
+				found=1;
+				break;
+			}
+		}
+		if (!found) return;
+		
+		pointdensity_cache_object(re, pd, obr);
+	}
 }
 
 static void free_pointdensity(Render *re, Tex *tex)

Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-29 07:17:12 UTC (rev 16813)
+++ branches/sim_physics/source/blender/src/buttons_shading.c	2008-09-29 07:56:41 UTC (rev 16814)
@@ -763,7 +763,7 @@
 		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",
+		uiDefButS(block, MENU, B_TEXREDR_PRV, "Particle System %x0|Object Vertices %x1",
 				X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->source, 0.0, 0.0, 0, 0, "Source");
 		
 		yco -= YSPACE;
@@ -786,6 +786,17 @@
 			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");
 		}
+		else if (pd->source == TEX_PD_OBJECT) {
+			uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Ob:",
+				X2CLM2, yco-=BUTH, BUTW2, BUTH, &(pd->object), "Object to render as points");
+			
+			yco -= YSPACE;
+			
+			uiDefBut(block, LABEL, B_NOP, "Cache vertices in:",
+				X2CLM2, yco-=BUTH, BUTW2, BUTH, 0, 0, 0, 0, 0, "");
+			uiDefButS(block, MENU, B_TEXREDR_PRV, "Object Space %x1|Global Space %x2",
+				X2CLM2, yco-=BUTH, BUTW2, BUTH, &pd->ob_cache_space, 0.0, 0.0, 0, 0, "Co-ordinate system to cache vertices in");
+		}
 	}
 
 }
@@ -4310,8 +4321,6 @@
 	uiBlockBeginAlign(block);
 	uiDefButF(block, NUM, B_MATPRV, "Step Size: ",
 		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_stepsize), 0.001, 100.0, 10, 2, "Ray marching step size");
-	uiDefButF(block, NUMSLI, B_MATPRV, "Density: ",
-		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->alpha), 0.0, 1.0, 0, 0, "Base opacity value");
 	uiDefButS(block, NUM, B_MATPRV, "Layer Depth: ",
 		X2CLM1, yco-=BUTH, BUTW2, BUTH, &(ma->vol_raydepth), 0.0, 512.0, 10, 2, "Number of layered volume ray intersections allowed per pixel");
 	uiBlockEndAlign(block);
@@ -4327,6 +4336,11 @@
 	
 	yco = PANEL_YMAX;
 	
+	uiDefButF(block, NUMSLI, B_MATPRV, "Density: ",
+		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->alpha), 0.0, 1.0, 0, 0, "Base opacity value");
+	
+	yco -= YSPACE;
+	
 	uiBlockBeginAlign(block);
 	uiDefButF(block, NUM, B_MATPRV, "Absorption: ",
 		X2CLM2, yco-=BUTH, BUTW2, BUTH, &(ma->vol_absorption), 0.0, 10.0, 10, 0, "Multiplier for absorption");





More information about the Bf-blender-cvs mailing list