Revision: 44844
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44844
Author:   campbellbarton
Date:     2012-03-13 01:11:08 +0000 (Tue, 13 Mar 2012)
Log Message:
-----------
workaround [#30480] Knife tool flicker

the problem was numeric precision when in ortho mode the start/end points for 
the view vector would be 2000 apart which caused trouble for the intersection 
test.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/editors/mesh/bmesh_tools.c
    trunk/blender/source/blender/editors/mesh/knifetool.c
    trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h        2012-03-12 
23:56:11 UTC (rev 44843)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h        2012-03-13 
01:11:08 UTC (rev 44844)
@@ -73,6 +73,7 @@
 
 float line_point_factor_v3(const float p[3], const float l1[3], const float 
l2[3]);
 float line_point_factor_v2(const float p[2], const float l1[2], const float 
l2[2]);
+void  limit_dist_v3(float v1[3], float v2[3], const float dist);
 
 /******************************* Intersection ********************************/
 

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c     2012-03-12 
23:56:11 UTC (rev 44843)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c     2012-03-13 
01:11:08 UTC (rev 44844)
@@ -1320,6 +1320,25 @@
        return(dot_v2v2(u, h)/dot_v2v2(u, u));
 }
 
+/* ensyre the distance between these points is no greater then 'dist'
+ * if it is, scale then both into the center */
+void limit_dist_v3(float v1[3], float v2[3], const float dist)
+{
+       const float dist_old = len_v3v3(v1, v2);
+
+       if (dist_old > dist) {
+               float v1_old[3];
+               float v2_old[3];
+               float fac = (dist / dist_old) * 0.5f;
+
+               copy_v3_v3(v1_old, v1);
+               copy_v3_v3(v2_old, v2);
+
+               interp_v3_v3v3(v1, v1_old, v2_old, 0.5f - fac);
+               interp_v3_v3v3(v2, v1_old, v2_old, 0.5f + fac);
+       }
+}
+
 /* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 
2d, assumes point is in quad */
 void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float 
v2[2], const float v3[2], const float pt[2], float r_uv[2])
 {

Modified: trunk/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/bmesh_tools.c     2012-03-12 
23:56:11 UTC (rev 44843)
+++ trunk/blender/source/blender/editors/mesh/bmesh_tools.c     2012-03-13 
01:11:08 UTC (rev 44844)
@@ -4447,7 +4447,7 @@
        BMIter iter;
        BMEdge *eed;
        BMOperator bmop;
-       float factor = RNA_float_get(op->ptr, "percent"), fac = factor /*, dfac 
*/ /* UNUSED */, df, s;
+       float factor = RNA_float_get(op->ptr, "percent"), /*, dfac */ /* UNUSED 
*/, df, s;
        int i, recursion = RNA_int_get(op->ptr, "recursion");
        const int use_even = RNA_boolean_get(op->ptr, "use_even");
        const int use_dist = RNA_boolean_get(op->ptr, "use_dist");
@@ -4484,9 +4484,8 @@
 
        mul_vn_fl(w, recursion, 1.0f / (float)ftot);
 
-       fac = factor;
        for (i = 0; i < recursion; i++) {
-               fac = w[recursion - i - 1] * factor;
+               float fac = w[recursion - i - 1] * factor;
 
                if (!EDBM_InitOpf(em, &bmop, op,
                                  "bevel geom=%hev percent=%f lengthlayer=%i 
use_lengths=%b use_even=%b use_dist=%b",

Modified: trunk/blender/source/blender/editors/mesh/knifetool.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/knifetool.c       2012-03-12 
23:56:11 UTC (rev 44843)
+++ trunk/blender/source/blender/editors/mesh/knifetool.c       2012-03-13 
01:11:08 UTC (rev 44844)
@@ -1178,6 +1178,16 @@
        mul_m4_v3(kcd->ob->imat, v3);
        mul_m4_v3(kcd->ob->imat, v4);
 
+       /* numeric error, 'v1' -> 'v2', 'v2' -> 'v4' can end up being ~2000 
units apart in otho mode
+        * (from ED_view3d_win_to_segment_clip() above)
+        * this gives precision error in 'knife_edge_tri_isect', rather then 
solving properly
+        * (which may involve using doubles everywhere!),
+        * limit the distance between these points */
+       if (kcd->is_ortho) {
+               limit_dist_v3(v1, v3, 200.0f);
+               limit_dist_v3(v2, v4, 200.0f);
+       }
+
        BLI_smallhash_init(ehash);
 
        /* test two triangles of sceen line's plane */

Modified: trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c        
2012-03-12 23:56:11 UTC (rev 44843)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Quaternion.c        
2012-03-13 01:11:08 UTC (rev 44844)
@@ -1101,7 +1101,7 @@
        }
 }
 
-/* axis vector suffers from precission errors, use this function to ensure */
+/* axis vector suffers from precision errors, use this function to ensure */
 static void quat__axis_angle_sanitize(float axis[3], float *angle)
 {
        if (axis) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to