- added Mesh->derived and Mesh->decimated DerivedMesh pointers
authorDaniel Dunbar <daniel@zuster.org>
Tue, 29 Mar 2005 16:43:39 +0000 (16:43 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 29 Mar 2005 16:43:39 +0000 (16:43 +0000)
 - removed DL_MESH displist type!!!! Now store a DerivedMesh directly.
 - May still be some issues left having to do with releasing this
   at the right time (old code just splashed free_displist all
   over the place).

21 files changed:
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_displist.h
source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/effect.c
source/blender/blenkernel/intern/exotic.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/subsurf.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/intern/noise.c
source/blender/blenlib/intern/storage.c
source/blender/makesdna/DNA_mesh_types.h
source/blender/python/api2_2x/NMesh.c
source/blender/renderconverter/intern/convertBlenderScene.c
source/blender/src/buttons_editing.c
source/blender/src/drawmesh.c
source/blender/src/drawobject.c
source/blender/src/edit.c
source/blender/src/editmesh_mods.c
source/blender/src/editobject.c

index e8a6a82ff48619c9e2c55de4dd94cef195ed328c..4fb8ae4905288a1aa2d2960bd6994dc1e7c0b46c 100644 (file)
@@ -46,6 +46,7 @@
  */
 
 struct Object;
+struct EditMesh;
 struct DispListMesh;
 
 typedef struct DerivedMesh DerivedMesh;
@@ -146,14 +147,18 @@ struct DerivedMesh {
        void (*release)(DerivedMesh *dm);
 };
 
+       /* Internal function, just temporarily exposed */
+DerivedMesh *derivedmesh_from_displistmesh(struct EditMesh *em, struct DispListMesh *dlm);
+
 DerivedMesh *mesh_get_derived(struct Object *ob);
-DerivedMesh *mesh_get_derived_render(struct Object *ob);
 DerivedMesh *mesh_get_base_derived(struct Object *ob);
 
+DerivedMesh *mesh_get_derived_render(struct Object *ob, int *needsFree_r);
+
        /* Utility function, just chooses appropriate DerivedMesh based
-        * on mesh flags.
+        * on mesh flags. Release result if *needsFree_r is true.
         */
-DerivedMesh *mesh_get_cage_derived(struct Object *ob);
+DerivedMesh *mesh_get_cage_derived(struct Object *ob, int *needsFree_r);
 
 #endif
 
index 0146d1a2341d16e67469e563d62db62dac12d509..ac8c601c5a5364d3f89b4f7442786b055d729a96 100644 (file)
@@ -45,7 +45,6 @@
 #define DL_VERTCOL              6
 #define DL_VERTS                7
 #define DL_NORS                 8
-#define DL_MESH                                        9
 
 /* dl->flag */
 #define DL_CYCL_U              1
@@ -133,8 +132,6 @@ typedef struct DispList {
        float *verts, *nors;
        int *index;
        unsigned int *col1, *col2;
-       struct DispListMesh *mesh;
-       
 } DispList;
 
 extern void copy_displist(struct ListBase *lbn, struct ListBase *lb);
index a23cd5755d1a615db1ca698c3ab0100cf8dcb933..39ea8c7a0c695316073dc5797bbe03a5e213a650 100644 (file)
 
 struct Mesh;
 struct Object;
-struct Displist;
 struct DispListMesh;
+struct DerivedMesh;
 struct EditMesh;
 
-struct DispListMesh *subsurf_make_dispListMesh_from_editmesh(struct EditMesh *em, int subdivLevels, int flags, short type);
-struct DispListMesh *subsurf_make_dispListMesh_from_mesh(struct Mesh *me, int subdivLevels, int flags);
+struct DerivedMesh *subsurf_make_derived_from_editmesh(struct EditMesh *em, int subdivLevels, int flags, short type);
+struct DerivedMesh *subsurf_make_derived_from_mesh(struct Mesh *me, int subdivLevels, int flags);
 
 #ifdef USE_CCGSUBSURFLIB
 struct DispListMesh *subsurf_ccg_make_dispListMesh_from_editmesh(struct EditMesh *em, int subdivLevels, int flags);
index c8d820db2819d57a2d407bd03db2bfbeb66a3805..1c6b6ebe2d3e80dc39552c5d3b6f93f168e339ca 100644 (file)
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
  * All rights reserved.
  *
  * The Original Code is: all of this file.
@@ -1072,14 +1072,12 @@ static void ssDM_release(DerivedMesh *dm)
 {
        SSDerivedMesh *ssdm = (SSDerivedMesh*) dm;
 
-       if (ssdm->needsFree) {
-               displistmesh_free(ssdm->dlm);
-       }
+       displistmesh_free(ssdm->dlm);
 
        MEM_freeN(dm);
 }
 
-static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm, int needsFree)
+DerivedMesh *derivedmesh_from_displistmesh(EditMesh *em, DispListMesh *dlm)
 {
        SSDerivedMesh *ssdm = MEM_mallocN(sizeof(*ssdm), "dm");
 
@@ -1110,7 +1108,6 @@ static DerivedMesh *getSSDerivedMesh(EditMesh *em, DispListMesh *dlm, int needsF
        
        ssdm->dlm = dlm;
        ssdm->em = em;
-       ssdm->needsFree = needsFree;
 
        return (DerivedMesh*) ssdm;
 }
@@ -1145,50 +1142,28 @@ DerivedMesh *mesh_get_derived(Object *ob)
        Mesh *me= ob->data;
 
        if (mesh_uses_displist(me)) {
-               DispList *dl;
-
                build_mesh_data(ob);
-               dl= find_displist(&me->disp, DL_MESH);
-
-                       // XXX, This test should not be here because
-                       // build_mesh_data should have made DLM... problem
-                       // is there is an exception for objects from dupli,
-                       // they only get displist built for first object.
-                       //
-                       // Would work fine except countall gets a derived
-                       // mesh before the displist has been evaluated.
-               if (dl) {
-                       if(G.obedit && me==G.obedit->data) {
-                               return getSSDerivedMesh(G.editMesh, dl->mesh, 0);
-                       } else {
-                               return getSSDerivedMesh(NULL, dl->mesh, 0);
-                       }
-               }
+
+               return me->derived;
        } 
 
        return NULL;
 }
 
-DerivedMesh *mesh_get_derived_render(Object *ob)
+DerivedMesh *mesh_get_derived_render(Object *ob, int *needsFree)
 {
        Mesh *me= ob->data;
 
        if (mesh_uses_displist(me)) {
                if (me->subdiv==me->subdivr) {
-                       DispList *dl= find_displist(&me->disp, DL_MESH);
-
-                       if(G.obedit && me==G.obedit->data) {
-                               return getSSDerivedMesh(G.editMesh, dl->mesh, 0);
-                       } else {
-                               return getSSDerivedMesh(NULL, dl->mesh, 0);
-                       }
+                       *needsFree = 0;
+                       return me->derived;
                } else {
+                       *needsFree = 1;
                        if(G.obedit && me==G.obedit->data) {
-                               DispListMesh *dlm = subsurf_make_dispListMesh_from_editmesh(G.editMesh, me->subdivr, me->flag, me->subsurftype);
-                               return getSSDerivedMesh(G.editMesh, dlm, 1);
+                               return subsurf_make_derived_from_editmesh(G.editMesh, me->subdivr, me->flag, me->subsurftype);
                        } else {
-                               DispListMesh *dlm = subsurf_make_dispListMesh_from_mesh(me, me->subdivr, me->flag);
-                               return getSSDerivedMesh(NULL, dlm, 1);
+                               return subsurf_make_derived_from_mesh(me, me->subdivr, me->flag);
                        }
                }
        }
@@ -1212,15 +1187,18 @@ DerivedMesh *mesh_get_base_derived(Object *ob)
        }
 }
 
-DerivedMesh *mesh_get_cage_derived(struct Object *ob)
+DerivedMesh *mesh_get_cage_derived(struct Object *ob, int *needsFree)
 {
        Mesh *me= ob->data;
        DerivedMesh *dm = NULL;
 
+       *needsFree = 0;
+
        if (me->flag&ME_OPT_EDGES) {
                dm = mesh_get_derived(ob);
        }
        if (!dm) {
+               *needsFree = 1;
                dm = mesh_get_base_derived(ob);
        }
 
index 7387aa545f2f45d40e3d703f9d65deeef3dcc14d..739376591ef7508fdf7e4fe417d298ee8f92d4ea 100644 (file)
@@ -328,7 +328,6 @@ void free_disp_elem(DispList *dl)
                if(dl->index) MEM_freeN(dl->index);
                if(dl->col1) MEM_freeN(dl->col1);
                if(dl->col2) MEM_freeN(dl->col2);
-               if(dl->mesh) displistmesh_free(dl->mesh);
                MEM_freeN(dl);
        }
 }
@@ -411,7 +410,7 @@ int displist_has_faces(ListBase *lb)
        
        dl= lb->first;
        while(dl) {
-               if ELEM6(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF, DL_MESH, DL_TRIA, DL_POLY)
+               if ELEM5(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF, DL_TRIA, DL_POLY)
                        return 1;
                dl= dl->next;
        }
@@ -434,7 +433,6 @@ void copy_displist(ListBase *lbn, ListBase *lb)
                dln->index= MEM_dupallocN(dl->index);
                dln->col1= MEM_dupallocN(dl->col1);
                dln->col2= MEM_dupallocN(dl->col2);
-               if (dl->mesh) dln->mesh= displistmesh_copy(dl->mesh);
                
                dl= dl->next;
        }
@@ -947,8 +945,6 @@ void shadeDispList(Object *ob)
 
                        dlm= dm->convertToDispListMesh(dm);
 
-                       dm->release(dm);
-
                        if (dlm && dlm->totvert) {
                                float *vnors, *vn;
                                int i;
@@ -1769,24 +1765,21 @@ void makeDispList(Object *ob)
        if(ob->type==OB_MESH) {
                me= ob->data;
                freedisplist(&(me->disp));
+               if (me->derived) {
+                       me->derived->release(me->derived);
+                       me->derived= NULL;
+               }
 
                tex_space_mesh(ob->data);
                
                if (ob!=G.obedit) mesh_modifier(ob, 's');
 
                if (mesh_uses_displist(me)) {  /* subsurf */
-                       DispListMesh *dlm;
-
                        if (ob==G.obedit) {
-                               dlm= subsurf_make_dispListMesh_from_editmesh(em, me->subdiv, me->flag, me->subsurftype);
+                               me->derived= subsurf_make_derived_from_editmesh(em, me->subdiv, me->flag, me->subsurftype);
                        } else {
-                               dlm= subsurf_make_dispListMesh_from_mesh(me, me->subdiv, me->flag);
+                               me->derived= subsurf_make_derived_from_mesh(me, me->subdiv, me->flag);
                        }
-
-                       dl= MEM_callocN(sizeof(*dl), "dl");
-                       dl->type= DL_MESH;
-                       dl->mesh= dlm;
-                       BLI_addtail(&me->disp, dl);
                }
 
                if (ob!=G.obedit) mesh_modifier(ob, 'e');
index d283c5808c69fcde5ab05a4cb5959d761d9e74f7..6fe6b708f58bad0fed9f0fe6a03e1d988e1cd835 100644 (file)
@@ -1234,8 +1234,6 @@ void build_particle_system(Object *ob)
                DerivedMesh *dm = mesh_get_derived(ob);
 
                dlm = dm->convertToDispListMesh(dm);
-
-               dm->release(dm);
        } else {
                dlm = NULL;
        }
index 2c16b76235acf787588a986b4c2381592175d7b7..cc96a0fdc4ff91e214c65c3231888b2092b48df0 100644 (file)
@@ -2559,7 +2559,6 @@ static int write_object_stl(FILE *fpSTL, Object *ob, Mesh *me)
                numfacets += write_displistmesh_stl(fpSTL, ob, dlm);
 
                displistmesh_free(dlm);
-               dm->release(dm);
        }
        else {
                numfacets += write_mesh_stl(fpSTL, ob, me);
index 039ce481a7618a8be6db4187f5fdee55568f3566..53f6f724b2268b9c4cf6a73043d18d6501346bde 100644 (file)
@@ -55,6 +55,7 @@
 #include "DNA_meshdata_types.h"
 
 #include "BKE_main.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_global.h"
 #include "BKE_mesh.h"
 #include "BKE_subsurf.h"
@@ -151,6 +152,7 @@ void free_mesh(Mesh *me)
 
        if(me->bb) MEM_freeN(me->bb);
        if(me->disp.first) freedisplist(&me->disp);
+       if(me->derived) me->derived->release(me->derived);
 }
 
 void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount)
@@ -422,6 +424,7 @@ void tex_space_mesh(Mesh *me)
 void make_orco_displist_mesh(Object *ob, int subdivlvl)
 {
        Mesh *me;
+       DerivedMesh *dm;
        DispListMesh *dlm;
        int i;
        
@@ -432,7 +435,9 @@ void make_orco_displist_mesh(Object *ob, int subdivlvl)
                cp_key(0, me->totvert, me->totvert, (char*) me->mvert->co, me->key, me->key->refkey, 0);
        }
 
-       dlm= subsurf_make_dispListMesh_from_mesh(me, subdivlvl, me->flag);
+       dm= subsurf_make_derived_from_mesh(me, subdivlvl, me->flag);
+       dlm= dm->convertToDispListMesh(dm);
+       dm->release(dm);
        
                /* Restore correct key */
        do_ob_key(ob);
index 6baba62053a84e93ad6a6a73ea57f4b313e78f0a..8c8863c332475e8540450d723121e3db20259719 100644 (file)
@@ -53,6 +53,7 @@
 #include "BKE_mesh.h"
 #include "BKE_subsurf.h"
 #include "BKE_displist.h"
+#include "BKE_DerivedMesh.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
@@ -1094,7 +1095,7 @@ static DispListMesh *subsurf_subdivide_to_displistmesh(HyperMesh *hme, short sub
        return dlm;
 }
 
-DispListMesh *subsurf_make_dispListMesh_from_editmesh(EditMesh *em, int subdivLevels, int flags, short type) {
+static DispListMesh *subsurf_make_dispListMesh_from_editmesh(EditMesh *em, int subdivLevels, int flags, short type) {
        if (subdivLevels<1) {
                return displistmesh_from_editmesh(em);
 #ifdef USE_CCGSUBSURFLIB
@@ -1108,7 +1109,11 @@ DispListMesh *subsurf_make_dispListMesh_from_editmesh(EditMesh *em, int subdivLe
        }
 }
 
-DispListMesh *subsurf_make_dispListMesh_from_mesh(Mesh *me, int subdivLevels, int flags) {
+DerivedMesh *subsurf_make_derived_from_editmesh(EditMesh *em, int subdivLevels, int flags, short type) {
+       return derivedmesh_from_displistmesh(em, subsurf_make_dispListMesh_from_editmesh(em, subdivLevels, flags, type));
+}
+
+static DispListMesh *subsurf_make_dispListMesh_from_mesh(Mesh *me, int subdivLevels, int flags) {
        if (subdivLevels<1) {
                return displistmesh_from_mesh(me, NULL);
 #ifdef USE_CCGSUBSURFLIB
@@ -1122,6 +1127,10 @@ DispListMesh *subsurf_make_dispListMesh_from_mesh(Mesh *me, int subdivLevels, in
        }
 }
 
+DerivedMesh *subsurf_make_derived_from_mesh(Mesh *me, int subdivLevels, int flags) {
+       return derivedmesh_from_displistmesh(NULL, subsurf_make_dispListMesh_from_mesh(me, subdivLevels, flags));
+}
+
        // editarmature.c
 void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3]) 
 {
index 88b2eecf89198bcd06333d8c94ecd28220e2f55c..98b47482d0ce579d57effd38700782d694bbe344 100644 (file)
@@ -1,3 +1,35 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License.  See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
 #ifdef USE_CCGSUBSURFLIB
 
 #include <stdlib.h>
index 1eaff59bf7b109d12176914e027d3d089a41c6b1..7797557c1f7a5e4c49baf6f776c58a8c7c4bbc16 100644 (file)
 #include <config.h>
 #endif
 
-#ifdef _WIN32
-#pragma warning (once : 4244) // "conversion from double to float"
-#pragma warning (once : 4305) // "truncation from const double to float"
-#endif
-
 /* local */
 float noise3_perlin(float vec[3]);
 float turbulence_perlin(float *point, float lofreq, float hifreq);
index c937fa02b43e2c638b77879d36814a5eef3642bd..50ac321d353ba364ab3cbcd6d863052658111b7e 100644 (file)
@@ -321,7 +321,6 @@ void BLI_adddirstrings()
        struct direntry * file;
        struct tm *tm;
        time_t zero= 0;
-       struct passwd *pwuser;
 
        file = &files[0];
        
@@ -356,12 +355,15 @@ void BLI_adddirstrings()
 #ifdef WIN32
                strcpy(files[num].owner,"user");
 #else
-               pwuser = getpwuid(files[num].s.st_uid);
-               if ( pwuser ) {
-                  strcpy(files[num].owner, pwuser->pw_name);
-               } else {
-                  sprintf(files[num].owner, "%d", files[num].s.st_uid);
-                }
+               {
+                       struct passwd *pwuser;
+                       pwuser = getpwuid(files[num].s.st_uid);
+                       if ( pwuser ) {
+                       strcpy(files[num].owner, pwuser->pw_name);
+                       } else {
+                               sprintf(files[num].owner, "%d", files[num].s.st_uid);
+            }
+               }
 #endif
 
                tm= localtime(&files[num].s.st_mtime);
index 79bf76618a6a942e7c0d6ce1f9b32d9941510906..796a06a21e62c1145966abedee47cdfa69476852 100644 (file)
@@ -35,6 +35,8 @@
 #include "DNA_listBase.h"
 #include "DNA_ID.h"
 
+struct DerivedMesh;
+struct DispListMesh;
 struct Ipo;
 struct Key;
 struct Material;
@@ -77,6 +79,11 @@ typedef struct Mesh {
        struct Mesh *texcomesh;
        float *orco;
 
+               /* not written in file, caches derived mesh */
+       struct DerivedMesh *derived;
+               /* hacky place to store temporary decimated mesh */
+       struct DispListMesh *decimated;
+
        struct OcInfo *oc;              /* not written in file */
        void *sumohandle;
 
@@ -87,14 +94,13 @@ typedef struct Mesh {
        float size[3];
        float rot[3];
        
+       float cubemapsize, pad;
+
        short smoothresh, flag;
 
-       short subdiv, subdivr, subdivdone;
+       short subdiv, subdivr;
        short totcol;
        short subsurftype; 
-       short reserved1;        /* Padding */
-
-       float cubemapsize;
 
 } Mesh;
 
index 563ceed2722308ebfa94d39a0ab449bb5639abd3..9a833045a13b140300c588cda594795420119cad 100644 (file)
@@ -2169,7 +2169,6 @@ static PyObject *M_NMesh_GetRawFromObject( PyObject * self, PyObject * args )
                        DispListMesh *dlm = dm->convertToDispListMesh(dm);
                        nmesh = new_NMesh_internal( me, dlm, NULL );
                        displistmesh_free(dlm);
-                       dm->release(dm);
                }
                else if( ( dl = find_displist( &ob->disp, DL_VERTS ) ) )
                        nmesh = new_NMesh_internal( me, NULL, dl->verts );
index 563600e69e1eb2af66b3c6a3ff36046b057c36b2..0d67fe6478a0009f621ea72e12a117c99e435684 100644 (file)
@@ -1354,9 +1354,12 @@ static void init_render_mesh(Object *ob)
        do_puno= mesh_modifier(ob, 's');
        
        if (mesh_uses_displist(me)) {
-               DerivedMesh *dm = mesh_get_derived_render(ob);
+               int needsFree;
+               DerivedMesh *dm = mesh_get_derived_render(ob, &needsFree);
                dlm = dm->convertToDispListMesh(dm);
-               dm->release(dm);
+               if (needsFree) {
+                       dm->release(dm);
+               }
 
                mvert= dlm->mvert;
                totvert= dlm->totvert;
index 7829aa467bd002e23736a56b54274e5d323cb806..b228bd444b6579225358ca66677534e8359e0a28 100644 (file)
@@ -264,7 +264,6 @@ static void decimate_faces(void)
 
        if(LOD_LoadMesh(&lod) ) {
                if( LOD_PreprocessMesh(&lod) ) {
-                       DispList *dl;
                        DispListMesh *dlm;
                        MFace *mfaceint;
 
@@ -275,11 +274,11 @@ static void decimate_faces(void)
                        }
 
                        /* ok, put back the stuff in a displist */
-                       freedisplist(&(ob->disp));
-                       dl= MEM_callocN(sizeof(DispList), "disp");
-                       BLI_addtail(&ob->disp, dl);
-                       dl->type= DL_MESH;
-                       dlm=dl->mesh= MEM_callocN(sizeof(DispListMesh), "dispmesh");
+                       if (me->decimated) {
+                               displistmesh_free(me->decimated);
+                       }
+
+                       dlm= me->decimated= MEM_callocN(sizeof(DispListMesh), "dispmesh");
                        dlm->mvert= MEM_callocN(lod.vertex_num*sizeof(MVert), "mvert");
                        dlm->mface= MEM_callocN(lod.face_num*sizeof(MFace), "mface");
                        dlm->totvert= lod.vertex_num;
@@ -320,8 +319,14 @@ static void decimate_cancel(void)
 
        ob= OBACT;
        if(ob) {
-               freedisplist(&ob->disp);
-               makeDispList(ob);
+               if (ob->type==OB_MESH) {
+                       Mesh *me = ob->data;
+                       
+                       if (me->decimated) {
+                               displistmesh_free(me->decimated);
+                               me->decimated = NULL;
+                       }
+               }
        }
        allqueue(REDRAWVIEW3D, 0);
 }
@@ -329,9 +334,6 @@ static void decimate_cancel(void)
 static void decimate_apply(void)
 {
        Object *ob;
-       DispList *dl;
-       DispListMesh *dlm;
-       Mesh *me;
        MFace *mface;
        MFace *mfaceint;
        int a;
@@ -339,11 +341,11 @@ static void decimate_apply(void)
        if(G.obedit) return;
 
        ob= OBACT;
-       if(ob) {
-               dl= ob->disp.first;
-               if(dl && dl->mesh) {
-                       dlm= dl->mesh;
-                       me= ob->data;
+       if(ob && ob->type==OB_MESH) {
+               Mesh *me = ob->data;
+
+               if (me->decimated) {
+                       DispListMesh *dlm= me->decimated;
 
                        // vertices
                        if(me->mvert) MEM_freeN(me->mvert);
@@ -369,7 +371,8 @@ static void decimate_apply(void)
                                test_index_mface(mface, 3);
                        }
 
-                       freedisplist(&ob->disp);
+                       displistmesh_free(me->decimated);
+                       me->decimated= NULL;
 
                        G.obedit= ob;
                        make_editMesh();
@@ -709,11 +712,11 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me)
        /* decimator */
        if(G.obedit==NULL) {
                int tottria= decimate_count_tria(ob);
-               DispList *dl;
+               Mesh *me = ob->data;
 
-               // wacko, wait for new displist system (ton)
-               if( (dl=ob->disp.first) && dl->mesh);
-               else decim_faces= tottria;
+               if (!me->decimated) {
+                       decim_faces= tottria;
+               }
 
                uiBlockBeginAlign(block);
                uiBlockSetCol(block, TH_BUT_SETTING1);
index 969aa2300be52fdb852f381f785cd2300e7fb080..bca1729cf6e2ad87befe5da77ef52c51f9ea3b58 100644 (file)
@@ -933,11 +933,12 @@ void draw_tface_mesh(Object *ob, Mesh *me, int dt)
 
                if(mesh_uses_displist(me) && editing==0) {
                        dm = mesh_get_derived(ob);
+                       dm->drawFacesTex(dm, draw_tface_mesh__set_draw);
                } else {
                        dm = mesh_get_base_derived(ob);
+                       dm->drawFacesTex(dm, draw_tface_mesh__set_draw);
+                       dm->release(dm);
                }
-               dm->drawFacesTex(dm, draw_tface_mesh__set_draw);
-               dm->release(dm);
 
                start = 0;
                totface = me->totface;
index d12b767290a5a422f841458516a8e6378b0a5660..2c3796c2496649d130f940b89a0836d5e314bb0c 100644 (file)
@@ -1000,9 +1000,8 @@ void calc_mesh_facedots_ext(void)
 }
 
 /* window coord, assuming all matrices are set OK */
-static void calc_meshverts(void)
+static void calc_meshverts(DerivedMesh *dm)
 {
-       DerivedMesh *dm = mesh_get_cage_derived(G.obedit);
        float co[3], mat[4][4];
        EditVert *eve;
 
@@ -1017,26 +1016,31 @@ static void calc_meshverts(void)
        }
 
        MTC_Mat4SwapMat4(G.vd->persmat, mat);
-       dm->release(dm);
 }
 
 /* window coord for current window, sets matrices temporal */
 void calc_meshverts_ext(void)
 {
+       int dmNeedsFree;
+       DerivedMesh *dm = mesh_get_cage_derived(G.obedit, &dmNeedsFree);
 
        areawinset(curarea->win);
        persp(PERSP_VIEW);
        
        mymultmatrix(G.obedit->obmat);
-       calc_meshverts();
+       calc_meshverts(dm);
        myloadmatrix(G.vd->viewmat);
-       
+
+       if (dmNeedsFree) {
+               dm->release(dm);
+       }
 }
 
 /* window coord for current window, sets matrices temporal, sets (eve->f & 2) when not visible */
 void calc_meshverts_ext_f2(void)
 {
-       DerivedMesh *dm = mesh_get_cage_derived(G.obedit);
+       int dmNeedsFree;
+       DerivedMesh *dm = mesh_get_cage_derived(G.obedit, &dmNeedsFree);
        float co[3], mat[4][4];
        EditVert *eve;
 
@@ -1063,7 +1067,9 @@ void calc_meshverts_ext_f2(void)
        MTC_Mat4SwapMat4(G.vd->persmat, mat);
        myloadmatrix(G.vd->viewmat);
 
-       dm->release(dm);
+       if (dmNeedsFree) {
+               dm->release(dm);
+       }
 }
 
 
@@ -1569,8 +1575,7 @@ static void draw_em_fancy(Object *ob, EditMesh *em, DerivedMesh *baseDM, Derived
        }
 
        if(ob==G.obedit) {
-                       // XXX Not clear this is needed here. - zr
-               calc_meshverts();
+               calc_meshverts(cageDM);
                draw_em_fancy_verts(em, cageDM);
 
                if(G.f & G_DRAWNORMALS) {
@@ -1620,8 +1625,8 @@ static void draw_mesh_fancy(Object *ob, DerivedMesh *baseDM, DerivedMesh *realDM
                // This is only for objects from the decimator and
                // is a temporal solution, a reconstruction of the
                // displist system should take care of it (zr/ton)
-       if(obDL && obDL->mesh) {
-               DispListMesh *dlm = obDL->mesh;
+       if(me->decimated) {
+               DispListMesh *dlm = me->decimated;
                MVert *mvert= dlm->mvert;
                MFace *mface= dlm->mface;
                int i;
@@ -1751,9 +1756,6 @@ static void draw_mesh_object(Object *ob, int dt)
        }
 
        baseDM->release(baseDM);
-       if (realDM) {
-               realDM->release(realDM);
-       }
 }
 
 /* ************** DRAW DISPLIST ****************** */
@@ -3737,6 +3739,7 @@ static int bbs_mesh_solid(Object *ob, DerivedMesh *dm, int facecol)
 void draw_object_backbufsel(Object *ob)
 {
        extern int em_solidoffs, em_wireoffs, em_vertoffs;      // let linker solve it... from editmesh_mods.c 
+       int dmNeedsFree;
        DerivedMesh *dm;
 
        mymultmatrix(ob->obmat);
@@ -3746,7 +3749,7 @@ void draw_object_backbufsel(Object *ob)
 
        switch( ob->type) {
        case OB_MESH:
-               dm = mesh_get_cage_derived(ob);
+               dm = mesh_get_cage_derived(ob, &dmNeedsFree);
 
                if(G.obedit) {
                        em_solidoffs= bbs_mesh_solid(ob, dm, G.scene->selectmode & SCE_SELECT_FACE);
@@ -3764,7 +3767,9 @@ void draw_object_backbufsel(Object *ob)
                }
                else bbs_mesh_solid(ob, dm, 1); // 1= facecol, faceselect
 
-               dm->release(dm);
+               if (dmNeedsFree) {
+                       dm->release(dm);
+               }
                break;
        case OB_CURVE:
        case OB_SURF:
index 35b973fc1514848ce86a613203ac3e7c24076e4a..fdcdf2401c16d6a676ce604618986c597f394b3b 100644 (file)
@@ -495,8 +495,6 @@ void count_object(Object *ob, int sel)
                        if (dm) {
                                totvert= dm->getNumVerts(dm);
                                totface= dm->getNumFaces(dm);
-
-                               dm->release(dm);
                        } else {
                                totvert= me->totvert;
                                totface= me->totface;
index dd5422ff4497bf73b4e40a6695f7e0abecc3575d..1a87e5ada3d51f693f80dbfa336892fd7be17c78 100644 (file)
@@ -628,7 +628,8 @@ static EditFace *findnearestface(short *dist)
 /* for interactivity, frontbuffer draw in current window */
 static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa)
 {
-       DerivedMesh *dm = mesh_get_cage_derived(G.obedit);
+       int dmNeedsFree;
+       DerivedMesh *dm = mesh_get_cage_derived(G.obedit, &dmNeedsFree);
 
        glDrawBuffer(GL_FRONT);
 
@@ -711,7 +712,9 @@ static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa)
        /* signal that frontbuf differs from back */
        curarea->win_swap= WIN_FRONT_OK;
 
-       dm->release(dm);
+       if (dmNeedsFree) {
+               dm->release(dm);
+       }
 }
 
 
index d139b05a6f8a79e88d550cfd4d474c1bc1066ca6..748d6508f5594ad0fd368318ab7d609019b36bf1 100644 (file)
@@ -96,6 +96,7 @@
 #include "BKE_booleanops.h"
 #include "BKE_curve.h"
 #include "BKE_displist.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_effect.h"
 #include "BKE_font.h"
 #include "BKE_global.h"
@@ -2151,6 +2152,7 @@ void convertmenu(void)
                                
                                if (mesh_uses_displist(oldme)) {
                                        DispListMesh *dlm;
+                                       DerivedMesh *dm;
 
                                        basedel = base;
 
@@ -2177,8 +2179,11 @@ void convertmenu(void)
                                                me->mat= MEM_dupallocN(oldme->mat);
                                                for(a=0; a<ob1->totcol; a++) id_us_plus((ID *)me->mat[a]);
                                        }
-                                               
-                                       dlm= subsurf_make_dispListMesh_from_mesh(oldme, oldme->subdiv, oldme->flag);
+                                       
+                                       dm= subsurf_make_derived_from_mesh(oldme, oldme->subdiv, oldme->flag);
+                                       dlm= dm->convertToDispListMesh(dm);
+                                       dm->release(dm);
+
                                        displistmesh_to_mesh(dlm, ob1->data);
                                        displistmesh_free(dlm);