[Bf-blender-cvs] [12a7eb6] BendyBones: Bendy Bones: Added ability to add custom reference prev/next bones for controlling handles

Joshua Leung noreply at git.blender.org
Tue May 17 16:40:53 CEST 2016


Commit: 12a7eb69c781b670ecffc7d207a9dacd12bc674c
Author: Joshua Leung
Date:   Mon May 16 23:56:46 2016 +1200
Branches: BendyBones
https://developer.blender.org/rB12a7eb69c781b670ecffc7d207a9dacd12bc674c

Bendy Bones: Added ability to add custom reference prev/next bones for controlling handles

This is an experimental option which makes it possible to specify which bone
to use as the reference handle for the previous/next bones, instead of only
using those that are directly connected on either end.

To use:
* Enable the "Use Custom Handle References" option in the Bendy Bones panel
* Set Start and/or End bones accordingly. If both are left blank, then the BBone
  will only respond to whatever offsets have been set by the animator
* Be careful when positioning the start/end bones! It will use the bone position
  as the point at which the handle currently sits - best results seem be when these
  bones are in line with the bbone to start with.

Why (according to @jpbouza):
When you have a very long chain of bbones, as they are all parented, when you rotate
the first bone in the chain (Y rotation, like twisting the chain), all the child
bones rotate. So the only way to avoid this is to add a copy rotation constraint to
each bone in the chain in order to override their parent rotation, thus achieving
control over twisting of each segment of the chain.

This commit makes it possible to have a bone (that is not a parent or child of the bone
being affected) to influence the bbone curvature as if they were.

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

M	release/scripts/startup/bl_ui/properties_data_bone.py
M	source/blender/blenkernel/intern/armature.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_action_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 e80a1bc..2c22259 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -193,8 +193,24 @@ class BONE_PT_curved(BoneButtonsPanel, Panel):
 
         sub = row.column(align=True)
         sub.label("Easing:")
-        sub.prop(bone, "bbone_in", text="Ease In")    # XXX: have this also be an overlay?
-        sub.prop(bone, "bbone_out", text="Ease Out")  # XXX: have this also be an overlay?
+        if pchan:
+            # XXX: have these also be an overlay?
+            sub.prop(bbone.bone, "bbone_in", text="Ease In")
+            sub.prop(bbone.bone, "bbone_out", text="Ease Out")
+        else:
+            sub.prop(bone, "bbone_in", text="Ease In")
+            sub.prop(bone, "bbone_out", text="Ease Out")
+
+        if pchan:
+            layout.separator()
+
+            col = layout.column()
+            col.prop(pchan, "use_bbone_custom_handles")
+
+            row = col.row()
+            row.active = pchan.use_bbone_custom_handles
+            row.prop_search(pchan, "bbone_custom_handle_start", ob.pose, "bones", text="In")
+            row.prop_search(pchan, "bbone_custom_handle_end", ob.pose, "bones", text="Out")
 
 
 
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 6cf7be2..90fc88d 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -499,13 +499,21 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
 	hlength1 = bone->ease1 * length * 0.390464f; /* 0.5f * sqrt(2) * kappa, the handle length for near-perfect circles */
 	hlength2 = bone->ease2 * length * 0.390464f;
 
-	/* evaluate next and prev bones */
-	if (bone->flag & BONE_CONNECTED)
-		prev = pchan->parent;
-	else
-		prev = NULL;
+	/* get "next" and "prev" bones - these are used for handle calculations */
+	if (pchan->bboneflag & PCHAN_BBONE_CUSTOM_HANDLES) {
+		/* use the provided bones as the next/prev - leave blank to eliminate this effect altogether */
+		prev = pchan->bbone_prev;
+		next = pchan->bbone_next;
+	}
+	else {
+		/* evaluate next and prev bones */
+		if (bone->flag & BONE_CONNECTED)
+			prev = pchan->parent;
+		else
+			prev = NULL;
 
-	next = pchan->child;
+		next = pchan->child;
+	}
 
 	/* find the handle points, since this is inside bone space, the
 	 * first point = (0, 0, 0)
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 678fd84..d6e2f23 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4926,6 +4926,9 @@ static void direct_link_pose(FileData *fd, bPose *pose)
 		pchan->child = newdataadr(fd, pchan->child);
 		pchan->custom_tx = newdataadr(fd, pchan->custom_tx);
 		
+		pchan->bbone_prev = newdataadr(fd, pchan->bbone_prev);
+		pchan->bbone_next = newdataadr(fd, pchan->bbone_next);
+		
 		direct_link_constraints(fd, &pchan->constraints);
 		
 		pchan->prop = newdataadr(fd, pchan->prop);
diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h
index 76b8ca0..1c8832f 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -199,7 +199,8 @@ typedef struct bPoseChannel {
 	char constflag;                 /* for quick detecting which constraints affect this channel */
 	char selectflag;                /* copy of bone flag, so you can work with library armatures, not for runtime use */
 	char drawflag;
-	char pad0[5];
+	char bboneflag;
+	char pad0[4];
 
 	struct Bone         *bone;      /* set on read file or rebuild pose */
 	struct bPoseChannel *parent;    /* set on read file or rebuild pose */
@@ -249,6 +250,9 @@ typedef struct bPoseChannel {
 	float curveOutX, curveOutY;
 	float scaleIn, scaleOut;
 	
+	struct bPoseChannel *bbone_prev; /* next/prev bones to use as handle references when calculating bbones (optional) */
+	struct bPoseChannel *bbone_next;
+	
 	void        *temp;              /* use for outliner */
 } bPoseChannel;
 
@@ -324,6 +328,12 @@ typedef enum ePchan_DrawFlag {
 #define PCHAN_CUSTOM_DRAW_SIZE(pchan) \
 	(pchan)->custom_scale * (((pchan)->drawflag & PCHAN_DRAW_NO_CUSTOM_BONE_SIZE) ? 1.0f : (pchan)->bone->length)
 
+/* PoseChannel->bboneflag */
+typedef enum ePchan_BBoneFlag {
+	/* Use custom reference bones (for roll and handle alignment), instead of immediate neighbours */
+	PCHAN_BBONE_CUSTOM_HANDLES    = (1 << 1),
+} ePchan_BBoneFlag;
+
 /* PoseChannel->rotmode and Object->rotmode */
 typedef enum eRotationModes {
 	/* quaternion rotations (default, and for older Blender versions) */
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index 2d49572..9e1bde7 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -875,6 +875,33 @@ static void rna_def_pose_channel(BlenderRNA *brna)
 	/* Curved bones settings - Applied on top of restpose values */
 	rna_def_bone_curved_common(srna, true);
 	
+	/* Custom BBone next/prev sources */
+	prop = RNA_def_property(srna, "use_bbone_custom_handles", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "bboneflag", PCHAN_BBONE_CUSTOM_HANDLES);
+	RNA_def_property_ui_text(prop, "Use Custom Handle References", 
+	                         "Use custom reference bones as handles for B-Bones instead of next/previous bones, "
+	                         "leave these blank to use only B-Bone offset properties to control the shape");
+	//RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
+	RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_IK_update");
+	
+	prop = RNA_def_property(srna, "bbone_custom_handle_start", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "bbone_prev");
+	RNA_def_property_struct_type(prop, "PoseBone");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "B-Bone Start Handle",
+	                         "Bone that serves as the start handle for the B-Bone curve");
+	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, "bbone_custom_handle_end", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "bbone_next");
+	RNA_def_property_struct_type(prop, "PoseBone");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "B-Bone End Handle",
+	                         "Bone that serves as the end handle for the B-Bone curve");
+	RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
+	RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_update");
+	
 	/* transform matrices - should be read-only since these are set directly by AnimSys evaluation */
 	prop = RNA_def_property(srna, "matrix_channel", PROP_FLOAT, PROP_MATRIX);
 	RNA_def_property_float_sdna(prop, NULL, "chan_mat");




More information about the Bf-blender-cvs mailing list