diff options
author | Daniel Dunbar <daniel@zuster.org> | 2005-07-17 01:03:28 +0400 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2005-07-17 01:03:28 +0400 |
commit | 6dd382f966aa08dc5d014d487818683ce417a693 (patch) | |
tree | 939105936b0b1ead8fca51ef22f73b38b967221e /source/blender | |
parent | 0d806074b34b2fe1c79076a0a0af6b13d0b0ef4e (diff) |
- added dontFreeVerts and dontFreeOther flags to displistmesh for
situations where data can be shared easily.
- added convertDisplistToMesh function for regular mesh DerivedMesh
interface (how many times can *you* use mesh in one sentence?)
- do_puno was uninitialized in init_render_mesh
- added mesh_get_derived_final (temporary), difference from
mesh_get_derived is it always returns a derived mesh, even if
no subsurf.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_displist.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 59 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 14 | ||||
-rw-r--r-- | source/blender/renderconverter/intern/convertBlenderScene.c | 2 |
4 files changed, 70 insertions, 7 deletions
diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index d75a8a65f0a..061fa6d13fa 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -98,6 +98,8 @@ struct DispListMesh { struct MFace *mface; struct TFace *tface; float *nors; // facenormals + + int dontFreeVerts, dontFreeOther; }; void displistmesh_free(DispListMesh *dlm); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 236d21bd710..9c5a18c4d86 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -67,6 +67,40 @@ typedef struct { float *extverts, *nors; } MeshDerivedMesh; +static DispListMesh *meshDM_convertToDispListMesh(DerivedMesh *dm) +{ + MeshDerivedMesh *mdm = (MeshDerivedMesh*) dm; + Mesh *me = mdm->ob->data; + DispListMesh *dlm = MEM_callocN(sizeof(*dlm), "dlm"); + + dlm->totvert = me->totvert; + dlm->totedge = me->totedge; + dlm->totface = me->totface; + dlm->mvert = me->mvert; + dlm->medge = me->medge; + dlm->mface = me->mface; + dlm->tface = me->tface; + dlm->mcol = me->mcol; + dlm->nors = mdm->nors; + dlm->dontFreeVerts = dlm->dontFreeOther = 1; + + if (mdm->extverts) { + int i; + + dlm->mvert = MEM_dupallocN(dlm->mvert); + + for (i=0; i<dlm->totvert; i++) { + dlm->mvert[i].co[0] = mdm->extverts[i*3 + 0]; + dlm->mvert[i].co[1] = mdm->extverts[i*3 + 1]; + dlm->mvert[i].co[2] = mdm->extverts[i*3 + 2]; + } + + displistmesh_calc_normals(dlm); + } + + return dlm; +} + static float *meshDM__getVertCo(MeshDerivedMesh *mdm, int index) { if (mdm->extverts) { @@ -380,6 +414,7 @@ static DerivedMesh *getMeshDerivedMesh(Object *ob, float *extverts, float *nors) { MeshDerivedMesh *mdm = MEM_callocN(sizeof(*mdm), "dm"); + mdm->dm.convertToDispListMesh = meshDM_convertToDispListMesh; mdm->dm.getNumVerts = meshDM_getNumVerts; mdm->dm.getNumFaces = meshDM_getNumFaces; @@ -876,6 +911,30 @@ DerivedMesh *mesh_get_derived(Object *ob) return NULL; } +DerivedMesh *mesh_get_derived_final(Object *ob) +{ + Mesh *me= ob->data; + + build_mesh_data(ob, G.obedit && me==G.obedit->data); + + if ((me->flag&ME_SUBSURF) && me->subdiv) { + if(G.obedit && me==G.obedit->data) { + return G.editMesh->derived; + } else { + return me->derived; + } + } else { + DispList *dl; + DispList *meDL; + + dl = find_displist(&ob->disp, DL_VERTS); + meDL = me->disp.first; + return getMeshDerivedMesh(ob, dl?dl->verts:NULL, meDL?meDL->nors:NULL); + } + + return NULL; +} + DerivedMesh *mesh_get_derived_render(Object *ob, int *needsFree) { Mesh *me= ob->data; diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 0532456c97b..36f559afdc9 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -111,12 +111,14 @@ static float fviewmat[4][4]; void displistmesh_free(DispListMesh *dlm) { // also check on mvert and mface, can be NULL after decimator (ton) - if (dlm->mvert) MEM_freeN(dlm->mvert); - if (dlm->medge) MEM_freeN(dlm->medge); - if (dlm->mface) MEM_freeN(dlm->mface); - if (dlm->mcol) MEM_freeN(dlm->mcol); - if (dlm->tface) MEM_freeN(dlm->tface); - if (dlm->nors) MEM_freeN(dlm->nors); + if (!dlm->dontFreeVerts && dlm->mvert) MEM_freeN(dlm->mvert); + if (!dlm->dontFreeOther) { + if (dlm->medge) MEM_freeN(dlm->medge); + if (dlm->mface) MEM_freeN(dlm->mface); + if (dlm->mcol) MEM_freeN(dlm->mcol); + if (dlm->tface) MEM_freeN(dlm->tface); + if (dlm->nors) MEM_freeN(dlm->nors); + } MEM_freeN(dlm); } diff --git a/source/blender/renderconverter/intern/convertBlenderScene.c b/source/blender/renderconverter/intern/convertBlenderScene.c index a26488fb6c8..3d962656690 100644 --- a/source/blender/renderconverter/intern/convertBlenderScene.c +++ b/source/blender/renderconverter/intern/convertBlenderScene.c @@ -1296,7 +1296,7 @@ static void init_render_mesh(Object *ob) unsigned int *vertcol; float xn, yn, zn, imat[3][3], mat[4][4]; //nor[3], float *extverts=0, *orco; - int a, a1, ok, do_puno, need_orco=0, totvlako, totverto, vertofs; + int a, a1, ok, do_puno=0, need_orco=0, totvlako, totverto, vertofs; int start, end, do_autosmooth=0, totvert = 0; DispListMesh *dlm = NULL; |