Commit: f81e8903b407e8faa5f6c78a90bd802bb85fb13e
Author: mano-wii
Date:   Tue Oct 9 10:23:31 2018 -0300
Branches: blender2.8
https://developer.blender.org/rBf81e8903b407e8faa5f6c78a90bd802bb85fb13e

Fix T55202: 3D Cursor Snapping not working correctly in Edit Mode.

Use `mesh_eval_final` in this case.

===================================================================

M       source/blender/editors/transform/transform_snap_object.c

===================================================================

diff --git a/source/blender/editors/transform/transform_snap_object.c 
b/source/blender/editors/transform/transform_snap_object.c
index a3ce35a223a..7f4f3d888fc 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -100,6 +100,7 @@ typedef struct SnapObjectData {
 typedef struct SnapObjectData_Mesh {
        SnapObjectData sd;
        BVHTreeFromMesh treedata;
+       const struct MPoly *poly;
        BVHTree *bvhtree[2]; /* from loose verts and from loose edges */
        uint has_looptris   : 1;
        uint has_loose_edge : 1;
@@ -428,12 +429,19 @@ static bool raycastMesh(
                        if (treedata->looptri && treedata->looptri_allocated == 
false) {
                                treedata->looptri = 
BKE_mesh_runtime_looptri_ensure(me);
                        }
+                       /* required for snapping with occlusion. */
+                       treedata->edge = me->medge;
+                       sod->poly = me->mpoly;
                }
        }
 
        if (treedata->tree == NULL) {
                BKE_bvhtree_from_mesh_get(treedata, me, BVHTREE_FROM_LOOPTRI, 
4);
 
+               /* required for snapping with occlusion. */
+               treedata->edge = me->medge;
+               sod->poly = me->mpoly;
+
                if (treedata->tree == NULL) {
                        return retval;
                }
@@ -736,22 +744,31 @@ static bool raycastObj(
 
        switch (ob->type) {
                case OB_MESH:
-                       if (use_obedit && BKE_object_is_in_editmode(ob)) {
+               {
+                       Mesh *me = ob->data;
+                       if (BKE_object_is_in_editmode(ob)) {
                                BMEditMesh *em = BKE_editmesh_from_object(ob);
-                               retval = raycastEditMesh(
-                                       sctx,
-                                       ray_start, ray_dir,
-                                       ob, em, obmat, ob_index,
-                                       ray_depth, r_loc, r_no, r_index, 
r_hit_list);
-                       }
-                       else {
-                               retval = raycastMesh(
-                                       sctx,
-                                       ray_start, ray_dir,
-                                       ob, ob->data, obmat, ob_index,
-                                       ray_depth, r_loc, r_no, r_index, 
r_hit_list);
+                               if (use_obedit) {
+                                       retval = raycastEditMesh(
+                                               sctx,
+                                               ray_start, ray_dir,
+                                               ob, em, obmat, ob_index,
+                                               ray_depth, r_loc, r_no, 
r_index, r_hit_list);
+                                       break;
+                               }
+                               else if (em->mesh_eval_final &&
+                                       
(em->mesh_eval_final->runtime.deformed_only == false))
+                               {
+                                       me = em->mesh_eval_final;
+                               }
                        }
+                       retval = raycastMesh(
+                               sctx,
+                               ray_start, ray_dir,
+                               ob, me, obmat, ob_index,
+                               ray_depth, r_loc, r_no, r_index, r_hit_list);
                        break;
+               }
        }
 
        if (retval) {
@@ -1202,12 +1219,11 @@ static short snap_mesh_polygon(
                nearest2d.get_edge_verts_index = 
(Nearest2DGetEdgeVertsCallback)cb_medge_verts_get;
                nearest2d.copy_vert_no         = 
(Nearest2DCopyVertNoCallback)cb_mvert_no_copy;
 
-               MPoly *mp = &((Mesh *)ob->data)->mpoly[*r_index];
-               const MLoop *ml;
+               const MPoly *mp = &((SnapObjectData_Mesh *)sod)->poly[*r_index];
+               const MLoop *ml = &treedata->loop[mp->loopstart];
                if (snapdata->snap_to_flag & SCE_SNAP_MODE_EDGE) {
                        elem = SCE_SNAP_MODE_EDGE;
-                       treedata->edge = ((Mesh *)ob->data)->medge;
-                       ml = &treedata->loop[mp->loopstart];
+                       BLI_assert(treedata->edge != NULL);
                        for (int i = mp->totloop; i--; ml++) {
                                cb_snap_edge(
                                        &nearest2d, ml->e, &neasrest_precalc,
@@ -1217,7 +1233,6 @@ static short snap_mesh_polygon(
                }
                else {
                        elem = SCE_SNAP_MODE_VERTEX;
-                       ml = &treedata->loop[mp->loopstart];
                        for (int i = mp->totloop; i--; ml++) {
                                cb_snap_vert(
                                        &nearest2d, ml->v, &neasrest_precalc,
@@ -2243,21 +2258,29 @@ static short snapObject(
 
        switch (ob->type) {
                case OB_MESH:
-                       if (use_obedit && BKE_object_is_in_editmode(ob)) {
+               {
+                       Mesh *me = ob->data;
+                       if (BKE_object_is_in_editmode(ob)) {
                                BMEditMesh *em = BKE_editmesh_from_object(ob);
-                               retval = snapEditMesh(
-                                       sctx, snapdata, ob, em, obmat,
-                                       dist_px,
-                                       r_loc, r_no, r_index);
-                       }
-                       else {
-                               retval = snapMesh(
-                                       sctx, snapdata, ob, ob->data, obmat,
-                                       dist_px,
-                                       r_loc, r_no, r_index);
+                               if (use_obedit) {
+                                       retval = snapEditMesh(
+                                               sctx, snapdata, ob, em, obmat,
+                                               dist_px,
+                                               r_loc, r_no, r_index);
+                                       break;
+                               }
+                               else if (em->mesh_eval_final &&
+                                       
(em->mesh_eval_final->runtime.deformed_only == false))
+                               {
+                                       me = em->mesh_eval_final;
+                               }
                        }
+                       retval = snapMesh(
+                               sctx, snapdata, ob, me, obmat,
+                               dist_px,
+                               r_loc, r_no, r_index);
                        break;
-
+               }
                case OB_ARMATURE:
                        retval = snapArmature(
                                snapdata,

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to