Revision: 15817
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15817
Author:   nicholasbishop
Date:     2008-07-27 21:21:10 +0200 (Sun, 27 Jul 2008)

Log Message:
-----------
Somewhat hacky support for undo in sculptmode; does a copy of MVert DerivedMesh 
data when pushing undo, but not for regular save/load.

Modified Paths:
--------------
    
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/modifier.c
    branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c
    
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c
    branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_mesh_types.h
    branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c

Modified: 
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- 
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
   2008-07-27 18:59:41 UTC (rev 15816)
+++ 
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/cdderivedmesh.c
   2008-07-27 19:21:10 UTC (rev 15817)
@@ -1263,8 +1263,6 @@
        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 @@
 
 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)

Modified: 
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/modifier.c
===================================================================
--- 
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/modifier.c    
    2008-07-27 18:59:41 UTC (rev 15816)
+++ 
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/modifier.c    
    2008-07-27 19:21:10 UTC (rev 15817)
@@ -7224,12 +7224,28 @@
                                                   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;
 }
 
 /***/

Modified: 
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c
===================================================================
--- 
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c    
    2008-07-27 18:59:41 UTC (rev 15816)
+++ 
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c    
    2008-07-27 19:21:10 UTC (rev 15817)
@@ -2767,6 +2767,9 @@
        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) {

Modified: 
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c
===================================================================
--- 
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c   
    2008-07-27 18:59:41 UTC (rev 15816)
+++ 
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/writefile.c   
    2008-07-27 19:21:10 UTC (rev 15817)
@@ -1173,7 +1173,7 @@
        }
 }
 
-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 @@
                                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 @@
        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);

Modified: 
branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_mesh_types.h
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_mesh_types.h   
2008-07-27 18:59:41 UTC (rev 15816)
+++ branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_mesh_types.h   
2008-07-27 19:21:10 UTC (rev 15817)
@@ -94,6 +94,9 @@
        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*/

Modified: branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c    
2008-07-27 18:59:41 UTC (rev 15816)
+++ branches/soc-2008-nicholasbishop/source/blender/src/sculptmode.c    
2008-07-27 19:21:10 UTC (rev 15817)
@@ -1825,6 +1825,9 @@
        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;


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to