[Bf-blender-cvs] [da5b6ed75bf] master: Modifiers: add minimum number of vertices to triangulate modifier.

Ish Bosamiya noreply at git.blender.org
Fri Mar 22 18:14:38 CET 2019


Commit: da5b6ed75bf08141dd19a0cc143d1a91b14a0f24
Author: Ish Bosamiya
Date:   Fri Mar 22 17:55:51 2019 +0100
Branches: master
https://developer.blender.org/rBda5b6ed75bf08141dd19a0cc143d1a91b14a0f24

Modifiers: add minimum number of vertices to triangulate modifier.

This lets you only triangulate n-gons when setting the number to 5 or more.

Differential Revision: https://developer.blender.org/D4367

===================================================================

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/alembic/intern/abc_mesh.cc
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/bmesh/operators/bmo_triangulate.c
M	source/blender/bmesh/tools/bmesh_triangulate.c
M	source/blender/bmesh/tools/bmesh_triangulate.h
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_triangulate.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index b047bbdcfec..59bf820560e 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1368,6 +1368,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col = row.column()
         col.label(text="Ngon Method:")
         col.prop(md, "ngon_method", text="")
+        col.label(text="Minimum Vertices:")
+        col.prop(md, "min_vertices", text="")
 
     def UV_WARP(self, layout, ob, md):
         split = layout.split()
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index cb22b1eaa04..cdb9312b3db 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -552,7 +552,7 @@ Mesh *AbcGenericMeshWriter::getFinalMesh(bool &r_needsfree)
 		struct BMeshFromMeshParams bmfmp = {true, false, false, 0};
 		BMesh *bm = BKE_mesh_to_bmesh_ex(mesh, &bmcp, &bmfmp);
 
-		BM_mesh_triangulate(bm, quad_method, ngon_method, tag_only, NULL, NULL, NULL);
+		BM_mesh_triangulate(bm, quad_method, ngon_method, 4, tag_only, NULL, NULL, NULL);
 
 		Mesh *result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL);
 		BM_mesh_free(bm);
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 986f35008bd..6c5eb269c5c 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -2920,5 +2920,16 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 				part->draw_as = PART_DRAW_NOT;
 			}
 		}
+
+		if (!DNA_struct_elem_find(fd->filesdna, "TriangulateModifierData", "int", "min_vertices")) {
+			for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) {
+				for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
+					if (md->type == eModifierType_Triangulate) {
+						TriangulateModifierData *smd = (TriangulateModifierData *)md;
+						smd->min_vertices = 4;
+					}
+				}
+			}
+		}
 	}
 }
diff --git a/source/blender/bmesh/operators/bmo_triangulate.c b/source/blender/bmesh/operators/bmo_triangulate.c
index 747b1769137..35f5c40a213 100644
--- a/source/blender/bmesh/operators/bmo_triangulate.c
+++ b/source/blender/bmesh/operators/bmo_triangulate.c
@@ -47,7 +47,7 @@ void bmo_triangulate_exec(BMesh *bm, BMOperator *op)
 	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, quad_method, ngon_method, true, op, slot_facemap_out, slot_facemap_double_out);
+	BM_mesh_triangulate(bm, quad_method, ngon_method, 4, true, op, slot_facemap_out, slot_facemap_double_out);
 
 	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);
diff --git a/source/blender/bmesh/tools/bmesh_triangulate.c b/source/blender/bmesh/tools/bmesh_triangulate.c
index 034151fa584..9be4e8f621c 100644
--- a/source/blender/bmesh/tools/bmesh_triangulate.c
+++ b/source/blender/bmesh/tools/bmesh_triangulate.c
@@ -83,8 +83,9 @@ static void bm_face_triangulate_mapping(
 
 
 void BM_mesh_triangulate(
-        BMesh *bm, const int quad_method, const int ngon_method, const bool tag_only,
-        BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_facemap_double_out)
+	BMesh *bm, const int quad_method, const int ngon_method, const int min_vertices,
+	const bool tag_only, BMOperator *op, BMOpSlot *slot_facemap_out,
+	BMOpSlot *slot_facemap_double_out)
 {
 	BMIter iter;
 	BMFace *face;
@@ -103,7 +104,7 @@ void BM_mesh_triangulate(
 	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) {
+			if (face->len >= min_vertices) {
 				if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
 					bm_face_triangulate_mapping(
 					        bm, face,
@@ -118,7 +119,7 @@ void BM_mesh_triangulate(
 		LinkNode *faces_double = NULL;
 
 		BM_ITER_MESH (face, &iter, bm, BM_FACES_OF_MESH) {
-			if (face->len > 3) {
+			if (face->len >= min_vertices) {
 				if (tag_only == false || BM_elem_flag_test(face, BM_ELEM_TAG)) {
 					BM_face_triangulate(
 					        bm, face,
diff --git a/source/blender/bmesh/tools/bmesh_triangulate.h b/source/blender/bmesh/tools/bmesh_triangulate.h
index 1b312ebadbf..b254246720c 100644
--- a/source/blender/bmesh/tools/bmesh_triangulate.h
+++ b/source/blender/bmesh/tools/bmesh_triangulate.h
@@ -24,7 +24,8 @@
 #define __BMESH_TRIANGULATE_H__
 
 void BM_mesh_triangulate(
-        BMesh *bm, const int quad_method, const int ngon_method, const bool tag_only,
+        BMesh *bm, const int quad_method, const int ngon_method,
+        const int min_vertices, const bool tag_only,
         BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_doubles_out);
 
 #endif  /* __BMESH_TRIANGULATE_H__ */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 34c049c0548..24edd9bec86 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -5423,7 +5423,7 @@ static void SCULPT_OT_set_persistent_base(wmOperatorType *ot)
 static void sculpt_dynamic_topology_triangulate(BMesh *bm)
 {
 	if (bm->totloop != bm->totface * 3) {
-		BM_mesh_triangulate(bm, MOD_TRIANGULATE_QUAD_BEAUTY, MOD_TRIANGULATE_NGON_EARCLIP, false, NULL, NULL, NULL);
+		BM_mesh_triangulate(bm, MOD_TRIANGULATE_QUAD_BEAUTY, MOD_TRIANGULATE_NGON_EARCLIP, 4, false, NULL, NULL, NULL);
 	}
 }
 
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 99b9b4ce361..126ef912b15 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1551,7 +1551,7 @@ typedef struct TriangulateModifierData {
 	int flag;
 	int quad_method;
 	int ngon_method;
-	char _pad[4];
+	int min_vertices;
 } TriangulateModifierData;
 
 /* TriangulateModifierData.flag */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 00dec553dcd..a0d37d34526 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4359,6 +4359,12 @@ static void rna_def_modifier_triangulate(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Polygon Method", "Method for splitting the polygons into triangles");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "min_vertices", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_int_sdna(prop, NULL, "min_vertices");
+	RNA_def_property_range(prop, 4, INT_MAX);
+	RNA_def_property_ui_text(prop, "Minimum Vertices", "Triangulate only polygons with vertex count greater than or equal to this number");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "keep_custom_normals", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_TRIANGULATE_KEEP_CUSTOMLOOP_NORMALS);
 	RNA_def_property_ui_text(prop, "Keep Normals",
diff --git a/source/blender/modifiers/intern/MOD_triangulate.c b/source/blender/modifiers/intern/MOD_triangulate.c
index e39698e142e..6bd24620da2 100644
--- a/source/blender/modifiers/intern/MOD_triangulate.c
+++ b/source/blender/modifiers/intern/MOD_triangulate.c
@@ -34,7 +34,7 @@
 
 #include "MOD_modifiertypes.h"
 
-static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int flag)
+static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_method, const int min_vertices, const int flag)
 {
 	Mesh *result;
 	BMesh *bm;
@@ -59,7 +59,7 @@ static Mesh *triangulate_mesh(Mesh *mesh, const int quad_method, const int ngon_
 	            .cd_mask_extra = cddata_masks,
 	        }));
 
-	BM_mesh_triangulate(bm, quad_method, ngon_method, false, NULL, NULL, NULL);
+	BM_mesh_triangulate(bm, quad_method, ngon_method, min_vertices, false, NULL, NULL, NULL);
 
 	result = BKE_mesh_from_bmesh_for_eval_nomain(bm, &cddata_masks);
 	BM_mesh_free(bm);
@@ -98,6 +98,7 @@ static void initData(ModifierData *md)
 	md->mode |= eModifierMode_Editmode;
 	tmd->quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE;
 	tmd->ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
+	tmd->min_vertices = 4;
 }
 
 static Mesh *applyModifier(
@@ -107,7 +108,7 @@ static Mesh *applyModifier(
 {
 	TriangulateModifierData *tmd = (TriangulateModifierData *)md;
 	Mesh *result;
-	if (!(result = triangulate_mesh(mesh, tmd->quad_method, tmd->ngon_method, tmd->flag))) {
+	if (!(result = triangulate_mesh(mesh, tmd->quad_method, tmd->ngon_method, tmd->min_vertices, tmd->flag))) {
 		return mesh;
 	}



More information about the Bf-blender-cvs mailing list