[Bf-blender-cvs] [f746ab9] temp-modifier-deltamush-experimental: Add option to use orco as rest source

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


Commit: f746ab95d818a06c51d0ece283fd02a82e3583e1
Author: Campbell Barton
Date:   Tue Mar 31 05:19:49 2015 +1100
Branches: temp-modifier-deltamush-experimental
https://developer.blender.org/rBf746ab95d818a06c51d0ece283fd02a82e3583e1

Add option to use orco as rest source

No need to store bind coords in the modifier.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.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/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 9dc006a..490c1af 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1401,11 +1401,13 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         row.prop(md, "use_pin_boundary")
 
         layout.label(text="Vertex Group:")
-        sub = layout.row(align=True)
-        sub.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
-        sub.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
+        row = layout.row(align=True)
+        row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+        row.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
 
-        layout.operator("object.correctivesmooth_bind", text="Unbind" if is_bind else "Bind")
+        layout.prop(md, "rest_source")
+        if md.rest_source == 'BIND':
+            layout.operator("object.correctivesmooth_bind", text="Unbind" if is_bind else "Bind")
 
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 52b2c5f..304e5aa 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4952,14 +4952,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 		else if (md->type == eModifierType_CorrectiveSmooth) {
 			CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData*)md;
 
-			if (csmd->positions) {
-				csmd->positions = newdataadr(fd, csmd->positions);
+			if (csmd->bind_coords) {
+				csmd->bind_coords = newdataadr(fd, csmd->bind_coords);
 				if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
-					BLI_endian_switch_float_array((float *)csmd->positions, csmd->positions_num * 3);
+					BLI_endian_switch_float_array((float *)csmd->bind_coords, csmd->bind_coords_num * 3);
 				}
 			}
 
-			csmd->positions_delta_cache = NULL;
+			/* runtime only */
+			csmd->delta_cache = NULL;
 		}
 	}
 }
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 298e5bd..2baff43 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1623,8 +1623,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 		else if (md->type == eModifierType_CorrectiveSmooth) {
 			CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
 
-			if (csmd->positions) {
-				writedata(wd, DATA, sizeof(float[3]) * csmd->positions_num, csmd->positions);
+			if (csmd->bind_coords) {
+				writedata(wd, DATA, sizeof(float[3]) * csmd->bind_coords_num, csmd->bind_coords);
 			}
 		}
 	}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index f5edb55..b64fb7c 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1293,19 +1293,21 @@ enum {
 typedef struct CorrectiveSmoothModifierData {
 	ModifierData modifier;
 
-	/* positions set during 'bind' operator */
-	float (*positions)[3];
-	unsigned int positions_num;
+	/* positions set during 'bind' operator
+	 * use for MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND */
+	float (*bind_coords)[3];
+	unsigned int bind_coords_num;
 
 	float lambda;
 	short repeat, flag;
-	char smooth_type, pad[3];
+	char smooth_type, rest_source;
+	char pad[2];
 
 	char defgrp_name[64];  /* MAX_VGROUP_NAME */
 
 	/* runtime-only cache (delta's between),
 	 * delta's between the original positions and the smoothed positions */
-	float (*positions_delta_cache)[3];
+	float (*delta_cache)[3];
 } CorrectiveSmoothModifierData;
 
 enum {
@@ -1313,6 +1315,11 @@ enum {
 	MOD_CORRECTIVESMOOTH_SMOOTH_EDGE_WEIGHT    = 1,
 };
 
+enum {
+	MOD_CORRECTIVESMOOTH_RESTSOURCE_BASE       = 0,
+	MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND       = 1,
+};
+
 /* Corrective Smooth modifier flags */
 enum {
 	MOD_CORRECTIVESMOOTH_INVERT_VGROUP         = (1 << 0),
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index c753d0b..e327d45 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1038,16 +1038,26 @@ static EnumPropertyItem *rna_DataTransferModifier_mix_mode_itemf(bContext *C, Po
 	return item;
 }
 
-
 static void rna_CorrectiveSmoothModifier_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
-	CorrectiveSmoothModifierData *dmmd = (CorrectiveSmoothModifierData *)ptr->data;
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)ptr->data;
 
-	MEM_SAFE_FREE(dmmd->positions_delta_cache);
+	MEM_SAFE_FREE(csmd->delta_cache);
 
 	rna_Modifier_update(bmain, scene, ptr);
 }
 
+static void rna_CorrectiveSmoothModifier_rest_source_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)ptr->data;
+
+	if (csmd->rest_source != MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND) {
+		MEM_SAFE_FREE(csmd->bind_coords);
+	}
+
+	rna_CorrectiveSmoothModifier_update(bmain, scene, ptr);
+}
+
 #else
 
 static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const char type[])
@@ -2139,6 +2149,14 @@ static void rna_def_modifier_correctivesmooth(BlenderRNA *brna)
 		{0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem modifier_rest_source_items[] = {
+		{MOD_CORRECTIVESMOOTH_RESTSOURCE_BASE, "BASE", 0, "Base Coords",
+		 "Use base mesh vert coords as the rest position"},
+		{MOD_CORRECTIVESMOOTH_RESTSOURCE_BIND, "BIND", 0, "Bind Coords",
+		 "Use bind vert coords for rest position"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "CorrectiveSmoothModifier", "Modifier");
 	RNA_def_struct_ui_text(srna, "Corrective Smooth Modifier", "Correct distortion caused by deformation");
 	RNA_def_struct_sdna(srna, "CorrectiveSmoothModifierData");
@@ -2157,6 +2175,12 @@ static void rna_def_modifier_correctivesmooth(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "Repeat", "");
 	RNA_def_property_update(prop, 0, "rna_CorrectiveSmoothModifier_update");
 
+	prop = RNA_def_property(srna, "rest_source", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "rest_source");
+	RNA_def_property_enum_items(prop, modifier_rest_source_items);
+	RNA_def_property_ui_text(prop, "Rest Source", "Select the source of rest positions");
+	RNA_def_property_update(prop, 0, "rna_CorrectiveSmoothModifier_rest_source_update");
+
 	prop = RNA_def_property(srna, "smooth_type", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "smooth_type");
 	RNA_def_property_enum_items(prop, modifier_smooth_type_items);
diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index 409f1f8..cdb759e 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -27,6 +27,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
@@ -54,57 +55,57 @@
 
 static void initData(ModifierData *md)
 {
-	CorrectiveSmoothModifierData *dmmd = (CorrectiveSmoothModifierData *)md;
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
 
-	dmmd->positions = NULL;
-	dmmd->positions_num = 0;
+	csmd->bind_coords = NULL;
+	csmd->bind_coords_num = 0;
 
-	dmmd->lambda = 0.5f;
-	dmmd->repeat = 5;
-	dmmd->flag = 0;
-	dmmd->smooth_type = MOD_CORRECTIVESMOOTH_SMOOTH_SIMPLE;
+	csmd->lambda = 0.5f;
+	csmd->repeat = 5;
+	csmd->flag = 0;
+	csmd->smooth_type = MOD_CORRECTIVESMOOTH_SMOOTH_SIMPLE;
 
-	dmmd->defgrp_name[0] = '\0';
+	csmd->defgrp_name[0] = '\0';
 
-	dmmd->positions_delta_cache = NULL;
+	csmd->delta_cache = NULL;
 }
 
 
 static void copyData(ModifierData *md, ModifierData *target)
 {
-	CorrectiveSmoothModifierData *dmmd = (CorrectiveSmoothModifierData *)md;
-	CorrectiveSmoothModifierData *t_dmmd = (CorrectiveSmoothModifierData *)target;
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
+	CorrectiveSmoothModifierData *tcsmd = (CorrectiveSmoothModifierData *)target;
 
 	modifier_copyData_generic(md, target);
 
-	if (dmmd->positions) {
-		t_dmmd->positions = MEM_dupallocN(dmmd->positions);
+	if (csmd->bind_coords) {
+		tcsmd->bind_coords = MEM_dupallocN(csmd->bind_coords);
 	}
 }
 
 
-static void freeBind(CorrectiveSmoothModifierData *dmmd)
+static void freeBind(CorrectiveSmoothModifierData *csmd)
 {
-	MEM_SAFE_FREE(dmmd->positions);
-	MEM_SAFE_FREE(dmmd->positions_delta_cache);
+	MEM_SAFE_FREE(csmd->bind_coords);
+	MEM_SAFE_FREE(csmd->delta_cache);
 
-	dmmd->positions_num = 0;
+	csmd->bind_coords_num = 0;
 }
 
 
 static void freeData(ModifierData *md)
 {
-	CorrectiveSmoothModifierData *dmmd = (CorrectiveSmoothModifierData *)md;
-	freeBind(dmmd);
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
+	freeBind(csmd);
 }
 
 
 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
 {
-	CorrectiveSmoothModifierData *dmmd = (CorrectiveSmoothModifierData *)md;
+	CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md;
 	CustomDataMask dataMask = 0;
 	/* ask for vertex groups if we need them */
-	if (dmmd->defgrp_name[0]) {
+	if (csmd->defgrp_name[0]) {
 		dataMask |= CD_MASK_MDEFORMVERT;
 	}
 	return dataMask;
@@ -171,12 +172,12 @@ static void dm_get_boundaries(DerivedMesh *dm, float *smooth_weights)
  */
 
 static void smooth_iter__simple(
-        CorrectiveSmoothModifierData *dmmd, DerivedMesh *dm,
-        float(*vertexCos)[3], unsigned int numVerts,
+        CorrectiveSmoothModifierData *csmd, DerivedMesh *dm,
+        float (*vertexCos)[3], unsigned int numVerts,
         const float *smooth_weights,
         unsigned int iterations)
 {
-	const float lambda = dmmd->lambda;
+	const float lambda = csmd->lambda;
 	unsigned int i;
 
 	const unsigned int numEdges = (unsigned int)dm->getNumEdges(dm);
@@ -256,14 +257,14 @@ static void smoot

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list