Correct fix for knife interior use, distance needed to be in object-space
authorCampbell Barton <ideasman42@gmail.com>
Mon, 5 May 2014 23:32:06 +0000 (09:32 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 5 May 2014 23:32:06 +0000 (09:32 +1000)
source/blender/editors/mesh/editmesh_knife.c

index 490603ac0a71f17e9c6e409959d0a8781010d6c9..366a8253849f06c49457775841c5a22c2316b918 100644 (file)
@@ -1156,37 +1156,30 @@ static void calc_ortho_extent(KnifeTool_OpData *kcd)
  * s in screen projection of p. */
 static bool point_is_visible(KnifeTool_OpData *kcd, const float p[3], const float s[2], bglMats *mats)
 {
-       float p1[3];
        BMFace *f_hit;
 
        /* If not cutting through, make sure no face is in front of p */
        if (!kcd->cut_through) {
                float dist;
-               float view[3];
+               float view[3], p_ofs[3];
 
                /* TODO: I think there's a simpler way to get the required raycast ray */
                ED_view3d_unproject(mats, view, s[0], s[1], 0.0f);
 
+               mul_m4_v3(kcd->ob->imat, view);
+
+               /* make p_ofs a little towards view, so ray doesn't hit p's face. */
+               sub_v3_v3(view, p);
+               dist = normalize_v3(view);
+               madd_v3_v3v3fl(p_ofs, p, view, KNIFE_FLT_EPSBIG * 3.0f);
+
                /* avoid projecting behind the viewpoint */
                if (kcd->is_ortho) {
                        dist = FLT_MAX;
                }
-               else {
-                       float p_world[3];
-                       mul_v3_m4v3(p_world, kcd->ob->obmat, p);
-                       dist = len_v3v3(view, p_world);
-               }
-
-               mul_m4_v3(kcd->ob->imat, view);
-
-               /* make p1 a little towards view, so ray doesn't hit p's face. */
-               copy_v3_v3(p1, p);
-               sub_v3_v3(view, p1);
-               normalize_v3(view);
-               madd_v3_v3fl(p1, view, 3.0f * KNIFE_FLT_EPSBIG);
 
                /* see if there's a face hit between p1 and the view */
-               f_hit = BKE_bmbvh_ray_cast(kcd->bmbvh, p1, view, KNIFE_FLT_EPS, &dist, NULL, NULL);
+               f_hit = BKE_bmbvh_ray_cast(kcd->bmbvh, p_ofs, view, KNIFE_FLT_EPS, &dist, NULL, NULL);
                if (f_hit)
                        return false;
        }