[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56093] trunk/blender/source/blender/ blenkernel/intern/editmesh_bvh.c: fix for BKE_bmbvh_ray_cast() returning one of the vertices normals rather then the face normal.

Campbell Barton ideasman42 at gmail.com
Tue Apr 16 17:35:03 CEST 2013


Revision: 56093
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56093
Author:   campbellbarton
Date:     2013-04-16 15:35:01 +0000 (Tue, 16 Apr 2013)
Log Message:
-----------
fix for BKE_bmbvh_ray_cast() returning one of the vertices normals rather then the face normal. also remove redundant NULL checks.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c

Modified: trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c	2013-04-16 15:16:48 UTC (rev 56092)
+++ trunk/blender/source/blender/blenkernel/intern/editmesh_bvh.c	2013-04-16 15:35:01 UTC (rev 56093)
@@ -197,36 +197,20 @@
 }
 
 /* taken from bvhutils.c */
-static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist),
-                                  const float v0[3],  const float v1[3], const float v2[3],
-                                  float r_uv[2], float UNUSED(e))
-{
-	float dist;
-
-	if (isect_ray_tri_v3((float *)ray->origin, (float *)ray->direction, v0, v1, v2, &dist, r_uv)) {
-		return dist;
-	}
-
-	return FLT_MAX;
-}
-
 static void raycallback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)
 {
 	BMBVHTree *tree = userdata;
-	BMLoop **ls = tree->em->looptris[index];
+	BMLoop **ltri = tree->em->looptris[index];
 	float dist, uv[2];
-	 
-	if (!ls[0] || !ls[1] || !ls[2])
-		return;
-	
-	dist = ray_tri_intersection(ray, hit->dist, ls[0]->v->co, ls[1]->v->co,
-	                            ls[2]->v->co, uv, tree->epsilon);
-	if (dist < hit->dist) {
+
+	if (isect_ray_tri_v3(ray->origin, ray->direction, ltri[0]->v->co, ltri[1]->v->co, ltri[2]->v->co, &dist, uv) &&
+	    (dist < hit->dist))
+	{
 		hit->dist = dist;
 		hit->index = index;
-		
-		copy_v3_v3(hit->no, ls[0]->v->no);
 
+		copy_v3_v3(hit->no, ltri[0]->f->no);
+
 		copy_v3_v3(hit->co, ray->direction);
 		normalize_v3(hit->co);
 		mul_v3_fl(hit->co, dist);
@@ -251,12 +235,13 @@
 	if (hit.index != -1 && hit.dist != dist) {
 		if (r_hitout) {
 			if (tree->flag & BMBVH_RETURN_ORIG) {
+				BMLoop **ltri = tree->em->looptris[hit.index];
 				const float *co1, *co2, *co3;
 				int i;
 
-				co1 = tree->em->looptris[hit.index][0]->v->co;
-				co2 = tree->em->looptris[hit.index][1]->v->co;
-				co3 = tree->em->looptris[hit.index][2]->v->co;
+				co1 = ltri[0]->v->co;
+				co2 = ltri[1]->v->co;
+				co3 = ltri[2]->v->co;
 				
 				for (i = 0; i < 3; i++) {
 					r_hitout[i] = co1[i] + ((co2[i] - co1[i]) * tree->uv[0]) +
@@ -290,19 +275,19 @@
 static void vertsearchcallback(void *userdata, int index, const float *UNUSED(co), BVHTreeNearest *hit)
 {
 	BMBVHTree *tree = userdata;
-	BMLoop **ls = tree->em->looptris[index];
+	BMLoop **ltri = tree->em->looptris[index];
 	float dist, maxdist, v[3];
 	int i;
 
 	maxdist = tree->maxdist;
 
 	for (i = 0; i < 3; i++) {
-		sub_v3_v3v3(v, hit->co, ls[i]->v->co);
+		sub_v3_v3v3(v, hit->co, ltri[i]->v->co);
 
 		dist = len_v3(v);
 		if (dist < hit->dist && dist < maxdist) {
-			copy_v3_v3(hit->co, ls[i]->v->co);
-			copy_v3_v3(hit->no, ls[i]->v->no);
+			copy_v3_v3(hit->co, ltri[i]->v->co);
+			copy_v3_v3(hit->no, ltri[i]->v->no);
 			hit->dist = dist;
 			hit->index = index;
 		}
@@ -321,23 +306,21 @@
 
 	BLI_bvhtree_find_nearest(tree->tree, co, &hit, vertsearchcallback, tree);
 	if (hit.dist != FLT_MAX && hit.index != -1) {
-		BMLoop **ls = tree->em->looptris[hit.index];
-		float dist, curdist = tree->maxdist, v[3];
+		BMLoop **ltri = tree->em->looptris[hit.index];
+		float dist, curdist = tree->maxdist;
 		int cur = 0, i;
 
 		/* maxdist = tree->maxdist; */  /* UNUSED */
 
 		for (i = 0; i < 3; i++) {
-			sub_v3_v3v3(v, hit.co, ls[i]->v->co);
-
-			dist = len_v3(v);
+			dist = len_v3v3(hit.co, ltri[i]->v->co);
 			if (dist < curdist) {
 				cur = i;
 				curdist = dist;
 			}
 		}
 
-		return ls[cur]->v;
+		return ltri[cur]->v;
 	}
 
 	return NULL;




More information about the Bf-blender-cvs mailing list