- Save MDISPS layer when applying modifier.

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.
This commit is contained in:
Sergey Sharybin 2010-09-26 18:29:54 +00:00
parent cf6b2ca034
commit 57527cb0ac
3 changed files with 17 additions and 1 deletions

View 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);

View 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)) {

View 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;
}
}