Fix T57620: display custom normals in Edit Mode.
[blender.git] / source / blender / blenkernel / intern / DerivedMesh.c
index de2cd5603a6bb802f79c0456305bd08d91811fb7..abad99a49094a2c71fe8060b49963346e73d23ab 100644 (file)
@@ -1151,6 +1151,14 @@ static void add_shapekey_layers(Mesh *me_dst, Mesh *me_src, Object *UNUSED(ob))
        }
 }
 
+static void mesh_copy_autosmooth(Mesh *me, Mesh *me_orig)
+{
+       if (me_orig->flag & ME_AUTOSMOOTH) {
+               me->flag |= ME_AUTOSMOOTH;
+               me->smoothresh = me_orig->smoothresh;
+       }
+}
+
 static void mesh_calc_modifiers(
         struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*inputVertexCos)[3],
         int useDeform,
@@ -1460,6 +1468,8 @@ static void mesh_calc_modifiers(
                                        }
                                        deformedVerts = NULL;
                                }
+
+                               mesh_copy_autosmooth(me, ob->data);
                        }
 
                        /* create an orco mesh in parallel */
@@ -1693,6 +1703,7 @@ static void editbmesh_calc_modifiers(
 
        if (r_cage && cageIndex == -1) {
                *r_cage = BKE_mesh_from_editmesh_with_coords_thin_wrap(em, dataMask, NULL);
+               mesh_copy_autosmooth(*r_cage, ob->data);
        }
 
        md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
@@ -1769,6 +1780,8 @@ static void editbmesh_calc_modifiers(
                                me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, 0);
                                ASSERT_IS_VALID_MESH(me);
 
+                               mesh_copy_autosmooth(me, ob->data);
+
                                if (deformedVerts) {
                                        BKE_mesh_apply_vert_coords(me, deformedVerts);
                                }
@@ -1822,6 +1835,8 @@ static void editbmesh_calc_modifiers(
                                        MEM_freeN(deformedVerts);
                                        deformedVerts = NULL;
                                }
+
+                               mesh_copy_autosmooth(me, ob->data);
                        }
                        me->runtime.deformed_only = false;
                }
@@ -1843,6 +1858,7 @@ static void editbmesh_calc_modifiers(
                                *r_cage = BKE_mesh_from_editmesh_with_coords_thin_wrap(
                                        em, mask,
                                        deformedVerts ? MEM_dupallocN(deformedVerts) : NULL);
+                               mesh_copy_autosmooth(*r_cage, ob->data);
                        }
                }
        }
@@ -1878,6 +1894,8 @@ static void editbmesh_calc_modifiers(
                *r_final = BKE_mesh_from_editmesh_with_coords_thin_wrap(em, dataMask, deformedVerts);
                deformedVerts = NULL;
 
+               mesh_copy_autosmooth(*r_final, ob->data);
+
                /* In this case, we should never have weight-modifying modifiers in stack... */
                if (do_init_statvis) {
                        editmesh_update_statvis_color(scene, ob);
@@ -1916,6 +1934,10 @@ static void editbmesh_calc_modifiers(
        if (!do_loop_normals) {
                BKE_mesh_ensure_normals_for_display(*r_final);
 
+               if (r_cage && *r_cage && (*r_cage != *r_final)) {
+                       BKE_mesh_ensure_normals_for_display(*r_cage);
+               }
+
                /* Some modifiers, like datatransfer, may generate those data, we do not want to keep them,
                 * as they are used by display code when available (i.e. even if autosmooth is disabled). */
                if (CustomData_has_layer(&(*r_final)->ldata, CD_NORMAL)) {