diff options
-rw-r--r-- | source/blender/bmesh/operators/bmo_triangulate.c | 3 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_triangulate.c | 40 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_triangulate.h | 3 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_triangulate.c | 2 |
5 files changed, 40 insertions, 10 deletions
diff --git a/source/blender/bmesh/operators/bmo_triangulate.c b/source/blender/bmesh/operators/bmo_triangulate.c index bbcb07e1174..e06929e339d 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.c +++ b/source/blender/bmesh/operators/bmo_triangulate.c @@ -44,11 +44,12 @@ void bmo_triangulate_exec(BMesh *bm, BMOperator *op) { const bool use_beauty = BMO_slot_bool_get(op->slots_in, "use_beauty"); + BMOpSlot *slot_facemap_out = BMO_slot_get(op->slots_out, "face_map.out"); BM_mesh_elem_hflag_disable_all(bm, BM_FACE | BM_EDGE, BM_ELEM_TAG, false); BMO_slot_buffer_hflag_enable(bm, op->slots_in, "faces", BM_FACE, BM_ELEM_TAG, false); - BM_mesh_triangulate(bm, use_beauty, true); + BM_mesh_triangulate(bm, use_beauty, true, op, slot_facemap_out); if (use_beauty) { BMO_op_callf(bm, op->flag, diff --git a/source/blender/bmesh/tools/bmesh_triangulate.c b/source/blender/bmesh/tools/bmesh_triangulate.c index 4ab5383f0b6..79f6c76afc7 100644 --- a/source/blender/bmesh/tools/bmesh_triangulate.c +++ b/source/blender/bmesh/tools/bmesh_triangulate.c @@ -30,28 +30,56 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_array.h" #include "bmesh.h" #include "bmesh_triangulate.h" /* own include */ -void BM_mesh_triangulate(BMesh *bm, const bool use_beauty, const bool tag_only) +/** + * a version of #BM_face_triangulate that maps to #BMOpSlot + */ +static void bm_face_triangulate_mapping(BMesh *bm, BMFace *face, const bool use_beauty, const bool use_tag, + BMOperator *op, BMOpSlot *slot_facemap_out) +{ + const int faces_array_tot = face->len - 3; + BMFace **faces_array = BLI_array_alloca(faces_array, faces_array_tot); + BLI_assert(face->len > 3); + + BM_face_triangulate(bm, face, faces_array, use_beauty, use_tag); + + if (faces_array) { + int i; + BMO_slot_map_elem_insert(op, slot_facemap_out, face, face); + for (i = 0; i < faces_array_tot; i++) { + BMO_slot_map_elem_insert(op, slot_facemap_out, faces_array[i], face); + } + } +} + + +void BM_mesh_triangulate(BMesh *bm, const bool use_beauty, const bool tag_only, + BMOperator *op, BMOpSlot *slot_facemap_out) { BMIter iter; BMFace *face; - if (tag_only == false) { + if (slot_facemap_out) { + /* same as below but call: bm_face_triangulate_mapping() */ BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) { if (face->len > 3) { - BM_face_triangulate(bm, face, NULL, use_beauty, false); + if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) { + bm_face_triangulate_mapping(bm, face, use_beauty, tag_only, + op, slot_facemap_out); + } } } } else { BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(face, BM_ELEM_TAG)) { - if (face->len > 3) { - BM_face_triangulate(bm, face, NULL, use_beauty, true); + if (face->len > 3) { + if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) { + BM_face_triangulate(bm, face, NULL, use_beauty, tag_only); } } } diff --git a/source/blender/bmesh/tools/bmesh_triangulate.h b/source/blender/bmesh/tools/bmesh_triangulate.h index ea271c98acb..936a90d3a16 100644 --- a/source/blender/bmesh/tools/bmesh_triangulate.h +++ b/source/blender/bmesh/tools/bmesh_triangulate.h @@ -30,6 +30,7 @@ #ifndef __BMESH_TRIAMGULATE_H__ #define __BMESH_TRIAMGULATE_H__ -void BM_mesh_triangulate(BMesh *bm, const bool use_beauty, const bool tag_only); +void BM_mesh_triangulate(BMesh *bm, const bool use_beauty, const bool tag_only, + BMOperator *op, BMOpSlot *slot_facemap_out); #endif /* __BMESH_TRIAMGULATE_H__ */ diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index c4d09de3d0e..10f4dc2aebc 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -4526,7 +4526,7 @@ static void SCULPT_OT_set_persistent_base(wmOperatorType *ot) static void sculpt_dynamic_topology_triangulate(BMesh *bm) { - BM_mesh_triangulate(bm, false, false); + BM_mesh_triangulate(bm, false, false, NULL, NULL); } void sculpt_pbvh_clear(Object *ob) diff --git a/source/blender/modifiers/intern/MOD_triangulate.c b/source/blender/modifiers/intern/MOD_triangulate.c index 2f0fbbd0507..1c22e9bf364 100644 --- a/source/blender/modifiers/intern/MOD_triangulate.c +++ b/source/blender/modifiers/intern/MOD_triangulate.c @@ -42,7 +42,7 @@ static DerivedMesh *triangulate_dm(DerivedMesh *dm, const int flag) bm = DM_to_bmesh(dm); - BM_mesh_triangulate(bm, (flag & MOD_TRIANGULATE_BEAUTY), false); + BM_mesh_triangulate(bm, (flag & MOD_TRIANGULATE_BEAUTY), false, NULL, NULL); result = CDDM_from_bmesh(bm, FALSE); BM_mesh_free(bm); |