diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_displist.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 27 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/displist.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/effect.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/exotic.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 26 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 2 | ||||
-rw-r--r-- | source/blender/python/api2_2x/NMesh.c | 4 | ||||
-rw-r--r-- | source/blender/renderconverter/intern/convertBlenderScene.c | 2 | ||||
-rw-r--r-- | source/blender/src/buttons_editing.c | 4 | ||||
-rw-r--r-- | source/blender/src/drawobject.c | 41 | ||||
-rw-r--r-- | source/blender/src/editobject.c | 2 |
13 files changed, 72 insertions, 61 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 7a44f9de9f9..6350332fd66 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -65,8 +65,14 @@ struct DerivedMesh { void (*getMappedVertCoEM)(DerivedMesh *dm, void *vert, float co_r[3]); - /* Convert to new DispListMesh, should be free'd by caller */ - struct DispListMesh* (*convertToDispListMesh)(DerivedMesh *dm); + /* Convert to new DispListMesh, should be free'd by caller. + * + * If allowShared is true then the caller is committing to not free'ng + * the DerivedMesh before free'ng the DispListMesh, which means that + * certain fields of the returned DispListMesh can safely be share with + * the DerivedMesh's internal data. + */ + struct DispListMesh* (*convertToDispListMesh)(DerivedMesh *dm, int allowShared); /* Iterate over all vertex points, calling DO_MINMAX with given args. * diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index 463b7b22e1d..1102603b6a4 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -103,6 +103,7 @@ void displistmesh_free(DispListMesh *dlm); void displistmesh_to_mesh(DispListMesh *dlm, struct Mesh *me); DispListMesh *displistmesh_copy(DispListMesh *odlm); +DispListMesh *displistmesh_copyShared(DispListMesh *odlm); /* * All the different DispList.type's use the diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 15f6b9fce9b..b26d40f60fe 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -78,7 +78,7 @@ typedef struct { int freeNors, freeVerts; } MeshDerivedMesh; -static DispListMesh *meshDM_convertToDispListMesh(DerivedMesh *dm) +static DispListMesh *meshDM_convertToDispListMesh(DerivedMesh *dm, int allowShared) { MeshDerivedMesh *mdm = (MeshDerivedMesh*) dm; Mesh *me = mdm->me; @@ -95,6 +95,17 @@ static DispListMesh *meshDM_convertToDispListMesh(DerivedMesh *dm) dlm->nors = mdm->nors; dlm->dontFreeVerts = dlm->dontFreeOther = dlm->dontFreeNors = 1; + if (!allowShared) { + dlm->mvert = MEM_dupallocN(dlm->mvert); + if (dlm->medge) dlm->medge = MEM_dupallocN(dlm->medge); + dlm->mface = MEM_dupallocN(dlm->mface); + if (dlm->tface) dlm->tface = MEM_dupallocN(dlm->tface); + if (dlm->mcol) dlm->mcol = MEM_dupallocN(dlm->mcol); + if (dlm->nors) dlm->nors = MEM_dupallocN(dlm->nors); + + dlm->dontFreeVerts = dlm->dontFreeOther = dlm->dontFreeNors = 0; + } + return dlm; } @@ -479,7 +490,7 @@ static DerivedMesh *getMeshDerivedMesh(Mesh *me, Object *ob, float (*vertCos)[3] // XXX this is kinda hacky because we shouldn't really be editing // the mesh here, however, we can't just call mesh_build_faceNormals(ob) // because in the case when a key is applied to a mesh the vertex normals - // would never be correctly computed (and renderer makes this assumption). + // would never be correctly computed. mesh_calc_normals(mdm->verts, me->totvert, me->mface, me->totface, &mdm->nors); mdm->freeNors = 1; } @@ -1229,11 +1240,15 @@ static int ssDM_getNumFaces(DerivedMesh *dm) return ssdm->dlm->totface; } -static DispListMesh *ssDM_convertToDispListMesh(DerivedMesh *dm) +static DispListMesh *ssDM_convertToDispListMesh(DerivedMesh *dm, int allowShared) { SSDerivedMesh *ssdm = (SSDerivedMesh*) dm; - return displistmesh_copy(ssdm->dlm); + if (allowShared) { + return displistmesh_copyShared(ssdm->dlm); + } else { + return displistmesh_copy(ssdm->dlm); + } } static void ssDM_release(DerivedMesh *dm) @@ -1401,7 +1416,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedM * one. */ if (dm && deformedVerts) { - DispListMesh *dlm = dm->convertToDispListMesh(dm); // XXX what if verts or nors were shared + DispListMesh *dlm = dm->convertToDispListMesh(dm, 0); int i; /* XXX, would like to avoid the conversion to a DLM here if possible. @@ -1526,7 +1541,7 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r, DerivedMesh **final_r) * one. */ if (dm && deformedVerts) { - DispListMesh *dlm = dm->convertToDispListMesh(dm); // XXX what if verts or nors were shared + DispListMesh *dlm = dm->convertToDispListMesh(dm, 0); int i; /* XXX, would like to avoid the conversion to a DLM here if possible. diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index fa1d61bbf02..13a832e2e3d 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -137,6 +137,14 @@ DispListMesh *displistmesh_copy(DispListMesh *odlm) return ndlm; } +DispListMesh *displistmesh_copyShared(DispListMesh *odlm) +{ + DispListMesh *ndlm= MEM_dupallocN(odlm); + ndlm->dontFreeNors = ndlm->dontFreeOther = ndlm->dontFreeVerts = 1; + + return ndlm; +} + void displistmesh_to_mesh(DispListMesh *dlm, Mesh *me) { if (dlm->totvert>MESH_MAX_VERTS) { @@ -718,7 +726,7 @@ void mesh_create_shadedColors(Object *ob, int onlyForMesh, unsigned int **col1_r } else { dm = mesh_get_derived_final(ob, &dmNeedsFree); } - dlm= dm->convertToDispListMesh(dm); + dlm= dm->convertToDispListMesh(dm, 1); col1 = MEM_mallocN(sizeof(*col1)*dlm->totface*4, "col1"); if (col2_r && (me->flag & ME_TWOSIDED)) { diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 690be225f6a..3f26957c1c1 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -1231,7 +1231,7 @@ void build_particle_system(Object *ob) /* init */ - dlm = dm->convertToDispListMesh(dm); + dlm = dm->convertToDispListMesh(dm, 1); totvert = dlm->totvert; give_mesh_mvert(me, dlm, totpart, co, no, paf->seed); diff --git a/source/blender/blenkernel/intern/exotic.c b/source/blender/blenkernel/intern/exotic.c index 0de307a98fb..6dff7284724 100644 --- a/source/blender/blenkernel/intern/exotic.c +++ b/source/blender/blenkernel/intern/exotic.c @@ -2511,7 +2511,7 @@ static int write_object_stl(FILE *fpSTL, Object *ob, Mesh *me) int numfacets = 0; int dmNeedsFree; DerivedMesh *dm = mesh_get_derived_final(ob, &dmNeedsFree); - DispListMesh *dlm = dm->convertToDispListMesh(dm); + DispListMesh *dlm = dm->convertToDispListMesh(dm, 1); numfacets += write_displistmesh_stl(fpSTL, ob, dlm); diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index 7aa26393443..a1786ed8898 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -163,7 +163,7 @@ static void *subsurfModifier_applyModifier(ModifierData *md, Object *ob, void *d Mesh *me = ob->data; if (dm) { - DispListMesh *dlm = dm->convertToDispListMesh(dm); // XXX what if verts were shared + DispListMesh *dlm = dm->convertToDispListMesh(dm, 0); int i; if (vertexCos) { @@ -189,21 +189,7 @@ static void *subsurfModifier_applyModifierEM(ModifierData *md, Object *ob, void SubsurfModifierData *smd = (SubsurfModifierData*) md; if (dm) { - DispListMesh *dlm = dm->convertToDispListMesh(dm); // XXX what if verts were shared - int i; - - if (vertexCos) { - int numVerts = dm->getNumVerts(dm); - - for (i=0; i<numVerts; i++) { - VECCOPY(dlm->mvert[i].co, vertexCos[i]); - } - } - - // XXX, should I worry about reuse of mCache in editmode? - dm = subsurf_make_derived_from_mesh(NULL, dlm, smd, 0, NULL, 1); - - return dm; + return subsurfModifier_applyModifier(md, ob, dm, vertexCos, 0, 1); } else { return subsurf_make_derived_from_editmesh(em, smd, vertexCos); } @@ -250,7 +236,7 @@ static void *buildModifier_applyModifier(ModifierData *md, Object *ob, void *der float frac; if (dm) { - dlm = dm->convertToDispListMesh(dm); + dlm = dm->convertToDispListMesh(dm, 1); mvert = dlm->mvert; medge = dlm->medge; mface = dlm->mface; @@ -600,7 +586,7 @@ static void *mirrorModifier_applyModifier(ModifierData *md, Object *ob, void *de MCol *mcol; if (dm) { - dlm = dm->convertToDispListMesh(dm); + dlm = dm->convertToDispListMesh(dm, 1); mvert = dlm->mvert; medge = dlm->medge; @@ -685,7 +671,7 @@ static void *mirrorModifier_applyModifierEM(ModifierData *md, Object *ob, void * med->v1 = (int) eed->v1->prev; med->v2 = (int) eed->v2->prev; - med->crease = eed->crease; + med->crease = (unsigned char) (eed->crease*255.0f); } for (i=0,efa=em->faces.first; i<ndlm->totface; i++,efa=efa->next) { MFace *mf = &ndlm->mface[i]; @@ -732,7 +718,7 @@ static void *decimateModifier_applyModifier(ModifierData *md, Object *ob, void * int a, numTris; if (dm) { - dlm = dm->convertToDispListMesh(dm); + dlm = dm->convertToDispListMesh(dm, 1); mvert = dlm->mvert; mface = dlm->mface; totvert = dlm->totvert; diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 5e10bfcf7b1..316b7425988 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -702,7 +702,7 @@ static void ccgDM_getMappedVertCoEM(DerivedMesh *dm, void *vert, float co_r[3]) co_r[1] = co[1]; co_r[2] = co[2]; } -static DispListMesh *ccgDM_convertToDispListMesh(DerivedMesh *dm) { +static DispListMesh *ccgDM_convertToDispListMesh(DerivedMesh *dm, int allowShared) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm; return ss_to_displistmesh(ccgdm->ss, ccgdm->fromEditmesh, ccgdm->me, ccgdm->dlm); diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index d4feea4a166..56aa95b85ec 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -2470,11 +2470,11 @@ static PyObject *M_NMesh_GetRawFromObject( PyObject * self, PyObject * args ) { int needsFree; DerivedMesh *dm = mesh_get_derived_final(ob, &needsFree); - DispListMesh *dlm = dm->convertToDispListMesh(dm); + DispListMesh *dlm = dm->convertToDispListMesh(dm, 1); nmesh = new_NMesh_internal(ob->data, dlm ); + displistmesh_free(dlm); if (needsFree) dm->release(dm); - displistmesh_free(dlm); } break; default: diff --git a/source/blender/renderconverter/intern/convertBlenderScene.c b/source/blender/renderconverter/intern/convertBlenderScene.c index 593910c7a29..ec8de661044 100644 --- a/source/blender/renderconverter/intern/convertBlenderScene.c +++ b/source/blender/renderconverter/intern/convertBlenderScene.c @@ -1317,7 +1317,7 @@ static void init_render_mesh(Object *ob) } dm = mesh_create_derived_render(ob); - dlm = dm->convertToDispListMesh(dm); + dlm = dm->convertToDispListMesh(dm, 1); mvert= dlm->mvert; totvert= dlm->totvert; diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index 0353803e0df..fa01b9c0745 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -663,7 +663,7 @@ static void modifiers_applyModifier(void *obv, void *mdv) return; } - dlm= dm->convertToDispListMesh(dm); + dlm= dm->convertToDispListMesh(dm, 1); ob->data= add_mesh(); displistmesh_to_mesh(dlm, ob->data); @@ -782,7 +782,7 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco uiDefIconButBitI(block, TOG, eModifierMode_Render, B_MODIFIER_RECALC, ICON_SCENE, x+width-120-90, y, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering"); uiDefIconButBitI(block, TOG, eModifierMode_Realtime, B_MODIFIER_RECALC, VICON_VIEW3D, x+width-120-90+20, y, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display"); if (mti->flags&eModifierTypeFlag_SupportsEditmode) { - uiDefIconButBitI(block, TOG, eModifierMode_Editmode, B_MODIFIER_RECALC, VICON_EDIT, x+width-120-90+40, y, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode"); + uiDefIconButBitI(block, TOG, eModifierMode_Editmode, B_MODIFIER_RECALC, VICON_EDIT, x+width-120-90+40, y, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode (only if enabled for display)"); } uiBlockEndAlign(block); diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c index b0942f08d72..9254dcf9cae 100644 --- a/source/blender/src/drawobject.c +++ b/source/blender/src/drawobject.c @@ -1333,6 +1333,23 @@ static void draw_dm_faces_sel(DerivedMesh *dm, unsigned char *baseCol, unsigned dm->drawMappedFacesEM(dm, draw_dm_faces_sel__setDrawOptions, cols); } +static int draw_dm_creases__setDrawOptions(void *userData, EditEdge *eed) +{ + if (eed->h==0 && eed->crease!=0.0) { + BIF_ThemeColorShade((eed->f&SELECT)?TH_EDGE_SELECT:TH_WIRE, 120*eed->crease); + return 1; + } else { + return 0; + } +} + +static void draw_dm_creases(DerivedMesh *dm) +{ + glLineWidth(3.0); + dm->drawMappedEdgesEM(dm, draw_dm_creases__setDrawOptions, NULL); + glLineWidth(1.0); +} + /* Second section of routines: Combine first sets to form fancy * drawing routines (for example rendering twice to get overlays). * @@ -1448,28 +1465,6 @@ static void draw_em_fancy_edges(DerivedMesh *cageDM) } } -static void draw_em_creases(EditMesh *em) -{ - EditEdge *eed; - float fac, *v1, *v2, vec[3]; - - glLineWidth(3.0); - glBegin(GL_LINES); - for(eed= em->edges.first; eed; eed= eed->next) { - if(eed->h==0 && eed->crease!=0.0) { - BIF_ThemeColor((eed->f&SELECT)?TH_EDGE_SELECT:TH_WIRE); - - v1= eed->v1->co; v2= eed->v2->co; - VECSUB(vec, v2, v1); - fac= 0.5 + eed->crease/2.0; - glVertex3f(v1[0] + fac*vec[0], v1[1] + fac*vec[1], v1[2] + fac*vec[2] ); - glVertex3f(v2[0] - fac*vec[0], v2[1] - fac*vec[1], v2[2] - fac*vec[2] ); - } - } - glEnd(); - glLineWidth(1.0); -} - static void draw_em_measure_stats(Object *ob, EditMesh *em) { EditEdge *eed; @@ -1689,7 +1684,7 @@ static void draw_em_fancy(Object *ob, EditMesh *em, DerivedMesh *cageDM, Derived draw_em_fancy_edges(cageDM); if(G.f & G_DRAWCREASES) { - draw_em_creases(em); + draw_dm_creases(cageDM); } if(ob==G.obedit) { diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 49eba192dcb..77561959a74 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -2199,7 +2199,7 @@ void convertmenu(void) } dm= mesh_create_derived_no_deform(ob, NULL); - dlm= dm->convertToDispListMesh(dm); + dlm= dm->convertToDispListMesh(dm, 1); displistmesh_to_mesh(dlm, ob1->data); displistmesh_free(dlm); dm->release(dm); |