Merge branch 'blender2.7'
[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                         add_customdata_mask(data->tar, CD_MASK_MDEFORMVERT);
144                 }
145                 else {
146                         /* Standard Object Target. */
147                         ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_TRANSFORM);
148                         add_relation(target_key, pose_key, con->name);
149                 }
150                 if (data->tar == object && data->subtarget[0]) {
151                         /* Prevent target's constraints from linking to anything from same
152                          * chain that it controls. */
153                         root_map->add_bone(data->subtarget, rootchan->name);
154                 }
155         }
156         /* Pole Target. */
157         /* TODO(sergey): This should get handled as part of the constraint code. */
158         if (data->poletar != NULL) {
159                 if ((data->poletar->type == OB_ARMATURE) && (data->polesubtarget[0])) {
160                         ComponentKey target_key(&data->poletar->id,
161                                                 DEG_NODE_TYPE_BONE,
162                                                 data->polesubtarget);
163                         add_relation(target_key, solver_key, con->name);
164                 }
165                 else if (data->polesubtarget[0] &&
166                          ELEM(data->poletar->type, OB_MESH, OB_LATTICE))
167                 {
168                         /* Vertex group target. */
169                         /* NOTE: for now, we don't need to represent vertex groups
170                          * separately. */
171                         ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_GEOMETRY);
172                         add_relation(target_key, solver_key, con->name);
173                         add_customdata_mask(data->poletar, CD_MASK_MDEFORMVERT);
174                 }
175                 else {
176                         ComponentKey target_key(&data->poletar->id, DEG_NODE_TYPE_TRANSFORM);
177                         add_relation(target_key, solver_key, con->name);
178                 }
179         }
180         DEG_DEBUG_PRINTF(
181                 (::Depsgraph *)graph_,
182                 BUILD,
183                 "\nStarting IK Build: pchan = %s, target = (%s, %s), "
184                 "segcount = %d\n",
185                 pchan->name, data->tar->id.name, data->subtarget, data->rootbone);
186         bPoseChannel *parchan = pchan;
187         /* Exclude tip from chain if needed. */
188         if (!(data->flag & CONSTRAINT_IK_TIP)) {
189                 parchan = pchan->parent;
190         }
191         root_map->add_bone(parchan->name, rootchan->name);
192         OperationKey parchan_transforms_key(&object->id, DEG_NODE_TYPE_BONE,
193                                             parchan->name, DEG_OPCODE_BONE_READY);
194         add_relation(parchan_transforms_key, solver_key, "IK Solver Owner");
195         /* Walk to the chain's root. */
196         int segcount = 0;
197         while (parchan != NULL) {
198                 /* Make IK-solver dependent on this bone's result, since it can only run
199                  * after the standard results of the bone are know. Validate links step
200                  * on the bone will ensure that users of this bone only grab the result
201                  * with IK solver results. */
202                 if (parchan != pchan) {
203                         OperationKey parent_key(&object->id,
204                                                 DEG_NODE_TYPE_BONE,
205                                                 parchan->name,
206                                                 DEG_OPCODE_BONE_READY);
207                         add_relation(parent_key, solver_key, "IK Chain Parent");
208                         OperationKey bone_done_key(&object->id,
209                                                    DEG_NODE_TYPE_BONE,
210                                                    parchan->name,
211                                                    DEG_OPCODE_BONE_DONE);
212                         add_relation(solver_key, bone_done_key, "IK Chain Result");
213                 }
214                 else {
215                         OperationKey final_transforms_key(&object->id,
216                                                           DEG_NODE_TYPE_BONE,
217                                                           parchan->name,
218                                                           DEG_OPCODE_BONE_DONE);
219                         add_relation(solver_key, final_transforms_key, "IK Solver Result");
220                 }
221                 parchan->flag |= POSE_DONE;
222                 root_map->add_bone(parchan->name, rootchan->name);
223                 /* continue up chain, until we reach target number of items. */
224                 DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
225                                  BUILD,
226                                  "  %d = %s\n",
227                                  segcount, parchan->name);
228                 /* TODO(sergey): This is an arbitrary value, which was just following
229                  * old code convention. */
230                 segcount++;
231                 if ((segcount == data->rootbone) || (segcount > 255)) {
232                         break;
233                 }
234                 parchan  = parchan->parent;
235         }
236         OperationKey pose_done_key(
237                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
238         add_relation(solver_key, pose_done_key, "PoseEval Result-Bone Link");
239 }
240
241 /* Spline IK Eval Steps */
242 void DepsgraphRelationBuilder::build_splineik_pose(Object *object,
243                                                    bPoseChannel *pchan,
244                                                    bConstraint *con,
245                                                    RootPChanMap *root_map)
246 {
247         bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
248         bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
249         OperationKey transforms_key(&object->id,
250                                     DEG_NODE_TYPE_BONE,
251                                     pchan->name,
252                                     DEG_OPCODE_BONE_READY);
253         OperationKey init_ik_key(&object->id,
254                                  DEG_NODE_TYPE_EVAL_POSE,
255                                  DEG_OPCODE_POSE_INIT_IK);
256         OperationKey solver_key(&object->id,
257                                 DEG_NODE_TYPE_EVAL_POSE,
258                                 rootchan->name,
259                                 DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
260         OperationKey pose_cleanup_key(
261                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_CLEANUP);
262         /* Solver depends on initialization. */
263         add_relation(init_ik_key, solver_key, "Init IK -> IK Solver");
264         /* Never cleanup before solver is run. */
265         add_relation(solver_key, pose_cleanup_key, "IK Solver -> Cleanup");
266         /* Attach owner to IK Solver. */
267         add_relation(transforms_key,
268                      solver_key,
269                      "Spline IK Solver Owner",
270                      DEPSREL_FLAG_GODMODE);
271         /* Attach path dependency to solver. */
272         if (data->tar != NULL) {
273                 /* TODO(sergey): For until we'll store partial matricies in the
274                  * depsgraph, we create dependency between target object and pose eval
275                  * component. See IK pose for a bit more information.
276                  */
277                 /* TODO: the bigggest point here is that we need the curve PATH and not
278                  * just the general geometry. */
279                 ComponentKey target_key(&data->tar->id, DEG_NODE_TYPE_GEOMETRY);
280                 ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
281                 add_relation(target_key, pose_key, "Curve.Path -> Spline IK");
282         }
283         pchan->flag |= POSE_DONE;
284         OperationKey final_transforms_key(
285                 &object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
286         add_relation(solver_key, final_transforms_key, "Spline IK Result");
287         root_map->add_bone(pchan->name, rootchan->name);
288         /* Walk to the chain's root/ */
289         int segcount = 0;
290         for (bPoseChannel *parchan = pchan->parent;
291              parchan != NULL;
292              parchan = parchan->parent)
293         {
294                 /* Make Spline IK solver dependent on this bone's result, since it can
295                  * only run after the standard results of the bone are know. Validate
296                  * links step on the bone will ensure that users of this bone only grab
297                  * the result with IK solver results. */
298                 if (parchan != pchan) {
299                         OperationKey parent_key(&object->id,
300                                                 DEG_NODE_TYPE_BONE,
301                                                 parchan->name,
302                                                 DEG_OPCODE_BONE_READY);
303                         add_relation(parent_key, solver_key, "Spline IK Solver Update");
304                         OperationKey bone_done_key(&object->id,
305                                                    DEG_NODE_TYPE_BONE,
306                                                    parchan->name,
307                                                    DEG_OPCODE_BONE_DONE);
308                         add_relation(solver_key, bone_done_key, "IK Chain Result");
309                 }
310                 parchan->flag |= POSE_DONE;
311                 OperationKey final_transforms_key(&object->id,
312                                                   DEG_NODE_TYPE_BONE,
313                                                   parchan->name,
314                                                   DEG_OPCODE_BONE_DONE);
315                 add_relation(
316                         solver_key, final_transforms_key, "Spline IK Solver Result");
317                 root_map->add_bone(parchan->name, rootchan->name);
318                 /* TODO(sergey): This is an arbitrary value, which was just following
319                  * old code convention. */
320                 segcount++;
321                 if ((segcount == data->chainlen) || (segcount > 255)) {
322                         break;
323                 }
324         }
325         OperationKey pose_done_key(
326                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
327         add_relation(solver_key, pose_done_key, "PoseEval Result-Bone Link");
328 }
329
330 /* Pose/Armature Bones Graph */
331 void DepsgraphRelationBuilder::build_rig(Object *object)
332 {
333         /* Armature-Data */
334         bArmature *armature = (bArmature *)object->data;
335         // TODO: selection status?
336         /* Attach links between pose operations. */
337         ComponentKey local_transform(&object->id, DEG_NODE_TYPE_TRANSFORM);
338         OperationKey pose_init_key(
339                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
340         OperationKey pose_init_ik_key(
341                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT_IK);
342         OperationKey pose_cleanup_key(
343                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_CLEANUP);
344         OperationKey pose_done_key(
345                 &object->id, DEG_NODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
346         add_relation(
347                 local_transform, pose_init_key, "Local Transform -> Pose Init");
348         add_relation(pose_init_key, pose_init_ik_key, "Pose Init -> Pose Init IK");
349         add_relation(
350                 pose_init_ik_key, pose_done_key, "Pose Init IK -> Pose Cleanup");
351         /* Make sure pose is up-to-date with armature updates. */
352         build_armature(armature);
353         OperationKey armature_key(&armature->id,
354                                   DEG_NODE_TYPE_PARAMETERS,
355                                   DEG_OPCODE_PLACEHOLDER,
356                                   "Armature Eval");
357         add_relation(armature_key, pose_init_key, "Data dependency");
358         /* IK Solvers.
359          *
360          * - These require separate processing steps are pose-level to be executed
361          *   between chains of bones (i.e. once the base transforms of a bunch of
362          *   bones is done).
363          *
364          * - We build relations for these before the dependencies between operations
365          *   in the same component as it is necessary to check whether such bones
366          *   are in the same IK chain (or else we get weird issues with either
367          *   in-chain references, or with bones being parented to IK'd bones).
368          *
369          * Unsolved Issues:
370          * - Care is needed to ensure that multi-headed trees work out the same as
371          *   in ik-tree building
372          * - Animated chain-lengths are a problem. */
373         RootPChanMap root_map;
374         bool pose_depends_on_local_transform = false;
375         LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
376                 LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) {
377                         switch (con->type) {
378                                 case CONSTRAINT_TYPE_KINEMATIC:
379                                         build_ik_pose(object, pchan, con, &root_map);
380                                         pose_depends_on_local_transform = true;
381                                         break;
382                                 case CONSTRAINT_TYPE_SPLINEIK:
383                                         build_splineik_pose(object, pchan, con, &root_map);
384                                         pose_depends_on_local_transform = true;
385                                         break;
386                                 /* Constraints which needs world's matrix for transform.
387                                  * TODO(sergey): More constraints here? */
388                                 case CONSTRAINT_TYPE_ROTLIKE:
389                                 case CONSTRAINT_TYPE_SIZELIKE:
390                                 case CONSTRAINT_TYPE_LOCLIKE:
391                                 case CONSTRAINT_TYPE_TRANSLIKE:
392                                         /* TODO(sergey): Add used space check. */
393                                         pose_depends_on_local_transform = true;
394                                         break;
395                                 default:
396                                         break;
397                         }
398                 }
399         }
400         // root_map.print_debug();
401         if (pose_depends_on_local_transform) {
402                 /* TODO(sergey): Once partial updates are possible use relation between
403                  * object transform and solver itself in it's build function. */
404                 ComponentKey pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
405                 ComponentKey local_transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
406                 add_relation(local_transform_key, pose_key, "Local Transforms");
407         }
408         /* Links between operations for each bone. */
409         LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
410                 OperationKey bone_local_key(&object->id,
411                                             DEG_NODE_TYPE_BONE,
412                                             pchan->name,
413                                             DEG_OPCODE_BONE_LOCAL);
414                 OperationKey bone_pose_key(&object->id,
415                                            DEG_NODE_TYPE_BONE,
416                                            pchan->name,
417                                            DEG_OPCODE_BONE_POSE_PARENT);
418                 OperationKey bone_ready_key(&object->id,
419                                             DEG_NODE_TYPE_BONE,
420                                             pchan->name,
421                                             DEG_OPCODE_BONE_READY);
422                 OperationKey bone_done_key(&object->id,
423                                            DEG_NODE_TYPE_BONE,
424                                            pchan->name,
425                                            DEG_OPCODE_BONE_DONE);
426                 pchan->flag &= ~POSE_DONE;
427                 /* Pose init to bone local. */
428                 add_relation(pose_init_key,
429                              bone_local_key,
430                              "Pose Init - Bone Local",
431                              DEPSREL_FLAG_GODMODE);
432                 /* Local to pose parenting operation. */
433                 add_relation(bone_local_key, bone_pose_key, "Bone Local - Bone Pose");
434                 /* Parent relation. */
435                 if (pchan->parent != NULL) {
436                         eDepsOperation_Code parent_key_opcode;
437                         /* NOTE: this difference in handling allows us to prevent lockups
438                          * while ensuring correct poses for separate chains. */
439                         if (root_map.has_common_root(pchan->name, pchan->parent->name)) {
440                                 parent_key_opcode = DEG_OPCODE_BONE_READY;
441                         }
442                         else {
443                                 parent_key_opcode = DEG_OPCODE_BONE_DONE;
444                         }
445
446                         OperationKey parent_key(&object->id,
447                                                 DEG_NODE_TYPE_BONE,
448                                                 pchan->parent->name,
449                                                 parent_key_opcode);
450                         add_relation(
451                                 parent_key, bone_pose_key, "Parent Bone -> Child Bone");
452                 }
453                 /* Build constraints. */
454                 if (pchan->constraints.first != NULL) {
455                         /* Build relations for indirectly linked objects. */
456                         BuilderWalkUserData data;
457                         data.builder = this;
458                         BKE_constraints_id_loop(
459                                 &pchan->constraints, constraint_walk, &data);
460                         /* Constraints stack and constraint dependencies. */
461                         build_constraints(&object->id,
462                                           DEG_NODE_TYPE_BONE,
463                                           pchan->name,
464                                           &pchan->constraints,
465                                           &root_map);
466                         /* Pose -> constraints. */
467                         OperationKey constraints_key(&object->id,
468                                                      DEG_NODE_TYPE_BONE,
469                                                      pchan->name,
470                                                      DEG_OPCODE_BONE_CONSTRAINTS);
471                         add_relation(bone_pose_key, constraints_key, "Constraints Stack");
472                         /* Constraints -> ready/ */
473                         /* TODO(sergey): When constraint stack is exploded, this step should
474                          * occur before the first IK solver.  */
475                         add_relation(
476                                 constraints_key, bone_ready_key, "Constraints -> Ready");
477                 }
478                 else {
479                         /* Pose -> Ready */
480                         add_relation(bone_pose_key, bone_ready_key, "Pose -> Ready");
481                 }
482                 /* Bone ready -> Bone done.
483                  * NOTE: For bones without IK, this is all that's needed.
484                  *       For IK chains however, an additional rel is created from IK
485                  *       to done, with transitive reduction removing this one. */
486                 add_relation(bone_ready_key, bone_done_key, "Ready -> Done");
487                 /* B-Bone shape is the real final step after Done if present. */
488                 if (pchan->bone != NULL && pchan->bone->segments > 1) {
489                         OperationKey bone_segments_key(&object->id,
490                                                        DEG_NODE_TYPE_BONE,
491                                                        pchan->name,
492                                                        DEG_OPCODE_BONE_SEGMENTS);
493                         /* B-Bone shape depends on the final position of the bone. */
494                         add_relation(bone_done_key,
495                                      bone_segments_key,
496                                      "Done -> B-Bone Segments");
497                         /* B-Bone shape depends on final position of handle bones. */
498                         bPoseChannel *prev, *next;
499                         BKE_pchan_bbone_handles_get(pchan, &prev, &next);
500                         if (prev) {
501                                 OperationKey prev_key(&object->id,
502                                                       DEG_NODE_TYPE_BONE,
503                                                       prev->name,
504                                                       DEG_OPCODE_BONE_DONE);
505                                 add_relation(prev_key,
506                                              bone_segments_key,
507                                              "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,
515                                              bone_segments_key,
516                                              "Next Handle -> B-Bone Segments");
517                         }
518                         /* Pose requires the B-Bone shape. */
519                         add_relation(bone_segments_key,
520                                      pose_done_key,
521                                      "PoseEval Result-Bone Link",
522                                      DEPSREL_FLAG_GODMODE);
523                         add_relation(bone_segments_key,
524                                      pose_cleanup_key,
525                                      "Cleanup dependency");
526                 }
527                 else {
528                         /* Assume that all bones must be done for the pose to be ready
529                          * (for deformers). */
530                         add_relation(bone_done_key,
531                                      pose_done_key,
532                                      "PoseEval Result-Bone Link");
533                         add_relation(bone_done_key,
534                                      pose_cleanup_key,
535                                      "Cleanup dependency");
536                 }
537                 /* Custom shape. */
538                 if (pchan->custom != NULL) {
539                         build_object(NULL, pchan->custom);
540                 }
541         }
542 }
543
544 void DepsgraphRelationBuilder::build_proxy_rig(Object *object)
545 {
546         bArmature *armature = (bArmature *)object->data;
547         Object *proxy_from = object->proxy_from;
548         build_armature(armature);
549         OperationKey pose_init_key(&object->id,
550                                    DEG_NODE_TYPE_EVAL_POSE,
551                                    DEG_OPCODE_POSE_INIT);
552         OperationKey pose_done_key(&object->id,
553                                    DEG_NODE_TYPE_EVAL_POSE,
554                                    DEG_OPCODE_POSE_DONE);
555         OperationKey pose_cleanup_key(&object->id,
556                                       DEG_NODE_TYPE_EVAL_POSE,
557                                       DEG_OPCODE_POSE_CLEANUP);
558         LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
559                 OperationKey bone_local_key(&object->id,
560                                             DEG_NODE_TYPE_BONE, pchan->name,
561                                             DEG_OPCODE_BONE_LOCAL);
562                 OperationKey bone_ready_key(&object->id,
563                                             DEG_NODE_TYPE_BONE,
564                                             pchan->name,
565                                             DEG_OPCODE_BONE_READY);
566                 OperationKey bone_done_key(&object->id,
567                                            DEG_NODE_TYPE_BONE,
568                                            pchan->name,
569                                            DEG_OPCODE_BONE_DONE);
570                 OperationKey from_bone_done_key(&proxy_from->id,
571                                                 DEG_NODE_TYPE_BONE,
572                                                 pchan->name,
573                                                 DEG_OPCODE_BONE_DONE);
574                 add_relation(pose_init_key, bone_local_key, "Pose Init -> Bone Local");
575                 add_relation(bone_local_key, bone_ready_key, "Local -> Ready");
576                 add_relation(bone_ready_key, bone_done_key, "Ready -> Done");
577                 add_relation(
578                         bone_done_key, pose_cleanup_key, "Bone Done -> Pose Cleanup");
579                 add_relation(bone_done_key,
580                             pose_done_key,
581                             "Bone Done -> Pose Done",
582                             DEPSREL_FLAG_GODMODE);
583
584                 /* Make sure bone in the proxy is not done before it's FROM is done. */
585                 if (pchan->bone && pchan->bone->segments > 1) {
586                         OperationKey from_bone_segments_key(&proxy_from->id,
587                                                             DEG_NODE_TYPE_BONE,
588                                                             pchan->name,
589                                                             DEG_OPCODE_BONE_SEGMENTS);
590                         add_relation(from_bone_segments_key,
591                                      bone_done_key,
592                                      "Bone Segments -> Bone Done",
593                                      DEPSREL_FLAG_GODMODE);
594                 }
595                 else {
596                         add_relation(from_bone_done_key,
597                                      bone_done_key,
598                                      "Bone Done -> Bone Done");
599                 }
600
601                 if (pchan->prop != NULL) {
602                         OperationKey bone_parameters(&object->id,
603                                                      DEG_NODE_TYPE_PARAMETERS,
604                                                      DEG_OPCODE_PARAMETERS_EVAL,
605                                                      pchan->name);
606                         OperationKey from_bone_parameters(&proxy_from->id,
607                                                           DEG_NODE_TYPE_PARAMETERS,
608                                                           DEG_OPCODE_PARAMETERS_EVAL,
609                                                           pchan->name);
610                         add_relation(from_bone_parameters,
611                                      bone_parameters,
612                                      "Proxy Bone Parameters");
613                 }
614         }
615 }
616
617 }  // namespace DEG