Triangulate modifier no longer uses bmesh operator api call, instead add a BM_mesh_tr...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 29 Jan 2013 10:31:05 +0000 (10:31 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 29 Jan 2013 10:31:05 +0000 (10:31 +0000)
source/blender/bmesh/CMakeLists.txt
source/blender/bmesh/bmesh.h
source/blender/bmesh/intern/bmesh_polygon.c
source/blender/bmesh/intern/bmesh_polygon.h
source/blender/bmesh/operators/bmo_triangulate.c
source/blender/bmesh/tools/bmesh_triangulate.c [new file with mode: 0644]
source/blender/bmesh/tools/bmesh_triangulate.h [new file with mode: 0644]
source/blender/modifiers/intern/MOD_triangulate.c

index 42a1a5e..aa1fb2d 100644 (file)
@@ -114,6 +114,8 @@ set(SRC
        tools/bmesh_decimate.h
        tools/bmesh_edgesplit.c
        tools/bmesh_edgesplit.h
+       tools/bmesh_triangulate.c
+       tools/bmesh_triangulate.h
 
        bmesh.h
        bmesh_class.h
index f593f78..3b33513 100644 (file)
@@ -268,8 +268,9 @@ extern "C" {
 
 #include "intern/bmesh_inline.h"
 
-#include "tools/bmesh_decimate.h"
 #include "tools/bmesh_bevel.h"
+#include "tools/bmesh_decimate.h"
+#include "tools/bmesh_triangulate.h"
 
 #ifdef __cplusplus
 }
index 5c3d164..b8b7abd 100644 (file)
@@ -845,8 +845,9 @@ static BMLoop *find_ear(BMFace *f, float (*verts)[3], const bool use_beauty, flo
  *
  * \note newedgeflag sets a flag layer flag, obviously not the header flag.
  */
-void BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], const short newedge_oflag,
-                         const short newface_oflag, BMFace **newfaces, const bool use_beauty)
+void BM_face_triangulate(BMesh *bm, BMFace *f,
+                         float (*projectverts)[3], BMFace **newfaces,
+                         const bool use_beauty, const bool use_tag)
 {
        int i, nvert, nf_i = 0;
        bool done;
@@ -900,8 +901,11 @@ void BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], const s
                        }
 
                        copy_v3_v3(f->no, l_iter->f->no);
-                       BMO_elem_flag_enable(bm, newl->e, newedge_oflag);
-                       BMO_elem_flag_enable(bm, f, newface_oflag);
+
+                       if (use_tag) {
+                               BM_elem_flag_enable(newl->e, BM_ELEM_TAG);
+                               BM_elem_flag_enable(f, BM_ELEM_TAG);
+                       }
                        
                        if (newfaces)
                                newfaces[nf_i++] = f;
index a0c6ac5..7c2b178 100644 (file)
@@ -44,9 +44,8 @@ void  BM_vert_normal_update_all(BMVert *v);
 void  BM_face_normal_flip(BMesh *bm, BMFace *f);
 bool  BM_face_point_inside_test(BMFace *f, const float co[3]);
 
-void  BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3],
-                          const short newedge_oflag, const short newface_oflag, BMFace **newfaces,
-                          const bool use_beauty);
+void  BM_face_triangulate(BMesh *bm, BMFace *f, float (*projectverts)[3], BMFace **newfaces,
+                          const bool use_beauty, const bool use_tag);
 
 void  BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len);
 
index 744f706..c4d1503 100644 (file)
 
 #include "intern/bmesh_operators_private.h" /* own include */
 
-#define EDGE_NEW       1
-#define FACE_NEW       1
-
 #define ELE_NEW                1
 #define FACE_MARK      2
 #define EDGE_MARK      4
 
 void bmo_triangulate_exec(BMesh *bm, BMOperator *op)
 {
-       BMOIter siter;
-       BMFace *face, **newfaces = NULL;
-       BLI_array_declare(newfaces);
-       float (*projectverts)[3] = NULL;
-       BLI_array_declare(projectverts);
-       int i;
        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");
-
-       for (face = BMO_iter_new(&siter, op->slots_in, "faces", BM_FACE); face; face = BMO_iter_step(&siter)) {
-
-               BLI_array_empty(projectverts);
-               BLI_array_empty(newfaces);
 
-               BLI_array_grow_items(projectverts, face->len * 3);
-               BLI_array_grow_items(newfaces, face->len);
+       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_face_triangulate(bm, face, projectverts, EDGE_NEW, FACE_NEW, newfaces, use_beauty);
+       BM_mesh_triangulate(bm, use_beauty, true);
 
-               BMO_slot_map_elem_insert(op, slot_facemap_out, face, face);
-               for (i = 0; newfaces[i]; i++) {
-                       BMO_slot_map_elem_insert(op, slot_facemap_out, newfaces[i], face);
-               }
-       }
-       
-       BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "edges.out", BM_EDGE, EDGE_NEW);
-       BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "faces.out", BM_FACE, FACE_NEW);
-       
-       BLI_array_free(projectverts);
-       BLI_array_free(newfaces);
+       BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "edges.out", BM_EDGE, BM_ELEM_TAG);
+       BMO_slot_buffer_from_enabled_hflag(bm, op, op->slots_out, "faces.out", BM_FACE, BM_ELEM_TAG);
 }
 
 void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op)
diff --git a/source/blender/bmesh/tools/bmesh_triangulate.c b/source/blender/bmesh/tools/bmesh_triangulate.c
new file mode 100644 (file)
index 0000000..7e6e41a
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Joseph Eagar
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/tools/bmesh_triangulate.c
+ *  \ingroup bmesh
+ *
+ * Triangulate.
+ *
+ */
+
+#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)
+{
+       BMIter iter;
+       BMFace *face;
+       float (*projectverts)[3] = NULL;
+       BLI_array_declare(projectverts);
+
+       if (tag_only == false) {
+               BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
+                       BLI_array_empty(projectverts);
+                       BLI_array_reserve(projectverts, face->len * 3);
+
+                       BM_face_triangulate(bm, face, projectverts, NULL, use_beauty, false);
+               }
+       }
+       else {
+               BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
+                       if (BM_elem_flag_test(face, BM_ELEM_TAG)) {
+                               BLI_array_empty(projectverts);
+                               BLI_array_grow_items(projectverts, face->len * 3);
+
+                               BM_face_triangulate(bm, face, projectverts, NULL, use_beauty, true);
+                       }
+               }
+       }
+
+       BLI_array_free(projectverts);
+}
diff --git a/source/blender/bmesh/tools/bmesh_triangulate.h b/source/blender/bmesh/tools/bmesh_triangulate.h
new file mode 100644 (file)
index 0000000..9632ab5
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Joseph Eagar
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/bmesh/tools/bmesh_triangulate.c
+ *  \ingroup bmesh
+ *
+ * Triangulate.
+ *
+ */
+
+#ifndef __BMESH_TRIAMGULATE_H__
+#define __BMESH_TRIAMGULATE_H__
+
+void BM_mesh_triangulate(BMesh *bm, const bool use_beauty, const bool tag_only);
+
+#endif  /* __BMESH_TRIAMGULATE_H__ */
index 645fd5e..2f0fbbd 100644 (file)
@@ -33,8 +33,6 @@
 #include "BKE_modifier.h"
 #include "BKE_tessmesh.h"
 
-/* triangulation modifier, directly calls the bmesh operator */
-
 static DerivedMesh *triangulate_dm(DerivedMesh *dm, const int flag)
 {
        DerivedMesh *result;
@@ -44,13 +42,7 @@ static DerivedMesh *triangulate_dm(DerivedMesh *dm, const int flag)
 
        bm = DM_to_bmesh(dm);
 
-       BM_mesh_elem_toolflags_ensure(bm);
-       BMO_push(bm, NULL);
-
-       BMO_op_callf(bm, BMO_FLAG_DEFAULTS,
-                    "triangulate faces=%af use_beauty=%b",
-                    (flag & MOD_TRIANGULATE_BEAUTY));
-       BMO_pop(bm);
+       BM_mesh_triangulate(bm, (flag & MOD_TRIANGULATE_BEAUTY), false);
 
        result = CDDM_from_bmesh(bm, FALSE);
        BM_mesh_free(bm);