[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40294] branches/bmesh/blender/source/ blender/editors/mesh/knifetool.c: Fix knife midpoint snapping when previous point was a vertex; also reduced snap radius to approximately match crosshairs.

Howard Trickey howard.trickey at gmail.com
Sat Sep 17 14:31:22 CEST 2011


Revision: 40294
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40294
Author:   howardt
Date:     2011-09-17 12:31:22 +0000 (Sat, 17 Sep 2011)
Log Message:
-----------
Fix knife midpoint snapping when previous point was a vertex; also reduced snap radius to approximately match crosshairs.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/editors/mesh/knifetool.c

Modified: branches/bmesh/blender/source/blender/editors/mesh/knifetool.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/knifetool.c	2011-09-17 12:25:51 UTC (rev 40293)
+++ branches/bmesh/blender/source/blender/editors/mesh/knifetool.c	2011-09-17 12:31:22 UTC (rev 40294)
@@ -90,7 +90,7 @@
 /* this code here is kindof messy. . .I might need to eventually rework it - joeedh*/
 
 #define MAXGROUP	30
-#define KMAXDIST	25	/*max mouse distance from edge before not detecting it*/
+#define KMAXDIST	10	/*max mouse distance from edge before not detecting it*/
 
 /* knifetool operator */
 typedef struct KnifeVert {
@@ -774,7 +774,7 @@
 	BLI_array_declare(edges);
 	BVHTreeOverlap *results, *result;
 	BMLoop **ls;
-	float cos[9], uv[3], lambda;
+	float cos[9], uv[3], lambda, depsilon;
 	unsigned int tot=0;
 	int i, j;
 	
@@ -782,6 +782,9 @@
 	copy_v3_v3(cos+3, v2);
 	copy_v3_v3(cos+6, v3);
 	
+	/* for comparing distances, error of intersection depends on triangle scale */
+	depsilon = 50*FLT_EPSILON*MAX3(len_v3v3(v1, v2), len_v3v3(v1, v3), len_v3v3(v2, v3));
+
 	BLI_bvhtree_insert(tree2, 0, cos, 3);
 	BLI_bvhtree_balance(tree2);
 	
@@ -807,18 +810,14 @@
 				if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, uv)) {
 					float no[3], view[3], sp[3];
 					
-					sub_v3_v3v3(p, kfe->v2->cageco, kfe->v1->cageco);
-					mul_v3_fl(p, lambda);
-					add_v3_v3(p, kfe->v1->cageco);
+					interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda);
 					
-					if (lambda < 0.0f-FLT_EPSILON*10 || lambda > 1.0 + FLT_EPSILON*10)
+					if (kcd->curvert && len_v3v3(kcd->curvert->cageco, p) < depsilon)
 						continue;
-					if (kcd->curvert && len_v3v3(kcd->curvert->cageco, p) < FLT_EPSILON*50)
+					if (kcd->prevvert && len_v3v3(kcd->prevvert->cageco, p) < depsilon)
 						continue;
-					if (kcd->prevvert && len_v3v3(kcd->prevvert->cageco, p) < FLT_EPSILON*50)
+					if (len_v3v3(kcd->prevcage, p) < depsilon || len_v3v3(kcd->vertcage, p) < depsilon)
 						continue;
-					if (len_v3v3(kcd->prevcage, p) < FLT_EPSILON*50 || len_v3v3(kcd->vertcage, p) < FLT_EPSILON*50)
-						continue;
 					
 					/*check if this point is visible in the viewport*/
 					knife_project_v3(kcd, p, sp);
@@ -841,7 +840,7 @@
 					if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) {
 						BMEdgeHit hit;
 						
-						if (len_v3v3(p, kcd->vertco) < FLT_EPSILON*50 || len_v3v3(p, kcd->prevco) < FLT_EPSILON*50)
+						if (len_v3v3(p, kcd->vertco) < depsilon || len_v3v3(p, kcd->prevco) < depsilon)
 							continue;
 						
 						hit.kfe = kfe;




More information about the Bf-blender-cvs mailing list