diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-12-12 10:11:27 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-12-12 10:37:16 +0400 |
commit | ab127c12d4d1f9db10435a904ec184560449938a (patch) | |
tree | 1a0356ddfb0c1d7ee1a3d2207805aea440fcf123 /source/blender/blenkernel | |
parent | e23f77b935c3d0a5f1cbc300d25000a0fdd1f765 (diff) |
Mesh API: Add BKE_mesh_origindex_map_create
This API function lets original data loop over its derived data,
Use for vertex paint, replacing custom function.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh_mapping.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mapping.c | 53 |
2 files changed, 57 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_mesh_mapping.h b/source/blender/blenkernel/BKE_mesh_mapping.h index 3c5377d7bf6..ee9e63e6975 100644 --- a/source/blender/blenkernel/BKE_mesh_mapping.h +++ b/source/blender/blenkernel/BKE_mesh_mapping.h @@ -117,6 +117,10 @@ void BKE_mesh_edge_poly_map_create( const struct MEdge *medge, const int totedge, const struct MPoly *mpoly, const int totpoly, const struct MLoop *mloop, const int totloop); +void BKE_mesh_origindex_map_create( + MeshElemMap **r_map, int **r_mem, + const int totorig, + const int *final_origindex, const int totfinal); /* smoothgroups */ int *BKE_mesh_calc_smoothgroups( diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index cbf4b4906f5..94f29b5b1a4 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -36,6 +36,7 @@ #include "BLI_math.h" #include "BKE_mesh_mapping.h" +#include "BKE_customdata.h" #include "BLI_strict_flags.h" @@ -289,6 +290,58 @@ void BKE_mesh_edge_poly_map_create(MeshElemMap **r_map, int **r_mem, *r_mem = indices; } +/** + * This function creates a map so the source-data (vert/edge/loop/poly) + * can loop over the destination data (using the destination arrays origindex). + * + * This has the advantage that it can operate on any data-types. + * + * \param totsource The total number of elements the that \a final_origindex points to. + * \param totfinal The size of \a final_origindex + * \param final_origindex The size of the final array. + * + * \note ``totsource`` could be ``totpoly``, + * ``totfinal`` could be ``tottessface`` and ``final_origindex`` its ORIGINDEX customdata. + * This would allow an MPoly to loop over its tessfaces. + */ +void BKE_mesh_origindex_map_create(MeshElemMap **r_map, int **r_mem, + const int totsource, + const int *final_origindex, const int totfinal) +{ + MeshElemMap *map = MEM_callocN(sizeof(MeshElemMap) * (size_t)totsource, "poly-tessface map"); + int *indices = MEM_mallocN(sizeof(int) * (size_t)totfinal, "poly-tessface map mem"); + int *index_step; + int i; + + /* count face users */ + for (i = 0; i < totfinal; i++) { + if (final_origindex[i] != ORIGINDEX_NONE) { + BLI_assert(final_origindex[i] < totsource); + map[final_origindex[i]].count++; + } + } + + /* create offsets */ + index_step = indices; + for (i = 0; i < totsource; i++) { + map[i].indices = index_step; + index_step += map[i].count; + + /* re-count, using this as an index below */ + map[i].count = 0; + } + + /* assign poly-tessface users */ + for (i = 0; i < totfinal; i++) { + if (final_origindex[i] != ORIGINDEX_NONE) { + MeshElemMap *map_ele = &map[final_origindex[i]]; + map_ele->indices[map_ele->count++] = i; + } + } + + *r_map = map; + *r_mem = indices; +} /** \} */ |