Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2018-11-22 13:38:03 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2018-11-23 23:19:23 +0300
commit1e820898ff4dfc734710a6640ca7bafc0bfc69db (patch)
tree8f68fba82219df0295d89581e49e105ff907ba80 /source/blender/blenkernel/intern/constraint.c
parente49c66efae9d9fb85154ca4b3073ae3733400708 (diff)
Depsgraph: add a new operation node for computing B-Bone segments.
Computing the shape of a B-Bone is a quite expensive operation, and there are multiple constraints that can access this information in a variety of useful ways. This means computing the shape once per bone and saving it is good for performance. Since the shape may depend on the position of up to two other bones, often in a "cyclic" manner, this computation has to be a separate node with its own dependencies. Reviewers: sergey Differential Revision: https://developer.blender.org/D3975
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r--source/blender/blenkernel/intern/constraint.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 96df4f402c5..d8956ce28b7 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -590,15 +590,12 @@ static void constraint_target_to_mat4(Object *ob, const char *substring, float m
/* skip length interpolation if set to head */
mul_m4_m4m4(mat, ob->obmat, pchan->pose_mat);
}
- else if (is_bbone) {
+ else if (is_bbone && pchan->bone->segments == pchan->runtime.bbone_segments) {
/* use point along bbone */
- Mat4 bbone[MAX_BBONE_SUBDIV];
+ Mat4 *bbone = pchan->runtime.bbone_pose_mats;
float tempmat[4][4];
float loc[3], fac;
- /* get bbone segments */
- b_bone_spline_setup(pchan, false, bbone);
-
/* figure out which segment(s) the headtail value falls in */
fac = (float)pchan->bone->segments * headtail;
@@ -2164,7 +2161,7 @@ static void armdef_get_tarmat(struct Depsgraph *UNUSED(depsgraph),
/* Compute and accumulate transformation for a single target bone. */
static void armdef_accumulate_bone(bConstraintTarget *ct, bPoseChannel *pchan, const float wco[3], bool force_envelope, float *r_totweight, float r_sum_mat[4][4], DualQuat *r_sum_dq)
{
- float mat[4][4], iobmat[4][4], iamat[4][4], basemat[4][4], co[3];
+ float mat[4][4], iobmat[4][4], basemat[4][4], co[3];
Bone *bone = pchan->bone;
float weight = ct->weight;
@@ -2172,9 +2169,6 @@ static void armdef_accumulate_bone(bConstraintTarget *ct, bPoseChannel *pchan, c
invert_m4_m4(iobmat, ct->tar->obmat);
mul_v3_m4v3(co, iobmat, wco);
- /* Inverted rest pose matrix: bone->chan_mat may not be final yet. */
- invert_m4_m4(iamat, bone->arm_mat);
-
/* Multiply by the envelope weight when appropriate. */
if (force_envelope || (bone->flag & BONE_MULT_VG_ENV)) {
weight *= distfactor_to_bone(co, bone->arm_head, bone->arm_tail,
@@ -2182,7 +2176,10 @@ static void armdef_accumulate_bone(bConstraintTarget *ct, bPoseChannel *pchan, c
}
/* Find the correct bone transform matrix in world space. */
- if (bone->segments > 1) {
+ if (bone->segments > 1 && bone->segments == pchan->runtime.bbone_segments) {
+ Mat4 *b_bone_mats = pchan->runtime.bbone_deform_mats;
+ float (*iamat)[4] = b_bone_mats[0].mat;
+
/* The target is a B-Bone:
* FIRST: find the segment (see b_bone_deform in armature.c)
* Need to transform co back to bonespace, only need y. */
@@ -2193,19 +2190,12 @@ static void armdef_accumulate_bone(bConstraintTarget *ct, bPoseChannel *pchan, c
CLAMP(a, 0, bone->segments - 1);
- /* SECOND: compute the matrix (see pchan_b_bone_defmats in armature.c) */
- Mat4 b_bone[MAX_BBONE_SUBDIV], b_bone_rest[MAX_BBONE_SUBDIV];
- float irmat[4][4];
-
- b_bone_spline_setup(pchan, false, b_bone);
- b_bone_spline_setup(pchan, true, b_bone_rest);
-
- invert_m4_m4(irmat, b_bone_rest[a].mat);
- mul_m4_series(mat, ct->matrix, b_bone[a].mat, irmat, iamat, iobmat);
+ /* Convert the selected matrix into object space. */
+ mul_m4_series(mat, ct->tar->obmat, b_bone_mats[a + 1].mat, iobmat);
}
else {
- /* Simple bone. */
- mul_m4_series(mat, ct->matrix, iamat, iobmat);
+ /* Simple bone. This requires DEG_OPCODE_BONE_DONE dependency due to chan_mat. */
+ mul_m4_series(mat, ct->tar->obmat, pchan->chan_mat, iobmat);
}
/* Accumulate the transformation. */