diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2008-07-27 23:21:10 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2008-07-27 23:21:10 +0400 |
commit | 5a3572beecf86bdbdc8fe1589567f5d4d66b095b (patch) | |
tree | dd71e5b7d7f855ddb959f541818e58e60d42a9cf | |
parent | 495a8d393745e65d4c0e2e72734871955cb8b20a (diff) |
Somewhat hacky support for undo in sculptmode; does a copy of MVert DerivedMesh data when pushing undo, but not for regular save/load.
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 18 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 3 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 7 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_mesh_types.h | 3 | ||||
-rw-r--r-- | source/blender/src/sculptmode.c | 3 |
6 files changed, 37 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index e48d159ba2f..c7d37610254 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1263,8 +1263,6 @@ DerivedMesh *MultiresDM_new(MultiresSubsurf *ms, DerivedMesh *orig, int numVerts mrdm->subco = MEM_callocN(sizeof(float)*3*numVerts, "multires subdivided coords"); mrdm->block_update = 0; - MultiresDM_calc_norm(mrdm); - dm->release = MultiresDM_release; return dm; @@ -1277,7 +1275,12 @@ Mesh *MultiresDM_get_mesh(DerivedMesh *dm) void *MultiresDM_get_vertnorm(DerivedMesh *dm) { - return ((MultiresDM*)dm)->norm; + MultiresDM *mrdm = (MultiresDM*)dm; + + if(!mrdm->norm) + MultiresDM_calc_norm(mrdm); + + return mrdm->norm; } void *MultiresDM_get_orco(DerivedMesh *dm) diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index a7c7abf305f..4f0960c73f2 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -7224,12 +7224,28 @@ static DerivedMesh *multiresModifier_applyModifier(ModifierData *md, Object *ob, int useRenderParams, int isFinalCalc) { MultiresModifierData *mmd = (MultiresModifierData*)md; + Mesh *me = get_mesh(ob); + DerivedMesh *final; /* TODO: for now just skip a level1 mesh */ if(mmd->lvl == 1) return dm; - return multires_dm_create_from_derived(mmd, dm, get_mesh(ob), useRenderParams, isFinalCalc); + final = multires_dm_create_from_derived(mmd, dm, me, useRenderParams, isFinalCalc); + if(me->mr_undo_state && me->mr_undo && me->mr_undo_tot == final->getNumVerts(final)) { + int i; + MVert *dst = CDDM_get_verts(final); + for(i = 0; i < me->mr_undo_tot; ++i) { + VecCopyf(dst[i].co, me->mr_undo[i].co); + } + CDDM_calc_normals(final); + } + if(me->mr_undo && me->mr_undo_state) + MEM_freeN(me->mr_undo); + me->mr_undo_state = 0; + me->mr_undo = NULL; + + return final; } /***/ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 3a6147a0ecc..9346e0f9931 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2767,6 +2767,9 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh) mesh->bb= NULL; mesh->mselect = NULL; + mesh->mr_undo = newdataadr(fd, mesh->mr_undo); + mesh->mr_undo_state = 1; + /* Multires data */ mesh->mr= newdataadr(fd, mesh->mr); if(mesh->mr) { diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ee1e442119b..57fe2c76128 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1173,7 +1173,7 @@ static void write_customdata(WriteData *wd, int count, CustomData *data, int par } } -static void write_meshs(WriteData *wd, ListBase *idbase) +static void write_meshs(WriteData *wd, ListBase *idbase, int mr_undo) { Mesh *mesh; MultiresLevel *lvl; @@ -1246,6 +1246,9 @@ static void write_meshs(WriteData *wd, ListBase *idbase) writestruct(wd, DATA, "MFace", mesh->pv->totface, mesh->pv->old_faces); writestruct(wd, DATA, "MEdge", mesh->pv->totedge, mesh->pv->old_edges); } + + if(mr_undo && mesh->mr_undo) + writestruct(wd, DATA, "MVert", mesh->mr_undo_tot, mesh->mr_undo); } mesh= mesh->id.next; } @@ -2031,7 +2034,7 @@ static int write_file_handle(int handle, MemFile *compare, MemFile *current, int write_objects (wd, &G.main->object); write_materials(wd, &G.main->mat); write_textures (wd, &G.main->tex); - write_meshs (wd, &G.main->mesh); + write_meshs (wd, &G.main->mesh, (current != NULL)); write_particlesettings(wd, &G.main->particle); write_nodetrees(wd, &G.main->nodetree); write_brushes (wd, &G.main->brush); diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 752a2360905..83f5637f21e 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -94,6 +94,9 @@ typedef struct Mesh { short totcol; short subsurftype; /* only kept for backwards compat, not used anymore */ + struct MVert *mr_undo; /* Store DerivedMesh vertices for multires undo */ + int mr_undo_tot, mr_undo_state; + struct Multires *mr; /* Multiresolution modeling data */ struct PartialVisibility *pv; /*ifdef WITH_VERSE*/ diff --git a/source/blender/src/sculptmode.c b/source/blender/src/sculptmode.c index 7b55893fa40..d899ecbdd24 100644 --- a/source/blender/src/sculptmode.c +++ b/source/blender/src/sculptmode.c @@ -1825,6 +1825,9 @@ void sculpt(void) MEM_freeN(a); sculpt_stroke_free(); + get_mesh(OBACT)->mr_undo = ss->mvert; + get_mesh(OBACT)->mr_undo_tot = ss->totvert; + sculpt_undo_push(G.scene->sculptdata.brush_type); if(G.vd->depths) G.vd->depths->damaged= 1; |