[Bf-blender-cvs] [673bd9a] master: Mesh Modifiers: Added Laplacian Deform

Alexander Pinzon noreply at git.blender.org
Sat Nov 23 21:11:03 CET 2013


Commit: 673bd9a009062807c16cc31a263018737c148a96
Author: Alexander Pinzon
Date:   Sun Nov 24 07:00:49 2013 +1100
http://developer.blender.org/rB673bd9a009062807c16cc31a263018737c148a96

Mesh Modifiers: Added Laplacian Deform

Part of soc-2013-sketch_mesh branch

See: http://wiki.blender.org/index.php/User:Apinzonf/Doc:2.6/Manual/Modifiers/Deform/Laplacian_Deform

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

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/editors/object/object_intern.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_ops.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
A	source/blender/modifiers/intern/MOD_laplaciandeform.c
M	source/blender/modifiers/intern/MOD_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 2883300..7e89224 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -373,6 +373,25 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             row.operator("object.hook_select", text="Select")
             row.operator("object.hook_assign", text="Assign")
 
+    def LAPLACIANDEFORM(self, layout, ob, md):
+        is_bind = md.is_bind
+
+        layout.prop(md, "iterations")
+
+        row = layout.row()
+        row.active = not is_bind
+        row.label(text="Anchors Vertex Group:")
+
+        row = layout.row()
+        row.enabled = not is_bind
+        row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+
+        layout.separator()
+
+        row = layout.row()
+        row.enabled = bool(md.vertex_group)
+        row.operator("object.laplaciandeform_bind", text="Unbind" if is_bind else "Bind")
+
     def LAPLACIANSMOOTH(self, layout, ob, md):
         layout.prop(md, "iterations")
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 3428e52..ad3b0df 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4825,6 +4825,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 			if (wmd->cmap_curve)
 				direct_link_curvemapping(fd, wmd->cmap_curve);
 		}
+		else if (md->type == eModifierType_LaplacianDeform) {
+			LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md;
+
+			lmd->vertexco = newdataadr(fd, lmd->vertexco);
+			if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
+				BLI_endian_switch_float_array(lmd->vertexco, lmd->total_verts * 3);
+			}
+			lmd->cache_system = NULL;
+		}
 	}
 }
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 1f417df..d985243 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1474,6 +1474,11 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
 			if (wmd->cmap_curve)
 				write_curvemapping(wd, wmd->cmap_curve);
 		}
+		else if(md->type==eModifierType_LaplacianDeform) {
+			LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData*) md;
+
+			writedata(wd, DATA, sizeof(float)*lmd->total_verts * 3, lmd->vertexco);
+		}
 	}
 }
 
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index bfed1f2..ce509e2 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -173,6 +173,7 @@ void OBJECT_OT_skin_root_mark(struct wmOperatorType *ot);
 void OBJECT_OT_skin_loose_mark_clear(struct wmOperatorType *ot);
 void OBJECT_OT_skin_radii_equalize(struct wmOperatorType *ot);
 void OBJECT_OT_skin_armature_create(struct wmOperatorType *ot);
+void OBJECT_OT_laplaciandeform_bind(struct wmOperatorType *ot);
 
 /* object_constraint.c */
 void OBJECT_OT_constraint_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 01dafe6..d4c6455 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2209,3 +2209,52 @@ void OBJECT_OT_ocean_bake(wmOperatorType *ot)
 	RNA_def_boolean(ot->srna, "free", FALSE, "Free", "Free the bake, rather than generating it");
 }
 
+/************************ LaplacianDeform bind operator *********************/
+
+static int laplaciandeform_poll(bContext *C)
+{
+	return edit_modifier_poll_generic(C, &RNA_LaplacianDeformModifier, 0);
+}
+
+static int laplaciandeform_bind_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = ED_object_active_context(C);
+	LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)edit_modifier_property_get(op, ob, eModifierType_LaplacianDeform);
+
+	if (!lmd)
+		return OPERATOR_CANCELLED;
+	if (lmd->flag & MOD_LAPLACIANDEFORM_BIND) {
+		lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND;
+	}
+	else {
+		lmd->flag |= MOD_LAPLACIANDEFORM_BIND;
+	}
+	DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+	WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
+	return OPERATOR_FINISHED;
+}
+
+static int laplaciandeform_bind_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+	if (edit_modifier_invoke_properties(C, op))
+		return laplaciandeform_bind_exec(C, op);
+	else 
+		return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_laplaciandeform_bind(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Laplacian Deform Bind";
+	ot->description = "Bind mesh to system in laplacian deform modifier";
+	ot->idname = "OBJECT_OT_laplaciandeform_bind";
+	
+	/* api callbacks */
+	ot->poll = laplaciandeform_poll;
+	ot->invoke = laplaciandeform_bind_invoke;
+	ot->exec = laplaciandeform_bind_exec;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+	edit_modifier_properties(ot);
+}
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index 6d760ac..74ac487 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -241,6 +241,7 @@ void ED_operatortypes_object(void)
 
 	WM_operatortype_append(OBJECT_OT_bake_image);
 	WM_operatortype_append(OBJECT_OT_drop_named_material);
+	WM_operatortype_append(OBJECT_OT_laplaciandeform_bind);
 }
 
 void ED_operatormacros_object(void)
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 5168c3c..ebaeb9c 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -965,6 +965,8 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
 						UI_icon_draw(x, y, ICON_MOD_TRIANGULATE); break;
 					case eModifierType_MeshCache:
 						UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;  /* XXX, needs own icon */
+					case eModifierType_LaplacianDeform:
+						UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;  /* XXX, needs own icon */
 					/* Default */
 					case eModifierType_None:
 					case eModifierType_ShapeKey:
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 11bdf70..8b2fde5 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -80,6 +80,7 @@ typedef enum ModifierType {
 	eModifierType_Triangulate       = 44,
 	eModifierType_UVWarp            = 45,
 	eModifierType_MeshCache         = 46,
+	eModifierType_LaplacianDeform   = 47,
 	NUM_MODIFIER_TYPES
 } ModifierType;
 
@@ -1295,4 +1296,20 @@ enum {
 };
 
 
+typedef struct LaplacianDeformModifierData {
+	ModifierData modifier;
+	char anchor_grp_name[64];  /* MAX_VGROUP_NAME */
+	int total_verts, repeat;
+	float *vertexco;
+	void *cache_system;  /* runtime only */
+	short flag, pad[3];
+
+} LaplacianDeformModifierData;
+
+/* Smooth modifier flags */
+enum {
+	MOD_LAPLACIANDEFORM_BIND = 1,
+};
+
+
 #endif  /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index d82bae1..5fa41c1 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -296,6 +296,7 @@ extern StructRNA RNA_KinematicConstraint;
 extern StructRNA RNA_Lamp;
 extern StructRNA RNA_LampSkySettings;
 extern StructRNA RNA_LampTextureSlot;
+extern StructRNA RNA_LaplacianDeformModifier;
 extern StructRNA RNA_LaplacianSmoothModifier;
 extern StructRNA RNA_Lattice;
 extern StructRNA RNA_LatticeModifier;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index eee7692..9df1896 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -87,6 +87,7 @@ EnumPropertyItem modifier_type_items[] = {
 	{eModifierType_Displace, "DISPLACE", ICON_MOD_DISPLACE, "Displace", ""},
 	{eModifierType_Hook, "HOOK", ICON_HOOK, "Hook", ""},
 	{eModifierType_LaplacianSmooth, "LAPLACIANSMOOTH", ICON_MOD_SMOOTH, "Laplacian Smooth", ""},
+	{eModifierType_LaplacianDeform, "LAPLACIANDEFORM", ICON_MOD_MESHDEFORM, "Laplacian Deform", ""},
 	{eModifierType_Lattice, "LATTICE", ICON_MOD_LATTICE, "Lattice", ""},
 	{eModifierType_MeshDeform, "MESH_DEFORM", ICON_MOD_MESHDEFORM, "Mesh Deform", ""},
 	{eModifierType_Shrinkwrap, "SHRINKWRAP", ICON_MOD_SHRINKWRAP, "Shrinkwrap", ""},
@@ -238,6 +239,8 @@ static StructRNA *rna_Modifier_refine(struct PointerRNA *ptr)
 			return &RNA_UVWarpModifier;
 		case eModifierType_MeshCache:
 			return &RNA_MeshCacheModifier;
+		case eModifierType_LaplacianDeform:
+			return &RNA_LaplacianDeformModifier;
 		/* Default */
 		case eModifierType_None:
 		case eModifierType_ShapeKey:
@@ -786,6 +789,18 @@ static void rna_UVWarpModifier_uvlayer_set(PointerRNA *ptr, const char *value)
 	rna_object_uvlayer_name_set(ptr, value, umd->uvlayer_name, sizeof(umd->uvlayer_name));
 }
 
+static void rna_LaplacianDeformModifier_vgroup_set(PointerRNA *ptr, const char *value)
+{
+	LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)ptr->data;
+	rna_object_vgroup_name_set(ptr, value, lmd->anchor_grp_name, sizeof(lmd->anchor_grp_name));
+}
+
+static int rna_LaplacianDeformModifier_is_bind_get(PointerRNA *ptr)
+{
+	LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)ptr->data;
+	return ((lmd->flag & MOD_LAPLACIANDEFORM_BIND) && (lmd->cache_system != NULL));
+}
+
 #else
 
 static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const char type[])
@@ -3681,6 +3696,36 @@ static void rna_def_modifier_meshcache(BlenderRNA *brna)
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
+static void rna_def_modifier_laplaciandeform(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	srna = RNA_def_struct(brna, "LaplacianDeformModifier", "Modifier");
+	RNA_def_struct_ui_text(srna, "Laplacian Deform Modifier", "Mesh deform modifier");
+	RNA_d

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list