add option for decimate-collapse to keep triangulated geometry (normally quads stay...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 23 Oct 2012 05:30:10 +0000 (05:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 23 Oct 2012 05:30:10 +0000 (05:30 +0000)
release/scripts/startup/bl_ui/properties_data_modifier.py
source/blender/bmesh/intern/bmesh_decimate.h
source/blender/bmesh/intern/bmesh_decimate_collapse.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/makesrna/intern/rna_modifier.c
source/blender/modifiers/intern/MOD_decimate.c

index 36e626d1a00d28f39f9df0c314bad27fcb2a2622..445178e4e429930714cc459754eb240501c2516a 100644 (file)
@@ -220,6 +220,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             row = layout.row()
             row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
             row.prop(md, "invert_vertex_group")
+            layout.prop(md, "use_triangulate")
         elif decimate_type == 'UNSUBDIV':
             layout.prop(md, "iterations")
         else:  # decimate_type == 'DISSOLVE':
index 04aa392fcf07e057ad4ed52790963fe619deba98..a5f4acc5f37adbcb3467bab7cc0e0af351227709 100644 (file)
@@ -27,7 +27,7 @@
  *  \ingroup bmesh
  */
 
-void BM_mesh_decimate_collapse(BMesh *bm, const float factor, float *vweights);
+void BM_mesh_decimate_collapse(BMesh *bm, const float factor, float *vweights, const int do_triangulate);
 
 void BM_mesh_decimate_unsubdivide_ex(BMesh *bm, const int iterations, const int tag_only);
 void BM_mesh_decimate_unsubdivide(BMesh *bm, const int iterations);
index ce10fe2fed14b3c1479d3130ce96424a3f7b6b2e..cbc7c0dac9d71521c4d910cef9e3ba6d11474c69 100644 (file)
@@ -855,7 +855,7 @@ static void bm_decim_edge_collapse(BMesh *bm, BMEdge *e,
  * \param vertex_weights Optional array of vertex  aligned weights [0 - 1],
  *        a vertex group is the usual source for this.
  */
-void BM_mesh_decimate_collapse(BMesh *bm, const float factor, float *vweights)
+void BM_mesh_decimate_collapse(BMesh *bm, const float factor, float *vweights, const int do_triangulate)
 {
        Heap *eheap;             /* edge heap */
        HeapNode **eheap_table;  /* edge index aligned table pointing to the eheap */
@@ -913,10 +913,12 @@ void BM_mesh_decimate_collapse(BMesh *bm, const float factor, float *vweights)
 
 
 #ifdef USE_TRIANGULATE
-       /* its possible we only had triangles, skip this step in that case */
-       if (LIKELY(use_triangulate)) {
-               /* temp convert quads to triangles */
-               bm_decim_triangulate_end(bm);
+       if (do_triangulate == FALSE) {
+               /* its possible we only had triangles, skip this step in that case */
+               if (LIKELY(use_triangulate)) {
+                       /* temp convert quads to triangles */
+                       bm_decim_triangulate_end(bm);
+               }
        }
 #endif
 
index 6853eefd2ec8a08f4b4f4bba40ac4b66998d31db..477d2c28f7c822d0086d74a73b8f8a0e7b6553d9 100644 (file)
@@ -374,7 +374,8 @@ typedef struct DecimateModifierData {
 } DecimateModifierData;
 
 enum {
-       MOD_DECIM_FLAG_INVERT_VGROUP = (1 << 0)
+       MOD_DECIM_FLAG_INVERT_VGROUP = (1 << 0),
+       MOD_DECIM_FLAG_TRIANGULATE   = (1 << 1)   /* for collapse only. dont convert tri pairs back to quads */
 };
 
 enum {
index 47212c4a231d642364012dab4543195ad698bd3a..12254a62f71992a909fb2e883a4fcb875f2e15be 100644 (file)
@@ -1166,6 +1166,11 @@ static void rna_def_modifier_decimate(BlenderRNA *brna)
        RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_DECIM_FLAG_INVERT_VGROUP);
        RNA_def_property_ui_text(prop, "Invert", "Invert vertex group influence");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+       prop = RNA_def_property(srna, "use_triangulate", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_DECIM_FLAG_TRIANGULATE);
+       RNA_def_property_ui_text(prop, "Triangulate", "Keep triangulated faces resulting from decimation");
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
        /* end collapse-only option */
 
        /* all modes use this */
index 71b3b6c883b72addb883c41c47d21f3517d06b3f..cb6eb127172044c1dc69dbb6bcf9032b731a87ea 100644 (file)
@@ -100,6 +100,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        BMEditMesh *em;
        BMesh *bm;
 
+       const int do_triangulate = (dmd->flag & MOD_DECIM_FLAG_TRIANGULATE) != 0;
+
        float *vweights = NULL;
 
 #ifdef USE_TIMEIT
@@ -146,7 +148,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 
        switch (dmd->mode) {
                case MOD_DECIM_MODE_COLLAPSE:
-                       BM_mesh_decimate_collapse(bm, dmd->percent, vweights);
+                       BM_mesh_decimate_collapse(bm, dmd->percent, vweights, do_triangulate);
                        break;
                case MOD_DECIM_MODE_UNSUBDIV:
                        BM_mesh_decimate_unsubdivide(bm, dmd->iter);