2016-11-17 14:34:46 +01:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2013 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup depsgraph
|
2016-11-17 14:34:46 +01:00
|
|
|
*
|
|
|
|
|
* Methods for constructing depsgraph
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "intern/builder/deg_builder_relations.h"
|
|
|
|
|
|
2020-12-04 11:28:09 +01:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <cstring> /* required for STREQ later on. */
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2017-06-06 12:14:39 +02:00
|
|
|
#include "BLI_blenlib.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
#include "DNA_action_types.h"
|
|
|
|
|
#include "DNA_anim_types.h"
|
|
|
|
|
#include "DNA_armature_types.h"
|
|
|
|
|
#include "DNA_constraint_types.h"
|
|
|
|
|
#include "DNA_customdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_action.h"
|
|
|
|
|
#include "BKE_armature.h"
|
2018-04-10 11:56:20 +02:00
|
|
|
#include "BKE_constraint.h"
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
|
|
|
|
|
|
#include "intern/builder/deg_builder.h"
|
|
|
|
|
#include "intern/builder/deg_builder_pchanmap.h"
|
2019-01-31 12:56:40 +01:00
|
|
|
#include "intern/debug/deg_debug.h"
|
|
|
|
|
#include "intern/node/deg_node.h"
|
|
|
|
|
#include "intern/node/deg_node_component.h"
|
|
|
|
|
#include "intern/node/deg_node_operation.h"
|
2016-11-17 14:34:46 +01:00
|
|
|
|
2020-01-24 11:11:38 +01:00
|
|
|
#include "intern/depsgraph_relation.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "intern/depsgraph_type.h"
|
2016-11-17 14:34:46 +01:00
|
|
|
|
2020-06-29 15:19:56 +02:00
|
|
|
namespace blender::deg {
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
/* IK Solver Eval Steps */
|
2017-11-23 11:39:28 +01:00
|
|
|
void DepsgraphRelationBuilder::build_ik_pose(Object *object,
|
2016-11-17 14:34:46 +01:00
|
|
|
bPoseChannel *pchan,
|
|
|
|
|
bConstraint *con,
|
|
|
|
|
RootPChanMap *root_map)
|
|
|
|
|
{
|
2020-04-10 13:58:56 +02:00
|
|
|
if ((con->flag & CONSTRAINT_DISABLE) != 0) {
|
2020-04-16 00:11:06 +10:00
|
|
|
/* Do not add disabled IK constraints to the relations. If these needs to be temporarily
|
2020-04-10 13:58:56 +02:00
|
|
|
* enabled, they will be added as temporary constraints during transform. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 14:34:46 +01:00
|
|
|
bKinematicConstraint *data = (bKinematicConstraint *)con->data;
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Attach owner to IK Solver to. */
|
2016-11-17 14:34:46 +01:00
|
|
|
bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data);
|
2020-01-28 14:50:13 +01:00
|
|
|
if (rootchan == nullptr) {
|
2017-10-16 22:20:34 +11:00
|
|
|
return;
|
|
|
|
|
}
|
2018-11-22 15:50:42 +01:00
|
|
|
OperationKey pchan_local_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_LOCAL);
|
|
|
|
|
OperationKey init_ik_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_INIT_IK);
|
2018-11-22 15:50:42 +01:00
|
|
|
OperationKey solver_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::EVAL_POSE, rootchan->name, OperationCode::POSE_IK_SOLVER);
|
|
|
|
|
OperationKey pose_cleanup_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_CLEANUP);
|
2017-09-25 18:48:38 +05:00
|
|
|
add_relation(pchan_local_key, init_ik_key, "IK Constraint -> Init IK Tree");
|
|
|
|
|
add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
|
2018-11-22 15:52:17 +01:00
|
|
|
/* Never cleanup before solver is run. */
|
|
|
|
|
add_relation(solver_key, pose_cleanup_key, "IK Solver -> Cleanup", RELATION_FLAG_GODMODE);
|
2019-04-23 17:47:11 +03:00
|
|
|
/* The ITASC solver currently accesses the target transforms in init tree :(
|
|
|
|
|
* TODO: Fix ITASC and remove this.
|
|
|
|
|
*/
|
|
|
|
|
bool is_itasc = (object->pose->iksolver == IKSOLVER_ITASC);
|
|
|
|
|
OperationKey target_dependent_key = is_itasc ? init_ik_key : solver_key;
|
2016-11-17 14:34:46 +01:00
|
|
|
/* IK target */
|
2018-11-22 15:50:42 +01:00
|
|
|
/* TODO(sergey): This should get handled as part of the constraint code. */
|
2020-01-28 14:50:13 +01:00
|
|
|
if (data->tar != nullptr) {
|
2019-04-23 17:47:11 +03:00
|
|
|
/* Different object - requires its transform. */
|
|
|
|
|
if (data->tar != object) {
|
|
|
|
|
ComponentKey target_key(&data->tar->id, NodeType::TRANSFORM);
|
|
|
|
|
add_relation(target_key, target_dependent_key, con->name);
|
|
|
|
|
}
|
|
|
|
|
/* Subtarget references: */
|
2016-11-17 14:34:46 +01:00
|
|
|
if ((data->tar->type == OB_ARMATURE) && (data->subtarget[0])) {
|
2019-04-23 17:47:11 +03:00
|
|
|
/* Bone - use the final transformation. */
|
|
|
|
|
OperationKey target_key(
|
|
|
|
|
&data->tar->id, NodeType::BONE, data->subtarget, OperationCode::BONE_DONE);
|
|
|
|
|
add_relation(target_key, target_dependent_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
2018-11-22 15:50:42 +01:00
|
|
|
else if (data->subtarget[0] && ELEM(data->tar->type, OB_MESH, OB_LATTICE)) {
|
|
|
|
|
/* Vertex group target. */
|
|
|
|
|
/* NOTE: for now, we don't need to represent vertex groups
|
|
|
|
|
* separately. */
|
2019-01-31 12:56:40 +01:00
|
|
|
ComponentKey target_key(&data->tar->id, NodeType::GEOMETRY);
|
2019-04-23 17:47:11 +03:00
|
|
|
add_relation(target_key, target_dependent_key, con->name);
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
add_customdata_mask(data->tar, DEGCustomDataMeshMasks::MaskVert(CD_MASK_MDEFORMVERT));
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
2018-11-22 15:50:42 +01:00
|
|
|
if (data->tar == object && data->subtarget[0]) {
|
2016-11-17 14:34:46 +01:00
|
|
|
/* Prevent target's constraints from linking to anything from same
|
2018-11-22 15:50:42 +01:00
|
|
|
* chain that it controls. */
|
2016-11-17 14:34:46 +01:00
|
|
|
root_map->add_bone(data->subtarget, rootchan->name);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Pole Target. */
|
|
|
|
|
/* TODO(sergey): This should get handled as part of the constraint code. */
|
2020-01-28 14:50:13 +01:00
|
|
|
if (data->poletar != nullptr) {
|
2019-04-23 17:47:11 +03:00
|
|
|
/* Different object - requires its transform. */
|
|
|
|
|
if (data->poletar != object) {
|
|
|
|
|
ComponentKey target_key(&data->poletar->id, NodeType::TRANSFORM);
|
|
|
|
|
add_relation(target_key, target_dependent_key, con->name);
|
|
|
|
|
}
|
|
|
|
|
/* Subtarget references: */
|
2016-11-17 14:34:46 +01:00
|
|
|
if ((data->poletar->type == OB_ARMATURE) && (data->polesubtarget[0])) {
|
2019-04-23 17:47:11 +03:00
|
|
|
/* Bone - use the final transformation. */
|
|
|
|
|
OperationKey target_key(
|
|
|
|
|
&data->poletar->id, NodeType::BONE, data->polesubtarget, OperationCode::BONE_DONE);
|
|
|
|
|
add_relation(target_key, target_dependent_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
2018-11-22 15:50:42 +01:00
|
|
|
else if (data->polesubtarget[0] && ELEM(data->poletar->type, OB_MESH, OB_LATTICE)) {
|
|
|
|
|
/* Vertex group target. */
|
|
|
|
|
/* NOTE: for now, we don't need to represent vertex groups
|
|
|
|
|
* separately. */
|
2019-01-31 12:56:40 +01:00
|
|
|
ComponentKey target_key(&data->poletar->id, NodeType::GEOMETRY);
|
2019-04-23 17:47:11 +03:00
|
|
|
add_relation(target_key, target_dependent_key, con->name);
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
add_customdata_mask(data->poletar, DEGCustomDataMeshMasks::MaskVert(CD_MASK_MDEFORMVERT));
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-22 15:50:42 +01:00
|
|
|
DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
|
|
|
|
|
BUILD,
|
|
|
|
|
"\nStarting IK Build: pchan = %s, target = (%s, %s), "
|
|
|
|
|
"segcount = %d\n",
|
2019-04-14 11:31:51 +03:00
|
|
|
pchan->name,
|
2020-01-28 14:50:13 +01:00
|
|
|
data->tar ? data->tar->id.name : "nullptr",
|
2019-04-14 11:31:51 +03:00
|
|
|
data->subtarget,
|
|
|
|
|
data->rootbone);
|
2016-11-17 14:34:46 +01:00
|
|
|
bPoseChannel *parchan = pchan;
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Exclude tip from chain if needed. */
|
2016-11-17 14:34:46 +01:00
|
|
|
if (!(data->flag & CONSTRAINT_IK_TIP)) {
|
|
|
|
|
parchan = pchan->parent;
|
|
|
|
|
}
|
|
|
|
|
root_map->add_bone(parchan->name, rootchan->name);
|
2019-01-31 12:56:40 +01:00
|
|
|
OperationKey parchan_transforms_key(
|
|
|
|
|
&object->id, NodeType::BONE, parchan->name, OperationCode::BONE_READY);
|
2017-06-01 16:20:48 +02:00
|
|
|
add_relation(parchan_transforms_key, solver_key, "IK Solver Owner");
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Walk to the chain's root. */
|
2016-11-17 14:34:46 +01:00
|
|
|
int segcount = 0;
|
2020-01-28 14:50:13 +01:00
|
|
|
while (parchan != nullptr) {
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Make IK-solver dependent on this bone's result, since it can only run
|
|
|
|
|
* after the standard results of the bone are know. Validate links step
|
|
|
|
|
* on the bone will ensure that users of this bone only grab the result
|
|
|
|
|
* with IK solver results. */
|
2016-11-17 14:34:46 +01:00
|
|
|
if (parchan != pchan) {
|
2018-11-22 15:50:42 +01:00
|
|
|
OperationKey parent_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, parchan->name, OperationCode::BONE_READY);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(parent_key, solver_key, "IK Chain Parent");
|
2018-11-22 15:50:42 +01:00
|
|
|
OperationKey bone_done_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, parchan->name, OperationCode::BONE_DONE);
|
2018-11-22 15:50:42 +01:00
|
|
|
add_relation(solver_key, bone_done_key, "IK Chain Result");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-11-22 15:50:42 +01:00
|
|
|
OperationKey final_transforms_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, parchan->name, OperationCode::BONE_DONE);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(solver_key, final_transforms_key, "IK Solver Result");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
parchan->flag |= POSE_DONE;
|
|
|
|
|
root_map->add_bone(parchan->name, rootchan->name);
|
2018-11-22 15:50:42 +01:00
|
|
|
/* continue up chain, until we reach target number of items. */
|
|
|
|
|
DEG_DEBUG_PRINTF((::Depsgraph *)graph_, BUILD, " %d = %s\n", segcount, parchan->name);
|
|
|
|
|
/* TODO(sergey): This is an arbitrary value, which was just following
|
|
|
|
|
* old code convention. */
|
2016-11-17 14:34:46 +01:00
|
|
|
segcount++;
|
2018-11-22 15:50:42 +01:00
|
|
|
if ((segcount == data->rootbone) || (segcount > 255)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-11-17 14:34:46 +01:00
|
|
|
parchan = parchan->parent;
|
|
|
|
|
}
|
2019-01-31 12:56:40 +01:00
|
|
|
OperationKey pose_done_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_DONE);
|
2018-11-22 15:50:42 +01:00
|
|
|
add_relation(solver_key, pose_done_key, "PoseEval Result-Bone Link");
|
2020-01-28 14:10:43 +01:00
|
|
|
|
|
|
|
|
/* Add relation when the root of this IK chain is influenced by another IK chain. */
|
|
|
|
|
build_inter_ik_chains(object, solver_key, rootchan, root_map);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Spline IK Eval Steps */
|
2017-11-23 11:39:28 +01:00
|
|
|
void DepsgraphRelationBuilder::build_splineik_pose(Object *object,
|
2016-11-17 14:34:46 +01:00
|
|
|
bPoseChannel *pchan,
|
|
|
|
|
bConstraint *con,
|
|
|
|
|
RootPChanMap *root_map)
|
|
|
|
|
{
|
|
|
|
|
bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
|
|
|
|
|
bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
|
2018-11-22 15:50:42 +01:00
|
|
|
OperationKey transforms_key(&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_READY);
|
|
|
|
|
OperationKey init_ik_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_INIT_IK);
|
|
|
|
|
OperationKey solver_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::EVAL_POSE, rootchan->name, OperationCode::POSE_SPLINE_IK_SOLVER);
|
|
|
|
|
OperationKey pose_cleanup_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_CLEANUP);
|
2018-09-26 18:16:16 +02:00
|
|
|
/* Solver depends on initialization. */
|
|
|
|
|
add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
|
2018-11-22 15:52:17 +01:00
|
|
|
/* Never cleanup before solver is run. */
|
|
|
|
|
add_relation(solver_key, pose_cleanup_key, "IK Solver -> Cleanup");
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Attach owner to IK Solver. */
|
2018-11-22 15:52:17 +01:00
|
|
|
add_relation(transforms_key, solver_key, "Spline IK Solver Owner", RELATION_FLAG_GODMODE);
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Attach path dependency to solver. */
|
2020-01-28 14:50:13 +01:00
|
|
|
if (data->tar != nullptr) {
|
2019-04-14 13:44:12 +03:00
|
|
|
ComponentKey target_geometry_key(&data->tar->id, NodeType::GEOMETRY);
|
|
|
|
|
add_relation(target_geometry_key, solver_key, "Curve.Path -> Spline IK");
|
|
|
|
|
ComponentKey target_transform_key(&data->tar->id, NodeType::TRANSFORM);
|
|
|
|
|
add_relation(target_transform_key, solver_key, "Curve.Transform -> Spline IK");
|
2019-04-13 17:36:57 +03:00
|
|
|
add_special_eval_flag(&data->tar->id, DAG_EVAL_NEED_CURVE_PATH);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
pchan->flag |= POSE_DONE;
|
2018-11-22 15:50:42 +01:00
|
|
|
OperationKey final_transforms_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_DONE);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(solver_key, final_transforms_key, "Spline IK Result");
|
2016-11-17 14:34:46 +01:00
|
|
|
root_map->add_bone(pchan->name, rootchan->name);
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Walk to the chain's root/ */
|
2019-04-14 13:44:12 +03:00
|
|
|
int segcount = 1;
|
2020-01-28 14:50:13 +01:00
|
|
|
for (bPoseChannel *parchan = pchan->parent; parchan != nullptr && segcount < data->chainlen;
|
2019-04-14 13:44:12 +03:00
|
|
|
parchan = parchan->parent, segcount++) {
|
2018-11-22 15:50:42 +01:00
|
|
|
/* Make Spline IK solver dependent on this bone's result, since it can
|
|
|
|
|
* only run after the standard results of the bone are know. Validate
|
|
|
|
|
* links step on the bone will ensure that users of this bone only grab
|
|
|
|
|
* the result with IK solver results. */
|
2019-04-14 13:44:12 +03:00
|
|
|
OperationKey parent_key(&object->id, NodeType::BONE, parchan->name, OperationCode::BONE_READY);
|
|
|
|
|
add_relation(parent_key, solver_key, "Spline IK Solver Update");
|
|
|
|
|
OperationKey bone_done_key(
|
|
|
|
|
&object->id, NodeType::BONE, parchan->name, OperationCode::BONE_DONE);
|
|
|
|
|
add_relation(solver_key, bone_done_key, "Spline IK Solver Result");
|
2016-11-17 14:34:46 +01:00
|
|
|
parchan->flag |= POSE_DONE;
|
|
|
|
|
root_map->add_bone(parchan->name, rootchan->name);
|
|
|
|
|
}
|
2019-01-31 12:56:40 +01:00
|
|
|
OperationKey pose_done_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_DONE);
|
2018-11-22 15:50:42 +01:00
|
|
|
add_relation(solver_key, pose_done_key, "PoseEval Result-Bone Link");
|
2020-01-28 14:10:43 +01:00
|
|
|
|
|
|
|
|
/* Add relation when the root of this IK chain is influenced by another IK chain. */
|
|
|
|
|
build_inter_ik_chains(object, solver_key, rootchan, root_map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DepsgraphRelationBuilder::build_inter_ik_chains(Object *object,
|
|
|
|
|
const OperationKey &solver_key,
|
|
|
|
|
const bPoseChannel *rootchan,
|
|
|
|
|
const RootPChanMap *root_map)
|
|
|
|
|
{
|
2020-01-30 12:04:13 +01:00
|
|
|
bPoseChannel *deepest_root = nullptr;
|
2020-01-28 14:10:43 +01:00
|
|
|
const char *root_name = rootchan->name;
|
|
|
|
|
|
|
|
|
|
/* Find shared IK chain root. */
|
|
|
|
|
for (bPoseChannel *parchan = rootchan->parent; parchan; parchan = parchan->parent) {
|
|
|
|
|
if (!root_map->has_common_root(root_name, parchan->name)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
deepest_root = parchan;
|
|
|
|
|
}
|
2020-01-30 12:04:13 +01:00
|
|
|
if (deepest_root == nullptr) {
|
2020-01-28 14:10:43 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationKey other_bone_key(
|
|
|
|
|
&object->id, NodeType::BONE, deepest_root->name, OperationCode::BONE_DONE);
|
|
|
|
|
add_relation(other_bone_key, solver_key, "IK Chain Overlap");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Pose/Armature Bones Graph */
|
2017-11-23 11:39:28 +01:00
|
|
|
void DepsgraphRelationBuilder::build_rig(Object *object)
|
2016-11-17 14:34:46 +01:00
|
|
|
{
|
|
|
|
|
/* Armature-Data */
|
2018-06-06 11:41:56 +02:00
|
|
|
bArmature *armature = (bArmature *)object->data;
|
2016-11-17 14:34:46 +01:00
|
|
|
// TODO: selection status?
|
2018-06-06 11:41:56 +02:00
|
|
|
/* Attach links between pose operations. */
|
2019-01-31 12:56:40 +01:00
|
|
|
ComponentKey local_transform(&object->id, NodeType::TRANSFORM);
|
|
|
|
|
OperationKey pose_init_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_INIT);
|
|
|
|
|
OperationKey pose_init_ik_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_INIT_IK);
|
|
|
|
|
OperationKey pose_cleanup_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_CLEANUP);
|
|
|
|
|
OperationKey pose_done_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_DONE);
|
2018-11-07 15:04:08 +01:00
|
|
|
add_relation(local_transform, pose_init_key, "Local Transform -> Pose Init");
|
|
|
|
|
add_relation(pose_init_key, pose_init_ik_key, "Pose Init -> Pose Init IK");
|
|
|
|
|
add_relation(pose_init_ik_key, pose_done_key, "Pose Init IK -> Pose Cleanup");
|
2016-11-17 14:34:46 +01:00
|
|
|
/* Make sure pose is up-to-date with armature updates. */
|
2018-06-06 11:41:56 +02:00
|
|
|
build_armature(armature);
|
2019-06-28 10:13:57 +02:00
|
|
|
OperationKey armature_key(&armature->id, NodeType::ARMATURE, OperationCode::ARMATURE_EVAL);
|
2018-11-07 15:04:08 +01:00
|
|
|
add_relation(armature_key, pose_init_key, "Data dependency");
|
2019-04-01 16:09:26 +02:00
|
|
|
/* Run cleanup even when there are no bones. */
|
|
|
|
|
add_relation(pose_init_key, pose_cleanup_key, "Init -> Cleanup");
|
2019-04-01 16:33:28 +02:00
|
|
|
/* IK Solvers.
|
2018-11-07 15:04:08 +01:00
|
|
|
*
|
2018-11-22 15:50:42 +01:00
|
|
|
* - These require separate processing steps are pose-level to be executed
|
|
|
|
|
* between chains of bones (i.e. once the base transforms of a bunch of
|
|
|
|
|
* bones is done).
|
2016-11-17 14:34:46 +01:00
|
|
|
*
|
2018-11-22 15:50:42 +01:00
|
|
|
* - We build relations for these before the dependencies between operations
|
|
|
|
|
* in the same component as it is necessary to check whether such bones
|
|
|
|
|
* are in the same IK chain (or else we get weird issues with either
|
|
|
|
|
* in-chain references, or with bones being parented to IK'd bones).
|
2016-11-17 14:34:46 +01:00
|
|
|
*
|
|
|
|
|
* Unsolved Issues:
|
2018-06-06 11:41:56 +02:00
|
|
|
* - Care is needed to ensure that multi-headed trees work out the same as
|
|
|
|
|
* in ik-tree building
|
2018-11-22 14:54:08 +01:00
|
|
|
* - Animated chain-lengths are a problem. */
|
2016-11-17 14:34:46 +01:00
|
|
|
RootPChanMap root_map;
|
|
|
|
|
bool pose_depends_on_local_transform = false;
|
2018-02-15 12:38:21 +01:00
|
|
|
LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
|
|
|
|
|
LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) {
|
2016-11-17 14:34:46 +01:00
|
|
|
switch (con->type) {
|
|
|
|
|
case CONSTRAINT_TYPE_KINEMATIC:
|
2017-11-23 11:39:28 +01:00
|
|
|
build_ik_pose(object, pchan, con, &root_map);
|
2016-11-17 14:34:46 +01:00
|
|
|
pose_depends_on_local_transform = true;
|
|
|
|
|
break;
|
|
|
|
|
case CONSTRAINT_TYPE_SPLINEIK:
|
2017-11-23 11:39:28 +01:00
|
|
|
build_splineik_pose(object, pchan, con, &root_map);
|
2016-11-17 14:34:46 +01:00
|
|
|
pose_depends_on_local_transform = true;
|
|
|
|
|
break;
|
|
|
|
|
/* Constraints which needs world's matrix for transform.
|
2018-11-22 14:54:08 +01:00
|
|
|
* TODO(sergey): More constraints here? */
|
2016-11-17 14:34:46 +01:00
|
|
|
case CONSTRAINT_TYPE_ROTLIKE:
|
|
|
|
|
case CONSTRAINT_TYPE_SIZELIKE:
|
|
|
|
|
case CONSTRAINT_TYPE_LOCLIKE:
|
|
|
|
|
case CONSTRAINT_TYPE_TRANSLIKE:
|
|
|
|
|
/* TODO(sergey): Add used space check. */
|
|
|
|
|
pose_depends_on_local_transform = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-22 15:50:42 +01:00
|
|
|
// root_map.print_debug();
|
2016-11-17 14:34:46 +01:00
|
|
|
if (pose_depends_on_local_transform) {
|
|
|
|
|
/* TODO(sergey): Once partial updates are possible use relation between
|
2018-11-22 14:54:08 +01:00
|
|
|
* object transform and solver itself in its build function. */
|
2019-01-31 12:56:40 +01:00
|
|
|
ComponentKey pose_key(&object->id, NodeType::EVAL_POSE);
|
|
|
|
|
ComponentKey local_transform_key(&object->id, NodeType::TRANSFORM);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(local_transform_key, pose_key, "Local Transforms");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
2018-06-06 11:41:56 +02:00
|
|
|
/* Links between operations for each bone. */
|
2018-02-15 12:38:21 +01:00
|
|
|
LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
|
2020-04-28 11:45:57 +02:00
|
|
|
build_idproperties(pchan->prop);
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey bone_local_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_LOCAL);
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey bone_pose_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_POSE_PARENT);
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey bone_ready_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_READY);
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey bone_done_key(&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_DONE);
|
2016-11-17 14:34:46 +01:00
|
|
|
pchan->flag &= ~POSE_DONE;
|
2017-07-19 12:44:27 +02:00
|
|
|
/* Pose init to bone local. */
|
2018-11-22 14:54:08 +01:00
|
|
|
add_relation(pose_init_key, bone_local_key, "Pose Init - Bone Local", RELATION_FLAG_GODMODE);
|
2017-07-19 12:44:27 +02:00
|
|
|
/* Local to pose parenting operation. */
|
2018-11-07 15:04:08 +01:00
|
|
|
add_relation(bone_local_key, bone_pose_key, "Bone Local - Bone Pose");
|
2017-07-19 12:44:27 +02:00
|
|
|
/* Parent relation. */
|
2020-01-28 14:50:13 +01:00
|
|
|
if (pchan->parent != nullptr) {
|
2019-01-31 12:56:40 +01:00
|
|
|
OperationCode parent_key_opcode;
|
2018-06-06 11:41:56 +02:00
|
|
|
/* NOTE: this difference in handling allows us to prevent lockups
|
2018-11-22 14:54:08 +01:00
|
|
|
* while ensuring correct poses for separate chains. */
|
2016-11-17 14:34:46 +01:00
|
|
|
if (root_map.has_common_root(pchan->name, pchan->parent->name)) {
|
2019-01-31 12:56:40 +01:00
|
|
|
parent_key_opcode = OperationCode::BONE_READY;
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2019-01-31 12:56:40 +01:00
|
|
|
parent_key_opcode = OperationCode::BONE_DONE;
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey parent_key(&object->id, NodeType::BONE, pchan->parent->name, parent_key_opcode);
|
2018-11-22 15:50:42 +01:00
|
|
|
add_relation(parent_key, bone_pose_key, "Parent Bone -> Child Bone");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
2018-09-24 18:46:51 +02:00
|
|
|
/* Build constraints. */
|
2020-01-28 14:50:13 +01:00
|
|
|
if (pchan->constraints.first != nullptr) {
|
2018-04-10 11:56:20 +02:00
|
|
|
/* Build relations for indirectly linked objects. */
|
|
|
|
|
BuilderWalkUserData data;
|
|
|
|
|
data.builder = this;
|
2018-11-22 15:50:42 +01:00
|
|
|
BKE_constraints_id_loop(&pchan->constraints, constraint_walk, &data);
|
2018-11-07 15:04:08 +01:00
|
|
|
/* Constraints stack and constraint dependencies. */
|
|
|
|
|
build_constraints(&object->id, NodeType::BONE, pchan->name, &pchan->constraints, &root_map);
|
|
|
|
|
/* Pose -> constraints. */
|
|
|
|
|
OperationKey constraints_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_CONSTRAINTS);
|
2019-03-13 15:13:52 +01:00
|
|
|
add_relation(bone_pose_key, constraints_key, "Pose -> Constraints Stack");
|
|
|
|
|
add_relation(bone_local_key, constraints_key, "Local -> Constraints Stack");
|
2018-11-07 15:04:08 +01:00
|
|
|
/* Constraints -> ready/ */
|
|
|
|
|
/* TODO(sergey): When constraint stack is exploded, this step should
|
2018-11-22 14:54:08 +01:00
|
|
|
* occur before the first IK solver. */
|
2018-11-07 15:04:08 +01:00
|
|
|
add_relation(constraints_key, bone_ready_key, "Constraints -> Ready");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-11-07 15:04:08 +01:00
|
|
|
/* Pose -> Ready */
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(bone_pose_key, bone_ready_key, "Pose -> Ready");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
2018-11-07 15:04:08 +01:00
|
|
|
/* Bone ready -> Bone done.
|
2016-11-17 14:34:46 +01:00
|
|
|
* NOTE: For bones without IK, this is all that's needed.
|
2018-06-06 11:41:56 +02:00
|
|
|
* For IK chains however, an additional rel is created from IK
|
2018-11-22 14:54:08 +01:00
|
|
|
* to done, with transitive reduction removing this one. */
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(bone_ready_key, bone_done_key, "Ready -> Done");
|
2018-11-22 13:38:03 +03:00
|
|
|
/* B-Bone shape is the real final step after Done if present. */
|
2019-04-29 14:19:56 +02:00
|
|
|
if (check_pchan_has_bbone(object, pchan)) {
|
2018-11-22 13:38:03 +03:00
|
|
|
OperationKey bone_segments_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_SEGMENTS);
|
2018-11-22 13:38:03 +03:00
|
|
|
/* B-Bone shape depends on the final position of the bone. */
|
2018-12-07 11:06:09 +01:00
|
|
|
add_relation(bone_done_key, bone_segments_key, "Done -> B-Bone Segments");
|
2018-11-22 13:38:03 +03:00
|
|
|
/* B-Bone shape depends on final position of handle bones. */
|
|
|
|
|
bPoseChannel *prev, *next;
|
2018-12-02 14:32:31 +11:00
|
|
|
BKE_pchan_bbone_handles_get(pchan, &prev, &next);
|
2018-11-22 13:38:03 +03:00
|
|
|
if (prev) {
|
2019-05-14 22:24:34 +03:00
|
|
|
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 &&
|
|
|
|
|
check_pchan_has_bbone_segments(object, prev)) {
|
|
|
|
|
opcode = OperationCode::BONE_SEGMENTS;
|
|
|
|
|
}
|
|
|
|
|
OperationKey prev_key(&object->id, NodeType::BONE, prev->name, opcode);
|
2018-12-07 11:06:09 +01:00
|
|
|
add_relation(prev_key, bone_segments_key, "Prev Handle -> B-Bone Segments");
|
2018-11-22 13:38:03 +03:00
|
|
|
}
|
|
|
|
|
if (next) {
|
|
|
|
|
OperationKey next_key(&object->id, NodeType::BONE, next->name, OperationCode::BONE_DONE);
|
2018-12-07 11:06:09 +01:00
|
|
|
add_relation(next_key, bone_segments_key, "Next Handle -> B-Bone Segments");
|
2018-11-22 13:38:03 +03:00
|
|
|
}
|
|
|
|
|
/* Pose requires the B-Bone shape. */
|
2018-12-07 11:06:09 +01:00
|
|
|
add_relation(
|
2018-12-07 11:17:34 +01:00
|
|
|
bone_segments_key, pose_done_key, "PoseEval Result-Bone Link", RELATION_FLAG_GODMODE);
|
2018-12-07 11:06:09 +01:00
|
|
|
add_relation(bone_segments_key, pose_cleanup_key, "Cleanup dependency");
|
2018-11-22 13:38:03 +03:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Assume that all bones must be done for the pose to be ready
|
|
|
|
|
* (for deformers). */
|
2018-12-07 11:06:09 +01:00
|
|
|
add_relation(bone_done_key, pose_done_key, "PoseEval Result-Bone Link");
|
2019-03-13 15:13:52 +01:00
|
|
|
|
|
|
|
|
/* Bones must be traversed before cleanup. */
|
2018-12-07 11:06:09 +01:00
|
|
|
add_relation(bone_done_key, pose_cleanup_key, "Done -> Cleanup");
|
2019-03-13 15:13:52 +01:00
|
|
|
|
|
|
|
|
add_relation(bone_ready_key, pose_cleanup_key, "Ready -> Cleanup");
|
2018-11-22 13:38:03 +03:00
|
|
|
}
|
2017-07-19 12:44:27 +02:00
|
|
|
/* Custom shape. */
|
2020-01-28 14:50:13 +01:00
|
|
|
if (pchan->custom != nullptr) {
|
2020-06-26 12:46:16 +02:00
|
|
|
build_object(pchan->custom);
|
2017-07-19 12:44:27 +02:00
|
|
|
}
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 11:39:28 +01:00
|
|
|
void DepsgraphRelationBuilder::build_proxy_rig(Object *object)
|
2016-11-17 14:34:46 +01:00
|
|
|
{
|
2018-06-06 11:41:56 +02:00
|
|
|
bArmature *armature = (bArmature *)object->data;
|
2018-01-29 15:06:44 +01:00
|
|
|
Object *proxy_from = object->proxy_from;
|
2018-06-06 11:41:56 +02:00
|
|
|
build_armature(armature);
|
2018-01-29 14:43:12 +01:00
|
|
|
OperationKey pose_init_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_INIT);
|
|
|
|
|
OperationKey pose_done_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_DONE);
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey pose_cleanup_key(&object->id, NodeType::EVAL_POSE, OperationCode::POSE_CLEANUP);
|
2018-02-15 12:38:21 +01:00
|
|
|
LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
|
2020-04-28 11:45:57 +02:00
|
|
|
build_idproperties(pchan->prop);
|
2018-01-29 14:43:12 +01:00
|
|
|
OperationKey bone_local_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_LOCAL);
|
2018-01-29 14:43:12 +01:00
|
|
|
OperationKey bone_ready_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_READY);
|
2018-01-29 14:43:12 +01:00
|
|
|
OperationKey bone_done_key(&object->id, NodeType::BONE, pchan->name, OperationCode::BONE_DONE);
|
2018-07-31 13:23:01 +02:00
|
|
|
OperationKey from_bone_done_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&proxy_from->id, NodeType::BONE, pchan->name, OperationCode::BONE_DONE);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(pose_init_key, bone_local_key, "Pose Init -> Bone Local");
|
|
|
|
|
add_relation(bone_local_key, bone_ready_key, "Local -> Ready");
|
|
|
|
|
add_relation(bone_ready_key, bone_done_key, "Ready -> Done");
|
2018-11-07 15:04:08 +01:00
|
|
|
add_relation(bone_done_key, pose_cleanup_key, "Bone Done -> Pose Cleanup");
|
2018-12-07 11:17:34 +01:00
|
|
|
add_relation(bone_done_key, pose_done_key, "Bone Done -> Pose Done", RELATION_FLAG_GODMODE);
|
2018-07-31 13:23:01 +02:00
|
|
|
/* Make sure bone in the proxy is not done before its FROM is done. */
|
2019-04-29 14:19:56 +02:00
|
|
|
if (check_pchan_has_bbone(object, pchan)) {
|
2018-11-22 13:38:03 +03:00
|
|
|
OperationKey from_bone_segments_key(
|
2019-01-31 12:56:40 +01:00
|
|
|
&proxy_from->id, NodeType::BONE, pchan->name, OperationCode::BONE_SEGMENTS);
|
2018-11-22 13:38:03 +03:00
|
|
|
add_relation(from_bone_segments_key,
|
|
|
|
|
bone_done_key,
|
2018-12-07 11:17:34 +01:00
|
|
|
"Bone Segments -> Bone Done",
|
2019-01-31 12:56:40 +01:00
|
|
|
RELATION_FLAG_GODMODE);
|
2018-11-22 13:38:03 +03:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
add_relation(from_bone_done_key, bone_done_key, "Bone Done -> Bone Done");
|
|
|
|
|
}
|
2018-07-31 13:23:01 +02:00
|
|
|
|
2019-04-15 19:53:52 +03:00
|
|
|
/* Parent relation: even though the proxy bone itself doesn't need
|
|
|
|
|
* the parent bone, some users expect the parent to be ready if the
|
|
|
|
|
* bone itself is (e.g. for computing the local space matrix).
|
|
|
|
|
*/
|
2020-01-28 14:50:13 +01:00
|
|
|
if (pchan->parent != nullptr) {
|
2019-04-15 19:53:52 +03:00
|
|
|
OperationKey parent_key(
|
|
|
|
|
&object->id, NodeType::BONE, pchan->parent->name, OperationCode::BONE_DONE);
|
|
|
|
|
add_relation(parent_key, bone_done_key, "Parent Bone -> Child Bone");
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 14:50:13 +01:00
|
|
|
if (pchan->prop != nullptr) {
|
2018-01-29 15:06:44 +01:00
|
|
|
OperationKey bone_parameters(
|
2019-01-31 12:56:40 +01:00
|
|
|
&object->id, NodeType::PARAMETERS, OperationCode::PARAMETERS_EVAL, pchan->name);
|
2018-01-29 15:06:44 +01:00
|
|
|
OperationKey from_bone_parameters(
|
2019-01-31 12:56:40 +01:00
|
|
|
&proxy_from->id, NodeType::PARAMETERS, OperationCode::PARAMETERS_EVAL, pchan->name);
|
2018-01-29 15:06:44 +01:00
|
|
|
add_relation(from_bone_parameters, bone_parameters, "Proxy Bone Parameters");
|
|
|
|
|
}
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-29 15:19:56 +02:00
|
|
|
} // namespace blender::deg
|