diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-03-14 22:35:21 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-03-14 22:35:21 +0400 |
commit | a0dbd88311ae85c6713a91a6dca97eee6e90db9d (patch) | |
tree | 8760c3ca5bc836c91c98ca584d60c66273f9932b /source/blender/blenkernel | |
parent | 64b2ecf6f9836a140d63235b2fc54dab527933e2 (diff) |
converting a mesh to a curve was unnecessarily using tessface's.
use mpolys instead and simplify checks for wire edges.
Also rename BKE_mesh_from_curve() --> BKE_mesh_to_curve() since this function converts a mesh into a curve.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh.c | 48 |
2 files changed, 20 insertions, 30 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 24535eb1fd6..c90ea90f09d 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -169,7 +169,7 @@ int BKE_mesh_nurbs_displist_to_mdata(struct Object *ob, struct ListBase *dispbas struct MLoopUV **alluv, int *_totloop, int *_totpoly); void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase, int use_orco_uv); void BKE_mesh_from_nurbs(struct Object *ob); -void BKE_mesh_from_curve(struct Scene *scene, struct Object *ob); +void BKE_mesh_to_curve(struct Scene *scene, struct Object *ob); void BKE_mesh_delete_material_index(struct Mesh *me, short index); void BKE_mesh_smooth_flag_set(struct Object *meshOb, int enableSmooth); void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh); diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index f6f60d03cf7..604a273efc5 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1586,60 +1586,50 @@ static void appendPolyLineVert(ListBase *lb, unsigned int index) BLI_addtail(lb, vl); } -void BKE_mesh_from_curve(Scene *scene, Object *ob) +void BKE_mesh_to_curve(Scene *scene, Object *ob) { /* make new mesh data from the original copy */ DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_MESH); MVert *mverts = dm->getVertArray(dm); MEdge *med, *medge = dm->getEdgeArray(dm); - MFace *mf, *mface = dm->getTessFaceArray(dm); + MPoly *mp, *mpoly = dm->getPolyArray(dm); + MLoop *mloop = dm->getLoopArray(dm); int totedge = dm->getNumEdges(dm); - int totface = dm->getNumTessFaces(dm); + int totpoly = dm->getNumPolys(dm); int totedges = 0; - int i, needsFree = 0; + int i; + bool needsFree = false; /* only to detect edge polylines */ - EdgeHash *eh = BLI_edgehash_new(); - EdgeHash *eh_edge = BLI_edgehash_new(); - + int *edge_users; ListBase edges = {NULL, NULL}; - /* create edges from all faces (so as to find edges not in any faces) */ - mf = mface; - for (i = 0; i < totface; i++, mf++) { - if (!BLI_edgehash_haskey(eh, mf->v1, mf->v2)) - BLI_edgehash_insert(eh, mf->v1, mf->v2, NULL); - if (!BLI_edgehash_haskey(eh, mf->v2, mf->v3)) - BLI_edgehash_insert(eh, mf->v2, mf->v3, NULL); - - if (mf->v4) { - if (!BLI_edgehash_haskey(eh, mf->v3, mf->v4)) - BLI_edgehash_insert(eh, mf->v3, mf->v4, NULL); - if (!BLI_edgehash_haskey(eh, mf->v4, mf->v1)) - BLI_edgehash_insert(eh, mf->v4, mf->v1, NULL); - } - else { - if (!BLI_edgehash_haskey(eh, mf->v3, mf->v1)) - BLI_edgehash_insert(eh, mf->v3, mf->v1, NULL); + /* get boundary edges */ + edge_users = MEM_callocN(sizeof(int) * totedge, __func__); + for (i = 0, mp = mpoly; i < totpoly; i++, mp++) { + MLoop *ml = &mloop[mp->loopstart]; + int j; + for (j = 0; j < mp->totloop; j++, ml++) { + edge_users[ml->e]++; } } + /* create edges from all faces (so as to find edges not in any faces) */ med = medge; for (i = 0; i < totedge; i++, med++) { - if (!BLI_edgehash_haskey(eh, med->v1, med->v2)) { + if (edge_users[i] == 0) { EdgeLink *edl = MEM_callocN(sizeof(EdgeLink), "EdgeLink"); - BLI_edgehash_insert(eh_edge, med->v1, med->v2, NULL); + // BLI_edgehash_insert(eh_edge, med->v1, med->v2, NULL); edl->edge = med; BLI_addtail(&edges, edl); totedges++; } } - BLI_edgehash_free(eh_edge, NULL); - BLI_edgehash_free(eh, NULL); + MEM_freeN(edge_users); if (edges.first) { Curve *cu = BKE_curve_add(G.main, ob->id.name + 2, OB_CURVE); @@ -1741,7 +1731,7 @@ void BKE_mesh_from_curve(Scene *scene, Object *ob) ob->type = OB_CURVE; /* curve objects can't contain DM in usual cases, we could free memory */ - needsFree = 1; + needsFree = true; } dm->needsFree = needsFree; |