diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-06-10 08:52:08 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-06-10 08:54:00 +0300 |
commit | a4bb4b6e6572e41426ea4bacd06dcbbeb72037e6 (patch) | |
tree | dd9ad7df05034dc9c74151c05717b662f0a896f6 /source/blender | |
parent | 48ca66cfe7826985f94a72af6cd6f750d797a46b (diff) |
Mesh: utility functions to access wrapped mesh coordinates
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_mesh.h | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/mesh_wrapper.c | 133 |
2 files changed, 146 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 52d458c108d..d08cd5eff3f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -678,7 +678,19 @@ struct Mesh *BKE_mesh_wrapper_from_editmesh(struct BMEditMesh *em, const struct Mesh *me_settings); void BKE_mesh_wrapper_ensure_mdata(struct Mesh *me); bool BKE_mesh_wrapper_minmax(const struct Mesh *me, float min[3], float max[3]); -void BKE_mesh_wrapper_normals_update(struct Mesh *me); + +int BKE_mesh_wrapper_vert_len(const struct Mesh *me); +int BKE_mesh_wrapper_edge_len(const struct Mesh *me); +int BKE_mesh_wrapper_loop_len(const struct Mesh *me); +int BKE_mesh_wrapper_poly_len(const struct Mesh *me); + +void BKE_mesh_wrapper_vert_coords_copy(const struct Mesh *me, + float (*vert_coords)[3], + int vert_coords_len); +void BKE_mesh_wrapper_vert_coords_copy_with_mat4(const struct Mesh *me, + float (*vert_coords)[3], + int vert_coords_len, + const float mat[4][4]); /* In DerivedMesh.c */ void BKE_mesh_wrapper_deferred_finalize(struct Mesh *me_eval, diff --git a/source/blender/blenkernel/intern/mesh_wrapper.c b/source/blender/blenkernel/intern/mesh_wrapper.c index f073feffedc..7f4f6b98700 100644 --- a/source/blender/blenkernel/intern/mesh_wrapper.c +++ b/source/blender/blenkernel/intern/mesh_wrapper.c @@ -164,3 +164,136 @@ bool BKE_mesh_wrapper_minmax(const Mesh *me, float min[3], float max[3]) BLI_assert(0); return false; } + +/* -------------------------------------------------------------------- */ +/** \name Mesh Coordinate Access + * \{ */ + +void BKE_mesh_wrapper_vert_coords_copy(const Mesh *me, + float (*vert_coords)[3], + int vert_coords_len) +{ + switch ((eMeshWrapperType)me->runtime.wrapper_type) { + case ME_WRAPPER_TYPE_BMESH: { + BMesh *bm = me->edit_mesh->bm; + BLI_assert(vert_coords_len <= bm->totvert); + EditMeshData *edit_data = me->runtime.edit_data; + if (edit_data->vertexCos != NULL) { + for (int i = 0; i < vert_coords_len; i++) { + copy_v3_v3(vert_coords[i], edit_data->vertexCos[i]); + } + } + else { + BMIter iter; + BMVert *v; + int i; + BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { + copy_v3_v3(vert_coords[i], v->co); + } + } + return; + } + case ME_WRAPPER_TYPE_MDATA: { + BLI_assert(vert_coords_len <= me->totvert); + const MVert *mvert = me->mvert; + for (int i = 0; i < vert_coords_len; i++) { + copy_v3_v3(vert_coords[i], mvert[i].co); + } + return; + } + } + BLI_assert(0); +} + +void BKE_mesh_wrapper_vert_coords_copy_with_mat4(const Mesh *me, + float (*vert_coords)[3], + int vert_coords_len, + const float mat[4][4]) +{ + switch ((eMeshWrapperType)me->runtime.wrapper_type) { + case ME_WRAPPER_TYPE_BMESH: { + BMesh *bm = me->edit_mesh->bm; + BLI_assert(vert_coords_len == bm->totvert); + EditMeshData *edit_data = me->runtime.edit_data; + if (edit_data->vertexCos != NULL) { + for (int i = 0; i < vert_coords_len; i++) { + mul_v3_m4v3(vert_coords[i], mat, edit_data->vertexCos[i]); + } + } + else { + BMIter iter; + BMVert *v; + int i; + BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { + mul_v3_m4v3(vert_coords[i], mat, v->co); + } + } + return; + } + case ME_WRAPPER_TYPE_MDATA: { + BLI_assert(vert_coords_len == me->totvert); + const MVert *mvert = me->mvert; + for (int i = 0; i < vert_coords_len; i++) { + mul_v3_m4v3(vert_coords[i], mat, mvert[i].co); + } + return; + } + } + BLI_assert(0); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Mesh Array Length Access + * \{ */ + +int BKE_mesh_wrapper_vert_len(const Mesh *me) +{ + switch ((eMeshWrapperType)me->runtime.wrapper_type) { + case ME_WRAPPER_TYPE_BMESH: + return me->edit_mesh->bm->totvert; + case ME_WRAPPER_TYPE_MDATA: + return me->totvert; + } + BLI_assert(0); + return -1; +} + +int BKE_mesh_wrapper_edge_len(const Mesh *me) +{ + switch ((eMeshWrapperType)me->runtime.wrapper_type) { + case ME_WRAPPER_TYPE_BMESH: + return me->edit_mesh->bm->totedge; + case ME_WRAPPER_TYPE_MDATA: + return me->totedge; + } + BLI_assert(0); + return -1; +} + +int BKE_mesh_wrapper_loop_len(const Mesh *me) +{ + switch ((eMeshWrapperType)me->runtime.wrapper_type) { + case ME_WRAPPER_TYPE_BMESH: + return me->edit_mesh->bm->totloop; + case ME_WRAPPER_TYPE_MDATA: + return me->totloop; + } + BLI_assert(0); + return -1; +} + +int BKE_mesh_wrapper_poly_len(const Mesh *me) +{ + switch ((eMeshWrapperType)me->runtime.wrapper_type) { + case ME_WRAPPER_TYPE_BMESH: + return me->edit_mesh->bm->totface; + case ME_WRAPPER_TYPE_MDATA: + return me->totpoly; + } + BLI_assert(0); + return -1; +} + +/** \} */ |