2016-11-17 14:34:46 +01:00
|
|
|
/*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Original Author: Joshua Leung
|
|
|
|
|
* Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2016-11-17 15:38:03 +01:00
|
|
|
/** \file blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
|
2016-11-17 14:34:46 +01:00
|
|
|
* \ingroup depsgraph
|
|
|
|
|
*
|
|
|
|
|
* Methods for constructing depsgraph
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "intern/builder/deg_builder_relations.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <cstring> /* required for STREQ later on. */
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
2017-06-06 12:14:39 +02:00
|
|
|
#include "BLI_blenlib.h"
|
2016-11-17 14:34:46 +01:00
|
|
|
|
2017-06-06 12:14:39 +02:00
|
|
|
extern "C" {
|
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"
|
2017-06-06 12:14:39 +02:00
|
|
|
} /* extern "C" */
|
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"
|
|
|
|
|
|
|
|
|
|
#include "intern/nodes/deg_node.h"
|
|
|
|
|
#include "intern/nodes/deg_node_component.h"
|
|
|
|
|
#include "intern/nodes/deg_node_operation.h"
|
|
|
|
|
|
|
|
|
|
#include "intern/depsgraph_intern.h"
|
|
|
|
|
#include "intern/depsgraph_types.h"
|
|
|
|
|
|
|
|
|
|
#include "util/deg_util_foreach.h"
|
|
|
|
|
|
|
|
|
|
namespace DEG {
|
|
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
|
{
|
|
|
|
|
bKinematicConstraint *data = (bKinematicConstraint *)con->data;
|
|
|
|
|
|
|
|
|
|
/* attach owner to IK Solver too
|
|
|
|
|
* - assume that owner is always part of chain
|
|
|
|
|
* - see notes on direction of rel below...
|
|
|
|
|
*/
|
|
|
|
|
bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data);
|
2017-10-16 22:20:34 +11:00
|
|
|
if (rootchan == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey pchan_local_key(&object->id, DEG_NODE_TYPE_BONE,
|
2017-09-25 18:48:38 +05:00
|
|
|
pchan->name, DEG_OPCODE_BONE_LOCAL);
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey init_ik_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
|
|
|
|
|
OperationKey solver_key(&object->id, DEG_NODE_TYPE_EVAL_POSE,
|
2017-09-25 18:48:38 +05:00
|
|
|
rootchan->name,
|
|
|
|
|
DEG_OPCODE_POSE_IK_SOLVER);
|
|
|
|
|
|
|
|
|
|
add_relation(pchan_local_key, init_ik_key, "IK Constraint -> Init IK Tree");
|
|
|
|
|
add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
/* IK target */
|
|
|
|
|
// XXX: this should get handled as part of the constraint code
|
|
|
|
|
if (data->tar != NULL) {
|
|
|
|
|
/* TODO(sergey): For until we'll store partial matricies in the depsgraph,
|
|
|
|
|
* we create dependency between target object and pose eval component.
|
|
|
|
|
*
|
|
|
|
|
* This way we ensuring the whole subtree is updated from scratch without
|
|
|
|
|
* need of intermediate matricies. This is an overkill, but good enough for
|
|
|
|
|
* testing IK solver.
|
|
|
|
|
*/
|
|
|
|
|
// FIXME: geometry targets...
|
2017-11-23 11:39:28 +01:00
|
|
|
ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
|
2016-11-17 14:34:46 +01:00
|
|
|
if ((data->tar->type == OB_ARMATURE) && (data->subtarget[0])) {
|
|
|
|
|
/* TODO(sergey): This is only for until granular update stores intermediate result. */
|
2017-11-23 11:39:28 +01:00
|
|
|
if (data->tar != object) {
|
2016-11-17 14:34:46 +01:00
|
|
|
/* different armature - can just read the results */
|
2017-06-01 15:40:02 +02:00
|
|
|
ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_BONE, data->subtarget);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(target_key, pose_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* same armature - we'll use the ready state only, just in case this bone is in the chain we're solving */
|
2017-06-01 15:40:02 +02:00
|
|
|
OperationKey target_key(&data->tar->id, DEG_NODE_TYPE_BONE, data->subtarget, DEG_OPCODE_BONE_DONE);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(target_key, solver_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (ELEM(data->tar->type, OB_MESH, OB_LATTICE) && (data->subtarget[0])) {
|
|
|
|
|
/* vertex group target */
|
|
|
|
|
/* NOTE: for now, we don't need to represent vertex groups separately... */
|
2017-06-01 15:40:02 +02:00
|
|
|
ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(target_key, solver_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
if (data->tar->type == OB_MESH) {
|
2018-10-14 19:59:27 +03:00
|
|
|
add_customdata_mask(target_key, CD_MASK_MDEFORMVERT);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Standard Object Target */
|
2017-06-01 15:40:02 +02:00
|
|
|
ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_TRANSFORM);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(target_key, pose_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-11-23 11:39:28 +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
|
|
|
|
|
* chain that it controls.
|
|
|
|
|
*/
|
|
|
|
|
root_map->add_bone(data->subtarget, rootchan->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Pole Target */
|
|
|
|
|
// XXX: this should get handled as part of the constraint code
|
|
|
|
|
if (data->poletar != NULL) {
|
|
|
|
|
if ((data->poletar->type == OB_ARMATURE) && (data->polesubtarget[0])) {
|
|
|
|
|
// XXX: same armature issues - ready vs done?
|
2017-06-01 15:40:02 +02:00
|
|
|
ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_BONE, data->polesubtarget);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(target_key, solver_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
else if (ELEM(data->poletar->type, OB_MESH, OB_LATTICE) && (data->polesubtarget[0])) {
|
|
|
|
|
/* vertex group target */
|
|
|
|
|
/* NOTE: for now, we don't need to represent vertex groups separately... */
|
2017-06-01 15:40:02 +02:00
|
|
|
ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_GEOMETRY);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(target_key, solver_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
if (data->poletar->type == OB_MESH) {
|
2018-10-14 19:59:27 +03:00
|
|
|
add_customdata_mask(target_key, CD_MASK_MDEFORMVERT);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2017-06-01 15:40:02 +02:00
|
|
|
ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_TRANSFORM);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(target_key, solver_key, con->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 11:52:49 +02:00
|
|
|
DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
|
|
|
|
|
BUILD, "\nStarting IK Build: pchan = %s, target = (%s, %s), segcount = %d\n",
|
2016-11-17 14:34:46 +01:00
|
|
|
pchan->name, data->tar->id.name, data->subtarget, data->rootbone);
|
|
|
|
|
|
|
|
|
|
bPoseChannel *parchan = pchan;
|
|
|
|
|
/* exclude tip from chain? */
|
|
|
|
|
if (!(data->flag & CONSTRAINT_IK_TIP)) {
|
|
|
|
|
parchan = pchan->parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
root_map->add_bone(parchan->name, rootchan->name);
|
|
|
|
|
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey parchan_transforms_key(&object->id, DEG_NODE_TYPE_BONE,
|
2016-11-17 14:34:46 +01:00
|
|
|
parchan->name, DEG_OPCODE_BONE_READY);
|
2017-06-01 16:20:48 +02:00
|
|
|
add_relation(parchan_transforms_key, solver_key, "IK Solver Owner");
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
/* Walk to the chain's root */
|
|
|
|
|
//size_t segcount = 0;
|
|
|
|
|
int segcount = 0;
|
|
|
|
|
|
|
|
|
|
while (parchan) {
|
|
|
|
|
/* 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...
|
|
|
|
|
*/
|
|
|
|
|
if (parchan != pchan) {
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey parent_key(&object->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(parent_key, solver_key, "IK Chain Parent");
|
2016-11-17 14:34:46 +01:00
|
|
|
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey done_key(&object->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(solver_key, done_key, "IK Chain Result");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey final_transforms_key(&object->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_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);
|
|
|
|
|
|
|
|
|
|
/* continue up chain, until we reach target number of items... */
|
2018-05-02 11:52:49 +02:00
|
|
|
DEG_DEBUG_PRINTF((::Depsgraph *)graph_, BUILD, " %d = %s\n", segcount, parchan->name);
|
2016-11-17 14:34:46 +01:00
|
|
|
segcount++;
|
|
|
|
|
if ((segcount == data->rootbone) || (segcount > 255)) break; /* 255 is weak */
|
|
|
|
|
|
|
|
|
|
parchan = parchan->parent;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey done_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
|
|
|
|
|
add_relation(solver_key, done_key, "PoseEval Result-Bone Link");
|
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);
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey transforms_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY);
|
2018-09-26 18:16:16 +02:00
|
|
|
OperationKey init_ik_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey solver_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
|
2016-11-17 14:34:46 +01:00
|
|
|
|
2018-09-26 18:16:16 +02:00
|
|
|
/* Solver depends on initialization. */
|
|
|
|
|
add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
|
|
|
|
|
|
2016-11-17 14:34:46 +01:00
|
|
|
/* attach owner to IK Solver too
|
|
|
|
|
* - assume that owner is always part of chain
|
|
|
|
|
* - see notes on direction of rel below...
|
|
|
|
|
*/
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(transforms_key, solver_key, "Spline IK Solver Owner");
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
/* attach path dependency to solver */
|
|
|
|
|
if (data->tar) {
|
|
|
|
|
/* TODO(sergey): For until we'll store partial matricies in the depsgraph,
|
|
|
|
|
* we create dependency between target object and pose eval component.
|
|
|
|
|
* See IK pose for a bit more information.
|
|
|
|
|
*/
|
|
|
|
|
// TODO: the bigggest point here is that we need the curve PATH and not just the general geometry...
|
2017-06-01 15:40:02 +02:00
|
|
|
ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY);
|
2017-11-23 11:39:28 +01:00
|
|
|
ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
|
2017-12-04 12:48:16 +01:00
|
|
|
add_relation(target_key, pose_key, "Curve.Path -> Spline IK");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pchan->flag |= POSE_DONE;
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey final_transforms_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_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);
|
|
|
|
|
|
|
|
|
|
/* Walk to the chain's root */
|
|
|
|
|
//size_t segcount = 0;
|
|
|
|
|
int segcount = 0;
|
|
|
|
|
|
|
|
|
|
for (bPoseChannel *parchan = pchan->parent; parchan; parchan = parchan->parent) {
|
|
|
|
|
/* 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...
|
|
|
|
|
*/
|
|
|
|
|
if (parchan != pchan) {
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey parent_key(&object->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(parent_key, solver_key, "Spline IK Solver Update");
|
2016-11-17 14:34:46 +01:00
|
|
|
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey done_key(&object->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(solver_key, done_key, "IK Chain Result");
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
parchan->flag |= POSE_DONE;
|
|
|
|
|
|
2017-11-23 11:39:28 +01:00
|
|
|
OperationKey final_transforms_key(&object->id, DEG_NODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(solver_key, final_transforms_key, "Spline IK Solver Result");
|
2016-11-17 14:34:46 +01:00
|
|
|
|
|
|
|
|
root_map->add_bone(parchan->name, rootchan->name);
|
|
|
|
|
|
|
|
|
|
/* continue up chain, until we reach target number of items... */
|
|
|
|
|
segcount++;
|
|
|
|
|
if ((segcount == data->chainlen) || (segcount > 255)) break; /* 255 is weak */
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey done_key(&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
|
|
|
|
|
add_relation(solver_key, done_key, "PoseEval Result-Bone Link");
|
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. */
|
2018-06-27 15:27:58 +02:00
|
|
|
ComponentKey local_transform(&object->id, DEG_NODE_TYPE_TRANSFORM);
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey pose_init_key(
|
|
|
|
|
&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
|
|
|
|
|
OperationKey pose_init_ik_key(
|
|
|
|
|
&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
|
|
|
|
|
OperationKey pose_cleanup_key(
|
|
|
|
|
&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_CLEANUP);
|
|
|
|
|
OperationKey pose_done_key(
|
|
|
|
|
&object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
|
|
|
|
|
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);
|
|
|
|
|
OperationKey armature_key(&armature->id,
|
|
|
|
|
DEG_NODE_TYPE_PARAMETERS,
|
|
|
|
|
DEG_OPCODE_PLACEHOLDER,
|
|
|
|
|
"Armature Eval");
|
2018-11-07 15:04:08 +01:00
|
|
|
add_relation(armature_key, pose_init_key, "Data dependency");
|
|
|
|
|
/* IK Solvers.
|
|
|
|
|
*
|
2016-11-17 14:34:46 +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)
|
|
|
|
|
*
|
|
|
|
|
* - We build relations for these before the dependencies
|
|
|
|
|
* between ops 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)
|
|
|
|
|
*
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//root_map.print_debug();
|
|
|
|
|
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 it's build function. */
|
2017-11-23 11:39:28 +01:00
|
|
|
ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
|
|
|
|
|
ComponentKey local_transform_key(&object->id, DEG_NODE_TYPE_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) {
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey bone_local_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_BONE_LOCAL);
|
|
|
|
|
OperationKey bone_pose_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_BONE_POSE_PARENT);
|
|
|
|
|
OperationKey bone_ready_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_BONE_READY);
|
|
|
|
|
OperationKey bone_done_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_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",
|
|
|
|
|
DEPSREL_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. */
|
2016-11-17 14:34:46 +01:00
|
|
|
if (pchan->parent != NULL) {
|
|
|
|
|
eDepsOperation_Code 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)) {
|
|
|
|
|
parent_key_opcode = DEG_OPCODE_BONE_READY;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
parent_key_opcode = DEG_OPCODE_BONE_DONE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey parent_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->parent->name,
|
|
|
|
|
parent_key_opcode);
|
2017-12-04 12:48:16 +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. */
|
2016-11-17 14:34:46 +01:00
|
|
|
if (pchan->constraints.first != NULL) {
|
2018-04-10 11:56:20 +02:00
|
|
|
/* Build relations for indirectly linked objects. */
|
|
|
|
|
BuilderWalkUserData data;
|
|
|
|
|
data.builder = this;
|
|
|
|
|
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,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
&pchan->constraints,
|
|
|
|
|
&root_map);
|
|
|
|
|
/* Pose -> constraints. */
|
|
|
|
|
OperationKey constraints_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_BONE_CONSTRAINTS);
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(bone_pose_key, constraints_key, "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 14:54:08 +01:00
|
|
|
/* Assume that all bones must be done for the pose to be ready
|
|
|
|
|
* (for deformers). */
|
2018-11-07 15:04:08 +01:00
|
|
|
add_relation(bone_done_key, pose_done_key, "PoseEval Result-Bone Link");
|
|
|
|
|
add_relation(bone_done_key, pose_cleanup_key, "Cleanup dependency");
|
2017-07-19 12:44:27 +02:00
|
|
|
/* Custom shape. */
|
|
|
|
|
if (pchan->custom != NULL) {
|
2017-11-24 14:25:04 +01:00
|
|
|
build_object(NULL, 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,
|
|
|
|
|
DEG_NODE_TYPE_EVAL_POSE,
|
|
|
|
|
DEG_OPCODE_POSE_INIT);
|
|
|
|
|
OperationKey pose_done_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_EVAL_POSE,
|
|
|
|
|
DEG_OPCODE_POSE_DONE);
|
2018-11-07 15:04:08 +01:00
|
|
|
OperationKey pose_cleanup_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_EVAL_POSE,
|
|
|
|
|
DEG_OPCODE_POSE_CLEANUP);
|
2018-02-15 12:38:21 +01:00
|
|
|
LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
|
2018-01-29 14:43:12 +01:00
|
|
|
OperationKey bone_local_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE, pchan->name,
|
|
|
|
|
DEG_OPCODE_BONE_LOCAL);
|
|
|
|
|
OperationKey bone_ready_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_BONE_READY);
|
|
|
|
|
OperationKey bone_done_key(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_BONE_DONE);
|
2018-07-31 13:23:01 +02:00
|
|
|
OperationKey from_bone_done_key(&proxy_from->id,
|
|
|
|
|
DEG_NODE_TYPE_BONE,
|
|
|
|
|
pchan->name,
|
|
|
|
|
DEG_OPCODE_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");
|
2017-06-01 14:49:17 +02:00
|
|
|
add_relation(bone_done_key, pose_done_key, "Bone Done -> Pose Done");
|
2018-01-29 15:06:44 +01:00
|
|
|
|
2018-07-31 13:23:01 +02:00
|
|
|
/* Make sure bone in the proxy is not done before it's FROM is done. */
|
|
|
|
|
add_relation(from_bone_done_key,
|
|
|
|
|
bone_done_key,
|
|
|
|
|
"From Bone Done -> Pose Done");
|
|
|
|
|
|
2018-01-29 15:06:44 +01:00
|
|
|
if (pchan->prop != NULL) {
|
|
|
|
|
OperationKey bone_parameters(&object->id,
|
|
|
|
|
DEG_NODE_TYPE_PARAMETERS,
|
|
|
|
|
DEG_OPCODE_PARAMETERS_EVAL,
|
|
|
|
|
pchan->name);
|
|
|
|
|
OperationKey from_bone_parameters(&proxy_from->id,
|
|
|
|
|
DEG_NODE_TYPE_PARAMETERS,
|
|
|
|
|
DEG_OPCODE_PARAMETERS_EVAL,
|
|
|
|
|
pchan->name);
|
|
|
|
|
add_relation(from_bone_parameters,
|
|
|
|
|
bone_parameters,
|
|
|
|
|
"Proxy Bone Parameters");
|
|
|
|
|
}
|
2016-11-17 14:34:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace DEG
|