own recent change to triangulate bmesh operator stopped filling in mapping slot ...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 5 Feb 2013 11:30:50 +0000 (11:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 5 Feb 2013 11:30:50 +0000 (11:30 +0000)
source/blender/bmesh/operators/bmo_triangulate.c
source/blender/bmesh/tools/bmesh_triangulate.c
source/blender/bmesh/tools/bmesh_triangulate.h
source/blender/editors/sculpt_paint/sculpt.c
source/blender/modifiers/intern/MOD_triangulate.c

index bbcb07e..e06929e 100644 (file)
 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,
index 4ab5383..79f6c76 100644 (file)
 #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);
                                }
                        }
                }
index ea271c9..936a90d 100644 (file)
@@ -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__ */
index c4d09de..10f4dc2 100644 (file)
@@ -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)
index 2f0fbbd..1c22e9b 100644 (file)
@@ -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);