[Bf-blender-cvs] [7ca0894] surface-deform-modifier: Implement target poly influence interpolation

Luca Rood noreply at git.blender.org
Tue Jan 3 22:54:29 CET 2017


Commit: 7ca0894a1719c9a04e8c1d8aec84c2e75ecfc6fa
Author: Luca Rood
Date:   Sat Dec 10 03:45:41 2016 -0200
Branches: surface-deform-modifier
https://developer.blender.org/rB7ca0894a1719c9a04e8c1d8aec84c2e75ecfc6fa

Implement target poly influence interpolation

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

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_surfacedeform.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 8f1492e..74227ce 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -948,13 +948,21 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         layout.label(text="Settings are inside the Physics tab")
 
     def SURFACE_DEFORM(self, layout, ob, md):
-        layout.prop(md, "target")
+        col = layout.column()
+        col.enabled = not md.is_bound
+
+        col.prop(md, "target")
+        col.prop(md, "falloff")
 
         layout.separator()
+
+        col = layout.column()
+        col.enabled = bool(md.target)
+
         if md.is_bound:
-            layout.operator("object.surfacedeform_bind", text="Unbind")
+            col.operator("object.surfacedeform_bind", text="Unbind")
         else:
-            layout.operator("object.surfacedeform_bind", text="Bind")
+            col.operator("object.surfacedeform_bind", text="Bind")
 
     def UV_PROJECT(self, layout, ob, md):
         split = layout.split()
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 76f0557..5be3dca 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5304,17 +5304,32 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 		}
 		else if (md->type == eModifierType_SurfaceDeform) {
 			SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
-			int i;
+			int i, j;
 
 			smd->verts = newdataadr(fd, smd->verts);
 
 			if (smd->verts) {
 				for (i = 0; i < smd->numverts; i++) {
-					smd->verts[i].vert_inds = newdataadr(fd, smd->verts[i].vert_inds);
-					smd->verts[i].vert_weights = newdataadr(fd, smd->verts[i].vert_weights);
-					if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
-						if (smd->verts[i].vert_inds)  BLI_endian_switch_int32_array(smd->verts[i].vert_inds, smd->verts[i].numverts);
-						if (smd->verts[i].vert_weights)  BLI_endian_switch_float_array(smd->verts[i].vert_weights, smd->verts[i].numverts);
+					smd->verts[i].binds = newdataadr(fd, smd->verts[i].binds);
+
+					if (smd->verts[i].binds) {
+						for (j = 0; j < smd->verts[i].numbinds; j++) {
+							smd->verts[i].binds[j].vert_inds = newdataadr(fd, smd->verts[i].binds[j].vert_inds);
+							smd->verts[i].binds[j].vert_weights = newdataadr(fd, smd->verts[i].binds[j].vert_weights);
+
+							if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
+								if (smd->verts[i].binds[j].vert_inds)
+									BLI_endian_switch_int32_array(smd->verts[i].binds[j].vert_inds, smd->verts[i].binds[j].numverts);
+
+								if (smd->verts[i].binds[j].vert_weights) {
+									if (smd->verts[i].binds[j].mode == MOD_SDEF_MODE_CENTROID ||
+									    smd->verts[i].binds[j].mode == MOD_SDEF_MODE_LOOPTRI)
+										BLI_endian_switch_float_array(smd->verts[i].binds[j].vert_weights, 3);
+									else
+										BLI_endian_switch_float_array(smd->verts[i].binds[j].vert_weights, smd->verts[i].binds[j].numverts);
+								}
+							}
+						}
 					}
 				}
 			}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 7d638cd..86a7a5a 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1832,18 +1832,25 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 		}
 		else if (md->type == eModifierType_SurfaceDeform) {
 			SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
-			int i;
+			int i, j;
 
 			writestruct(wd, DATA, SDefVert, smd->numverts, smd->verts);
 
 			if (smd->verts) {
 				for (i = 0; i < smd->numverts; i++) {
-					writedata(wd, DATA, sizeof(int) * smd->verts[i].numverts, smd->verts[i].vert_inds);
+					writestruct(wd, DATA, SDefBind, smd->verts[i].numbinds, smd->verts[i].binds);
 
-					if (smd->verts[i].mode == MOD_SDEF_MODE_CENTROID)
-						writedata(wd, DATA, sizeof(float) * 3, smd->verts[i].vert_weights);
-					else
-						writedata(wd, DATA, sizeof(float) * smd->verts[i].numverts, smd->verts[i].vert_weights);
+					if (smd->verts[i].binds) {
+						for (j = 0; j < smd->verts[i].numbinds; j++) {
+							writedata(wd, DATA, sizeof(int) * smd->verts[i].binds[j].numverts, smd->verts[i].binds[j].vert_inds);
+
+							if (smd->verts[i].binds[j].mode == MOD_SDEF_MODE_CENTROID ||
+							    smd->verts[i].binds[j].mode == MOD_SDEF_MODE_LOOPTRI)
+								writedata(wd, DATA, sizeof(float) * 3, smd->verts[i].binds[j].vert_weights);
+							else
+								writedata(wd, DATA, sizeof(float) * smd->verts[i].binds[j].numverts, smd->verts[i].binds[j].vert_weights);
+						}
+					}
 				}
 			}
 		}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 6e4c172..22303a8 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1571,23 +1571,29 @@ enum {
 	MOD_MESHSEQ_READ_COLOR = (1 << 3),
 };
 
+typedef struct SDefBind {
+	int *vert_inds;
+	int numverts;
+	int mode;
+	float *vert_weights;
+	float normal_dist;
+	float influence;
+} SDefBind;
+
 typedef struct SDefVert {
-    int *vert_inds;
-    int numverts;
-    int mode;
-    float *vert_weights;
-    float normal_dist;
-    char pad[4];
+	SDefBind *binds;
+	int numbinds;
+	char pad[4];
 } SDefVert;
 
 typedef struct SurfaceDeformModifierData {
-    ModifierData modifier;
+	ModifierData modifier;
 
 	struct Object *target;	/* bind target object */
 	SDefVert *verts;		/* vertex bind data */
+	float falloff;
 	int numverts, numpoly;
 	int flags;
-	char pad[4];
 } SurfaceDeformModifierData;
 
 /* Surface Deform modifier flags */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index c761316..363e91e 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4726,6 +4726,11 @@ static void rna_def_modifier_surfacedeform(BlenderRNA *brna)
 	RNA_def_property_pointer_funcs(prop, NULL, "rna_SurfaceDeformModifier_target_set", NULL, "rna_Mesh_object_poll");
 	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
 	RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
+	
+	prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_range(prop, 2.0f, 16.0f);
+	RNA_def_property_ui_text(prop, "Interpolation falloff", "Controls how much nearby polygons influence deformation");
+	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
 	prop = RNA_def_property(srna, "is_bound", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_funcs(prop, "rna_SurfaceDeformModifier_is_bound_get", NULL);
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c
index 121ef77..ea5e28f 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -17,22 +17,68 @@
 
 #include "MOD_util.h"
 
+typedef struct SDefAdjacency {
+	struct SDefAdjacency *next;
+	int index;
+} SDefAdjacency;
+
+typedef struct SDefEdgePolys {
+	int polys[2], num;
+} SDefEdgePolys;
+
 typedef struct SDefBindCalcData {
-	BVHTreeFromMesh *treeData;
-	MPoly *mpoly;
-	MLoop *mloop;
-	MLoopTri *looptri;
-	MVert *mvert;
-	SDefVert *verts;
-	float (*vertexCos)[3];
+	BVHTreeFromMesh * const treeData;
+	SDefAdjacency ** const vert_edges;
+	SDefEdgePolys * const edge_polys;
+	SDefVert * const bind_verts;
+	const MLoopTri * const looptri;
+	MPoly * const mpoly;
+	MEdge * const medge;
+	MLoop * const mloop;
+	MVert * const mvert;
+	float (* const vertexCos)[3];
+	const float falloff;
+	int success;
 } SDefBindCalcData;
 
+typedef struct SDefBindPoly {
+	struct SDefBindPoly *next;
+	float (*coords)[3];
+	float (*coords_v2)[2];
+	float point_v2[2];
+	float weight_components[3]; /* indices: 0 = angular weight; 1 = projected point weight; 2 = actual point weights; */
+	float weight;
+	float scales[2];
+	float centroid[3];
+	float centroid_v2[2];
+	float normal[3];
+	float cent_edgemid_vecs_v2[2][2];
+	float edgemid_angle;
+	float point_edgemid_angles[2];
+	float corner_edgemid_angles[2];
+	float dominant_angle_weight;
+	int index;
+	int numverts;
+	int loopstart;
+	int edge_inds[2];
+	int edge_vert_inds[2];
+	int corner_ind;
+	int dominant_edge;
+	bool inside;
+} SDefBindPoly;
+
+typedef struct SDefBindWeightData {
+	SDefBindPoly *bind_polys;
+	int numbinds;
+} SDefBindWeightData;
+
 static void initData(ModifierData *md)
 {
 	SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *) md;
-	smd->target	= NULL;
-	smd->verts	= NULL;
-	smd->flags  = 0;
+	smd->target	 = NULL;
+	smd->verts	 = NULL;
+	smd->flags   = 0;
+	smd->falloff = 4.0f;
 }
 
 static void freeData(ModifierData *md)
@@ -40,16 +86,25 @@ static void freeData(ModifierData *md)
 	SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *) md;
 
 	if (smd->verts) {
-		int i;
+		int i, j;
 		for (i = 0; i < smd->numverts; i++) {
-			if (smd->verts[i].vert_inds)
-				MEM_freeN(smd->verts[i].vert_inds);
+			if (smd->verts[i].binds) {
+				for (j = 0; j < smd->verts[i].numbinds; j++) {
+					if (smd->verts[i].binds[j].vert_inds) {
+						MEM_freeN(smd->verts[i].binds[j].vert_inds);
+					}
+
+					if (smd->verts[i].binds[j].vert_weights) {
+						MEM_freeN(smd->verts[i].binds[j].vert_weights);
+					}
+				}
 
-			if (smd->verts[i].vert_weights)
-				MEM_freeN(smd->verts[i].vert_weights);
+				MEM_freeN(smd->verts[i].binds);
+			}
 		}
 
 		MEM_freeN(smd->verts);
+		smd->verts = NULL;
 	}
 }
 
@@ -61,16 +116,24 @@ static void copyData(ModifierData *md, ModifierData *target)
 	*tsmd = *smd;
 
 	if (smd->verts) {
-		int i;
+		int i, j;
 
 		tsmd->verts = MEM_dupallocN(smd->verts);
 
 		for (i = 0; i < smd->numverts; i++) {
-			if (smd->verts[i].vert_inds)
-				tsmd->verts[i].vert_inds = MEM_dupallocN(smd->verts[i].vert_inds);
+			if (smd->verts[i].binds) {
+				tsmd->verts[i].binds = MEM_dupallocN(smd->verts[i].binds);
 
-			if (smd->verts[i].vert_weights)
-				tsmd->verts[i].vert_weights = MEM_dupallocN(sm

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list