[Bf-blender-cvs] [a00a03e6a6e] temp-angavrilov-constraints: tweak: add options to drive B-Bone scale from handle local scale channels.
Alexander Gavrilov
noreply at git.blender.org
Sun Dec 13 15:39:11 CET 2020
Commit: a00a03e6a6eb4e74d9641f1740a117a76e0fe614
Author: Alexander Gavrilov
Date: Sun Dec 13 16:01:58 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rBa00a03e6a6eb4e74d9641f1740a117a76e0fe614
tweak: add options to drive B-Bone scale from handle local scale channels.
===================================================================
M release/scripts/startup/bl_ui/properties_data_bone.py
M source/blender/blenkernel/BKE_armature.h
M source/blender/blenkernel/intern/armature.c
M source/blender/blenloader/intern/versioning_290.c
M source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
M source/blender/draw/engines/overlay/overlay_armature.c
M source/blender/editors/armature/armature_add.c
M source/blender/editors/armature/armature_utils.c
M source/blender/makesdna/DNA_armature_types.h
M source/blender/makesrna/intern/rna_armature.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_bone.py b/release/scripts/startup/bl_ui/properties_data_bone.py
index cd2baee84d7..39a61aabdbd 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -177,26 +177,50 @@ class BONE_PT_curved(BoneButtonsPanel, Panel):
col.prop(bbone, "bbone_scaleouty", text="Out Y")
col.prop(bbone, "bbone_scaleout_len", text="Out Len")
- topcol.prop(bone, "use_scale_segments")
-
col = topcol.column(align=True)
col.prop(bbone, "bbone_easein", text="Ease In")
col.prop(bbone, "bbone_easeout", text="Out")
col.prop(bone, "use_scale_easing")
+ topcol.prop(bone, "use_scale_segments")
+
col = topcol.column(align=True)
col.prop(bone, "bbone_handle_type_start", text="Start Handle")
- col = col.column(align=True)
- col.active = (bone.bbone_handle_type_start != 'AUTO')
- col.prop_search(bone, "bbone_custom_handle_start", arm, bone_list, text="Custom")
+ col2 = col.column(align=True)
+ col2.active = (bone.bbone_handle_type_start != 'AUTO')
+ col2.prop_search(bone, "bbone_custom_handle_start", arm, bone_list, text="Custom")
+
+ row = col.row(align=True)
+ row.use_property_split = False
+ split = row.split(factor=0.4)
+ split.alignment = 'RIGHT'
+ split.label(text="Scale")
+ row2 = split.row(align=True)
+ row2.prop(bone, "bbone_handle_scale_start", index=0, text="X", toggle=True)
+ row2.prop(bone, "bbone_handle_scale_start", index=1, text="Y", toggle=True)
+ row2.prop(bone, "bbone_handle_scale_start", index=2, text="Len", toggle=True)
+ row2.prop(bone, "bbone_handle_scale_start", index=3, text="Ease", toggle=True)
+ row.label(icon="BLANK1")
col = topcol.column(align=True)
col.prop(bone, "bbone_handle_type_end", text="End Handle")
- col = col.column(align=True)
- col.active = (bone.bbone_handle_type_end != 'AUTO')
- col.prop_search(bone, "bbone_custom_handle_end", arm, bone_list, text="Custom")
+ col2 = col.column(align=True)
+ col2.active = (bone.bbone_handle_type_end != 'AUTO')
+ col2.prop_search(bone, "bbone_custom_handle_end", arm, bone_list, text="Custom")
+
+ row = col.row(align=True)
+ row.use_property_split = False
+ split = row.split(factor=0.4)
+ split.alignment = 'RIGHT'
+ split.label(text="Scale")
+ row2 = split.row(align=True)
+ row2.prop(bone, "bbone_handle_scale_end", index=0, text="X", toggle=True)
+ row2.prop(bone, "bbone_handle_scale_end", index=1, text="Y", toggle=True)
+ row2.prop(bone, "bbone_handle_scale_end", index=2, text="Len", toggle=True)
+ row2.prop(bone, "bbone_handle_scale_end", index=3, text="Ease", toggle=True)
+ row.label(icon="BLANK1")
class BONE_PT_relations(BoneButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index ecb4acf3fa7..7dd2ef03582 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -90,6 +90,10 @@ typedef struct EditBone {
/** Type of next/prev bone handles */
char bbone_prev_type;
char bbone_next_type;
+ /** B-Bone flags. */
+ int bbone_flag;
+ short bbone_prev_flag;
+ short bbone_next_flag;
/** Next/prev bones to use as handle references when calculating bbones (optional) */
struct EditBone *bbone_prev;
struct EditBone *bbone_next;
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 54ef0a309c8..7c06cb4176a 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -963,7 +963,7 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
{
bPoseChannel *next, *prev;
Bone *bone = pchan->bone;
- float imat[4][4], posemat[4][4];
+ float imat[4][4], posemat[4][4], tmpmat[4][4];
float delta[3];
memset(param, 0, sizeof(*param));
@@ -971,7 +971,7 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
param->segments = bone->segments;
param->length = bone->length;
- param->do_scale_segments = !!(bone->flag & BONE_SCALE_SEGMENTS);
+ param->do_scale_segments = !!(bone->bbone_flag & BBONE_SCALE_SEGMENTS);
if (!rest) {
float scale[3];
@@ -1002,6 +1002,11 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
invert_m4_m4(imat, pchan->pose_mat);
}
+ float prev_scale[3], next_scale[3];
+
+ copy_v3_fl(prev_scale, 1.0f);
+ copy_v3_fl(next_scale, 1.0f);
+
if (prev) {
float h1[3];
bool done = false;
@@ -1047,6 +1052,12 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
if (!param->prev_bbone) {
/* Find the previous roll to interpolate. */
mul_m4_m4m4(param->prev_mat, imat, rest ? prev->bone->arm_mat : prev->pose_mat);
+
+ /* Retrieve the local scale of the bone if necessary. */
+ if ((bone->bbone_prev_flag & BBONE_HANDLE_SCALE_ANY) && !rest) {
+ BKE_armature_mat_pose_to_bone(prev, prev->pose_mat, tmpmat);
+ mat4_to_size(prev_scale, tmpmat);
+ }
}
}
@@ -1094,6 +1105,12 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
/* Find the next roll to interpolate as well. */
mul_m4_m4m4(param->next_mat, imat, rest ? next->bone->arm_mat : next->pose_mat);
+
+ /* Retrieve the local scale of the bone if necessary. */
+ if ((bone->bbone_next_flag & BBONE_HANDLE_SCALE_ANY) && !rest) {
+ BKE_armature_mat_pose_to_bone(next, next->pose_mat, tmpmat);
+ mat4_to_size(next_scale, tmpmat);
+ }
}
/* Add effects from bbone properties over the top
@@ -1117,7 +1134,7 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
param->roll1 = bone->roll1 + (!rest ? pchan->roll1 : 0.0f);
param->roll2 = bone->roll2 + (!rest ? pchan->roll2 : 0.0f);
- if (bone->flag & BONE_ADD_PARENT_END_ROLL) {
+ if (bone->bbone_flag & BBONE_ADD_PARENT_END_ROLL) {
if (prev) {
if (prev->bone) {
param->roll1 += prev->bone->roll2;
@@ -1143,7 +1160,7 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
param->curve_out_x = bone->curve_out_x + (!rest ? pchan->curve_out_x : 0.0f);
param->curve_out_y = bone->curve_out_y + (!rest ? pchan->curve_out_y : 0.0f);
- if (bone->flag & BONE_SCALE_EASING) {
+ if (bone->bbone_flag & BBONE_SCALE_EASING) {
param->ease1 *= param->scale_in_len;
param->curve_in_x *= param->scale_in_len;
param->curve_in_y *= param->scale_in_len;
@@ -1152,6 +1169,37 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel *pchan,
param->curve_out_x *= param->scale_out_len;
param->curve_out_y *= param->scale_out_len;
}
+
+ /* Custom handle scale. */
+ if (bone->bbone_prev_flag & BBONE_HANDLE_SCALE_X) {
+ param->scale_in_x *= prev_scale[0];
+ }
+ if (bone->bbone_prev_flag & BBONE_HANDLE_SCALE_Y) {
+ param->scale_in_y *= prev_scale[2];
+ }
+ if (bone->bbone_prev_flag & BBONE_HANDLE_SCALE_LEN) {
+ param->scale_in_len *= prev_scale[1];
+ }
+ if (bone->bbone_prev_flag & BBONE_HANDLE_SCALE_EASE) {
+ param->ease1 *= prev_scale[1];
+ param->curve_in_x *= prev_scale[1];
+ param->curve_in_y *= prev_scale[1];
+ }
+
+ if (bone->bbone_next_flag & BBONE_HANDLE_SCALE_X) {
+ param->scale_out_x *= next_scale[0];
+ }
+ if (bone->bbone_next_flag & BBONE_HANDLE_SCALE_Y) {
+ param->scale_out_y *= next_scale[2];
+ }
+ if (bone->bbone_next_flag & BBONE_HANDLE_SCALE_LEN) {
+ param->scale_out_len *= next_scale[1];
+ }
+ if (bone->bbone_next_flag & BBONE_HANDLE_SCALE_EASE) {
+ param->ease2 *= next_scale[1];
+ param->curve_out_x *= next_scale[1];
+ param->curve_out_y *= next_scale[1];
+ }
}
}
@@ -1364,9 +1412,12 @@ int BKE_pchan_bbone_spline_compute(BBoneSplineParameters *param,
CLAMP_MIN(param->scale_in_len, 0.0001f);
CLAMP_MIN(param->scale_out_len, 0.0001f);
+ const float log_scale_in_len = logf(param->scale_in_len);
+ const float log_scale_out_len = logf(param->scale_out_len);
+
for (int i = 0; i < param->segments; i++) {
- float fac = (0.5f + i) / param->segments;
- segment_scales[i] = interpf(param->scale_out_len, param->scale_in_len, fac);
+ const float fac = ((float)i) / (param->segments - 1);
+ segment_scales[i] = expf(interpf(log_scale_out_len, log_scale_in_len, fac));
}
/* Compute segment vertex offsets along the curve length. */
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 4c8d47b9636..eb1d0ef11ce 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -592,6 +592,10 @@ static void do_versions_291_fcurve_handles_limit(FCurve *fcu)
static void do_version_bones_bbone_len_scale(ListBase *lb)
{
LISTBASE_FOREACH (Bone *, bone, lb) {
+ if (bone->flag & BONE_ADD_PARENT_END_ROLL) {
+ bone->bbone_flag |= BBONE_ADD_PARENT_END_ROLL;
+ }
+
bone->scale_in_len = bone->scale_out_len = 1.0f;
do_version_bones_bbone_len_scale(&bone->childbase);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
index 32c36d78250..e4591e2e994 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
@@ -421,7 +421,7 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
if (prev) {
OperationCode opcode = OperationCode::BONE_DONE;
/* Inheriting parent roll requires access to prev handle's B-Bone properties. */
- if ((pchan->bone->flag & BONE_ADD_PARENT_END_ROLL) != 0 &&
+ if ((pchan->bone->bbone_flag & BBONE_ADD_PARENT_END_ROLL) != 0 &&
check_pchan_has_bbone_segments(object, prev)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list