diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-23 09:30:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-23 09:30:10 +0400 |
commit | 1ea210a8dcab7f9123e8680844835c876c61b0e4 (patch) | |
tree | 1dc9cc9e32f9685039dcef69484baab3cfdaabbc /source | |
parent | bbe0deb8afb0094b169a9abb04df7458cd49786b (diff) |
add option for decimate-collapse to keep triangulated geometry (normally quads stay as quads when not collapsed).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_decimate.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_decimate_collapse.c | 12 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 5 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_decimate.c | 4 |
5 files changed, 18 insertions, 8 deletions
diff --git a/source/blender/bmesh/intern/bmesh_decimate.h b/source/blender/bmesh/intern/bmesh_decimate.h index 04aa392fcf0..a5f4acc5f37 100644 --- a/source/blender/bmesh/intern/bmesh_decimate.h +++ b/source/blender/bmesh/intern/bmesh_decimate.h @@ -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); diff --git a/source/blender/bmesh/intern/bmesh_decimate_collapse.c b/source/blender/bmesh/intern/bmesh_decimate_collapse.c index ce10fe2fed1..cbc7c0dac9d 100644 --- a/source/blender/bmesh/intern/bmesh_decimate_collapse.c +++ b/source/blender/bmesh/intern/bmesh_decimate_collapse.c @@ -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 diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 6853eefd2ec..477d2c28f7c 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -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 { diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 47212c4a231..12254a62f71 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -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 */ diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c index 71b3b6c883b..cb6eb127172 100644 --- a/source/blender/modifiers/intern/MOD_decimate.c +++ b/source/blender/modifiers/intern/MOD_decimate.c @@ -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); |