diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-05-21 13:38:02 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-05-21 16:20:06 +0300 |
commit | 3a73d31c561822d78dea9c404976a7653932308f (patch) | |
tree | 64c184a094fae30cae0bde28a5ee7a2946eb7709 /source/blender/blenkernel/intern/mesh_mapping.c | |
parent | 92a3ac4dd2d4e6a03f888bd7f9902d7785472062 (diff) |
BKE Mesh mapping: add 'vert to looptri' mapping generator.
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_mapping.c')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mapping.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index c8bb2e0e758..a472b6e5bc1 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -262,6 +262,51 @@ void BKE_mesh_vert_loop_map_create(MeshElemMap **r_map, int **r_mem, } /** + * Generates a map where the key is the edge and the value is a list of looptris that use that edge. + * The lists are allocated from one memory pool. + */ +void BKE_mesh_vert_looptri_map_create( + MeshElemMap **r_map, int **r_mem, + const MVert *UNUSED(mvert), const int totvert, + const MLoopTri *mlooptri, const int totlooptri, + const MLoop *mloop, const int UNUSED(totloop)) +{ + MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)totvert, __func__); + int *indices = MEM_mallocN(sizeof(int) * (size_t)totlooptri * 3, __func__); + int *index_step; + const MLoopTri *mlt; + int i; + + /* count face users */ + for (i = 0, mlt = mlooptri; i < totlooptri; mlt++, i++) { + for (int j = 3; j--;) { + map[mloop[mlt->tri[j]].v].count++; + } + } + + /* create offsets */ + index_step = indices; + for (i = 0; i < totvert; i++) { + map[i].indices = index_step; + index_step += map[i].count; + + /* re-count, using this as an index below */ + map[i].count = 0; + } + + /* assign looptri-edge users */ + for (i = 0, mlt = mlooptri; i < totlooptri; mlt++, i++) { + for (int j = 3; j--;) { + MeshElemMap *map_ele = &map[mloop[mlt->tri[j]].v]; + map_ele->indices[map_ele->count++] = i; + } + } + + *r_map = map; + *r_mem = indices; +} + +/** * Generates a map where the key is the vertex and the value is a list of edges that use that vertex as an endpoint. * The lists are allocated from one memory pool. */ |