[Bf-blender-cvs] [d8ef9ec] BendyBones: Initial patch for improved bendy bones
Joshua Leung
noreply at git.blender.org
Tue May 17 16:40:08 CEST 2016
Commit: d8ef9ec1a85f51db4ae56decd404352d8de9f8d8
Author: Joshua Leung
Date: Fri Jan 22 23:50:00 2016 +1300
Branches: BendyBones
https://developer.blender.org/rBd8ef9ec1a85f51db4ae56decd404352d8de9f8d8
Initial patch for improved bendy bones
Author: Jose Molina
Idea: Daniel M Lara (pepeland)
===================================================================
M release/scripts/startup/bl_ui/properties_data_bone.py
M source/blender/blenkernel/intern/armature.c
M source/blender/editors/armature/armature_add.c
M source/blender/editors/armature/armature_utils.c
M source/blender/editors/armature/editarmature_retarget.c
M source/blender/editors/armature/pose_transform.c
M source/blender/editors/include/ED_armature.h
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 690c22c..abf62da 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -188,11 +188,13 @@ class BONE_PT_relations(BoneButtonsPanel, Panel):
sub.prop(bone, "use_connect")
sub.prop(bone, "use_inherit_rotation")
sub.prop(bone, "use_inherit_scale")
+ sub.prop(bone, "use_endroll_as_inroll")
sub = col.column()
sub.active = (not bone.parent or not bone.use_connect)
sub.prop(bone, "use_local_location")
+
class BONE_PT_display(BoneButtonsPanel, Panel):
bl_label = "Display"
@@ -370,6 +372,18 @@ class BONE_PT_deform(BoneButtonsPanel, Panel):
sub.prop(bone, "bbone_segments", text="Segments")
sub.prop(bone, "bbone_in", text="Ease In")
sub.prop(bone, "bbone_out", text="Ease Out")
+ sub.prop(bone, "bbone_rollin", text="Roll In")
+ sub.prop(bone, "bbone_rollout", text="Roll Out")
+
+ sub.label(text="Curve XY:")
+ sub.prop(bone, "bbone_curveinx", text="Roll Curve in X")
+ sub.prop(bone, "bbone_curveiny", text="Roll Curve in Y")
+ sub.prop(bone, "bbone_curveoutx", text="Roll Curve out X")
+ sub.prop(bone, "bbone_curveouty", text="Roll Curve out Y")
+
+ sub.label(text="Scale In/Out:")
+ sub.prop(bone, "bbone_scalein", text="Scale In")
+ sub.prop(bone, "bbone_scaleout", text="Scale Out")
class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel):
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 1a3afbb..0af69e8 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -601,6 +601,25 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
roll2 = 0.0;
}
+ /* add extra rolls */
+ float extraRoll1 = bone->roll1 / (180 / M_PI);
+
+ if (bone->flag & BONE_ADD_PARENT_END_ROLL){
+ extraRoll1 = extraRoll1 + prev->bone->roll2 / (180 / M_PI);
+ }
+ float extraRoll2 = bone->roll2 / (180 / M_PI);
+
+ roll1 = roll1 + extraRoll1;
+ roll2 = roll2 + extraRoll2;
+
+ /* extra curve x / y */
+
+ h1[0] = h1[0] + bone->curveInX;
+ h1[2] = h1[2] + bone->curveInY;
+
+ h2[0] = h2[0] + bone->curveOutX;
+ h2[2] = h2[2] + bone->curveOutY;
+
/* make curve */
if (bone->segments > MAX_BBONE_SUBDIV)
bone->segments = MAX_BBONE_SUBDIV;
@@ -624,6 +643,32 @@ void b_bone_spline_setup(bPoseChannel *pchan, int rest, Mat4 result_array[MAX_BB
/* correct for scaling when this matrix is used in scaled space */
mul_m4_series(result_array[a].mat, iscalemat, result_array[a].mat, scalemat);
}
+
+ float scaleFactorIn = 1.0;
+ if (a <= bone->segments - 1){
+ scaleFactorIn = 1.0 + (bone->scaleIn - 1.0)*((1.0*(bone->segments - a - 1)) / (1.0*(bone->segments - 1)));
+ }
+
+ float scaleFactorOut = 1.0;
+ if (a >= 0){
+ scaleFactorOut = 1.0 + (bone->scaleOut - 1.0)*((1.0*(a + 1)) / (1.0*(bone->segments - 1)));
+ }
+
+ float bscalemat[4][4], ibscalemat[4][4];
+ float bscale[3];
+
+ bscale[0] = 1.0*scaleFactorIn*scaleFactorOut;
+ bscale[1] = 1.0 / bone->segments;
+ bscale[2] = 1.0*scaleFactorIn*scaleFactorOut;
+
+
+ size_to_mat4(bscalemat, bscale);
+ mul_m4_m4m4(result_array[a].mat, result_array[a].mat, bscalemat);
+ //printf("a %d",a);
+ //print_m4("result_array[a].mat", result_array[a].mat);
+
+ //copy_m4_m4(bone->bbone_mat[a], result_array[a].mat);
+
}
}
@@ -669,9 +714,17 @@ static void pchan_b_bone_defmats(bPoseChannel *pchan, bPoseChanDeform *pdef_info
float tmat[4][4];
invert_m4_m4(tmat, b_bone_rest[a].mat);
-
- mul_m4_series(b_bone_mats[a + 1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, tmat, b_bone_mats[0].mat);
-
+ /*
+ printf("#################### %d #######################",a);
+ print_m4("b_bone_mats[a + 1].mat", b_bone_mats[a + 1].mat);
+ print_m4("pchan->chan_mat", pchan->chan_mat);
+ print_m4("bone->arm_mat", bone->arm_mat);
+ print_m4("b_bone[a].mat", b_bone[a].mat);
+ print_m4("tmat", tmat);
+ print_m4("b_bone_mats[0].mat", b_bone_mats[0].mat);
+ */
+ mul_m4_series(b_bone_mats[a + 1].mat, pchan->chan_mat, bone->arm_mat, b_bone[a].mat, b_bone_mats[0].mat);//, tmat, b_bone_mats[0].mat);
+ //print_m4("b_bone_mats[a + 1].mat", b_bone_mats[a + 1].mat);
if (use_quaternion)
mat4_to_dquat(&b_bone_dual_quats[a], bone->arm_mat, b_bone_mats[a + 1].mat);
}
@@ -681,11 +734,21 @@ static void b_bone_deform(bPoseChanDeform *pdef_info, Bone *bone, float co[3], D
{
Mat4 *b_bone = pdef_info->b_bone_mats;
float (*mat)[4] = b_bone[0].mat;
- float segment, y;
+ float segment, x, y, z;
int a;
-
+ //printf("*****************************************************\n");
/* need to transform co back to bonespace, only need y */
+ x = mat[0][0] * co[0] + mat[1][0] * co[1] + mat[2][0] * co[2] + mat[3][0];
y = mat[0][1] * co[0] + mat[1][1] * co[1] + mat[2][1] * co[2] + mat[3][1];
+ z = mat[0][2] * co[0] + mat[1][2] * co[1] + mat[2][2] * co[2] + mat[3][2];
+
+ float pos[3];
+ pos[0] = x;
+ pos[1] = y;
+ pos[2] = z;
+
+ //print_m4("mat",mat);
+ //print_v3("pos", pos);
/* now calculate which of the b_bones are deforming this */
segment = bone->length / ((float)bone->segments);
@@ -699,6 +762,91 @@ static void b_bone_deform(bPoseChanDeform *pdef_info, Bone *bone, float co[3], D
copy_dq_dq(dq, &(pdef_info->b_bone_dual_quats)[a]);
}
else {
+
+ /* start scale in/out deform*/
+
+ float scaleFactorIn = 1.0 + (bone->scaleIn - 1.0)*((1.0*(bone->segments - a - 1)) / (1.0*(bone->segments - 1)));;
+ float scaleFactorOut = 1.0 + (bone->scaleOut - 1.0)*((1.0*(a + 1)) / (1.0*(bone->segments - 1)));
+
+ float bscalemat[4][4], ibscalemat[4][4];
+ float bscale[3];
+
+ bscale[0] = 1.0*scaleFactorIn*scaleFactorOut;
+ bscale[1] = 1.0*scaleFactorIn*scaleFactorOut;
+ bscale[2] = 1.0;
+
+
+ size_to_mat4(bscalemat, bscale);
+ bscalemat[3][0] = -1.0*bone->arm_head[0] * (bscale[0] - 1.0);
+ bscalemat[3][1] = -1.0*bone->arm_head[1] * (bscale[1] - 1.0);
+ //bscalemat[3][3] = 1.0;
+
+
+ //print_m4("bscalemat", bscalemat);
+ //print_v4("co antes", co);
+ //mul_m4_v3(bscalemat, co);
+ ////add_m4_m4m4(b_bone[a + 1].mat, b_bone[a + 1].mat, bscalemat);
+ //print_v4("co despues", co);
+
+
+
+ /* end scale in/out deform*/
+
+ /* start extra roll deform*/
+
+ float extraRoll1 = (bone->roll1 / (180 / M_PI))*((1.0*(bone->segments - a - 1)) / (1.0*(bone->segments - 1)));
+ float extraRoll2 = (bone->roll2 / (180 / M_PI))*((1.0*(a + 1)) / (1.0*(bone->segments - 1)));
+ float extraRoll = extraRoll2 - extraRoll1;
+
+ float cosExtraRoll = cos(extraRoll);
+ float sinExtraRoll = sin(extraRoll);
+
+ float matRot[4][4];
+
+ matRot[0][0] = cosExtraRoll;
+ matRot[0][1] = -sinExtraRoll;
+ matRot[0][2] = 0.0;
+ matRot[0][3] = 0.0;
+ matRot[1][0] = sinExtraRoll;
+ matRot[1][1] = cosExtraRoll;
+ matRot[1][2] = 0.0;
+ matRot[1][3] = 0.0;
+ matRot[2][0] = 0.0;
+ matRot[2][1] = 0.0;
+ matRot[2][2] = 1.0;
+ matRot[2][3] = 0.0;
+ matRot[3][0] = 0.0;
+ matRot[3][1] = 0.0;
+ matRot[3][2] = 0.0;
+ matRot[3][3] = 1.0;
+
+ //mul_m4_v3(matRot, co);
+
+ /* end extra roll deform*/
+
+
+ /* start x/y pos deform */
+ float matPos[4][4];
+
+ matPos[0][0] = 1.0;
+ matPos[0][1] = 0.0;
+ matPos[0][2] = 0.0;
+ matPos[0][3] = 0.0;
+ matPos[1][0] = 0.0;
+ matPos[1][1] = 1.0;
+ matPos[1][2] = 0.0;
+ matPos[1][3] = 0.0;
+ matPos[2][0] = 0.0;
+ matPos[2][1] = 0.0;
+ matPos[2][2] = 1.0;
+ matPos[2][3] = 0.0;
+ matPos[3][0] = bone->curveInX*((0.5*(bone->segments - a - 1)) / (1.0*(bone->segments - 1)));
+ matPos[3][1] = -bone->curveInY*((0.5*(bone->segments - a - 1)) / (1.0*(bone->segments - 1)));
+ matPos[3][2] = 0.0;
+ matPos[3][3] = 1.0;
+ //mul_m4_v3(matPos, co);
+ /* end x/y pos deform */
+
mul_m4_v3(b_bone[a + 1].mat, co);
if (defmat) {
diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c
index 6afc5a3..847b45d 100644
--- a/source/blender/editors/armature/armature_add.c
+++ b/source/blender/editors/armature/armature_add.c
@@ -83,6 +83,15 @@ EditBone *ED_armature_edit_bone_add(bArmature *arm, const char *name)
bone->segments = 1;
bone->layer = arm->layer;
+ bone->roll1 = 0.0f;
+ bone->roll2 = 0.0f;
+ bone->curveInX = 0.0f;
+ bone->curveInY = 0.0f;
+ bone->curveOutX = 0.0f;
+ bone->curveOutY = 0.0f;
+ bone->scaleIn = 1.0f;
+ bone->scaleOut = 1.0f;
+
return bone;
}
@@ -890,6 +899,16 @@ static int armature_extrude_exec(bContext *C, wmOperator *op)
newbone->segments = 1;
newbone->layer = ebone->layer;
+ newbone->roll1 = ebone->roll1;
+ newbone->roll2 = ebone->roll2;
+ newbone->curveInX = ebone->curveInX;
+ newbone->curveInY = ebone->curveInY;
+ newbone->curveOutX = ebone->curveOutX;
+ newbone->curveOutY = ebone->curveOutY;
+ newbone->scaleIn = ebone->scaleIn;
+ newbone->scaleOut = ebone->scaleOut;
+
+
BLI_strncpy(newbone->name, ebone->name, sizeof(newbone->name));
if (flipbone && forked) { // only set if mirror edit
diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c
index 85c6835..d73536e 100644
--- a/source/blender/editors/armature/armature_utils.c
+++ b/source/blender/editors/armature/armature_utils.c
@@ -456,7 +456,16 @@ EditBone *make_boneList(ListBase *edbo, ListBase *bones, EditBone *parent, Bone
eBone->rad_tail = curBone->rad_tail;
eBone->segments = curBone->segments;
eBone->layer = curBone->layer;
-
+
+ eBone->roll1 = curBone->roll1;
+ eBone->roll2 = curBone->roll2;
+ eBone->curveInX = curBone->curveInX;
+ eBone->curveInY = curBone->curveInY;
+ eBone->curveOutX = curBone->curveOutX;
+ eBone->curveOutY = curBone->curveOutY;
+ eBone->scaleIn = curBone->scaleIn;
+ eBone->scaleOut = curBone->scaleOut;
+
if (curBone->prop)
eBone->prop = IDP_CopyProperty(curBone->prop);
@@ -611,7 +620,17 @@ void ED_armature_from_edit(bArmature *arm)
newBone->rad_tail = e
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list