diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-07-23 08:08:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-07-23 08:08:27 +0300 |
commit | 8155d25d395c30efd7724509afe2e50fb58c6d87 (patch) | |
tree | d00ff393c5f710d6f885b889892ed819b19166ec /source/blender/blenkernel/intern | |
parent | 60822ec183a514f38f478ec3f3a167f59865f027 (diff) |
Utility function to get poly -> looptri mapping
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mapping.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index 1d8978586b6..c03f1feef9c 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -406,6 +406,37 @@ void BKE_mesh_origindex_map_create(MeshElemMap **r_map, int **r_mem, *r_mem = indices; } +/** + * A version of #BKE_mesh_origindex_map_create that takes a looptri array. + * Making a poly -> looptri map. + */ +void BKE_mesh_origindex_map_create_looptri( + MeshElemMap **r_map, int **r_mem, + const MPoly *mpoly, const int mpoly_num, + const MLoopTri *looptri, const int looptri_num) +{ + MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)mpoly_num, "poly-tessface map"); + int *indices = MEM_mallocN(sizeof(int) * (size_t)looptri_num, "poly-tessface map mem"); + int *index_step; + int i; + + /* create offsets */ + index_step = indices; + for (i = 0; i < mpoly_num; i++) { + map[i].indices = index_step; + index_step += ME_POLY_TRI_TOT(&mpoly[i]); + } + + /* assign poly-tessface users */ + for (i = 0; i < looptri_num; i++) { + MeshElemMap *map_ele = &map[looptri[i].poly]; + map_ele->indices[map_ele->count++] = i; + } + + *r_map = map; + *r_mem = indices; +} + /** \} */ |