Use mdisps layer from edit_mesh when adding/removing multires modifier
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 13 Dec 2010 10:24:05 +0000 (10:24 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 13 Dec 2010 10:24:05 +0000 (10:24 +0000)
when object is in edit mode.

source/blender/blenkernel/intern/multires.c
source/blender/editors/object/object_modifier.c

index 7f7433f8965b0375c492293b5c9dac3c25590a83..802bc32f5716788f5b3a6638fd2ea2a6bcb9e293 100644 (file)
@@ -37,6 +37,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
 #include "BLI_pbvh.h"
+#include "BLI_editVert.h"
 
 #include "BKE_cdderivedmesh.h"
 #include "BKE_mesh.h"
@@ -278,7 +279,10 @@ void multiresModifier_set_levels_from_disps(MultiresModifierData *mmd, Object *o
        Mesh *me = ob->data;
        MDisps *mdisp;
 
-       mdisp = CustomData_get_layer(&me->fdata, CD_MDISPS);
+       if(me->edit_mesh)
+               mdisp = CustomData_get_layer(&me->edit_mesh->fdata, CD_MDISPS);
+       else
+               mdisp = CustomData_get_layer(&me->fdata, CD_MDISPS);
 
        if(mdisp) {
                mmd->totlvl = get_levels_from_disps(ob);
index cf34e8855920eb331689a40bd48c70aa0c047ebb..ba1778a6a38e2a41c6a654f239846239bc3f49c9 100644 (file)
@@ -42,6 +42,7 @@
 #include "BLI_listbase.h"
 #include "BLI_string.h"
 #include "BLI_path_util.h"
+#include "BLI_editVert.h"
 
 #include "BKE_curve.h"
 #include "BKE_context.h"
@@ -68,6 +69,7 @@
 #include "ED_armature.h"
 #include "ED_object.h"
 #include "ED_screen.h"
+#include "ED_mesh.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -192,8 +194,16 @@ int ED_object_modifier_remove(ReportList *reports, Main *bmain, Scene *scene, Ob
        else if(md->type == eModifierType_Multires) {
                Mesh *me= ob->data;
 
-               CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface);
-               CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface);
+               if(me->edit_mesh) {
+                       EditMesh *em= me->edit_mesh;
+                       /* CustomData_external_remove is used here only to mark layer as non-external
+                          for further free-ing, so zero element count looks safer than em->totface */
+                       CustomData_external_remove(&em->fdata, &me->id, CD_MDISPS, 0);
+                       EM_free_data_layer(em, &em->fdata, CD_MDISPS);
+               } else {
+                       CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface);
+                       CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface);
+               }
        }
 
        if(ELEM(md->type, eModifierType_Softbody, eModifierType_Cloth) &&