[Bf-blender-cvs] [a67aae98fe1] blender-v2.79-release: Screw Modifier: remove doubles option

Campbell Barton noreply at git.blender.org
Fri Sep 8 12:08:18 CEST 2017


Commit: a67aae98fe1300a8caf49cf4bb6d39df7c79dfdd
Author: Campbell Barton
Date:   Thu Sep 7 00:10:13 2017 +1000
Branches: blender-v2.79-release
https://developer.blender.org/rBa67aae98fe1300a8caf49cf4bb6d39df7c79dfdd

Screw Modifier: remove doubles option

Vertices on the axis can be optionally merged,
nice for creating objects which close at the end-points.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_screw.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index d72855fab6b..836af49911a 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -747,6 +747,10 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "steps")
         col.prop(md, "render_steps")
         col.prop(md, "use_smooth_shade")
+        col.prop(md, "use_merge_vertices")
+        sub = col.column()
+        sub.active = md.use_merge_vertices
+        sub.prop(md, "merge_threshold")
 
         col = split.column()
         row = col.row()
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index b33674d41ee..67b29264d6c 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -924,9 +924,10 @@ typedef struct ScrewModifierData {
 	unsigned int iter;
 	float screw_ofs;
 	float angle;
-	char axis;
-	char pad;
+	float merge_dist;
 	short flag;
+	char axis;
+	char pad[5];
 } ScrewModifierData;
 
 enum {
@@ -937,6 +938,7 @@ enum {
 	MOD_SCREW_SMOOTH_SHADING = (1 << 5),
 	MOD_SCREW_UV_STRETCH_U   = (1 << 6),
 	MOD_SCREW_UV_STRETCH_V   = (1 << 7),
+	MOD_SCREW_MERGE          = (1 << 8),
 };
 
 typedef struct OceanModifierData {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 1a8dd05a7b5..e53237ae2c1 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3413,6 +3413,13 @@ static void rna_def_modifier_screw(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Screw", "Offset the revolution along its axis");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	prop = RNA_def_property(srna, "merge_threshold", PROP_FLOAT, PROP_DISTANCE);
+	RNA_def_property_float_sdna(prop, NULL, "merge_dist");
+	RNA_def_property_range(prop, 0, FLT_MAX);
+	RNA_def_property_ui_range(prop, 0, 1, 1, 4);
+	RNA_def_property_ui_text(prop, "Merge Distance", "Limit below which to merge vertices");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "use_normal_flip", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SCREW_NORMAL_FLIP);
 	RNA_def_property_ui_text(prop, "Flip", "Flip normals of lathed faces");
@@ -3428,6 +3435,12 @@ static void rna_def_modifier_screw(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Object Screw", "Use the distance between the objects to make a screw");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+	/* Vertex merging parameters */
+	prop = RNA_def_property(srna, "use_merge_vertices", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SCREW_MERGE);
+	RNA_def_property_ui_text(prop, "Merge Vertices", "Merge adjacent vertices (screw offset must be zero)");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
 	prop = RNA_def_property(srna, "use_smooth_shade", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SCREW_SMOOTH_SHADING);
 	RNA_def_property_ui_text(prop, "Smooth Shading", "Output faces with smooth shading rather than flat shaded");
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index 87859cd240a..2c3d7f394bb 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -112,6 +112,56 @@ static void screwvert_iter_step(ScrewVertIter *iter)
 	}
 }
 
+static DerivedMesh *dm_remove_doubles_on_axis(
+        DerivedMesh *result, MVert *mvert_new, const uint totvert, const uint step_tot,
+        const float axis_vec[3], const float axis_offset[3], const float merge_threshold)
+{
+	const float merge_threshold_sq = SQUARE(merge_threshold);
+	const bool use_offset = axis_offset != NULL;
+	uint tot_doubles = 0;
+	for (uint i = 0; i < totvert; i += 1) {
+		float axis_co[3];
+		if (use_offset) {
+			float offset_co[3];
+			sub_v3_v3v3(offset_co, mvert_new[i].co, axis_offset);
+			project_v3_v3v3_normalized(axis_co, offset_co, axis_vec);
+			add_v3_v3(axis_co, axis_offset);
+		}
+		else {
+			project_v3_v3v3_normalized(axis_co, mvert_new[i].co, axis_vec);
+		}
+		const float dist_sq = len_squared_v3v3(axis_co, mvert_new[i].co);
+		if (dist_sq <= merge_threshold_sq) {
+			mvert_new[i].flag |= ME_VERT_TMP_TAG;
+			tot_doubles += 1;
+			copy_v3_v3(mvert_new[i].co, axis_co);
+		}
+	}
+
+	if (tot_doubles != 0) {
+		uint tot = totvert * step_tot;
+		int *full_doubles_map = MEM_mallocN(sizeof(int) * tot, __func__);
+		copy_vn_i(full_doubles_map, (int)tot, -1);
+
+		uint tot_doubles_left = tot_doubles;
+		for (uint i = 0; i < totvert; i += 1) {
+			if (mvert_new[i].flag & ME_VERT_TMP_TAG) {
+				int *doubles_map = &full_doubles_map[totvert + i] ;
+				for (uint step = 1; step < step_tot; step += 1) {
+					*doubles_map = (int)i;
+					doubles_map += totvert;
+				}
+				tot_doubles_left -= 1;
+				if (tot_doubles_left == 0) {
+					break;
+				}
+			}
+		}
+		result = CDDM_merge_verts(result, full_doubles_map, (int)(tot_doubles * (step_tot - 1)), CDDM_MERGE_VERTS_DUMP_IF_MAPPED);
+		MEM_freeN(full_doubles_map);
+	}
+	return result;
+}
 
 static void initData(ModifierData *md)
 {
@@ -123,6 +173,7 @@ static void initData(ModifierData *md)
 	ltmd->steps = 16;
 	ltmd->render_steps = 16;
 	ltmd->iter = 1;
+	ltmd->merge_dist = 0.01f;
 }
 
 static void copyData(ModifierData *md, ModifierData *target)
@@ -1050,6 +1101,16 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 		MEM_freeN(vert_loop_map);
 	}
 
+	if ((ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f)) {
+		DerivedMesh *result_prev = result;
+		result = dm_remove_doubles_on_axis(
+		        result, mvert_new, totvert, step_tot,
+		        axis_vec, ltmd->ob_axis ? mtx_tx[3] : NULL, ltmd->merge_dist);
+		if (result != result_prev) {
+			result->dirty |= DM_DIRTY_NORMALS;
+		}
+	}
+
 	if ((ltmd->flag & MOD_SCREW_NORMAL_CALC) == 0) {
 		result->dirty |= DM_DIRTY_NORMALS;
 	}



More information about the Bf-blender-cvs mailing list