Merge branch 'master' into blender2.8
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_relations_rig.cc
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Joshua Leung
22  * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
28  *  \ingroup depsgraph
29  *
30  * Methods for constructing depsgraph
31  */
32
33 #include "intern/builder/deg_builder_relations.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <cstring>  /* required for STREQ later on. */
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_utildefines.h"
42 #include "BLI_blenlib.h"
43
44 extern "C" {
45 #include "DNA_action_types.h"
46 #include "DNA_anim_types.h"
47 #include "DNA_armature_types.h"
48 #include "DNA_constraint_types.h"
49 #include "DNA_customdata_types.h"
50 #include "DNA_object_types.h"
51
52 #include "BKE_action.h"
53 #include "BKE_armature.h"
54 #include "BKE_constraint.h"
55 } /* extern "C" */
56
57 #include "DEG_depsgraph.h"
58 #include "DEG_depsgraph_build.h"
59
60 #include "intern/builder/deg_builder.h"
61 #include "intern/builder/deg_builder_pchanmap.h"
62
63 #include "intern/nodes/deg_node.h"
64 #include "intern/nodes/deg_node_component.h"
65 #include "intern/nodes/deg_node_operation.h"
66
67 #include "intern/depsgraph_intern.h"
68 #include "intern/depsgraph_types.h"
69
70 #include "util/deg_util_foreach.h"
71
72 namespace DEG {
73
74 /* IK Solver Eval Steps */
75 void DepsgraphRelationBuilder::build_ik_pose(Object *object,
76                                              bPoseChannel *pchan,
77                                              bConstraint *con,
78                                              RootPChanMap *root_map)
79 {
80         bKinematicConstraint *data = (bKinematicConstraint *)con->data;
81         /* Attach owner to IK Solver to. */
82         bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data);
83         if (rootchan == NULL) {
84                 return;
85         }
86         OperationKey pchan_local_key(&object->id,
87                                      DEG_NODE_TYPE_BONE,
88                                      pchan->name,
89                                      DEG_OPCODE_BONE_LOCAL);
90         OperationKey init_ik_key(
91                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
92         OperationKey solver_key(&object->id,
93                                 DEG_NODE_TYPE_EVAL_POSE,
94                                 rootchan->name,
95                                 DEG_OPCODE_POSE_IK_SOLVER);
96         OperationKey pose_cleanup_key(
97                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_CLEANUP);
98         add_relation(pchan_local_key, init_ik_key, "IK Constraint -> Init IK Tree");
99         add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
100         /* Never cleanup before solver is run. */
101         add_relation(solver_key,
102                      pose_cleanup_key,
103                      "IK Solver -> Cleanup",
104                      DEPSREL_FLAG_GODMODE);
105         /* IK target */
106         /* TODO(sergey): This should get handled as part of the constraint code. */
107         if (data->tar != NULL) {
108                 /* TODO(sergey): For until we'll store partial matricies in the
109                  * depsgraph, we create dependency between target object and pose eval
110                  * component.
111                  *
112                  * This way we ensuring the whole subtree is updated from scratch
113                  * without need of intermediate matricies. This is an overkill, but good
114                  * enough for testing IK solver. */
115                 ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
116                 if ((data->tar->type == OB_ARMATURE) && (data->subtarget[0])) {
117                         /* TODO(sergey): This is only for until granular update stores
118                          * intermediate result. */
119                         if (data->tar != object) {
120                                 /* Different armature - can just read the results. */
121                                 ComponentKey target_key(
122                                         &data->tar->id, DEG_NODE_TYPE_BONE, data->subtarget);
123                                 add_relation(target_key, pose_key, con->name);
124                         }
125                         else {
126                                 /* Same armature - we'll use the ready state only, just in case
127                                  * this bone is in the chain we're solving. */
128                                 OperationKey target_key(&data->tar->id,
129                                                         DEG_NODE_TYPE_BONE,
130                                                         data->subtarget,
131                                                         DEG_OPCODE_BONE_DONE);
132                                 add_relation(target_key, solver_key, con->name);
133                         }
134                 }
135                 else if (data->subtarget[0] &&
136                          ELEM(data->tar->type, OB_MESH, OB_LATTICE))
137                 {
138                         /* Vertex group target. */
139                         /* NOTE: for now, we don't need to represent vertex groups
140                          * separately. */
141                         ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY);
142                         add_relation(target_key, solver_key, con->name);
143                         if (data->tar->type == OB_MESH) {
144                                 add_customdata_mask(target_key, CD_MASK_MDEFORMVERT);
145                         }
146                 }
147                 else {
148                         /* Standard Object Target. */
149                         ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_TRANSFORM);
150                         add_relation(target_key, pose_key, con->name);
151                 }
152                 if (data->tar == object && data->subtarget[0]) {
153                         /* Prevent target's constraints from linking to anything from same
154                          * chain that it controls. */
155                         root_map->add_bone(data->subtarget, rootchan->name);
156                 }
157         }
158         /* Pole Target. */
159         /* TODO(sergey): This should get handled as part of the constraint code. */
160         if (data->poletar != NULL) {
161                 if ((data->poletar->type == OB_ARMATURE) && (data->polesubtarget[0])) {
162                         ComponentKey target_key(&data->poletar->id,
163                                                 DEG_NODE_TYPE_BONE,
164                                                 data->polesubtarget);
165                         add_relation(target_key, solver_key, con->name);
166                 }
167                 else if (data->polesubtarget[0] &&
168                          ELEM(data->poletar->type, OB_MESH, OB_LATTICE))
169                 {
170                         /* Vertex group target. */
171                         /* NOTE: for now, we don't need to represent vertex groups
172                          * separately. */
173                         ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_GEOMETRY);
174                         add_relation(target_key, solver_key, con->name);
175                         if (data->poletar->type == OB_MESH) {
176                                 add_customdata_mask(target_key, CD_MASK_MDEFORMVERT);
177                         }
178                 }
179                 else {
180                         ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_TRANSFORM);
181                         add_relation(target_key, solver_key, con->name);
182                 }
183         }
184         DEG_DEBUG_PRINTF(
185                 (::Depsgraph *)graph_,
186                 BUILD,
187                 "\nStarting IK Build: pchan = %s, target = (%s, %s), "
188                 "segcount = %d\n",
189                 pchan->name, data->tar->id.name, data->subtarget, data->rootbone);
190         bPoseChannel *parchan = pchan;
191         /* Exclude tip from chain if needed. */
192         if (!(data->flag & CONSTRAINT_IK_TIP)) {
193                 parchan = pchan->parent;
194         }
195         root_map->add_bone(parchan->name, rootchan->name);
196         OperationKey parchan_transforms_key(&object->id, DEG_NODE_TYPE_BONE,
197                                             parchan->name, DEG_OPCODE_BONE_READY);
198         add_relation(parchan_transforms_key, solver_key, "IK Solver Owner");
199         /* Walk to the chain's root. */
200         int segcount = 0;
201         while (parchan != NULL) {
202                 /* Make IK-solver dependent on this bone's result, since it can only run
203                  * after the standard results of the bone are know. Validate links step
204                  * on the bone will ensure that users of this bone only grab the result
205                  * with IK solver results. */
206                 if (parchan != pchan) {
207                         OperationKey parent_key(&object->id,
208                                                 DEG_NODE_TYPE_BONE,
209                                                 parchan->name,
210                                                 DEG_OPCODE_BONE_READY);
211                         add_relation(parent_key, solver_key, "IK Chain Parent");
212                         OperationKey bone_done_key(&object->id,
213                                                    DEG_NODE_TYPE_BONE,
214                                                    parchan->name,
215                                                    DEG_OPCODE_BONE_DONE);
216                         add_relation(solver_key, bone_done_key, "IK Chain Result");
217                 }
218                 else {
219                         OperationKey final_transforms_key(&object->id,
220                                                           DEG_NODE_TYPE_BONE,
221                                                           parchan->name,
222                                                           DEG_OPCODE_BONE_DONE);
223                         add_relation(solver_key, final_transforms_key, "IK Solver Result");
224                 }
225                 parchan->flag |= POSE_DONE;
226                 root_map->add_bone(parchan->name, rootchan->name);
227                 /* continue up chain, until we reach target number of items. */
228                 DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
229                                  BUILD,
230                                  "  %d = %s\n",
231                                  segcount, parchan->name);
232                 /* TODO(sergey): This is an arbitrary value, which was just following
233                  * old code convention. */
234                 segcount++;
235                 if ((segcount == data->rootbone) || (segcount > 255)) {
236                         break;
237                 }
238                 parchan  = parchan->parent;
239         }
240         OperationKey pose_done_key(
241                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
242         add_relation(solver_key, pose_done_key, "PoseEval Result-Bone Link");
243 }
244
245 /* Spline IK Eval Steps */
246 void DepsgraphRelationBuilder::build_splineik_pose(Object *object,
247                                                    bPoseChannel *pchan,
248                                                    bConstraint *con,
249                                                    RootPChanMap *root_map)
250 {
251         bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
252         bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
253         OperationKey transforms_key(&object->id,
254                                     DEG_NODE_TYPE_BONE,
255                                     pchan->name,
256                                     DEG_OPCODE_BONE_READY);
257         OperationKey init_ik_key(&object->id,
258                                  DEG_NODE_TYPE_EVAL_POSE,
259                                  DEG_OPCODE_POSE_INIT_IK);
260         OperationKey solver_key(&object->id,
261                                 DEG_NODE_TYPE_EVAL_POSE,
262                                 rootchan->name,
263                                 DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
264         OperationKey pose_cleanup_key(
265                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_CLEANUP);
266         /* Solver depends on initialization. */
267         add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
268         /* Never cleanup before solver is run. */
269         add_relation(solver_key, pose_cleanup_key, "IK Solver -> Cleanup");
270         /* Attach owner to IK Solver. */
271         add_relation(transforms_key,
272                      solver_key,
273                      "Spline IK Solver Owner",
274                      DEPSREL_FLAG_GODMODE);
275         /* Attach path dependency to solver. */
276         if (data->tar != NULL) {
277                 /* TODO(sergey): For until we'll store partial matricies in the
278                  * depsgraph, we create dependency between target object and pose eval
279                  * component. See IK pose for a bit more information.
280                  */
281                 /* TODO: the bigggest point here is that we need the curve PATH and not
282                  * just the general geometry. */
283                 ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY);
284                 ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
285                 add_relation(target_key, pose_key, "Curve.Path -> Spline IK");
286         }
287         pchan->flag |= POSE_DONE;
288         OperationKey final_transforms_key(
289                 &object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
290         add_relation(solver_key, final_transforms_key, "Spline IK Result");
291         root_map->add_bone(pchan->name, rootchan->name);
292         /* Walk to the chain's root/ */
293         int segcount = 0;
294         for (bPoseChannel *parchan = pchan->parent;
295              parchan != NULL;
296              parchan = parchan->parent)
297         {
298                 /* Make Spline IK solver dependent on this bone's result, since it can
299                  * only run after the standard results of the bone are know. Validate
300                  * links step on the bone will ensure that users of this bone only grab
301                  * the result with IK solver results. */
302                 if (parchan != pchan) {
303                         OperationKey parent_key(&object->id,
304                                                 DEG_NODE_TYPE_BONE,
305                                                 parchan->name,
306                                                 DEG_OPCODE_BONE_READY);
307                         add_relation(parent_key, solver_key, "Spline IK Solver Update");
308                         OperationKey bone_done_key(&object->id,
309                                                    DEG_NODE_TYPE_BONE,
310                                                    parchan->name,
311                                                    DEG_OPCODE_BONE_DONE);
312                         add_relation(solver_key, bone_done_key, "IK Chain Result");
313                 }
314                 parchan->flag |= POSE_DONE;
315                 OperationKey final_transforms_key(&object->id,
316                                                   DEG_NODE_TYPE_BONE,
317                                                   parchan->name,
318                                                   DEG_OPCODE_BONE_DONE);
319                 add_relation(
320                         solver_key, final_transforms_key, "Spline IK Solver Result");
321                 root_map->add_bone(parchan->name, rootchan->name);
322                 /* TODO(sergey): This is an arbitrary value, which was just following
323                  * old code convention. */
324                 segcount++;
325                 if ((segcount == data->chainlen) || (segcount > 255)) {
326                         break;
327                 }
328         }
329         OperationKey pose_done_key(
330                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
331         add_relation(solver_key, pose_done_key, "PoseEval Result-Bone Link");
332 }
333
334 /* Pose/Armature Bones Graph */
335 void DepsgraphRelationBuilder::build_rig(Object *object)
336 {
337         /* Armature-Data */
338         bArmature *armature = (bArmature *)object->data;
339         // TODO: selection status?
340         /* Attach links between pose operations. */
341         ComponentKey local_transform(&object->id, DEG_NODE_TYPE_TRANSFORM);
342         OperationKey pose_init_key(
343                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
344         OperationKey pose_init_ik_key(
345                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
346         OperationKey pose_cleanup_key(
347                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_CLEANUP);
348         OperationKey pose_done_key(
349                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
350         add_relation(
351                 local_transform, pose_init_key, "Local Transform -> Pose Init");
352         add_relation(pose_init_key, pose_init_ik_key, "Pose Init -> Pose Init IK");
353         add_relation(
354                 pose_init_ik_key, pose_done_key, "Pose Init IK -> Pose Cleanup");
355         /* Make sure pose is up-to-date with armature updates. */
356         build_armature(armature);
357         OperationKey armature_key(&armature->id,
358                                   DEG_NODE_TYPE_PARAMETERS,
359                                   DEG_OPCODE_PLACEHOLDER,
360                                   "Armature Eval");
361         add_relation(armature_key, pose_init_key, "Data dependency");
362         /* IK Solvers.
363          *
364          * - These require separate processing steps are pose-level to be executed
365          *   between chains of bones (i.e. once the base transforms of a bunch of
366          *   bones is done).
367          *
368          * - We build relations for these before the dependencies between operations
369          *   in the same component as it is necessary to check whether such bones
370          *   are in the same IK chain (or else we get weird issues with either
371          *   in-chain references, or with bones being parented to IK'd bones).
372          *
373          * Unsolved Issues:
374          * - Care is needed to ensure that multi-headed trees work out the same as
375          *   in ik-tree building
376          * - Animated chain-lengths are a problem. */
377         RootPChanMap root_map;
378         bool pose_depends_on_local_transform = false;
379         LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
380                 LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) {
381                         switch (con->type) {
382                                 case CONSTRAINT_TYPE_KINEMATIC:
383                                         build_ik_pose(object, pchan, con, &root_map);
384                                         pose_depends_on_local_transform = true;
385                                         break;
386                                 case CONSTRAINT_TYPE_SPLINEIK:
387                                         build_splineik_pose(object, pchan, con, &root_map);
388                                         pose_depends_on_local_transform = true;
389                                         break;
390                                 /* Constraints which needs world's matrix for transform.
391                                  * TODO(sergey): More constraints here? */
392                                 case CONSTRAINT_TYPE_ROTLIKE:
393                                 case CONSTRAINT_TYPE_SIZELIKE:
394                                 case CONSTRAINT_TYPE_LOCLIKE:
395                                 case CONSTRAINT_TYPE_TRANSLIKE:
396                                         /* TODO(sergey): Add used space check. */
397                                         pose_depends_on_local_transform = true;
398                                         break;
399                                 default:
400                                         break;
401                         }
402                 }
403         }
404         // root_map.print_debug();
405         if (pose_depends_on_local_transform) {
406                 /* TODO(sergey): Once partial updates are possible use relation between
407                  * object transform and solver itself in it's build function. */
408                 ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
409                 ComponentKey local_transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
410                 add_relation(local_transform_key, pose_key, "Local Transforms");
411         }
412         /* Links between operations for each bone. */
413         LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
414                 OperationKey bone_local_key(&object->id,
415                                             DEG_NODE_TYPE_BONE,
416                                             pchan->name,
417                                             DEG_OPCODE_BONE_LOCAL);
418                 OperationKey bone_pose_key(&object->id,
419                                            DEG_NODE_TYPE_BONE,
420                                            pchan->name,
421                                            DEG_OPCODE_BONE_POSE_PARENT);
422                 OperationKey bone_ready_key(&object->id,
423                                             DEG_NODE_TYPE_BONE,
424                                             pchan->name,
425                                             DEG_OPCODE_BONE_READY);
426                 OperationKey bone_done_key(&object->id,
427                                            DEG_NODE_TYPE_BONE,
428                                            pchan->name,
429                                            DEG_OPCODE_BONE_DONE);
430                 pchan->flag &= ~POSE_DONE;
431                 /* Pose init to bone local. */
432                 add_relation(pose_init_key,
433                              bone_local_key,
434                              "Pose Init - Bone Local",
435                              DEPSREL_FLAG_GODMODE);
436                 /* Local to pose parenting operation. */
437                 add_relation(bone_local_key, bone_pose_key, "Bone Local - Bone Pose");
438                 /* Parent relation. */
439                 if (pchan->parent != NULL) {
440                         eDepsOperation_Code parent_key_opcode;
441                         /* NOTE: this difference in handling allows us to prevent lockups
442                          * while ensuring correct poses for separate chains. */
443                         if (root_map.has_common_root(pchan->name, pchan->parent->name)) {
444                                 parent_key_opcode = DEG_OPCODE_BONE_READY;
445                         }
446                         else {
447                                 parent_key_opcode = DEG_OPCODE_BONE_DONE;
448                         }
449
450                         OperationKey parent_key(&object->id,
451                                                 DEG_NODE_TYPE_BONE,
452                                                 pchan->parent->name,
453                                                 parent_key_opcode);
454                         add_relation(
455                                 parent_key, bone_pose_key, "Parent Bone -> Child Bone");
456                 }
457                 /* Build constraints. */
458                 if (pchan->constraints.first != NULL) {
459                         /* Build relations for indirectly linked objects. */
460                         BuilderWalkUserData data;
461                         data.builder = this;
462                         BKE_constraints_id_loop(
463                                 &pchan->constraints, constraint_walk, &data);
464                         /* Constraints stack and constraint dependencies. */
465                         build_constraints(&object->id,
466                                           DEG_NODE_TYPE_BONE,
467                                           pchan->name,
468                                           &pchan->constraints,
469                                           &root_map);
470                         /* Pose -> constraints. */
471                         OperationKey constraints_key(&object->id,
472                                                      DEG_NODE_TYPE_BONE,
473                                                      pchan->name,
474                                                      DEG_OPCODE_BONE_CONSTRAINTS);
475                         add_relation(bone_pose_key, constraints_key, "Constraints Stack");
476                         /* Constraints -> ready/ */
477                         /* TODO(sergey): When constraint stack is exploded, this step should
478                          * occur before the first IK solver.  */
479                         add_relation(
480                                 constraints_key, bone_ready_key, "Constraints -> Ready");
481                 }
482                 else {
483                         /* Pose -> Ready */
484                         add_relation(bone_pose_key, bone_ready_key, "Pose -> Ready");
485                 }
486                 /* Bone ready -> Bone done.
487                  * NOTE: For bones without IK, this is all that's needed.
488                  *       For IK chains however, an additional rel is created from IK
489                  *       to done, with transitive reduction removing this one. */
490                 add_relation(bone_ready_key, bone_done_key, "Ready -> Done");
491                 /* B-Bone shape is the real final step after Done if present. */
492                 if (pchan->bone != NULL && pchan->bone->segments > 1) {
493                         OperationKey bone_segments_key(&object->id,
494                                                        DEG_NODE_TYPE_BONE,
495                                                        pchan->name,
496                                                        DEG_OPCODE_BONE_SEGMENTS);
497                         /* B-Bone shape depends on the final position of the bone. */
498                         add_relation(bone_done_key, bone_segments_key, "Done -> B-Bone Segments");
499                         /* B-Bone shape depends on final position of handle bones. */
500                         bPoseChannel *prev, *next;
501                         BKE_pchan_bbone_handles_get(pchan, &prev, &next);
502                         if (prev) {
503                                 OperationKey prev_key(&object->id,
504                                                       DEG_NODE_TYPE_BONE,
505                                                       prev->name,
506                                                       DEG_OPCODE_BONE_DONE);
507                                 add_relation(prev_key, bone_segments_key, "Prev Handle -> B-Bone Segments");
508                         }
509                         if (next) {
510                                 OperationKey next_key(&object->id,
511                                                       DEG_NODE_TYPE_BONE,
512                                                       next->name,
513                                                       DEG_OPCODE_BONE_DONE);
514                                 add_relation(next_key, bone_segments_key, "Next Handle -> B-Bone Segments");
515                         }
516                         /* Pose requires the B-Bone shape. */
517                         add_relation(bone_segments_key, pose_done_key, "PoseEval Result-Bone Link");
518                         add_relation(bone_segments_key, pose_cleanup_key, "Cleanup dependency");
519                 }
520                 else {
521                         /* Assume that all bones must be done for the pose to be ready
522                          * (for deformers). */
523                         add_relation(bone_done_key, pose_done_key, "PoseEval Result-Bone Link");
524                         add_relation(bone_done_key, pose_cleanup_key, "Cleanup dependency");
525                 }
526                 /* Custom shape. */
527                 if (pchan->custom != NULL) {
528                         build_object(NULL, pchan->custom);
529                 }
530         }
531 }
532
533 void DepsgraphRelationBuilder::build_proxy_rig(Object *object)
534 {
535         bArmature *armature = (bArmature *)object->data;
536         Object *proxy_from = object->proxy_from;
537         build_armature(armature);
538         OperationKey pose_init_key(&object->id,
539                                    DEG_NODE_TYPE_EVAL_POSE,
540                                    DEG_OPCODE_POSE_INIT);
541         OperationKey pose_done_key(&object->id,
542                                    DEG_NODE_TYPE_EVAL_POSE,
543                                    DEG_OPCODE_POSE_DONE);
544         OperationKey pose_cleanup_key(&object->id,
545                                       DEG_NODE_TYPE_EVAL_POSE,
546                                       DEG_OPCODE_POSE_CLEANUP);
547         LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
548                 OperationKey bone_local_key(&object->id,
549                                             DEG_NODE_TYPE_BONE, pchan->name,
550                                             DEG_OPCODE_BONE_LOCAL);
551                 OperationKey bone_ready_key(&object->id,
552                                             DEG_NODE_TYPE_BONE,
553                                             pchan->name,
554                                             DEG_OPCODE_BONE_READY);
555                 OperationKey bone_done_key(&object->id,
556                                            DEG_NODE_TYPE_BONE,
557                                            pchan->name,
558                                            DEG_OPCODE_BONE_DONE);
559                 OperationKey from_bone_done_key(&proxy_from->id,
560                                                 DEG_NODE_TYPE_BONE,
561                                                 pchan->name,
562                                                 DEG_OPCODE_BONE_DONE);
563                 add_relation(pose_init_key, bone_local_key, "Pose Init -> Bone Local");
564                 add_relation(bone_local_key, bone_ready_key, "Local -> Ready");
565                 add_relation(bone_ready_key, bone_done_key, "Ready -> Done");
566                 add_relation(
567                         bone_done_key, pose_cleanup_key, "Bone Done -> Pose Cleanup");
568                 add_relation(bone_done_key, pose_done_key, "Bone Done -> Pose Done");
569
570                 /* Make sure bone in the proxy is not done before it's FROM is done. */
571                 if (pchan->bone && pchan->bone->segments > 1) {
572                         OperationKey from_bone_segments_key(&proxy_from->id,
573                                                             DEG_NODE_TYPE_BONE,
574                                                             pchan->name,
575                                                             DEG_OPCODE_BONE_SEGMENTS);
576                         add_relation(from_bone_segments_key,
577                                      bone_done_key,
578                                      "From Bone Segments -> Bone Done");
579                 }
580                 else {
581                         add_relation(from_bone_done_key,
582                                      bone_done_key,
583                                      "From Bone Done -> Bone Done");
584                 }
585
586                 if (pchan->prop != NULL) {
587                         OperationKey bone_parameters(&object->id,
588                                                      DEG_NODE_TYPE_PARAMETERS,
589                                                      DEG_OPCODE_PARAMETERS_EVAL,
590                                                      pchan->name);
591                         OperationKey from_bone_parameters(&proxy_from->id,
592                                                           DEG_NODE_TYPE_PARAMETERS,
593                                                           DEG_OPCODE_PARAMETERS_EVAL,
594                                                           pchan->name);
595                         add_relation(from_bone_parameters,
596                                      bone_parameters,
597                                      "Proxy Bone Parameters");
598                 }
599         }
600 }
601
602 }  // namespace DEG