[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25321] trunk/blender/source/blender/ blenlib: Sculpt:

Brecht Van Lommel brecht at blender.org
Fri Dec 11 17:59:09 CET 2009


Revision: 25321
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25321
Author:   blendix
Date:     2009-12-11 17:59:09 +0100 (Fri, 11 Dec 2009)

Log Message:
-----------
Sculpt:
* Temporary workaround for sculpt not working well with small polygons,
  still seems to be some issues, but can at least paint now.
* Small optimization avoiding local function variable aliasing.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/BLI_pbvh.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/blenlib/intern/pbvh.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2009-12-11 16:30:27 UTC (rev 25320)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2009-12-11 16:59:09 UTC (rev 25321)
@@ -85,6 +85,8 @@
 	float v0[3], float v1[3], float v2[3], float *lambda, float *uv);
 int isect_ray_tri_threshold_v3(float p1[3], float d[3],
 	float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold);
+int isect_ray_tri_epsilon_v3(float p1[3], float d[3],
+	float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float epsilon);
 
 /* point in polygon */
 int isect_point_tri_v2(float p[2], float a[2], float b[2], float c[2]);

Modified: trunk/blender/source/blender/blenlib/BLI_pbvh.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_pbvh.h	2009-12-11 16:30:27 UTC (rev 25320)
+++ trunk/blender/source/blender/blenlib/BLI_pbvh.h	2009-12-11 16:59:09 UTC (rev 25321)
@@ -100,6 +100,8 @@
 	struct DMGridData ***griddata, struct DMGridAdjacency **gridadj);
 void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node,
 	int *uniquevert, int *totvert);
+void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node,
+	int **vert_indices, struct MVert **verts);
 
 void BLI_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
 void BLI_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3]);
@@ -149,11 +151,30 @@
 	float *fno;
 } PBVHVertexIter;
 
-void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi, int mode);
-
 #define BLI_pbvh_vertex_iter_begin(bvh, node, vi, mode) \
-	/* XXX breaks aliasing! */ \
-	BLI_pbvh_node_verts_iter_init(bvh, node, &vi, mode); \
+	{ \
+		struct DMGridData **grids; \
+		struct MVert *verts; \
+		int *grid_indices, totgrid, gridsize, *vert_indices, uniq_verts, totvert; \
+		\
+		memset(&vi, 0, sizeof(PBVHVertexIter)); \
+		\
+		BLI_pbvh_node_get_grids(bvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids, NULL); \
+		BLI_pbvh_node_num_verts(bvh, node, &uniq_verts, &totvert); \
+		BLI_pbvh_node_get_verts(bvh, node, &vert_indices, &verts); \
+		\
+		vi.grids= grids; \
+		vi.grid_indices= grid_indices; \
+		vi.totgrid= (grids)? totgrid: 1; \
+		vi.gridsize= gridsize; \
+		\
+		if(mode == PBVH_ITER_ALL) \
+			vi.totvert = totvert; \
+		else \
+			vi.totvert= uniq_verts; \
+		vi.vert_indices= vert_indices; \
+		vi.mverts= verts; \
+	}\
 	\
 	for(vi.i=0, vi.g=0; vi.g<vi.totgrid; vi.g++) { \
 		if(vi.grids) { \

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2009-12-11 16:30:27 UTC (rev 25320)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2009-12-11 16:59:09 UTC (rev 25321)
@@ -458,6 +458,39 @@
 	return 1;
 }
 
+int isect_ray_tri_epsilon_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float epsilon)
+{
+	float p[3], s[3], e1[3], e2[3], q[3];
+	float a, f, u, v;
+	
+	sub_v3_v3v3(e1, v1, v0);
+	sub_v3_v3v3(e2, v2, v0);
+	
+	cross_v3_v3v3(p, d, e2);
+	a = dot_v3v3(e1, p);
+	if (a == 0.0f) return 0;
+	f = 1.0f/a;
+	
+	sub_v3_v3v3(s, p1, v0);
+	
+	cross_v3_v3v3(q, s, e1);
+	*lambda = f * dot_v3v3(e2, q);
+	if ((*lambda < 0.0)) return 0;
+	
+	u = f * dot_v3v3(s, p);
+	if ((u < -epsilon)||(u > 1.0+epsilon)) return 0;
+	
+	v = f * dot_v3v3(d, q);
+	if ((v < -epsilon)||((u + v) > 1.0+epsilon)) return 0;
+
+	if(uv) {
+		uv[0]= u;
+		uv[1]= v;
+	}
+	
+	return 1;
+}
+
 int isect_ray_tri_threshold_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv, float threshold)
 {
 	float p[3], s[3], e1[3], e2[3], q[3];

Modified: trunk/blender/source/blender/blenlib/intern/pbvh.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/pbvh.c	2009-12-11 16:30:27 UTC (rev 25320)
+++ trunk/blender/source/blender/blenlib/intern/pbvh.c	2009-12-11 16:59:09 UTC (rev 25321)
@@ -1006,11 +1006,10 @@
 	node->flag |= PBVH_UpdateNormals|PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateDrawBuffers|PBVH_UpdateRedraw;
 }
 
-void BLI_pbvh_node_get_verts(PBVHNode *node, int **vert_indices, int *totvert, int *allvert)
+void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node, int **vert_indices, MVert **verts)
 {
 	if(vert_indices) *vert_indices= node->vert_indices;
-	if(totvert) *totvert= node->uniq_verts;
-	if(allvert) *allvert= node->uniq_verts + node->face_verts;
+	if(verts) *verts= bvh->verts;
 }
 
 void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *totvert)
@@ -1100,7 +1099,7 @@
 
 	if((tmin > tzmax) || (tzmin > tmax))
 		return 0;
-
+	
 	return 1;
 
 	/* XXX: Not sure about this? 
@@ -1142,7 +1141,7 @@
 	{	
 		float dist = FLT_MAX;
 			
-		if(!isect_ray_tri_threshold_v3(ray_start, ray_normal, t0, t1, t2,
+		if(!isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t1, t2,
 					 &dist, NULL, 0.001f))
 			dist = FLT_MAX;
 
@@ -1300,18 +1299,3 @@
 	}
 }
 
-void BLI_pbvh_node_verts_iter_init(PBVH *bvh, PBVHNode *node, PBVHVertexIter *vi, int mode)
-{
-	memset(vi, 0, sizeof(PBVHVertexIter));
-	vi->grids= bvh->grids;
-	vi->grid_indices= node->prim_indices;
-	vi->totgrid= (bvh->grids)? node->totprim: 1;
-	vi->gridsize= bvh->gridsize;
-
-	vi->totvert= node->uniq_verts;
-	if(mode == PBVH_ITER_ALL)
-		vi->totvert += node->face_verts;
-	vi->vert_indices= node->vert_indices;
-	vi->mverts= bvh->verts;
-}
-





More information about the Bf-blender-cvs mailing list