[Bf-blender-cvs] [b9b13f8] temp-modifier-deltamush-experimental: Change bind logic

Campbell Barton noreply at git.blender.org
Mon Mar 30 21:08:43 CEST 2015


Commit: b9b13f825d1f0807e03d3824098fde30547642b5
Author: Campbell Barton
Date:   Tue Mar 31 06:08:07 2015 +1100
Branches: temp-modifier-deltamush-experimental
https://developer.blender.org/rBb9b13f825d1f0807e03d3824098fde30547642b5

Change bind logic

remove bind flag, bind state now just uses NULL check

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

M	source/blender/editors/object/object_modifier.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_correctivesmooth.c

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

diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index aee2aac..c4491fe 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -1824,14 +1824,34 @@ static int correctivesmooth_poll(bContext *C)
 
 static int correctivesmooth_bind_exec(bContext *C, wmOperator *op)
 {
+	Scene *scene = CTX_data_scene(C);
 	Object *ob = ED_object_active_context(C);
-	CorrectiveSmoothModifierData *mmd = (CorrectiveSmoothModifierData *)edit_modifier_property_get(op, ob, eModifierType_CorrectiveSmooth);
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)edit_modifier_property_get(op, ob, eModifierType_CorrectiveSmooth);
+	bool is_bind;
 
-	if (!mmd) {
+	if (!csmd) {
 		return OPERATOR_CANCELLED;
 	}
 
-	mmd->flag ^= MOD_CORRECTIVESMOOTH_BIND;
+	if (!modifier_isEnabled(scene, &csmd->modifier, eModifierMode_Realtime)) {
+		BKE_report(op->reports, RPT_ERROR, "Modifier is disabled");
+		return OPERATOR_CANCELLED;
+	}
+
+	is_bind = (csmd->bind_coords != NULL);
+
+	MEM_SAFE_FREE(csmd->bind_coords);
+	MEM_SAFE_FREE(csmd->delta_cache);
+
+	if (is_bind) {
+		/* toggle off */
+		csmd->bind_coords_num = 0;
+	}
+	else {
+		/* signam to modifier to recalculate */
+		csmd->bind_coords_num = (unsigned int)-1;
+	}
+
 	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
 
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index b64fb7c..45d3681 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1296,6 +1296,8 @@ typedef struct CorrectiveSmoothModifierData {
 	/* positions set during 'bind' operator
 	 * use for MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND */
 	float (*bind_coords)[3];
+
+	/* note: -1 is used to bind */
 	unsigned int bind_coords_num;
 
 	float lambda;
@@ -1323,9 +1325,8 @@ enum {
 /* Corrective Smooth modifier flags */
 enum {
 	MOD_CORRECTIVESMOOTH_INVERT_VGROUP         = (1 << 0),
-	MOD_CORRECTIVESMOOTH_BIND                  = (1 << 1),
-	MOD_CORRECTIVESMOOTH_ONLY_SMOOTH           = (1 << 2),
-	MOD_CORRECTIVESMOOTH_PIN_BOUNDARY          = (1 << 3),
+	MOD_CORRECTIVESMOOTH_ONLY_SMOOTH           = (1 << 1),
+	MOD_CORRECTIVESMOOTH_PIN_BOUNDARY          = (1 << 2),
 };
 
 typedef struct UVWarpModifierData {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index e327d45..f9ca491 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1053,11 +1053,18 @@ static void rna_CorrectiveSmoothModifier_rest_source_update(Main *bmain, Scene *
 
 	if (csmd->rest_source != MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) {
 		MEM_SAFE_FREE(csmd->bind_coords);
+		csmd->bind_coords_num = 0;
 	}
 
 	rna_CorrectiveSmoothModifier_update(bmain, scene, ptr);
 }
 
+static int rna_CorrectiveSmoothModifier_is_bind_get(PointerRNA *ptr)
+{
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)ptr->data;
+	return (csmd->bind_coords != NULL);
+}
+
 #else
 
 static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const char type[])
@@ -2200,8 +2207,8 @@ static void rna_def_modifier_correctivesmooth(BlenderRNA *brna)
 	RNA_def_property_update(prop, 0, "rna_CorrectiveSmoothModifier_update");
 
 	prop = RNA_def_property(srna, "is_bind", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_CORRECTIVESMOOTH_BIND);
 	RNA_def_property_ui_text(prop, "Bind current shape", "");
+	RNA_def_property_boolean_funcs(prop, "rna_CorrectiveSmoothModifier_is_bind_get", NULL);
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index cdb759e..90f107b 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -558,32 +558,28 @@ static void correctivesmooth_modifier_do(
         float (*vertexCos)[3], unsigned int numVerts)
 {
 	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
-	const bool use_bind = (csmd->flag & MOD_CORRECTIVESMOOTH_BIND) != 0;
-	const bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH)  != 0;
+	bool use_only_smooth = (csmd->flag & MOD_CORRECTIVESMOOTH_ONLY_SMOOTH) != 0;
 	MDeformVert *dvert = NULL;
 	int defgrp_index;
 
 	modifier_get_vgroup(ob, dm, csmd->defgrp_name, &dvert, &defgrp_index);
 
-	if (UNLIKELY((use_bind == false && (csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND)) ||
-	             (use_only_smooth == true)))
+	/* if rest bind_coords not are defined, set them (only run during bind) */
+	if ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) &&
+	    /* signal to recalculate, whoever sets MUST also free bind coords */
+	    (csmd->bind_coords_num == (unsigned int)-1))
 	{
-		if ((use_bind == false) && (csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND)) {
-			freeBind(csmd);
-		}
-		smooth_verts(csmd, dm, dvert, defgrp_index, vertexCos, numVerts);
-		return;
+		BLI_assert(csmd->bind_coords == NULL);
+		csmd->bind_coords = MEM_dupallocN(vertexCos);
+		csmd->bind_coords_num = numVerts;
+		BLI_assert(csmd->bind_coords != NULL);
 	}
 
-	/* if rest bind_coords not are defined, set them (only run during bind) */
-	if (csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) {
-		if (!csmd->bind_coords) {
-			csmd->bind_coords = MEM_dupallocN(vertexCos);
-			csmd->bind_coords_num = numVerts;
-			if (!csmd->bind_coords) {
-				return;
-			}
-		}
+	if (UNLIKELY(use_only_smooth ||
+	             ((csmd->rest_source == MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) && (csmd->bind_coords == NULL))))
+	{
+		smooth_verts(csmd, dm, dvert, defgrp_index, vertexCos, numVerts);
+		return;
 	}
 
 	/* If the number of verts has changed, the bind is invalid, so we do nothing */




More information about the Bf-blender-cvs mailing list