Blender V5.3
deg_builder_nodes_rig.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2013 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
12
13#include <cstdlib>
14
15#include "DNA_armature_types.h"
17#include "DNA_object_types.h"
18#include "DNA_scene_types.h"
19
20#include "BLI_listbase.hh"
21
22#include "BKE_action.hh"
23#include "BKE_armature.hh"
24#include "BKE_constraint.h"
25#include "BKE_lib_query.hh"
26
27#include "DEG_depsgraph.hh"
29
34
35namespace blender::deg {
36
38 bPoseChannel *pchan,
39 int pchan_index)
40{
41 /* Pull indirect dependencies via constraints. */
43 data.builder = this;
45
46 /* Create node for constraint stack. */
47 Scene *scene_cow = get_cow_datablock(scene_);
48 Object *object_cow = get_cow_datablock(object);
51 pchan->name,
53 [scene_cow, object_cow, pchan_index](blender::Depsgraph *depsgraph) {
54 BKE_pose_constraints_evaluate(
55 depsgraph, scene_cow, object_cow, pchan_index);
56 });
57}
58
60{
61 bKinematicConstraint *data = static_cast<bKinematicConstraint *>(con->data);
62
63 /* Find the chain's root. */
65 if (rootchan == nullptr) {
66 return;
67 }
68
71 {
72 return;
73 }
74
75 int rootchan_index = BLI_findindex(&object->pose->chanbase, rootchan);
76 BLI_assert(rootchan_index != -1);
77
78 /* Operation node for evaluating/running IK Solver. */
79 Scene *scene_cow = get_cow_datablock(scene_);
80 Object *object_cow = get_cow_datablock(object);
83 rootchan->name,
85 [scene_cow, object_cow, rootchan_index](blender::Depsgraph *depsgraph) {
86 BKE_pose_iktree_evaluate(depsgraph, scene_cow, object_cow, rootchan_index);
87 });
88}
89
91 bPoseChannel *pchan,
92 bConstraint *con)
93{
94 bSplineIKConstraint *data = static_cast<bSplineIKConstraint *>(con->data);
95
96 /* Find the chain's root. */
98
101 {
102 return;
103 }
104
105 /* Operation node for evaluating/running Spline IK Solver.
106 * Store the "root bone" of this chain in the solver, so it knows where to
107 * start. */
108 int rootchan_index = BLI_findindex(&object->pose->chanbase, rootchan);
109 BLI_assert(rootchan_index != -1);
110
111 Scene *scene_cow = get_cow_datablock(scene_);
112 Object *object_cow = get_cow_datablock(object);
115 rootchan->name,
117 [scene_cow, object_cow, rootchan_index](blender::Depsgraph *depsgraph) {
118 BKE_pose_splineik_evaluate(
119 depsgraph, scene_cow, object_cow, rootchan_index);
120 });
121}
122
123/* Pose/Armature Bones Graph */
125{
126 bArmature *armature = id_cast<bArmature *>(object->data);
127 Scene *scene_cow = get_cow_datablock(scene_);
128 Object *object_cow = get_cow_datablock(object);
129 OperationNode *op_node;
130 /* Animation and/or drivers linking pose-bones to base-armature used to define them.
131 *
132 * NOTE: AnimData here is really used to control animated deform properties,
133 * which ideally should be able to be unique across different
134 * instances. Eventually, we need some type of proxy/isolation
135 * mechanism in-between here to ensure that we can use same rig
136 * multiple times in same scene. */
137 /* Armature. */
138 build_armature(armature);
139 /* Rebuild pose if not up to date. */
140 if (object->pose == nullptr || (object->pose->flag & POSE_RECALC)) {
141 /* By definition, no need to tag depsgraph as dirty from here, so we can pass nullptr bmain. */
142 BKE_pose_rebuild(nullptr, object, armature, true);
143 }
144 else {
145 /* Ensure the pose bone indices are up to date, so that the rest of the depsgraph building code
146 * can use `pchan->bone_get(armature)`, which is faster than passing the object. */
148 }
149
150 /* Speed optimization for animation lookups. */
151 if (object->pose != nullptr) {
153 if (object->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
155 }
156 }
157 /* Pose Rig Graph
158 * ==============
159 *
160 * Pose Component:
161 * - Mainly used for referencing Bone components.
162 * - This is where the evaluation operations for init/exec/cleanup
163 * (ik) solvers live, and are later hooked up (so that they can be
164 * interleaved during runtime) with bone-operations they depend on/affect.
165 * - init_pose_eval() and cleanup_pose_eval() are absolute first and last
166 * steps of pose eval process. ALL bone operations must be performed
167 * between these two...
168 *
169 * Bone Component:
170 * - Used for representing each bone within the rig
171 * - Acts to encapsulate the evaluation operations (base matrix + parenting,
172 * and constraint stack) so that they can be easily found.
173 * - Everything else which depends on bone-results hook up to the component
174 * only so that we can redirect those to point at either the
175 * post-IK/post-constraint/post-matrix steps, as needed. */
176 /* Pose eval context. */
177 op_node = add_operation_node(&object->id,
180 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
181 BKE_pose_eval_init(depsgraph, scene_cow, object_cow);
182 });
183 op_node->set_as_entry();
184
185 op_node = add_operation_node(&object->id,
188 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
189 BKE_pose_eval_init_ik(depsgraph, scene_cow, object_cow);
190 });
191
195 [scene_cow, object_cow](blender::Depsgraph *depsgraph) {
196 BKE_pose_eval_cleanup(depsgraph, scene_cow, object_cow);
197 });
198
199 op_node = add_operation_node(
200 &object->id,
203 [object_cow](blender::Depsgraph *depsgraph) { BKE_pose_eval_done(depsgraph, object_cow); });
204 op_node->set_as_exit();
205 /* Bones. */
206 int pchan_index = 0;
207 for (bPoseChannel &pchan : object->pose->chanbase) {
208 /* Node for bone evaluation. */
209 op_node = add_operation_node(
211 op_node->set_as_entry();
212
213 /* Add a separate node for bone visibility. Getting the visibility doesn't need the pose of the
214 * bone to be evaluated, so drivers that target the bone's "hide" RNA property can depend on
215 * this operation, rather than the BONE_LOCAL node. See #152121. */
217
220 pchan.name,
222 [scene_cow, object_cow, pchan_index](blender::Depsgraph *depsgraph) {
223 BKE_pose_eval_bone(depsgraph, scene_cow, object_cow, pchan_index);
224 });
225
226 /* NOTE: Dedicated noop for easier relationship construction. */
228
229 op_node = add_operation_node(&object->id,
231 pchan.name,
233 [object_cow, pchan_index](blender::Depsgraph *depsgraph) {
234 BKE_pose_bone_done(depsgraph, object_cow, pchan_index);
235 });
236
237 /* B-Bone shape computation - the real last step if present. */
238 if (check_pchan_has_bbone(object, &pchan)) {
239 op_node = add_operation_node(&object->id,
241 pchan.name,
243 [object_cow, pchan_index](blender::Depsgraph *depsgraph) {
244 BKE_pose_eval_bbone_segments(
245 depsgraph, object_cow, pchan_index);
246 });
247 }
248
249 op_node->set_as_exit();
250
251 /* Custom properties. */
252 bool add_idprops_operation = false;
253 if (pchan.prop != nullptr) {
255 add_idprops_operation = true;
256 }
257 if (pchan.system_properties != nullptr) {
259 add_idprops_operation = true;
260 }
261 if (add_idprops_operation) {
264 }
265 /* Build constraints. */
266 if (pchan.constraints.first() != nullptr) {
267 build_pose_constraints(object, &pchan, pchan_index);
268 }
269 /* IK Solvers.
270 *
271 * - These require separate processing steps are pose-level
272 * to be executed between chains of bones (i.e. once the
273 * base transforms of a bunch of bones is done)
274 *
275 * Unsolved Issues:
276 * - Care is needed to ensure that multi-headed trees work out the same
277 * as in ik-tree building
278 * - Animated chain-lengths are a problem. */
279 for (bConstraint &con : pchan.constraints) {
280 switch (con.type) {
282 build_ik_pose(object, &pchan, &con);
283 break;
284
286 build_splineik_pose(object, &pchan, &con);
287 break;
288
289 default:
290 break;
291 }
292 }
293 /* Custom shape. */
294 if (pchan.custom != nullptr) {
295 /* NOTE: The relation builder will ensure visibility of the custom shape object. */
297 }
298 pchan_index++;
299 }
300}
301
302} // namespace blender::deg
Blender kernel action and pose functionality.
Object is a sort of wrapper for general info.
virtual bool check_pchan_has_bbone(const Object *object, const bPoseChannel *pchan)
virtual void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index)
virtual void build_object(int base_index, Object *object, eDepsNode_LinkedState_Type linked_state, bool is_visible)
OperationNode * add_operation_node(ComponentNode *comp_node, OperationCode opcode, const DepsEvalOperationCb &op=nullptr, const char *name="", int name_tag=-1)
static void constraint_walk(bConstraint *constraint, ID **idpoin, bool is_reference, void *user_data)
virtual void build_armature(bArmature *armature)
T * get_cow_datablock(const T *orig) const
virtual void build_ik_pose(Object *object, bPoseChannel *pchan, bConstraint *con)
virtual void build_rig(Object *object)
virtual void build_splineik_pose(Object *object, bPoseChannel *pchan, bConstraint *con)
virtual void build_idproperties(IDProperty *id_property)
bool has_operation_node(ID *id, NodeType comp_type, const char *comp_name, OperationCode opcode, const char *name="", int name_tag=-1)
@ DEG_ID_LINKED_INDIRECTLY
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, bool do_id_user)
@ POSE_CONSTRAINTS_NEED_UPDATE_FLAGS
void BKE_pose_channels_hash_ensure(bPose *pose) ATTR_NONNULL(1)
void BKE_pose_ensure_bone_indices(const Object &pose_object)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
BMesh const char void * data
void BKE_pose_update_constraint_flags(Object &pose_ob)
bPoseChannel * BKE_armature_splineik_solver_find_root(bPoseChannel *pchan, bSplineIKConstraint *data)
void BKE_constraints_id_loop(ListBaseT< bConstraint > *list, ConstraintIDFunc func, const int flag, void *userdata)
bPoseChannel * BKE_armature_ik_solver_find_root(bPoseChannel *pchan, bKinematicConstraint *data)
ListBaseT< struct bConstraint > constraints