diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_displist.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_subsurf.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 52 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 21 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/effect.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/exotic.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf.c | 13 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 32 |
10 files changed, 82 insertions, 66 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index e8a6a82ff48..4fb8ae49052 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -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 diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index 0146d1a2341..ac8c601c5a5 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -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); diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h index a23cd5755d1..39ea8c7a0c6 100644 --- a/source/blender/blenkernel/BKE_subsurf.h +++ b/source/blender/blenkernel/BKE_subsurf.h @@ -33,12 +33,12 @@ 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); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index c8d820db281..1c6b6ebe2d3 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -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); } diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 7387aa545f2..739376591ef 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -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'); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index d283c5808c6..6fe6b708f58 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -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; } diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c index 2c16b76235a..cc96a0fdc4f 100644 --- a/source/blender/blenkernel/intern/exotic.c +++ b/source/blender/blenkernel/intern/exotic.c @@ -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); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 039ce481a76..53f6f724b22 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -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); diff --git a/source/blender/blenkernel/intern/subsurf.c b/source/blender/blenkernel/intern/subsurf.c index 6baba62053a..8c8863c3324 100644 --- a/source/blender/blenkernel/intern/subsurf.c +++ b/source/blender/blenkernel/intern/subsurf.c @@ -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]) { diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 88b2eecf891..98b47482d0c 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -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> |