[Bf-blender-cvs] [0dfacad7bf9] temp-angavrilov-bbone-custom-handles: Move B-Bone custom handle settings to Edit mode.

Alexander Gavrilov noreply at git.blender.org
Tue Aug 7 20:08:26 CEST 2018


Commit: 0dfacad7bf9857b090d86a6fd7a9d504921e3d7c
Author: Alexander Gavrilov
Date:   Sun Aug 5 18:48:05 2018 +0300
Branches: temp-angavrilov-bbone-custom-handles
https://developer.blender.org/rB0dfacad7bf9857b090d86a6fd7a9d504921e3d7c

Move B-Bone custom handle settings to Edit mode.

Custom handle settings actually affect the B-Bone rest shape,
so they should be changed in Edit mode rather than Pose mode.
This is necessary to be able to display the correct rest shape
of the bone in Edit Mode.

Also, instead of flags, introduce an enum to specify the handle
operation modes, so that new ones could be added later.

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

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/blenloader/intern/versioning_280.c
M	source/blender/editors/armature/armature_add.c
M	source/blender/editors/armature/armature_intern.h
M	source/blender/editors/armature/armature_utils.c
M	source/blender/editors/armature/editarmature_retarget.c
M	source/blender/editors/include/ED_armature.h
M	source/blender/makesdna/DNA_action_types.h
M	source/blender/makesdna/DNA_armature_types.h
M	source/blender/makesrna/intern/rna_armature.c
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 6d364ee6539..58007836df1 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -130,6 +130,7 @@ class BONE_PT_curved(BoneButtonsPanel, Panel):
         bone = context.bone
         # arm = context.armature
         pchan = None
+        edit = False
 
         if ob and bone:
             pchan = ob.pose.bones[bone.name]
@@ -137,6 +138,7 @@ class BONE_PT_curved(BoneButtonsPanel, Panel):
         elif bone is None:
             bone = context.edit_bone
             bbone = bone
+            edit = True
         else:
             bbone = bone
 
@@ -169,24 +171,29 @@ class BONE_PT_curved(BoneButtonsPanel, Panel):
         col.prop(bbone, "bbone_easein", text="Ease In")
         col.prop(bbone, "bbone_easeout", text="Out")
 
-        if pchan:
-            layout.separator()
-
-            col = layout.column()
-            col.use_property_split = False
-            col.prop(pchan, "use_bbone_custom_handles")
+        col = layout.column()
+        col.use_property_decorate = False
+        col.prop(bone, "bbone_handle_type_start", text="Start Handle")
 
-            col = layout.column(align=True)
-            col.active = pchan.use_bbone_custom_handles
-            col.use_property_split = True
+        col = col.column()
+        col.active = (bone.bbone_handle_type_start != "AUTO")
+        if edit:
+            col.prop_search(bone, "bbone_custom_handle_start", ob.data, "edit_bones", text="Custom")
+        else:
+            # read-only
+            col.prop(bbone, "bbone_custom_handle_start", text="Custom")
 
-            sub = col.column()
-            sub.prop_search(pchan, "bbone_custom_handle_start", ob.pose, "bones", text="Custom Handle Start")
-            sub.prop_search(pchan, "bbone_custom_handle_end", ob.pose, "bones", text="End")
+        col = layout.column()
+        col.use_property_decorate = False
+        col.prop(bone, "bbone_handle_type_end", text="End Handle")
 
-            sub = col.column(align=True)
-            sub.prop(pchan, "use_bbone_relative_start_handle", text="Relative Handle Start")
-            sub.prop(pchan, "use_bbone_relative_end_handle", text="End")
+        col = col.column()
+        col.active = (bone.bbone_handle_type_end != "AUTO")
+        if edit:
+            col.prop_search(bone, "bbone_custom_handle_end", ob.data, "edit_bones", text="Custom")
+        else:
+            # read-only
+            col.prop(bbone, "bbone_custom_handle_end", text="Custom")
 
 
 class BONE_PT_relations(BoneButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index cea81a82f4b..1e9f48d43c2 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -461,20 +461,26 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
 	}
 
 	/* 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->bbone_prev_type == BBONE_HANDLE_AUTO) {
+		/* use connected parent */
 		if (bone->flag & BONE_CONNECTED)
 			prev = pchan->parent;
 		else
 			prev = NULL;
+	}
+	else {
+		/* use the provided bones as the next/prev - leave blank to eliminate this effect altogether */
+		prev = pchan->bbone_prev;
+	}
 
+	if (bone->bbone_next_type == BBONE_HANDLE_AUTO) {
+		/* use connected child */
 		next = pchan->child;
 	}
+	else {
+		/* use the provided bones as the next/prev - leave blank to eliminate this effect altogether */
+		next = pchan->bbone_next;
+	}
 
 	/* find the handle points, since this is inside bone space, the
 	 * first point = (0, 0, 0)
@@ -494,8 +500,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
 		float difmat[4][4], result[3][3], imat3[3][3];
 
 		/* transform previous point inside this bone space */
-		if ((pchan->bboneflag & PCHAN_BBONE_CUSTOM_HANDLES) &&
-		    (pchan->bboneflag & PCHAN_BBONE_CUSTOM_START_REL))
+		if (bone->bbone_prev_type == BBONE_HANDLE_RELATIVE)
 		{
 			/* Use delta movement (from restpose), and apply this relative to the current bone's head */
 			if (rest) {
@@ -550,8 +555,7 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
 		float difmat[4][4], result[3][3], imat3[3][3];
 
 		/* transform next point inside this bone space */
-		if ((pchan->bboneflag & PCHAN_BBONE_CUSTOM_HANDLES) &&
-		    (pchan->bboneflag & PCHAN_BBONE_CUSTOM_END_REL))
+		if (bone->bbone_next_type == BBONE_HANDLE_RELATIVE)
 		{
 			/* Use delta movement (from restpose), and apply this relative to the current bone's tail */
 			if (rest) {
@@ -1993,6 +1997,18 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_
 			BKE_pose_channels_hash_free(pose);
 			BLI_freelinkN(&pose->chanbase, pchan);
 		}
+		else {
+			/* find the custom B-Bone handles */
+			if (pchan->bone->bbone_prev)
+				pchan->bbone_prev = BKE_pose_channel_find_name(pose, pchan->bone->bbone_prev->name);
+			else
+				pchan->bbone_prev = NULL;
+
+			if (pchan->bone->bbone_next)
+				pchan->bbone_next = BKE_pose_channel_find_name(pose, pchan->bone->bbone_next->name);
+			else
+				pchan->bbone_next = NULL;
+		}
 	}
 	/* printf("rebuild pose %s, %d bones\n", ob->id.name, counter); */
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 293114c4b79..75b64339227 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3600,6 +3600,20 @@ static void lib_link_pose(FileData *fd, Main *bmain, Object *ob, bPose *pose)
 
 	BLI_ghash_free(bone_hash, NULL, NULL);
 
+	/* rebuild if B-Bone custom handles are inconsistent */
+	if (!rebuild) {
+		for (bPoseChannel *pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
+			bool ok = ((!pchan->bbone_prev && !pchan->bone->bbone_prev) ||
+			           (pchan->bbone_prev && pchan->bbone_prev->bone == pchan->bone->bbone_prev)) &&
+			          ((!pchan->bbone_next && !pchan->bone->bbone_next) ||
+			           (pchan->bbone_next && pchan->bbone_next->bone == pchan->bone->bbone_next));
+
+			if (UNLIKELY(!ok)) {
+				rebuild = true;
+				break;
+			}
+		}
+	}
 
 	if (rebuild) {
 		DEG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
@@ -3640,6 +3654,9 @@ static void direct_link_bones(FileData *fd, Bone *bone)
 	bone->prop = newdataadr(fd, bone->prop);
 	IDP_DirectLinkGroup_OrFree(&bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
 
+	bone->bbone_next = newdataadr(fd, bone->bbone_next);
+	bone->bbone_prev = newdataadr(fd, bone->bbone_prev);
+
 	bone->flag &= ~BONE_DRAW_ACTIVE;
 
 	link_list(fd, &bone->childbase);
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index aed1fd8b416..269374b84bd 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -56,6 +56,7 @@
 #include "DNA_genfile.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_workspace_types.h"
+#include "DNA_armature_types.h"
 
 #include "BKE_collection.h"
 #include "BKE_constraint.h"
@@ -750,6 +751,31 @@ void do_versions_after_linking_280(Main *bmain)
 	}
 #endif
 
+	{
+		/* Copy B-Bone custom handle settings from pose to bone */
+		for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
+			bArmature *arm = ob->data;
+
+			if (ob->pose && arm->id.lib == ob->id.lib) {
+				for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+					/* do the copying if the 2.7 flag is enabled, while the new settings are empty */
+					if (pchan->bone && (pchan->bboneflag & PCHAN_BBONE_CUSTOM_HANDLES) &&
+						pchan->bone->bbone_prev_type == BBONE_HANDLE_AUTO &&
+						pchan->bone->bbone_next_type == BBONE_HANDLE_AUTO &&
+						pchan->bone->bbone_prev == NULL && pchan->bone->bbone_next == NULL)
+					{
+						pchan->bone->bbone_prev_type = (pchan->bboneflag & PCHAN_BBONE_CUSTOM_START_REL) ? BBONE_HANDLE_RELATIVE : BBONE_HANDLE_ABSOLUTE;
+						pchan->bone->bbone_next_type = (pchan->bboneflag & PCHAN_BBONE_CUSTOM_END_REL) ? BBONE_HANDLE_RELATIVE : BBONE_HANDLE_ABSOLUTE;
+
+						if (pchan->bbone_prev)
+							pchan->bone->bbone_prev = pchan->bbone_prev->bone;
+						if (pchan->bbone_next)
+							pchan->bone->bbone_next = pchan->bbone_next->bone;
+					}
+				}
+			}
+		}
+	}
 }
 
 /* NOTE: this version patch is intended for versions < 2.52.2, but was initially introduced in 2.27 already.
diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c
index c1fb1dcf82f..aafe3e6d08d 100644
--- a/source/blender/editors/armature/armature_add.c
+++ b/source/blender/editors/armature/armature_add.c
@@ -433,6 +433,8 @@ EditBone *duplicateEditBoneObjects(EditBone *curBone, const char *name, ListBase
 	curBone->temp.ebone = eBone;
 	eBone->temp.ebone = curBone;
 
+	eBone->ebflag &= ~(EDIT_BONE_HAS_REFS);
+
 	if (name != NULL) {
 		BLI_strncpy(eBone->name, name, sizeof(eBone->name));
 	}
@@ -561,6 +563,16 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op)
 				ebone->flag &= ~BONE_CONNECTED;
 			}
 
+			/* update custom handle links */
+			if (ebone_iter->bbone_prev && ebone_iter->bbone_prev->temp.ebone) {
+					ebone_iter->bbone_prev = ebone_iter->bbone_prev->temp.ebone;
+					ebone_iter->bbone_prev->ebflag |= EDIT_BONE_HAS_REFS;
+			}
+			if (ebone_iter->bbone_next && ebone_iter->bbone_next->temp.ebone) {
+					ebone_iter->bbone_next = ebone_iter->bbone_next->temp.ebone;
+					ebone_iter->bbone_next->ebflag |= EDIT_BONE_HAS_REFS;
+			}
+
 			/* Lets try to fix any constraint subtargets that might
 			 * have been duplicated
 			 */
@@ -751,6 +763,16 @@ static int armature_symmetrize_ex

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list