diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-05-28 04:45:53 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-05-28 04:46:58 +0300 |
commit | 3e0c6a8ca2e2859dabc488dee2356357c5fdc0c0 (patch) | |
tree | 97bc3965c7f5df0fe557be1056319f7f041feb1a /source/blender/bmesh | |
parent | 46d8bcb617bcc774e6b312e555edba54a3654f75 (diff) |
BMesh: util functions to get edge loops from verts
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.c | 31 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.h | 3 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_core.c | 14 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_edgenet.c | 12 |
4 files changed, 42 insertions, 18 deletions
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index fb7f936318b..7664108f348 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -46,6 +46,37 @@ #define SELECT 1 +/** + * Fill in an edge array from a vertex array (connected polygon loop). + * + * \returns false if any edges aren't found . + */ +bool BM_edges_from_verts(BMEdge **edge_arr, BMVert **vert_arr, const int len) +{ + int i, i_prev = len - 1; + for (i = 0; i < len; i++) { + edge_arr[i_prev] = BM_edge_exists(vert_arr[i_prev], vert_arr[i]); + if (edge_arr[i_prev] == NULL) { + return false; + } + i_prev = i; + } + return true; +} + +/** + * Fill in an edge array from a vertex array (connected polygon loop). + * Creating edges as-needed. + */ +void BM_edges_from_verts_ensure(BMesh *bm, BMEdge **edge_arr, BMVert **vert_arr, const int len) +{ + int i, i_prev = len - 1; + for (i = 0; i < len; i++) { + edge_arr[i_prev] = BM_edge_create(bm, vert_arr[i_prev], vert_arr[i], NULL, BM_CREATE_NO_DOUBLE); + i_prev = i; + } +} + /* prototypes */ static void bm_loop_attrs_copy( BMesh *source_mesh, BMesh *target_mesh, diff --git a/source/blender/bmesh/intern/bmesh_construct.h b/source/blender/bmesh/intern/bmesh_construct.h index 0e3ca75681a..29503679547 100644 --- a/source/blender/bmesh/intern/bmesh_construct.h +++ b/source/blender/bmesh/intern/bmesh_construct.h @@ -29,6 +29,9 @@ struct BMAllocTemplate; +bool BM_edges_from_verts(BMEdge **edge_arr, BMVert **vert_arr, const int len); +void BM_edges_from_verts_ensure(BMesh *bm, BMEdge **edge_arr, BMVert **vert_arr, const int len); + BMFace *BM_face_create_quad_tri( BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, const BMFace *f_example, const eBMCreateFlag create_flag); diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index d33f28ae197..20a88b0e17c 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -485,21 +485,13 @@ BMFace *BM_face_create_verts( const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges) { BMEdge **edge_arr = BLI_array_alloca(edge_arr, len); - int i, i_prev = len - 1; if (create_edges) { - for (i = 0; i < len; i++) { - edge_arr[i_prev] = BM_edge_create(bm, vert_arr[i_prev], vert_arr[i], NULL, BM_CREATE_NO_DOUBLE); - i_prev = i; - } + BM_edges_from_verts_ensure(bm, edge_arr, vert_arr, len); } else { - for (i = 0; i < len; i++) { - edge_arr[i_prev] = BM_edge_exists(vert_arr[i_prev], vert_arr[i]); - if (edge_arr[i_prev] == NULL) { - return NULL; - } - i_prev = i; + if (BM_edges_from_verts(edge_arr, vert_arr, len) == false) { + return NULL; } } diff --git a/source/blender/bmesh/tools/bmesh_edgenet.c b/source/blender/bmesh/tools/bmesh_edgenet.c index 2767f87be4a..2a1946df7ae 100644 --- a/source/blender/bmesh/tools/bmesh_edgenet.c +++ b/source/blender/bmesh/tools/bmesh_edgenet.c @@ -166,8 +166,8 @@ static BMFace *bm_edgenet_face_from_path( { BMFace *f; LinkNode *v_lnk; - unsigned int i; - unsigned int i_prev; + int i; + bool ok; BMVert **vert_arr = BLI_array_alloca(vert_arr, path_len); BMEdge **edge_arr = BLI_array_alloca(edge_arr, path_len); @@ -176,11 +176,9 @@ static BMFace *bm_edgenet_face_from_path( vert_arr[i] = v_lnk->link; } - i_prev = path_len - 1; - for (i = 0; i < path_len; i++) { - edge_arr[i_prev] = BM_edge_exists(vert_arr[i], vert_arr[i_prev]); - i_prev = i; - } + ok = BM_edges_from_verts(edge_arr, vert_arr, i); + BLI_assert(ok); + UNUSED_VARS_NDEBUG(ok); /* no need for this, we do overlap checks before allowing the path to be used */ #if 0 |