[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28478] branches/render25/source/blender: hair collision test is a little better.

Joseph Eagar joeedh at gmail.com
Wed Apr 28 00:46:06 CEST 2010


Revision: 28478
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28478
Author:   joeedh
Date:     2010-04-28 00:46:04 +0200 (Wed, 28 Apr 2010)

Log Message:
-----------
hair collision test is a little better.  also fixed a mem leak and hopefully fixed a hang that can happen sometimes.

Modified Paths:
--------------
    branches/render25/source/blender/blenkernel/intern/cloth.c
    branches/render25/source/blender/blenkernel/intern/collision.c
    branches/render25/source/blender/editors/space_graph/graph_draw.c

Modified: branches/render25/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/cloth.c	2010-04-27 22:29:11 UTC (rev 28477)
+++ branches/render25/source/blender/blenkernel/intern/cloth.c	2010-04-27 22:46:04 UTC (rev 28478)
@@ -195,7 +195,7 @@
 {
 	unsigned int i;
 	BVHTree *bvhtree, *bvhspringtree = NULL;
-	GHash *gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
+	GHash *gh;
 	Cloth *cloth;
 	ClothVertex *verts, *v;
 	MFace *mfaces;
@@ -220,6 +220,7 @@
 	bvhtree = BLI_bvhtree_new(cloth->numfaces, epsilon, 4, 26);
 	
 	// fill tree
+	gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
 	for(i = 0; i < cloth->numfaces; i++, mfaces++)
 	{
 		BLI_ghash_insert(gh, &verts[mfaces->v1], NULL);
@@ -647,6 +648,9 @@
 		if ( cloth->bvhselftree )
 			BLI_bvhtree_free ( cloth->bvhselftree );
 
+		if ( cloth->bvhspringtree )
+			BLI_bvhtree_free ( cloth->bvhspringtree );
+
 		// we save our faces for collision objects
 		if ( cloth->mfaces )
 			MEM_freeN ( cloth->mfaces );

Modified: branches/render25/source/blender/blenkernel/intern/collision.c
===================================================================
--- branches/render25/source/blender/blenkernel/intern/collision.c	2010-04-27 22:29:11 UTC (rev 28477)
+++ branches/render25/source/blender/blenkernel/intern/collision.c	2010-04-27 22:46:04 UTC (rev 28478)
@@ -1450,7 +1450,7 @@
 
 	for (i=0; i<result; i++, overlap++) {
 		MFace *mf = collmd->mfaces + overlap->indexB;
-		float v1[3], v2[3], v3[3], v4[3], no[3], vec[3];
+		float v1[3], v2[3], v3[3], v4[3], no[3], vec[3], ov1[3], ov2[3], ov3[3];
 
 		if (overlap->indexA < 0 || overlap->indexA >= cloth->numverts)
 			continue;
@@ -1482,7 +1482,27 @@
 		if (isect_ray_tri_v3(cv->tx, no, v1, v2, v3, &lambda, uv) ||
 			(mf->v4 && isect_ray_tri_v3(cv->tx, vec, v1, v3, v4, &lambda, uv)))
 		{
-			if (!frefs[j] || lambda < dis[j]) {
+			/*we need to compute distance to the plane of the previous time step's face, not the current one*/
+			VECCOPY(ov1, collmd->current_x[mf->v1].co);
+			VECCOPY(ov2, collmd->current_x[mf->v2].co);
+			VECCOPY(ov3, collmd->current_x[mf->v3].co);
+
+			normal_tri_v3(no, ov1, ov2, ov3);
+			mul_v3_fl(no, epsilon);
+
+			add_v3_v3(ov1, no);
+			add_v3_v3(ov2, no);
+			add_v3_v3(ov3, no);
+
+			normalize_v3(no);
+			mul_v3_fl(no, -1.0);
+
+			isect_ray_tri_plane_v3(cv->txold, no, ov1, ov2, ov3, &lambda, uv);
+
+			if (lambda < 0.0)
+				continue;
+
+			if (!frefs[j] || fabs(lambda) < dis[j]) {
 				frefs[j] = mf;
 				dis[j] = lambda;
 			}
@@ -1687,6 +1707,9 @@
 			}
 
 			ret += cloth_bvh_edge_objcollisions_nearcheck ( clmd, collmd, result, overlap, dt);
+
+			if (overlap)
+				MEM_freeN(overlap);
 		}
 		rounds++;
 		

Modified: branches/render25/source/blender/editors/space_graph/graph_draw.c
===================================================================
--- branches/render25/source/blender/editors/space_graph/graph_draw.c	2010-04-27 22:29:11 UTC (rev 28477)
+++ branches/render25/source/blender/editors/space_graph/graph_draw.c	2010-04-27 22:46:04 UTC (rev 28478)
@@ -527,7 +527,7 @@
 		 */
 		// TODO: perhaps we should have 1.0 frames as upper limit so that curves don't get too distorted?
 	samplefreq= *((float *)grid) / U.v2d_min_gridsize;
-	if (samplefreq < 0.00001f) samplefreq= 0.00001f;
+	if (samplefreq < 0.001f) samplefreq= 0.001f;
 	
 	
 	/* the start/end times are simply the horizontal extents of the 'cur' rect */





More information about the Bf-blender-cvs mailing list