diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-03-22 14:07:45 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-03-22 14:07:45 +0300 |
commit | 29acdb48899a25c32726ee8411088d8086a5cdb4 (patch) | |
tree | ce2437de462b5bd27b0a9f1b10436d4b6a3f547e /source/blender/blenkernel/intern | |
parent | 3b5dec4afccf0b8ab8a67894223b2fc6576f5a24 (diff) |
Mesh API: add BKE_mesh_vert_edge_vert_map_create
Handy when you need to reference connected verts directly.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mapping.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index 8dce3c372f6..c8bb2e0e758 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -305,6 +305,49 @@ void BKE_mesh_vert_edge_map_create(MeshElemMap **r_map, int **r_mem, } /** + * A version of #BKE_mesh_vert_edge_map_create that references connected vertices directly (not their edges). + */ +void BKE_mesh_vert_edge_vert_map_create( + MeshElemMap **r_map, int **r_mem, + const MEdge *medge, int totvert, int totedge) +{ + MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)totvert, "vert-edge map"); + int *indices = MEM_mallocN(sizeof(int[2]) * (size_t)totedge, "vert-edge map mem"); + int *i_pt = indices; + + int i; + + /* Count number of edges for each vertex */ + for (i = 0; i < totedge; i++) { + map[medge[i].v1].count++; + map[medge[i].v2].count++; + } + + /* Assign indices mem */ + for (i = 0; i < totvert; i++) { + map[i].indices = i_pt; + i_pt += map[i].count; + + /* Reset 'count' for use as index in last loop */ + map[i].count = 0; + } + + /* Find the users */ + for (i = 0; i < totedge; i++) { + const unsigned int v[2] = {medge[i].v1, medge[i].v2}; + + map[v[0]].indices[map[v[0]].count] = (int)v[1]; + map[v[1]].indices[map[v[1]].count] = (int)v[0]; + + map[v[0]].count++; + map[v[1]].count++; + } + + *r_map = map; + *r_mem = indices; +} + +/** * Generates a map where the key is the edge and the value is a list of polygons that use that edge. * The lists are allocated from one memory pool. */ |