- Save MDISPS layer when applying modifier.
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 26 Sep 2010 18:29:54 +0000 (18:29 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 26 Sep 2010 18:29:54 +0000 (18:29 +0000)
  All sculpting used to disappear before. Save MDISPS if new mesh has got the same faces amount.
  NOTE: maybe some other layers should be saved?
- Apply multires modififier if MDISPS was auto-created.
  Multires's applyModifier used to return unchanged DM when MDISPS was auto-created.
- Set multires totlvl from MDISPS layer when new multires was added to mesh with existing MDISPS layer.

source/blender/blenkernel/intern/DerivedMesh.c
source/blender/editors/object/object_modifier.c
source/blender/modifiers/intern/MOD_multires.c

index de7b962e38a59105a0ad449d9944720d9ede0509..0b3bd106544e097cc031123af7937c47ceaac60e 100644 (file)
@@ -239,6 +239,15 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me)
        if(!CustomData_has_layer(&tmp.fdata, CD_MFACE))
                CustomData_add_layer(&tmp.fdata, CD_MFACE, CD_ASSIGN, dm->dupFaceArray(dm), totface);
 
+       /* object had got displacement layer, should copy this layer to save sculpted data */
+       /* NOTE: maybe some other layers should be copied? nazgul */
+       if(CustomData_has_layer(&me->fdata, CD_MDISPS)) {
+               if (totface == me->totface) {
+                       MDisps *mdisps = CustomData_get_layer(&me->fdata, CD_MDISPS);
+                       CustomData_add_layer(&tmp.fdata, CD_MDISPS, CD_DUPLICATE, mdisps, totface);
+               }
+       }
+
        mesh_update_customdata_pointers(&tmp);
 
        CustomData_free(&me->vdata, me->totvert);
index 7cf24d5d07d4e1fd394033bd77269c41ef8edb7a..ec44383f1dd08dfd28ee05c130a167c2e0acef30 100644 (file)
@@ -132,6 +132,9 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *sc
                }
                else if(type == eModifierType_Surface)
                        DAG_scene_sort(bmain, scene);
+               else if(type == eModifierType_Multires)
+                       /* set totlvl from existing MDISPS layer if object already had it */
+                       multiresModifier_set_levels_from_disps(new_md, ob);
        }
 
        DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
@@ -431,6 +434,11 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob,
                        DM_to_mesh(dm, me);
 
                        dm->release(dm);
+
+                       if(md->type == eModifierType_Multires) {
+                               CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface);
+                               CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface);
+                       }
                }
        } 
        else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
index dd99c88a68491fd41d9fee13659ce87dad2de8aa..988ce3921a7c4a81afa9430d0c845d4eb88ae354 100644 (file)
@@ -74,7 +74,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
                if(!CustomData_get_layer(&me->fdata, CD_MDISPS)) {
                        /* multires always needs a displacement layer */
                        CustomData_add_layer(&me->fdata, CD_MDISPS, CD_CALLOC, NULL, me->totface);
-                       return dm;
                }
        }