[Bf-blender-cvs] [1212bed] wiggly-widgets: Rework workflow for connecting Face Maps and bones

Julian Eisel noreply at git.blender.org
Sun Nov 8 18:04:33 CET 2015


Commit: 1212bedfa4bdd8f34d9523facd9fdc6fc7408316
Author: Julian Eisel
Date:   Sun Nov 8 16:25:28 2015 +0100
Branches: wiggly-widgets
https://developer.blender.org/rB1212bedfa4bdd8f34d9523facd9fdc6fc7408316

Rework workflow for connecting Face Maps and bones

Previously, a Face Map was 'connected to a bone' by giving it the same name as the Face Map, and assigning the armature which includes the bone to the object's Face Map using an Armature modifier. This was pretty unintuitive and tiresome to set up and it also brought some technical issues (there was no nice way to find a Face Map assigned to a bone from the bone - this means we couldn't use Face Maps together with bones in pose mode as current design approach would require).

So finally I came up with a new approach:
The bone context in the Properties Editor got a new panel "Face Maps". In this panel there is a search button to choose an object. After an object is chosen, a Face Map from this object can be chosen using a second search button. That means a user can assign a Face Map to a bone directly, without having to worry about the armature.

This approach currently has the limitation that only one Face Map can be assigned to a bone (a Face Map can be used by multiple bones though). This means we can later use one Face Map to manipulate multiple bones, but we can't use multiple Face Maps to manipulate one bone.
Anyway, this could be changed easily later, but I'd rather avoid this since it complicates the UI/workflow again.

----

Old code is kept.
Also includes minor cleanup.

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

M	release/scripts/startup/bl_ui/properties_data_bone.py
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/makesdna/DNA_action_types.h
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_pose.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_bone.py b/release/scripts/startup/bl_ui/properties_data_bone.py
index 690c22c..724e495 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -193,6 +193,33 @@ class BONE_PT_relations(BoneButtonsPanel, Panel):
         sub.prop(bone, "use_local_location")
 
 
+class BONE_PT_facemaps(BoneButtonsPanel, Panel):
+    bl_label = "Face Maps"
+
+    @classmethod
+    def poll(cls, context):
+        return context.object and context.bone
+
+    def draw(self, context):
+        layout = self.layout
+
+        ob = context.object
+        bone = context.bone
+        pchan = ob.pose.bones[bone.name]
+
+        col = layout.column()
+        col.prop(pchan, "facemap_object", text="Object")
+
+        col = layout.column()
+        if pchan.facemap_object:
+            col.prop_search(pchan, "facemap", pchan.facemap_object, "face_maps")
+        else:
+            # ugly, used to add inactive search field since prop_search
+            # doesn't support passing pchan.facemap_object if it's unset
+            col.enabled = False
+            col.prop(pchan, "facemap")
+
+
 class BONE_PT_display(BoneButtonsPanel, Panel):
     bl_label = "Display"
 
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index a26552b..bdf246c 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -902,10 +902,24 @@ static void WIDGETGROUP_shapekey_draw(const struct bContext *C, struct wmWidgetG
 }
 #endif
 
+/* draw facemaps depending on the selected bone in pose mode */
+#define USE_FACEMAP_FROM_BONE
+
 static int WIDGETGROUP_armature_facemap_poll(const struct bContext *C, struct wmWidgetGroupType *UNUSED(wgrouptype))
 {
 	Object *ob = CTX_data_active_object(C);
 
+#ifdef USE_FACEMAP_FROM_BONE
+	if (ob && BKE_object_pose_context_check(ob)) {
+		bPoseChannel *pchan;
+		for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+			if (pchan->fmap) {
+				BLI_assert(pchan->fmap_object);
+				return true;
+			}
+		}
+	}
+#else
 	if (ob && ob->type == OB_MESH && ob->fmaps.first) {
 		ModifierData *md;
 		VirtualModifierData virtualModifierData;
@@ -914,13 +928,17 @@ static int WIDGETGROUP_armature_facemap_poll(const struct bContext *C, struct wm
 	
 		/* exception for shape keys because we can edit those */
 		for (; md; md = md->next) {
-			if (modifier_isEnabled(CTX_data_scene(C), md, eModifierMode_Realtime) && md->type == eModifierType_Armature) {
+			if (modifier_isEnabled(CTX_data_scene(C), md, eModifierMode_Realtime) &&
+			    md->type == eModifierType_Armature)
+			{
 				ArmatureModifierData *amd = (ArmatureModifierData *) md;
 				if (amd->object && (amd->deformflag & ARM_DEF_FACEMAPS))
 					return true;
-				}
 			}
+		}
 	}
+#endif
+
 	return false;
 }
 
@@ -928,16 +946,40 @@ static void WIDGETGROUP_armature_facemap_create(const struct bContext *C, struct
 {
 	Object *ob = CTX_data_active_object(C);
 	wmWidget *widget;
-	Object *armature;
 	PointerRNA famapptr;
 	PropertyRNA *prop;
+
+	const float color_shape[4] = {1.0f, 0.3f, 0.0f, 1.0f};
+
+
+#ifdef USE_FACEMAP_FROM_BONE
+	bPoseChannel *pchan;
+
+	for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+		if (pchan->fmap) {
+			Object *fmap_ob = pchan->fmap_object;
+			bFaceMap *fmap = pchan->fmap;
+			PointerRNA *opptr;
+
+			widget = WIDGET_facemap_new(wgroup, fmap->name, 0, fmap_ob, BLI_findindex(&fmap_ob->fmaps, fmap));
+
+			RNA_pointer_create(&fmap_ob->id, &RNA_FaceMap, fmap, &famapptr);
+			WM_widget_set_property(widget, FACEMAP_SLOT_FACEMAP, &famapptr, "name");
+			WM_widget_set_colors(widget, color_shape, color_shape);
+			WM_widget_set_flag(widget, WM_WIDGET_DRAW_HOVER, true);
+			opptr = WM_widget_set_operator(widget, "TRANSFORM_OT_translate");
+			if ((prop = RNA_struct_find_property(opptr, "release_confirm"))) {
+				RNA_property_boolean_set(opptr, prop, true);
+			}
+		}
+	}
+#else
+	Object *armature;
 	ModifierData *md;
 	VirtualModifierData virtualModifierData;
 	int index = 0;
 	bFaceMap *fmap = ob->fmaps.first;
 
-	const float color_shape[4] = {1.0f, 0.3f, 0.0f, 1.0f};
-
 
 	md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
 	
@@ -969,6 +1011,7 @@ static void WIDGETGROUP_armature_facemap_create(const struct bContext *C, struct
 			}
 		}
 	}
+#endif
 }
 
 
diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h
index d574694..a18d9c9 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -205,6 +205,9 @@ typedef struct bPoseChannel {
 	struct bPoseChannel *parent;    /* set on read file or rebuild pose */
 	struct bPoseChannel *child;     /* set on read file or rebuild pose, the 'ik' child, for b-bones */
 
+	struct Object *fmap_object;     /* object from which facemap can be chosen */
+	struct bFaceMap *fmap;          /* facemap from fmap_object, used to manipulate bone */
+
 	struct ListBase iktree;         /* "IK trees" - only while evaluating pose */
 	struct ListBase siktree;        /* Spline-IK "trees" - only while evaluating pose */
 
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index 5ae82b9..ecbafbd 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -69,7 +69,7 @@ typedef struct bDeformGroup {
 /* Face Maps*/
 typedef struct bFaceMap {
 	struct bFaceMap *next, *prev;
-	char name[64];	/* MAX_VGROUP_NAME */
+	char name[64];  /* MAX_VGROUP_NAME */
 } bFaceMap;
 
 
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index 27ff0a6..22dbb2e 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -822,6 +822,21 @@ static void rna_def_pose_channel(BlenderRNA *brna)
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Child", "Child of this pose bone");
 	
+	prop = RNA_def_property(srna, "facemap_object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "fmap_object");
+	RNA_def_property_struct_type(prop, "Object");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Face Map Object", "Object from which a face map can be chosen to"
+	                         "manipulate this bone");
+	RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
+	RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_update");
+	
+	prop = RNA_def_property(srna, "facemap", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "fmap");
+	RNA_def_property_struct_type(prop, "FaceMap");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Face Map", "Use a face map of the custom object to manipulate this bone");
+	
 	/* Transformation settings */
 	prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
 	RNA_def_property_float_sdna(prop, NULL, "loc");




More information about the Bf-blender-cvs mailing list