add option for decimate-collapse to keep triangulated geometry (normally quads stay as quads when not collapsed).

This commit is contained in:
Campbell Barton
2012-10-23 05:30:10 +00:00
parent bbe0deb8af
commit 1ea210a8dc
6 changed files with 19 additions and 8 deletions

View 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':

View 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);

View 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

View 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 {

View 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 */

View 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);