7a5d2b4afa4a88a521be57dfe6e6e58b1ac6138e
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_relations.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.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_camera_types.h"
49 #include "DNA_cachefile_types.h"
50 #include "DNA_constraint_types.h"
51 #include "DNA_curve_types.h"
52 #include "DNA_effect_types.h"
53 #include "DNA_gpencil_types.h"
54 #include "DNA_group_types.h"
55 #include "DNA_key_types.h"
56 #include "DNA_lamp_types.h"
57 #include "DNA_material_types.h"
58 #include "DNA_mask_types.h"
59 #include "DNA_mesh_types.h"
60 #include "DNA_meta_types.h"
61 #include "DNA_movieclip_types.h"
62 #include "DNA_node_types.h"
63 #include "DNA_particle_types.h"
64 #include "DNA_lightprobe_types.h"
65 #include "DNA_object_types.h"
66 #include "DNA_rigidbody_types.h"
67 #include "DNA_scene_types.h"
68 #include "DNA_speaker_types.h"
69 #include "DNA_texture_types.h"
70 #include "DNA_world_types.h"
71 #include "DNA_object_force_types.h"
72
73 #include "BKE_action.h"
74 #include "BKE_armature.h"
75 #include "BKE_animsys.h"
76 #include "BKE_collection.h"
77 #include "BKE_constraint.h"
78 #include "BKE_curve.h"
79 #include "BKE_effect.h"
80 #include "BKE_collision.h"
81 #include "BKE_fcurve.h"
82 #include "BKE_key.h"
83 #include "BKE_library.h"
84 #include "BKE_main.h"
85 #include "BKE_material.h"
86 #include "BKE_mball.h"
87 #include "BKE_modifier.h"
88 #include "BKE_node.h"
89 #include "BKE_object.h"
90 #include "BKE_particle.h"
91 #include "BKE_rigidbody.h"
92 #include "BKE_sound.h"
93 #include "BKE_tracking.h"
94 #include "BKE_world.h"
95
96 #include "RNA_access.h"
97 #include "RNA_types.h"
98 } /* extern "C" */
99
100 #include "DEG_depsgraph.h"
101 #include "DEG_depsgraph_build.h"
102
103 #include "intern/builder/deg_builder.h"
104 #include "intern/builder/deg_builder_pchanmap.h"
105
106 #include "intern/nodes/deg_node.h"
107 #include "intern/nodes/deg_node_component.h"
108 #include "intern/nodes/deg_node_id.h"
109 #include "intern/nodes/deg_node_operation.h"
110 #include "intern/nodes/deg_node_time.h"
111
112 #include "intern/depsgraph_intern.h"
113 #include "intern/depsgraph_types.h"
114
115 #include "util/deg_util_foreach.h"
116
117 namespace DEG {
118
119 /* ***************** */
120 /* Relations Builder */
121
122 /* TODO(sergey): This is somewhat weak, but we don't want neither false-positive
123  * time dependencies nor special exceptions in the depsgraph evaluation.
124  */
125 static bool python_driver_depends_on_time(ChannelDriver *driver)
126 {
127         if (driver->expression[0] == '\0') {
128                 /* Empty expression depends on nothing. */
129                 return false;
130         }
131         if (strchr(driver->expression, '(') != NULL) {
132                 /* Function calls are considered dependent on a time. */
133                 return true;
134         }
135         if (strstr(driver->expression, "frame") != NULL) {
136                 /* Variable `frame` depends on time. */
137                 /* TODO(sergey): This is a bit weak, but not sure about better way of
138                  * handling this.
139                  */
140                 return true;
141         }
142         /* Possible indirect time relation s should be handled via variable
143          * targets.
144          */
145         return false;
146 }
147
148 static bool particle_system_depends_on_time(ParticleSystem *psys)
149 {
150         ParticleSettings *part = psys->part;
151         /* Non-hair particles we always consider dependent on time. */
152         if (part->type != PART_HAIR) {
153                 return true;
154         }
155         /* Dynamics always depends on time. */
156         if (psys->flag & PSYS_HAIR_DYNAMICS) {
157                 return true;
158         }
159         /* TODO(sergey): Check what else makes hair dependent on time. */
160         return false;
161 }
162
163 static bool object_particles_depends_on_time(Object *object)
164 {
165         if (object->type != OB_MESH) {
166                 return false;
167         }
168         LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
169                 if (particle_system_depends_on_time(psys)) {
170                         return true;
171                 }
172         }
173         return false;
174 }
175
176 static bool check_id_has_anim_component(ID *id)
177 {
178         AnimData *adt = BKE_animdata_from_id(id);
179         if (adt == NULL) {
180                 return false;
181         }
182         return (adt->action != NULL) ||
183                (!BLI_listbase_is_empty(&adt->nla_tracks));
184 }
185
186 /* **** General purpose functions ****  */
187
188 DepsgraphRelationBuilder::DepsgraphRelationBuilder(Main *bmain,
189                                                    Depsgraph *graph)
190     : bmain_(bmain),
191       graph_(graph),
192       scene_(NULL)
193 {
194 }
195
196 TimeSourceDepsNode *DepsgraphRelationBuilder::get_node(
197         const TimeSourceKey &key) const
198 {
199         if (key.id) {
200                 /* XXX TODO */
201                 return NULL;
202         }
203         else {
204                 return graph_->time_source;
205         }
206 }
207
208 ComponentDepsNode *DepsgraphRelationBuilder::get_node(
209         const ComponentKey &key) const
210 {
211         IDDepsNode *id_node = graph_->find_id_node(key.id);
212         if (!id_node) {
213                 fprintf(stderr, "find_node component: Could not find ID %s\n",
214                         (key.id != NULL) ? key.id->name : "<null>");
215                 return NULL;
216         }
217
218         ComponentDepsNode *node = id_node->find_component(key.type, key.name);
219         return node;
220 }
221
222 OperationDepsNode *DepsgraphRelationBuilder::get_node(
223         const OperationKey &key) const
224 {
225         OperationDepsNode *op_node = find_node(key);
226         if (op_node == NULL) {
227                 fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
228                         operationCodeAsString(key.opcode), key.name);
229         }
230         return op_node;
231 }
232
233 DepsNode *DepsgraphRelationBuilder::get_node(const RNAPathKey &key) const
234 {
235         return graph_->find_node_from_pointer(&key.ptr, key.prop);
236 }
237
238 OperationDepsNode *DepsgraphRelationBuilder::find_node(
239         const OperationKey &key) const
240 {
241         IDDepsNode *id_node = graph_->find_id_node(key.id);
242         if (!id_node) {
243                 return NULL;
244         }
245         ComponentDepsNode *comp_node = id_node->find_component(key.component_type,
246                                                                key.component_name);
247         if (!comp_node) {
248                 return NULL;
249         }
250         return comp_node->find_operation(key.opcode, key.name, key.name_tag);
251 }
252
253 bool DepsgraphRelationBuilder::has_node(const OperationKey &key) const
254 {
255         return find_node(key) != NULL;
256 }
257
258 DepsRelation *DepsgraphRelationBuilder::add_time_relation(
259         TimeSourceDepsNode *timesrc,
260         DepsNode *node_to,
261         const char *description,
262         bool check_unique)
263 {
264         if (timesrc && node_to) {
265                 return graph_->add_new_relation(timesrc, node_to, description, check_unique);
266         }
267         else {
268                 DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
269                                  BUILD, "add_time_relation(%p = %s, %p = %s, %s) Failed\n",
270                                  timesrc,   (timesrc) ? timesrc->identifier().c_str() : "<None>",
271                                  node_to,   (node_to) ? node_to->identifier().c_str() : "<None>",
272                                  description);
273         }
274         return NULL;
275 }
276
277 DepsRelation *DepsgraphRelationBuilder::add_operation_relation(
278         OperationDepsNode *node_from,
279         OperationDepsNode *node_to,
280         const char *description,
281         bool check_unique)
282 {
283         if (node_from && node_to) {
284                 return graph_->add_new_relation(node_from,
285                                                 node_to,
286                                                 description,
287                                                 check_unique);
288         }
289         else {
290                 DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
291                                  BUILD, "add_operation_relation(%p = %s, %p = %s, %s) Failed\n",
292                                  node_from, (node_from) ? node_from->identifier().c_str() : "<None>",
293                                  node_to,   (node_to)   ? node_to->identifier().c_str() : "<None>",
294                                  description);
295         }
296         return NULL;
297 }
298
299 void DepsgraphRelationBuilder::add_collision_relations(
300         const OperationKey &key,
301         Object *object,
302         Collection *collection,
303         const char *name)
304 {
305         ListBase *relations = deg_build_collision_relations(graph_, collection, eModifierType_Collision);
306
307         LISTBASE_FOREACH (CollisionRelation *, relation, relations) {
308                 if (relation->ob != object) {
309                         ComponentKey trf_key(&relation->ob->id, DEG_NODE_TYPE_TRANSFORM);
310                         add_relation(trf_key, key, name);
311
312                         ComponentKey coll_key(&relation->ob->id, DEG_NODE_TYPE_GEOMETRY);
313                         add_relation(coll_key, key, name);
314                 }
315         }
316 }
317
318 void DepsgraphRelationBuilder::add_forcefield_relations(
319         const OperationKey &key,
320         Object *object,
321         ParticleSystem *psys,
322         EffectorWeights *eff,
323         bool add_absorption,
324         const char *name)
325 {
326         ListBase *relations = deg_build_effector_relations(graph_, eff->group);
327
328         LISTBASE_FOREACH (EffectorRelation *, relation, relations) {
329                 if (relation->ob != object) {
330                         ComponentKey eff_key(&relation->ob->id, DEG_NODE_TYPE_TRANSFORM);
331                         add_relation(eff_key, key, name);
332
333                         if (relation->pd->forcefield == PFIELD_SMOKEFLOW && relation->pd->f_source) {
334                                 ComponentKey trf_key(&relation->pd->f_source->id,
335                                                      DEG_NODE_TYPE_TRANSFORM);
336                                 add_relation(trf_key, key, "Smoke Force Domain");
337                                 ComponentKey eff_key(&relation->pd->f_source->id,
338                                                      DEG_NODE_TYPE_GEOMETRY);
339                                 add_relation(eff_key, key, "Smoke Force Domain");
340                         }
341                         if (add_absorption && (relation->pd->flag & PFIELD_VISIBILITY)) {
342                                 add_collision_relations(key,
343                                                         object,
344                                                         NULL,
345                                                         "Force Absorption");
346                         }
347                 }
348                 if (relation->psys) {
349                         if (relation->ob != object) {
350                                 ComponentKey eff_key(&relation->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES);
351                                 add_relation(eff_key, key, name);
352                                 /* TODO: remove this when/if EVAL_PARTICLES is sufficient
353                                  * for up to date particles.
354                                  */
355                                 ComponentKey mod_key(&relation->ob->id, DEG_NODE_TYPE_GEOMETRY);
356                                 add_relation(mod_key, key, name);
357                         }
358                         else if (relation->psys != psys) {
359                                 OperationKey eff_key(&relation->ob->id,
360                                                      DEG_NODE_TYPE_EVAL_PARTICLES,
361                                                      DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
362                                                      relation->psys->name);
363                                 add_relation(eff_key, key, name);
364                         }
365                 }
366         }
367 }
368
369 Depsgraph *DepsgraphRelationBuilder::getGraph()
370 {
371         return graph_;
372 }
373
374 /* **** Functions to build relations between entities  **** */
375
376 void DepsgraphRelationBuilder::begin_build()
377 {
378 }
379
380 void DepsgraphRelationBuilder::build_id(ID *id)
381 {
382         if (id == NULL) {
383                 return;
384         }
385         switch (GS(id->name)) {
386                 case ID_AR:
387                         build_armature((bArmature *)id);
388                         break;
389                 case ID_CA:
390                         build_camera((Camera *)id);
391                         break;
392                 case ID_GR:
393                         build_collection(DEG_COLLECTION_OWNER_UNKNOWN, NULL, (Collection *)id);
394                         break;
395                 case ID_OB:
396                         build_object(NULL, (Object *)id);
397                         break;
398                 case ID_KE:
399                         build_shapekeys((Key *)id);
400                         break;
401                 case ID_LA:
402                         build_lamp((Lamp *)id);
403                         break;
404                 case ID_LP:
405                         build_lightprobe((LightProbe *)id);
406                         break;
407                 case ID_NT:
408                         build_nodetree((bNodeTree *)id);
409                         break;
410                 case ID_MA:
411                         build_material((Material *)id);
412                         break;
413                 case ID_TE:
414                         build_texture((Tex *)id);
415                         break;
416                 case ID_WO:
417                         build_world((World *)id);
418                         break;
419                 case ID_MSK:
420                         build_mask((Mask *)id);
421                         break;
422                 case ID_MC:
423                         build_movieclip((MovieClip *)id);
424                         break;
425                 case ID_ME:
426                 case ID_CU:
427                 case ID_MB:
428                 case ID_LT:
429                         build_object_data_geometry_datablock(id);
430                         break;
431                 case ID_SPK:
432                         build_speaker((Speaker *)id);
433                         break;
434                 default:
435                         fprintf(stderr, "Unhandled ID %s\n", id->name);
436                         BLI_assert(!"Should never happen");
437                         break;
438         }
439 }
440
441 void DepsgraphRelationBuilder::build_collection(
442         eDepsNode_CollectionOwner owner_type,
443         Object *object,
444         Collection *collection)
445 {
446         const bool allow_restrict_flags = (owner_type == DEG_COLLECTION_OWNER_SCENE);
447         if (allow_restrict_flags) {
448                 const int restrict_flag = (graph_->mode == DAG_EVAL_VIEWPORT)
449                         ? COLLECTION_RESTRICT_VIEW
450                         : COLLECTION_RESTRICT_RENDER;
451                 if (collection->flag & restrict_flag) {
452                         return;
453                 }
454         }
455         const bool group_done = built_map_.checkIsBuiltAndTag(collection);
456         OperationKey object_transform_final_key(object != NULL ? &object->id : NULL,
457                                                 DEG_NODE_TYPE_TRANSFORM,
458                                                 DEG_OPCODE_TRANSFORM_FINAL);
459         if (!group_done) {
460                 LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
461                         if (allow_restrict_flags) {
462                                 const int restrict_flag = (graph_->mode == DAG_EVAL_VIEWPORT)
463                                         ? OB_RESTRICT_VIEW
464                                         : OB_RESTRICT_RENDER;
465                                 if (cob->ob->restrictflag & restrict_flag) {
466                                         continue;
467                                 }
468                         }
469                         build_object(NULL, cob->ob);
470                 }
471                 LISTBASE_FOREACH (CollectionChild *, child, &collection->children) {
472                         build_collection(owner_type, NULL, child->collection);
473                 }
474         }
475         if (object != NULL) {
476                 FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(collection, ob, graph_->mode)
477                 {
478                         ComponentKey dupli_transform_key(&ob->id, DEG_NODE_TYPE_TRANSFORM);
479                         add_relation(dupli_transform_key, object_transform_final_key, "Dupligroup");
480                 }
481                 FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END;
482         }
483 }
484
485 void DepsgraphRelationBuilder::build_object(Base *base, Object *object)
486 {
487         if (built_map_.checkIsBuiltAndTag(object)) {
488                 if (base != NULL) {
489                         build_object_flags(base, object);
490                 }
491                 return;
492         }
493         /* Object Transforms */
494         eDepsOperation_Code base_op = (object->parent) ? DEG_OPCODE_TRANSFORM_PARENT
495                                                        : DEG_OPCODE_TRANSFORM_LOCAL;
496         OperationKey base_op_key(&object->id, DEG_NODE_TYPE_TRANSFORM, base_op);
497         OperationKey local_transform_key(&object->id,
498                                          DEG_NODE_TYPE_TRANSFORM,
499                                          DEG_OPCODE_TRANSFORM_LOCAL);
500         OperationKey parent_transform_key(&object->id,
501                                           DEG_NODE_TYPE_TRANSFORM,
502                                           DEG_OPCODE_TRANSFORM_PARENT);
503         OperationKey final_transform_key(&object->id,
504                                          DEG_NODE_TYPE_TRANSFORM,
505                                          DEG_OPCODE_TRANSFORM_FINAL);
506         OperationKey ob_ubereval_key(&object->id,
507                                      DEG_NODE_TYPE_TRANSFORM,
508                                      DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
509         /* Various flags, flushing from bases/collections. */
510         build_object_flags(base, object);
511         /* Parenting. */
512         if (object->parent != NULL) {
513                 /* Make sure parent object's relations are built. */
514                 build_object(NULL, object->parent);
515                 /* Parent relationship. */
516                 build_object_parent(object);
517                 /* Local -> parent. */
518                 add_relation(local_transform_key,
519                              parent_transform_key,
520                              "ObLocal -> ObParent");
521         }
522         /* Modifiers. */
523         if (object->modifiers.first != NULL) {
524                 BuilderWalkUserData data;
525                 data.builder = this;
526                 modifiers_foreachIDLink(object, modifier_walk, &data);
527         }
528         /* Constraints. */
529         if (object->constraints.first != NULL) {
530                 BuilderWalkUserData data;
531                 data.builder = this;
532                 BKE_constraints_id_loop(&object->constraints, constraint_walk, &data);
533         }
534         /* Object constraints. */
535         if (object->constraints.first != NULL) {
536                 OperationKey constraint_key(&object->id,
537                                             DEG_NODE_TYPE_TRANSFORM,
538                                             DEG_OPCODE_TRANSFORM_CONSTRAINTS);
539                 /* Constraint relations. */
540                 build_constraints(&object->id,
541                                   DEG_NODE_TYPE_TRANSFORM,
542                                   "",
543                                   &object->constraints,
544                                   NULL);
545                 /* operation order */
546                 add_relation(base_op_key, constraint_key, "ObBase-> Constraint Stack");
547                 add_relation(constraint_key, final_transform_key, "ObConstraints -> Done");
548                 // XXX
549                 add_relation(constraint_key, ob_ubereval_key, "Temp Ubereval");
550                 add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval");
551         }
552         else {
553                 /* NOTE: Keep an eye here, we skip some relations here to "streamline"
554                  * dependencies and avoid transitive relations which causes overhead.
555                  * But once we get rid of uber eval node this will need reconsideration.
556                  */
557                 if (object->rigidbody_object == NULL) {
558                         /* Rigid body will hook up another node inbetween, so skip
559                          * relation here to avoid transitive relation.
560                          */
561                         add_relation(base_op_key, ob_ubereval_key, "Temp Ubereval");
562                 }
563                 add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval");
564         }
565         /* Animation data */
566         build_animdata(&object->id);
567         /* Object data. */
568         build_object_data(object);
569         /* Particle systems. */
570         if (object->particlesystem.first != NULL) {
571                 build_particles(object);
572         }
573         /* Grease pencil. */
574         if (object->gpd != NULL) {
575                 build_gpencil(object->gpd);
576         }
577         /* Proxy object to copy from. */
578         if (object->proxy_from != NULL) {
579                 build_object(NULL, object->proxy_from);
580                 ComponentKey ob_pose_key(&object->proxy_from->id, DEG_NODE_TYPE_EVAL_POSE);
581                 ComponentKey proxy_pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
582                 add_relation(ob_pose_key, proxy_pose_key, "Proxy Pose");
583
584                 ComponentKey ob_transform_key(&object->proxy_from->id, DEG_NODE_TYPE_TRANSFORM);
585                 ComponentKey proxy_transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
586                 add_relation(ob_transform_key, proxy_transform_key, "Proxy Transform");
587         }
588         if (object->proxy_group != NULL) {
589                 build_object(NULL, object->proxy_group);
590                 OperationKey proxy_group_ubereval_key(&object->proxy_group->id,
591                                                       DEG_NODE_TYPE_TRANSFORM,
592                                                       DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
593                 add_relation(proxy_group_ubereval_key, final_transform_key, "Proxy Group Transform");
594         }
595         /* Object dupligroup. */
596         if (object->dup_group != NULL) {
597                 build_collection(DEG_COLLECTION_OWNER_OBJECT, object, object->dup_group);
598         }
599 }
600
601 void DepsgraphRelationBuilder::build_object_flags(Base *base, Object *object)
602 {
603         if (base == NULL) {
604                 return;
605         }
606         OperationKey view_layer_done_key(&scene_->id,
607                                          DEG_NODE_TYPE_LAYER_COLLECTIONS,
608                                          DEG_OPCODE_VIEW_LAYER_EVAL);
609         OperationKey object_flags_key(&object->id,
610                                       DEG_NODE_TYPE_OBJECT_FROM_LAYER,
611                                       DEG_OPCODE_OBJECT_BASE_FLAGS);
612         add_relation(view_layer_done_key, object_flags_key, "Base flags flush");
613 }
614
615 void DepsgraphRelationBuilder::build_object_data(Object *object)
616 {
617         if (object->data == NULL) {
618                 return;
619         }
620         ID *obdata_id = (ID *)object->data;
621         /* Object data animation. */
622         if (!built_map_.checkIsBuilt(obdata_id)) {
623                 build_animdata(obdata_id);
624         }
625         /* type-specific data. */
626         switch (object->type) {
627                 case OB_MESH:
628                 case OB_CURVE:
629                 case OB_FONT:
630                 case OB_SURF:
631                 case OB_MBALL:
632                 case OB_LATTICE:
633                 {
634                         build_object_data_geometry(object);
635                         break;
636                 }
637                 case OB_ARMATURE:
638                         if (ID_IS_LINKED(object) && object->proxy_from != NULL) {
639                                 build_proxy_rig(object);
640                         }
641                         else {
642                                  build_rig(object);
643                         }
644                         break;
645                 case OB_LAMP:
646                         build_object_data_lamp(object);
647                         break;
648                 case OB_CAMERA:
649                         build_object_data_camera(object);
650                         break;
651                 case OB_LIGHTPROBE:
652                         build_object_data_lightprobe(object);
653                         break;
654                 case OB_SPEAKER:
655                         build_object_data_speaker(object);
656                         break;
657         }
658         Key *key = BKE_key_from_object(object);
659         if (key != NULL) {
660                 ComponentKey geometry_key((ID *)object->data, DEG_NODE_TYPE_GEOMETRY);
661                 ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY);
662                 add_relation(key_key, geometry_key, "Shapekeys");
663                 build_nested_shapekey(&object->id, key);
664         }
665 }
666
667 void DepsgraphRelationBuilder::build_object_data_camera(Object *object)
668 {
669         Camera *camera = (Camera *)object->data;
670         build_camera(camera);
671         ComponentKey object_parameters_key(&object->id, DEG_NODE_TYPE_PARAMETERS);
672         ComponentKey camera_parameters_key(&camera->id, DEG_NODE_TYPE_PARAMETERS);
673         add_relation(camera_parameters_key, object_parameters_key, "Camera -> Object");
674 }
675
676 void DepsgraphRelationBuilder::build_object_data_lamp(Object *object)
677 {
678         Lamp *lamp = (Lamp *)object->data;
679         build_lamp(lamp);
680         ComponentKey object_parameters_key(&object->id, DEG_NODE_TYPE_PARAMETERS);
681         ComponentKey lamp_parameters_key(&lamp->id, DEG_NODE_TYPE_PARAMETERS);
682         add_relation(lamp_parameters_key, object_parameters_key, "Light -> Object");
683 }
684
685 void DepsgraphRelationBuilder::build_object_data_lightprobe(Object *object)
686 {
687         LightProbe *probe = (LightProbe *)object->data;
688         build_lightprobe(probe);
689         OperationKey probe_key(&probe->id,
690                                DEG_NODE_TYPE_PARAMETERS,
691                                DEG_OPCODE_LIGHT_PROBE_EVAL);
692         OperationKey object_key(&object->id,
693                                 DEG_NODE_TYPE_PARAMETERS,
694                                 DEG_OPCODE_LIGHT_PROBE_EVAL);
695         add_relation(probe_key, object_key, "LightProbe Update");
696 }
697
698 void DepsgraphRelationBuilder::build_object_data_speaker(Object *object)
699 {
700         Speaker *speaker = (Speaker *)object->data;
701         build_speaker(speaker);
702         OperationKey probe_key(&speaker->id,
703                                DEG_NODE_TYPE_PARAMETERS,
704                                DEG_OPCODE_SPEAKER_EVAL);
705         OperationKey object_key(&object->id,
706                                 DEG_NODE_TYPE_PARAMETERS,
707                                 DEG_OPCODE_SPEAKER_EVAL);
708         add_relation(probe_key, object_key, "Speaker Update");
709 }
710
711 void DepsgraphRelationBuilder::build_object_parent(Object *object)
712 {
713         /* XXX: for now, need to use the component key (not just direct to the parent op),
714          * or else the matrix doesn't get reset/
715          */
716         // XXX: @sergey - it would be good if we got that backwards flushing working
717         // when tagging for updates.
718         //OperationKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT);
719         ComponentKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
720
721         /* type-specific links */
722         switch (object->partype) {
723                 case PARSKEL:  /* Armature Deform (Virtual Modifier) */
724                 {
725                         ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
726                         add_relation(parent_key, ob_key, "Armature Deform Parent");
727                         break;
728                 }
729
730                 case PARVERT1: /* Vertex Parent */
731                 case PARVERT3:
732                 {
733                         ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
734                         add_relation(parent_key, ob_key, "Vertex Parent");
735
736                         /* XXX not sure what this is for or how you could be done properly - lukas */
737                         OperationDepsNode *parent_node = find_operation_node(parent_key);
738                         if (parent_node != NULL) {
739                                 parent_node->customdata_mask |= CD_MASK_ORIGINDEX;
740                         }
741
742                         ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
743                         add_relation(transform_key, ob_key, "Vertex Parent TFM");
744                         break;
745                 }
746
747                 case PARBONE: /* Bone Parent */
748                 {
749                         ComponentKey parent_bone_key(&object->parent->id,
750                                                      DEG_NODE_TYPE_BONE,
751                                                      object->parsubstr);
752                         OperationKey parent_transform_key(&object->parent->id,
753                                                           DEG_NODE_TYPE_TRANSFORM,
754                                                           DEG_OPCODE_TRANSFORM_FINAL);
755                         add_relation(parent_bone_key, ob_key, "Bone Parent");
756                         add_relation(parent_transform_key, ob_key, "Armature Parent");
757                         break;
758                 }
759
760                 default:
761                 {
762                         if (object->parent->type == OB_LATTICE) {
763                                 /* Lattice Deform Parent - Virtual Modifier */
764                                 // XXX: no virtual modifiers should be left!
765                                 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
766                                 ComponentKey geom_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
767
768                                 add_relation(parent_key, ob_key, "Lattice Deform Parent");
769                                 add_relation(geom_key, ob_key, "Lattice Deform Parent Geom");
770                         }
771                         else if (object->parent->type == OB_CURVE) {
772                                 Curve *cu = (Curve *)object->parent->data;
773
774                                 if (cu->flag & CU_PATH) {
775                                         /* Follow Path */
776                                         ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
777                                         add_relation(parent_key, ob_key, "Curve Follow Parent");
778
779                                         ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
780                                         add_relation(transform_key, ob_key, "Curve Follow TFM");
781                                 }
782                                 else {
783                                         /* Standard Parent */
784                                         ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
785                                         add_relation(parent_key, ob_key, "Curve Parent");
786                                 }
787                         }
788                         else {
789                                 /* Standard Parent */
790                                 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
791                                 add_relation(parent_key, ob_key, "Parent");
792                         }
793                         break;
794                 }
795         }
796
797         /* exception case: parent is duplivert */
798         if ((object->type == OB_MBALL) && (object->parent->transflag & OB_DUPLIVERTS)) {
799                 //dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert");
800         }
801 }
802
803 void DepsgraphRelationBuilder::build_constraints(ID *id,
804                                                  eDepsNode_Type component_type,
805                                                  const char *component_subdata,
806                                                  ListBase *constraints,
807                                                  RootPChanMap *root_map)
808 {
809         OperationKey constraint_op_key(
810                 id,
811                 component_type,
812                 component_subdata,
813                 (component_type == DEG_NODE_TYPE_BONE)
814                         ? DEG_OPCODE_BONE_CONSTRAINTS
815                         : DEG_OPCODE_TRANSFORM_CONSTRAINTS);
816         /* Add dependencies for each constraint in turn. */
817         for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) {
818                 const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
819                 /* Invalid constraint type. */
820                 if (cti == NULL) {
821                         continue;
822                 }
823                 /* Special case for camera tracking -- it doesn't use targets to
824                  * define relations.
825                  */
826                 /* TODO: we can now represent dependencies in a much richer manner,
827                  * so review how this is done.
828                  */
829                 if (ELEM(cti->type,
830                          CONSTRAINT_TYPE_FOLLOWTRACK,
831                          CONSTRAINT_TYPE_CAMERASOLVER,
832                          CONSTRAINT_TYPE_OBJECTSOLVER))
833                 {
834                         bool depends_on_camera = false;
835                         if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
836                                 bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
837                                 if (((data->clip) ||
838                                      (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0])
839                                 {
840                                         depends_on_camera = true;
841                                 }
842                                 if (data->depth_ob) {
843                                         ComponentKey depth_transform_key(&data->depth_ob->id,
844                                                                          DEG_NODE_TYPE_TRANSFORM);
845                                         ComponentKey depth_geometry_key(&data->depth_ob->id,
846                                                                         DEG_NODE_TYPE_GEOMETRY);
847                                         add_relation(depth_transform_key, constraint_op_key, cti->name);
848                                         add_relation(depth_geometry_key, constraint_op_key, cti->name);
849                                 }
850                         }
851                         else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
852                                 depends_on_camera = true;
853                         }
854                         if (depends_on_camera && scene_->camera != NULL) {
855                                 ComponentKey camera_key(&scene_->camera->id, DEG_NODE_TYPE_TRANSFORM);
856                                 add_relation(camera_key, constraint_op_key, cti->name);
857                         }
858                         /* TODO(sergey): This is more a TimeSource -> MovieClip ->
859                          * Constraint dependency chain.
860                          */
861                         TimeSourceKey time_src_key;
862                         add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation");
863                 }
864                 else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
865                         /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint
866                          * dependency chain.
867                          */
868                         TimeSourceKey time_src_key;
869                         add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation");
870                         bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data;
871                         if (data->cache_file) {
872                                 ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE);
873                                 add_relation(cache_key, constraint_op_key, cti->name);
874                         }
875                 }
876                 else if (cti->get_constraint_targets) {
877                         ListBase targets = {NULL, NULL};
878                         cti->get_constraint_targets(con, &targets);
879                         LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) {
880                                 if (ct->tar == NULL) {
881                                         continue;
882                                 }
883                                 if (ELEM(con->type,
884                                          CONSTRAINT_TYPE_KINEMATIC,
885                                          CONSTRAINT_TYPE_SPLINEIK))
886                                 {
887                                         /* Ignore IK constraints - these are handled separately
888                                          * (on pose level).
889                                          */
890                                 }
891                                 else if (ELEM(con->type,
892                                               CONSTRAINT_TYPE_FOLLOWPATH,
893                                               CONSTRAINT_TYPE_CLAMPTO))
894                                 {
895                                         /* These constraints require path geometry data. */
896                                         ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
897                                         add_relation(target_key, constraint_op_key, cti->name);
898                                         ComponentKey target_transform_key(&ct->tar->id,
899                                                                           DEG_NODE_TYPE_TRANSFORM);
900                                         add_relation(target_transform_key, constraint_op_key, cti->name);
901                                 }
902                                 else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) {
903                                         /* bone */
904                                         if (&ct->tar->id == id) {
905                                                 /* same armature  */
906                                                 eDepsOperation_Code target_key_opcode;
907                                                 /* Using "done" here breaks in-chain deps, while using
908                                                  * "ready" here breaks most production rigs instead.
909                                                  * So, we do a compromise here, and only do this when an
910                                                  * IK chain conflict may occur.
911                                                  */
912                                                 if (root_map->has_common_root(component_subdata,
913                                                                               ct->subtarget))
914                                                 {
915                                                         target_key_opcode = DEG_OPCODE_BONE_READY;
916                                                 }
917                                                 else {
918                                                         target_key_opcode = DEG_OPCODE_BONE_DONE;
919                                                 }
920                                                 OperationKey target_key(&ct->tar->id,
921                                                                         DEG_NODE_TYPE_BONE,
922                                                                         ct->subtarget,
923                                                                         target_key_opcode);
924                                                 add_relation(target_key, constraint_op_key, cti->name);
925                                         }
926                                         else {
927                                                 /* Different armature - we can safely use the result
928                                                  * of that.
929                                                  */
930                                                 OperationKey target_key(&ct->tar->id,
931                                                                         DEG_NODE_TYPE_BONE,
932                                                                         ct->subtarget,
933                                                                         DEG_OPCODE_BONE_DONE);
934                                                 add_relation(target_key, constraint_op_key, cti->name);
935                                         }
936                                 }
937                                 else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) &&
938                                          (ct->subtarget[0]))
939                                 {
940                                         /* Vertex group. */
941                                         /* NOTE: for now, we don't need to represent vertex groups
942                                          * separately.
943                                          */
944                                         ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
945                                         add_relation(target_key, constraint_op_key, cti->name);
946                                         if (ct->tar->type == OB_MESH) {
947                                                 OperationDepsNode *node2 = find_operation_node(target_key);
948                                                 if (node2 != NULL) {
949                                                         node2->customdata_mask |= CD_MASK_MDEFORMVERT;
950                                                 }
951                                         }
952                                 }
953                                 else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
954                                         /* Constraints which requires the target object surface. */
955                                         ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
956                                         add_relation(target_key, constraint_op_key, cti->name);
957                                         /* NOTE: obdata eval now doesn't necessarily depend on the
958                                          * object's transform.
959                                          */
960                                         ComponentKey target_transform_key(&ct->tar->id,
961                                                                           DEG_NODE_TYPE_TRANSFORM);
962                                         add_relation(target_transform_key, constraint_op_key, cti->name);
963                                 }
964                                 else {
965                                         /* Standard object relation. */
966                                         // TODO: loc vs rot vs scale?
967                                         if (&ct->tar->id == id) {
968                                                 /* Constraint targetting own object:
969                                                  * - This case is fine IFF we're dealing with a bone
970                                                  *   constraint pointing to its own armature. In that
971                                                  *   case, it's just transform -> bone.
972                                                  * - If however it is a real self targetting case, just
973                                                  *   make it depend on the previous constraint (or the
974                                                  *   pre-constraint state).
975                                                  */
976                                                 if ((ct->tar->type == OB_ARMATURE) &&
977                                                     (component_type == DEG_NODE_TYPE_BONE))
978                                                 {
979                                                         OperationKey target_key(&ct->tar->id,
980                                                                                 DEG_NODE_TYPE_TRANSFORM,
981                                                                                 DEG_OPCODE_TRANSFORM_FINAL);
982                                                         add_relation(target_key, constraint_op_key, cti->name);
983                                                 }
984                                                 else {
985                                                         OperationKey target_key(&ct->tar->id,
986                                                                                 DEG_NODE_TYPE_TRANSFORM,
987                                                                                 DEG_OPCODE_TRANSFORM_LOCAL);
988                                                         add_relation(target_key, constraint_op_key, cti->name);
989                                                 }
990                                         }
991                                         else {
992                                                 /* Normal object dependency. */
993                                                 OperationKey target_key(&ct->tar->id,
994                                                                         DEG_NODE_TYPE_TRANSFORM,
995                                                                         DEG_OPCODE_TRANSFORM_FINAL);
996                                                 add_relation(target_key, constraint_op_key, cti->name);
997                                         }
998                                 }
999                                 /* Constraints which needs world's matrix for transform.
1000                                  * TODO(sergey): More constraints here?
1001                                  */
1002                                 if (ELEM(con->type,
1003                                          CONSTRAINT_TYPE_ROTLIKE,
1004                                          CONSTRAINT_TYPE_SIZELIKE,
1005                                          CONSTRAINT_TYPE_LOCLIKE,
1006                                          CONSTRAINT_TYPE_TRANSLIKE))
1007                                 {
1008                                         /* TODO(sergey): Add used space check. */
1009                                         ComponentKey target_transform_key(&ct->tar->id,
1010                                                                           DEG_NODE_TYPE_TRANSFORM);
1011                                         add_relation(target_transform_key, constraint_op_key, cti->name);
1012                                 }
1013                         }
1014                         if (cti->flush_constraint_targets) {
1015                                 cti->flush_constraint_targets(con, &targets, 1);
1016                         }
1017                 }
1018         }
1019 }
1020
1021 void DepsgraphRelationBuilder::build_animdata(ID *id)
1022 {
1023         /* Animation curves and NLA. */
1024         build_animdata_curves(id);
1025         /* Drivers. */
1026         build_animdata_drivers(id);
1027 }
1028
1029 void DepsgraphRelationBuilder::build_animdata_curves(ID *id)
1030 {
1031         AnimData *adt = BKE_animdata_from_id(id);
1032         if (adt == NULL) {
1033                 return;
1034         }
1035         if (adt->action != NULL) {
1036                 build_action(adt->action);
1037         }
1038         if (adt->action == NULL && adt->nla_tracks.first == NULL) {
1039                 return;
1040         }
1041         /* Wire up dependency to time source. */
1042         ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
1043         /* Relation from action itself. */
1044         if (adt->action != NULL) {
1045                 ComponentKey action_key(&adt->action->id, DEG_NODE_TYPE_ANIMATION);
1046                 add_relation(action_key, adt_key, "Action -> Animation");
1047         }
1048         /* Get source operations. */
1049         DepsNode *node_from = get_node(adt_key);
1050         BLI_assert(node_from != NULL);
1051         if (node_from == NULL) {
1052                 return;
1053         }
1054         OperationDepsNode *operation_from = node_from->get_exit_operation();
1055         BLI_assert(operation_from != NULL);
1056         /* Build relations from animation operation to properties it changes. */
1057         if (adt->action != NULL) {
1058                 build_animdata_curves_targets(id, adt_key,
1059                                       operation_from,
1060                                       &adt->action->curves);
1061         }
1062         LISTBASE_FOREACH(NlaTrack *, nlt, &adt->nla_tracks) {
1063                 build_animdata_nlastrip_targets(id, adt_key,
1064                                                 operation_from,
1065                                                 &nlt->strips);
1066         }
1067 }
1068
1069 void DepsgraphRelationBuilder::build_animdata_curves_targets(
1070         ID *id, ComponentKey &adt_key,
1071         OperationDepsNode *operation_from,
1072         ListBase *curves)
1073 {
1074         /* Iterate over all curves and build relations. */
1075         PointerRNA id_ptr;
1076         RNA_id_pointer_create(id, &id_ptr);
1077         LISTBASE_FOREACH(FCurve *, fcu, curves) {
1078                 PointerRNA ptr;
1079                 PropertyRNA *prop;
1080                 int index;
1081                 if (!RNA_path_resolve_full(&id_ptr, fcu->rna_path,
1082                                            &ptr, &prop, &index))
1083                 {
1084                         continue;
1085                 }
1086                 DepsNode *node_to = graph_->find_node_from_pointer(&ptr, prop);
1087                 if (node_to == NULL) {
1088                         continue;
1089                 }
1090                 OperationDepsNode *operation_to = node_to->get_entry_operation();
1091                 /* NOTE: Special case for bones, avoid relation from animation to
1092                  * each of the bones. Bone evaluation could only start from pose
1093                  * init anyway.
1094                  */
1095                 if (operation_to->opcode == DEG_OPCODE_BONE_LOCAL) {
1096                         OperationKey pose_init_key(id,
1097                                                    DEG_NODE_TYPE_EVAL_POSE,
1098                                                    DEG_OPCODE_POSE_INIT);
1099                         add_relation(adt_key, pose_init_key, "Animation -> Prop", true);
1100                         continue;
1101                 }
1102                 graph_->add_new_relation(operation_from, operation_to,
1103                                          "Animation -> Prop",
1104                                          true);
1105                 /* It is possible that animation is writing to a nested ID datablock,
1106                  * need to make sure animation is evaluated after target ID is copied.
1107                  */
1108                 const IDDepsNode *id_node_from = operation_from->owner->owner;
1109                 const IDDepsNode *id_node_to = operation_to->owner->owner;
1110                 if (id_node_from != id_node_to) {
1111                         ComponentKey cow_key(id_node_to->id_orig,
1112                                              DEG_NODE_TYPE_COPY_ON_WRITE);
1113                         add_relation(cow_key, adt_key, "Target CoW -> Animation", true);
1114                 }
1115         }
1116 }
1117
1118 void DepsgraphRelationBuilder::build_animdata_nlastrip_targets(
1119         ID *id, ComponentKey &adt_key,
1120         OperationDepsNode *operation_from,
1121         ListBase *strips)
1122 {
1123         LISTBASE_FOREACH(NlaStrip *, strip, strips) {
1124                 if (strip->act != NULL) {
1125                         build_animdata_curves_targets(id, adt_key,
1126                                                       operation_from,
1127                                                       &strip->act->curves);
1128                 }
1129                 else if (strip->strips.first != NULL) {
1130                         build_animdata_nlastrip_targets(id, adt_key,
1131                                                         operation_from,
1132                                                         &strip->strips);
1133                 }
1134         }
1135 }
1136
1137 void DepsgraphRelationBuilder::build_animdata_drivers(ID *id)
1138 {
1139         AnimData *adt = BKE_animdata_from_id(id);
1140         if (adt == NULL) {
1141                 return;
1142         }
1143         ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
1144         LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
1145                 OperationKey driver_key(id,
1146                                         DEG_NODE_TYPE_PARAMETERS,
1147                                         DEG_OPCODE_DRIVER,
1148                                         fcu->rna_path ? fcu->rna_path : "",
1149                                         fcu->array_index);
1150
1151                 /* create the driver's relations to targets */
1152                 build_driver(id, fcu);
1153                 /* Special case for array drivers: we can not multithread them because
1154                  * of the way how they work internally: animation system will write the
1155                  * whole array back to RNA even when changing individual array value.
1156                  *
1157                  * Some tricky things here:
1158                  * - array_index is -1 for single channel drivers, meaning we only have
1159                  *   to do some magic when array_index is not -1.
1160                  * - We do relation from next array index to a previous one, so we don't
1161                  *   have to deal with array index 0.
1162                  *
1163                  * TODO(sergey): Avoid liner lookup somehow.
1164                  */
1165                 if (fcu->array_index > 0) {
1166                         FCurve *fcu_prev = NULL;
1167                         LISTBASE_FOREACH (FCurve *, fcu_candidate, &adt->drivers) {
1168                                 /* Writing to different RNA paths is  */
1169                                 const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1170                                 if (!STREQ(fcu_candidate->rna_path, rna_path)) {
1171                                         continue;
1172                                 }
1173                                 /* We only do relation from previous fcurve to previous one. */
1174                                 if (fcu_candidate->array_index >= fcu->array_index) {
1175                                         continue;
1176                                 }
1177                                 /* Choose fcurve with highest possible array index. */
1178                                 if (fcu_prev == NULL ||
1179                                     fcu_candidate->array_index > fcu_prev->array_index)
1180                                 {
1181                                         fcu_prev = fcu_candidate;
1182                                 }
1183                         }
1184                         if (fcu_prev != NULL) {
1185                                 OperationKey prev_driver_key(id,
1186                                                              DEG_NODE_TYPE_PARAMETERS,
1187                                                              DEG_OPCODE_DRIVER,
1188                                                              fcu_prev->rna_path ? fcu_prev->rna_path : "",
1189                                                              fcu_prev->array_index);
1190                                 OperationKey driver_key(id,
1191                                                         DEG_NODE_TYPE_PARAMETERS,
1192                                                         DEG_OPCODE_DRIVER,
1193                                                         fcu->rna_path ? fcu->rna_path : "",
1194                                                         fcu->array_index);
1195                                 add_relation(prev_driver_key, driver_key, "Driver Order");
1196                         }
1197                 }
1198
1199                 /* prevent driver from occurring before own animation... */
1200                 if (adt->action || adt->nla_tracks.first) {
1201                         add_relation(adt_key, driver_key, "AnimData Before Drivers");
1202                 }
1203         }
1204 }
1205
1206 void DepsgraphRelationBuilder::build_action(bAction *action)
1207 {
1208         if (built_map_.checkIsBuiltAndTag(action)) {
1209                 return;
1210         }
1211         TimeSourceKey time_src_key;
1212         ComponentKey animation_key(&action->id, DEG_NODE_TYPE_ANIMATION);
1213         add_relation(time_src_key, animation_key, "TimeSrc -> Animation");
1214 }
1215
1216 void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
1217 {
1218         ChannelDriver *driver = fcu->driver;
1219         OperationKey driver_key(id,
1220                                 DEG_NODE_TYPE_PARAMETERS,
1221                                 DEG_OPCODE_DRIVER,
1222                                 fcu->rna_path ? fcu->rna_path : "",
1223                                 fcu->array_index);
1224         /* Driver -> data components (for interleaved evaluation
1225          * bones/constraints/modifiers).
1226          */
1227         build_driver_data(id, fcu);
1228         /* Loop over variables to get the target relationships. */
1229         build_driver_variables(id, fcu);
1230         /* It's quite tricky to detect if the driver actually depends on time or
1231          * not, so for now we'll be quite conservative here about optimization and
1232          * consider all python drivers to be depending on time.
1233          */
1234         if ((driver->type == DRIVER_TYPE_PYTHON) &&
1235             python_driver_depends_on_time(driver))
1236         {
1237                 TimeSourceKey time_src_key;
1238                 add_relation(time_src_key, driver_key, "TimeSrc -> Driver");
1239         }
1240 }
1241
1242 void DepsgraphRelationBuilder::build_driver_data(ID *id, FCurve *fcu)
1243 {
1244         OperationKey driver_key(id,
1245                                 DEG_NODE_TYPE_PARAMETERS,
1246                                 DEG_OPCODE_DRIVER,
1247                                 fcu->rna_path ? fcu->rna_path : "",
1248                                 fcu->array_index);
1249         const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1250         const RNAPathKey self_key(id, rna_path);
1251         if (GS(id->name) == ID_AR && strstr(rna_path, "bones[")) {
1252                 /* Drivers on armature-level bone settings (i.e. bbone stuff),
1253                  * which will affect the evaluation of corresponding pose bones.
1254                  */
1255                 IDDepsNode *arm_node = graph_->find_id_node(id);
1256                 char *bone_name = BLI_str_quoted_substrN(rna_path, "bones[");
1257                 if (arm_node != NULL && bone_name != NULL) {
1258                         /* Find objects which use this, and make their eval callbacks
1259                          * depend on this.
1260                          */
1261                         foreach (DepsRelation *rel, arm_node->outlinks) {
1262                                 IDDepsNode *to_node = (IDDepsNode *)rel->to;
1263                                 /* We only care about objects with pose data which use this. */
1264                                 if (GS(to_node->id_orig->name) == ID_OB) {
1265                                         Object *object = (Object *)to_node->id_orig;
1266                                         // NOTE: object->pose may be NULL
1267                                         bPoseChannel *pchan = BKE_pose_channel_find_name(object->pose,
1268                                                                                          bone_name);
1269                                         if (pchan != NULL) {
1270                                                 OperationKey bone_key(&object->id,
1271                                                                       DEG_NODE_TYPE_BONE,
1272                                                                       pchan->name,
1273                                                                       DEG_OPCODE_BONE_LOCAL);
1274                                                 add_relation(driver_key,
1275                                                              bone_key,
1276                                                              "Arm Bone -> Driver -> Bone");
1277                                         }
1278                                 }
1279                         }
1280                         /* Free temp data. */
1281                         MEM_freeN(bone_name);
1282                         bone_name = NULL;
1283                 }
1284                 else {
1285                         fprintf(stderr,
1286                                 "Couldn't find armature bone name for driver path - '%s'\n",
1287                                 rna_path);
1288                 }
1289         }
1290         else {
1291                 RNAPathKey target_key(id, rna_path);
1292                 add_relation(driver_key, target_key, "Driver -> Target");
1293                 /* Similar to the case with f-curves, driver might drive a nested
1294                  * datablock, which means driver execution should wait for that
1295                  * datablock to be copied.
1296                  */
1297                 {
1298                         PointerRNA id_ptr;
1299                         PointerRNA ptr;
1300                         RNA_id_pointer_create(id, &id_ptr);
1301                         if (RNA_path_resolve_full(&id_ptr, fcu->rna_path, &ptr, NULL, NULL)) {
1302                                 if (id_ptr.id.data != ptr.id.data) {
1303                                         ComponentKey cow_key((ID *)ptr.id.data,
1304                                                              DEG_NODE_TYPE_COPY_ON_WRITE);
1305                                         add_relation(cow_key,
1306                                                      driver_key,
1307                                                      "Target CoW -> Driver",
1308                                                      true);
1309                                 }
1310                         }
1311                 }
1312                 if (RNA_pointer_is_null(&target_key.ptr)) {
1313                         /* TODO(sergey): This would only mean that driver is broken.
1314                          * so we can't create relation anyway. However, we need to avoid
1315                          * adding drivers which are known to be buggy to a dependency
1316                          * graph, in order to save computational power.
1317                          */
1318                 }
1319                 else {
1320                         if (target_key.prop != NULL &&
1321                             RNA_property_is_idprop(target_key.prop))
1322                         {
1323                                 OperationKey parameters_key(id,
1324                                                             DEG_NODE_TYPE_PARAMETERS,
1325                                                             DEG_OPCODE_PARAMETERS_EVAL);
1326                                 add_relation(target_key,
1327                                              parameters_key,
1328                                              "Driver Target -> Properties");
1329                         }
1330                         add_relation(driver_key, target_key, "Driver -> Target");
1331                 }
1332         }
1333 }
1334
1335 void DepsgraphRelationBuilder::build_driver_variables(ID *id, FCurve *fcu)
1336 {
1337         ChannelDriver *driver = fcu->driver;
1338         OperationKey driver_key(id,
1339                                 DEG_NODE_TYPE_PARAMETERS,
1340                                 DEG_OPCODE_DRIVER,
1341                                 fcu->rna_path ? fcu->rna_path : "",
1342                                 fcu->array_index);
1343         const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1344         const RNAPathKey self_key(id, rna_path);
1345
1346         LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
1347                 /* Only used targets. */
1348                 DRIVER_TARGETS_USED_LOOPER(dvar)
1349                 {
1350                         if (dtar->id == NULL) {
1351                                 continue;
1352                         }
1353                         build_id(dtar->id);
1354                         /* Special handling for directly-named bones. */
1355                         if ((dtar->flag & DTAR_FLAG_STRUCT_REF) &&
1356                             (((Object *)dtar->id)->type == OB_ARMATURE) &&
1357                             (dtar->pchan_name[0]))
1358                         {
1359                                 Object *object = (Object *)dtar->id;
1360                                 bPoseChannel *target_pchan =
1361                                         BKE_pose_channel_find_name(object->pose,
1362                                                                    dtar->pchan_name);
1363                                 if (target_pchan == NULL) {
1364                                         continue;
1365                                 }
1366                                 OperationKey variable_key(dtar->id,
1367                                                           DEG_NODE_TYPE_BONE,
1368                                                           target_pchan->name,
1369                                                           DEG_OPCODE_BONE_DONE);
1370                                 if (is_same_bone_dependency(variable_key, self_key)) {
1371                                         continue;
1372                                 }
1373                                 add_relation(variable_key, driver_key, "Bone Target -> Driver");
1374                         }
1375                         else if (dtar->flag & DTAR_FLAG_STRUCT_REF) {
1376                                 /* Get node associated with the object's transforms. */
1377                                 if (dtar->id == id) {
1378                                         /* Ignore input dependency if we're driving properties of
1379                                          * the same ID, otherwise we'll be ending up in a cyclic
1380                                          * dependency here.
1381                                          */
1382                                         continue;
1383                                 }
1384                                 OperationKey target_key(dtar->id,
1385                                                         DEG_NODE_TYPE_TRANSFORM,
1386                                                         DEG_OPCODE_TRANSFORM_FINAL);
1387                                 add_relation(target_key, driver_key, "Target -> Driver");
1388                         }
1389                         else if (dtar->rna_path) {
1390                                 RNAPathKey variable_key(dtar->id, dtar->rna_path);
1391                                 if (RNA_pointer_is_null(&variable_key.ptr)) {
1392                                         continue;
1393                                 }
1394                                 if (is_same_bone_dependency(variable_key, self_key) ||
1395                                     is_same_nodetree_node_dependency(variable_key, self_key) ||
1396                                     is_same_shapekey_dependency(variable_key, self_key))
1397                                 {
1398                                         continue;
1399                                 }
1400                                 add_relation(variable_key, driver_key, "RNA Target -> Driver");
1401                         }
1402                         else {
1403                                 if (dtar->id == id) {
1404                                         /* Ignore input dependency if we're driving properties of
1405                                          * the same ID, otherwise we'll be ending up in a cyclic
1406                                          * dependency here.
1407                                          */
1408                                         continue;
1409                                 }
1410                                 /* Resolve path to get node. */
1411                                 RNAPathKey target_key(dtar->id,
1412                                                       dtar->rna_path ? dtar->rna_path : "");
1413                                 add_relation(target_key, driver_key, "RNA Target -> Driver");
1414                         }
1415                 }
1416                 DRIVER_TARGETS_LOOPER_END
1417         }
1418 }
1419
1420 void DepsgraphRelationBuilder::build_world(World *world)
1421 {
1422         if (built_map_.checkIsBuiltAndTag(world)) {
1423                 return;
1424         }
1425         build_animdata(&world->id);
1426         /* TODO: other settings? */
1427         /* world's nodetree */
1428         if (world->nodetree != NULL) {
1429                 build_nodetree(world->nodetree);
1430                 ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_SHADING);
1431                 ComponentKey world_key(&world->id, DEG_NODE_TYPE_SHADING);
1432                 add_relation(ntree_key, world_key, "NTree->World Shading Update");
1433                 build_nested_nodetree(&world->id, world->nodetree);
1434         }
1435 }
1436
1437 void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
1438 {
1439         RigidBodyWorld *rbw = scene->rigidbody_world;
1440
1441         OperationKey init_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD);
1442         OperationKey sim_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM);
1443
1444         /* rel between the two sim-nodes */
1445         add_relation(init_key, sim_key, "Rigidbody [Init -> SimStep]");
1446
1447         /* set up dependencies between these operations and other builtin nodes --------------- */
1448
1449         /* time dependency */
1450         TimeSourceKey time_src_key;
1451         add_relation(time_src_key, init_key, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)");
1452
1453         /* objects - simulation participants */
1454         if (rbw->group) {
1455                 build_collection(DEG_COLLECTION_OWNER_OBJECT, NULL, rbw->group);
1456
1457                 FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->group, object)
1458                 {
1459                         if (object->type != OB_MESH) {
1460                                 continue;
1461                         }
1462
1463                         /* hook up evaluation order...
1464                          * 1) flushing rigidbody results follows base transforms being applied
1465                          * 2) rigidbody flushing can only be performed after simulation has been run
1466                          *
1467                          * 3) simulation needs to know base transforms to figure out what to do
1468                          *    XXX: there's probably a difference between passive and active
1469                          *         - passive don't change, so may need to know full transform...
1470                          */
1471                         OperationKey rbo_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1472
1473                         eDepsOperation_Code trans_opcode = object->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL;
1474                         OperationKey trans_op(&object->id, DEG_NODE_TYPE_TRANSFORM, trans_opcode);
1475
1476                         add_relation(sim_key, rbo_key, "Rigidbody Sim Eval -> RBO Sync");
1477
1478                         /* Geometry must be known to create the rigid body. RBO_MESH_BASE uses the non-evaluated
1479                          * mesh, so then the evaluation is unnecessary. */
1480                         if (object->rigidbody_object->mesh_source != RBO_MESH_BASE) {
1481                                 ComponentKey geom_key(&object->id, DEG_NODE_TYPE_GEOMETRY);
1482                                 add_relation(geom_key, init_key, "Object Geom Eval -> Rigidbody Rebuild");
1483                         }
1484
1485                         /* if constraints exist, those depend on the result of the rigidbody sim
1486                          * - This allows constraints to modify the result of the sim (i.e. clamping)
1487                          *   while still allowing the sim to depend on some changes to the objects.
1488                          *   Also, since constraints are hooked up to the final nodes, this link
1489                          *   means that we can also fit in there too...
1490                          * - Later, it might be good to include a constraint in the stack allowing us
1491                          *   to control whether rigidbody eval gets interleaved into the constraint stack
1492                          */
1493                         if (object->constraints.first) {
1494                                 OperationKey constraint_key(&object->id,
1495                                                             DEG_NODE_TYPE_TRANSFORM,
1496                                                             DEG_OPCODE_TRANSFORM_CONSTRAINTS);
1497                                 add_relation(rbo_key, constraint_key, "RBO Sync -> Ob Constraints");
1498                         }
1499                         else {
1500                                 /* Final object transform depends on rigidbody.
1501                                  *
1502                                  * NOTE: Currently we consider final here an ubereval node.
1503                                  * If it is gone we'll need to reconsider relation here.
1504                                  */
1505                                 OperationKey uber_key(&object->id,
1506                                                       DEG_NODE_TYPE_TRANSFORM,
1507                                                       DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
1508                                 add_relation(rbo_key, uber_key, "RBO Sync -> Uber (Temp)");
1509                         }
1510
1511                         /* Needed to get correct base values. */
1512                         add_relation(trans_op, sim_key, "Base Ob Transform -> Rigidbody Sim Eval");
1513                 }
1514                 FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
1515         }
1516
1517         /* constraints */
1518         if (rbw->constraints) {
1519                 FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(rbw->constraints, object)
1520                 {
1521                         RigidBodyCon *rbc = object->rigidbody_constraint;
1522                         if (rbc == NULL || rbc->ob1 == NULL || rbc->ob2 == NULL) {
1523                                 /* When either ob1 or ob2 is NULL, the constraint doesn't work. */
1524                                 continue;
1525                         }
1526
1527                         /* final result of the constraint object's transform controls how the
1528                          * constraint affects the physics sim for these objects
1529                          */
1530                         ComponentKey trans_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1531                         OperationKey ob1_key(&rbc->ob1->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1532                         OperationKey ob2_key(&rbc->ob2->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1533
1534                         /* - constrained-objects sync depends on the constraint-holder */
1535                         add_relation(trans_key, ob1_key, "RigidBodyConstraint -> RBC.Object_1");
1536                         add_relation(trans_key, ob2_key, "RigidBodyConstraint -> RBC.Object_2");
1537
1538                         /* - ensure that sim depends on this constraint's transform */
1539                         add_relation(trans_key, sim_key, "RigidBodyConstraint Transform -> RB Simulation");
1540                 }
1541                 FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
1542         }
1543 }
1544
1545 void DepsgraphRelationBuilder::build_particles(Object *object)
1546 {
1547         TimeSourceKey time_src_key;
1548         OperationKey obdata_ubereval_key(&object->id,
1549                                          DEG_NODE_TYPE_GEOMETRY,
1550                                          DEG_OPCODE_GEOMETRY_UBEREVAL);
1551         OperationKey eval_init_key(&object->id,
1552                                    DEG_NODE_TYPE_EVAL_PARTICLES,
1553                                    DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
1554
1555         /* Particle systems. */
1556         LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
1557                 ParticleSettings *part = psys->part;
1558
1559                 /* Build particle settings relations.
1560                  *
1561                  * NOTE: The call itself ensures settings are only build once.
1562                  */
1563                 build_particle_settings(part);
1564
1565                 /* This particle system. */
1566                 OperationKey psys_key(&object->id,
1567                                       DEG_NODE_TYPE_EVAL_PARTICLES,
1568                                       DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
1569                                       psys->name);
1570
1571                 /* Update particle system when settings changes. */
1572                 OperationKey particle_settings_key(&part->id,
1573                                                    DEG_NODE_TYPE_PARAMETERS,
1574                                                    DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
1575                 add_relation(particle_settings_key, eval_init_key, "Particle Settings Change");
1576                 add_relation(eval_init_key, psys_key, "Init -> PSys");
1577                 /* TODO(sergey): Currently particle update is just a placeholder,
1578                  * hook it to the ubereval node so particle system is getting updated
1579                  * on playback.
1580                  */
1581                 add_relation(psys_key, obdata_ubereval_key, "PSys -> UberEval");
1582                 /* Collisions */
1583                 if (part->type != PART_HAIR) {
1584                         add_collision_relations(psys_key,
1585                                                 object,
1586                                                 part->collision_group,
1587                                                 "Particle Collision");
1588                 }
1589                 else if ((psys->flag & PSYS_HAIR_DYNAMICS) &&
1590                          psys->clmd != NULL &&
1591                          psys->clmd->coll_parms != NULL)
1592                 {
1593                         add_collision_relations(psys_key,
1594                                                 object,
1595                                                 psys->clmd->coll_parms->group,
1596                                                 "Hair Collision");
1597                 }
1598                 /* Effectors. */
1599                 add_forcefield_relations(psys_key,
1600                                          object,
1601                                          psys,
1602                                          part->effector_weights,
1603                                          part->type == PART_HAIR,
1604                                          "Particle Field");
1605                 /* Boids .*/
1606                 if (part->boids) {
1607                         LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
1608                                 LISTBASE_FOREACH (BoidRule *, rule, &state->rules) {
1609                                         Object *ruleob = NULL;
1610                                         if (rule->type == eBoidRuleType_Avoid) {
1611                                                 ruleob = ((BoidRuleGoalAvoid *)rule)->ob;
1612                                         }
1613                                         else if (rule->type == eBoidRuleType_FollowLeader) {
1614                                                 ruleob = ((BoidRuleFollowLeader *)rule)->ob;
1615                                         }
1616                                         if (ruleob) {
1617                                                 ComponentKey ruleob_key(&ruleob->id,
1618                                                                         DEG_NODE_TYPE_TRANSFORM);
1619                                                 add_relation(ruleob_key, psys_key, "Boid Rule");
1620                                         }
1621                                 }
1622                         }
1623                 }
1624                 switch (part->ren_as) {
1625                         case PART_DRAW_OB:
1626                                 if (part->dup_ob != NULL) {
1627                                         /* Make sure object's relations are all built.  */
1628                                         build_object(NULL, part->dup_ob);
1629                                         /* Build relation for the particle visualization. */
1630                                         build_particles_visualization_object(object,
1631                                                                              psys,
1632                                                                              part->dup_ob);
1633                                 }
1634                                 break;
1635                         case PART_DRAW_GR:
1636                                 if (part->dup_group != NULL) {
1637                                         build_collection(DEG_COLLECTION_OWNER_OBJECT, NULL, part->dup_group);
1638                                         LISTBASE_FOREACH (CollectionObject *, go, &part->dup_group->gobject) {
1639                                                 build_particles_visualization_object(object,
1640                                                                                      psys,
1641                                                                                      go->ob);
1642                                         }
1643                                 }
1644                                 break;
1645                 }
1646         }
1647
1648         /* Particle depends on the object transform, so that channel is to be ready
1649          * first.
1650          *
1651          * TODO(sergey): This relation should be altered once real granular update
1652          * is implemented.
1653          */
1654         ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1655         add_relation(transform_key, obdata_ubereval_key, "Partcile Eval");
1656
1657         OperationKey point_cache_reset_key(&object->id,
1658                                            DEG_NODE_TYPE_CACHE,
1659                                            DEG_OPCODE_POINT_CACHE_RESET);
1660         add_relation(transform_key, point_cache_reset_key, "Object Transform -> Point Cache Reset");
1661         add_relation(point_cache_reset_key, obdata_ubereval_key, "Point Cache Reset -> UberEval");
1662 }
1663
1664 void DepsgraphRelationBuilder::build_particle_settings(ParticleSettings *part)
1665 {
1666         if (built_map_.checkIsBuiltAndTag(part)) {
1667                 return;
1668         }
1669         /* Animation data relations. */
1670         build_animdata(&part->id);
1671 }
1672
1673 void DepsgraphRelationBuilder::build_particles_visualization_object(
1674         Object *object,
1675         ParticleSystem *psys,
1676         Object *draw_object)
1677 {
1678         OperationKey psys_key(&object->id,
1679                               DEG_NODE_TYPE_EVAL_PARTICLES,
1680                               DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
1681                               psys->name);
1682         OperationKey obdata_ubereval_key(&object->id,
1683                                          DEG_NODE_TYPE_GEOMETRY,
1684                                          DEG_OPCODE_GEOMETRY_UBEREVAL);
1685         ComponentKey dup_ob_key(&draw_object->id, DEG_NODE_TYPE_TRANSFORM);
1686         add_relation(dup_ob_key, psys_key, "Particle Object Visualization");
1687         if (draw_object->type == OB_MBALL) {
1688                 ComponentKey dup_geometry_key(&draw_object->id, DEG_NODE_TYPE_GEOMETRY);
1689                 add_relation(obdata_ubereval_key,
1690                              dup_geometry_key,
1691                              "Particle MBall Visualization");
1692         }
1693 }
1694
1695 void DepsgraphRelationBuilder::build_cloth(Object *object,
1696                                            ModifierData * /*md*/)
1697 {
1698         OperationKey cache_key(&object->id,
1699                                DEG_NODE_TYPE_CACHE,
1700                                DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER);
1701         /* Cache component affects on modifier. */
1702         OperationKey modifier_key(&object->id,
1703                                   DEG_NODE_TYPE_GEOMETRY,
1704                                   DEG_OPCODE_GEOMETRY_UBEREVAL);
1705         add_relation(cache_key, modifier_key, "Cloth Cache -> Cloth");
1706 }
1707
1708 /* Shapekeys */
1709 void DepsgraphRelationBuilder::build_shapekeys(Key *key)
1710 {
1711         if (built_map_.checkIsBuiltAndTag(key)) {
1712                 return;
1713         }
1714         /* attach animdata to geometry */
1715         build_animdata(&key->id);
1716 }
1717
1718 /**
1719  * ObData Geometry Evaluation
1720  * ==========================
1721  *
1722  * The evaluation of geometry on objects is as follows:
1723  * - The actual evaluated of the derived geometry (e.g. DerivedMesh, DispList)
1724  *   occurs in the Geometry component of the object which references this.
1725  *   This includes modifiers, and the temporary "ubereval" for geometry.
1726  *   Therefore, each user of a piece of shared geometry data ends up evaluating
1727  *   its own version of the stuff, complete with whatever modifiers it may use.
1728  *
1729  * - The datablocks for the geometry data - "obdata" (e.g. ID_ME, ID_CU, ID_LT.)
1730  *   are used for
1731  *     1) calculating the bounding boxes of the geometry data,
1732  *     2) aggregating inward links from other objects (e.g. for text on curve)
1733  *        and also for the links coming from the shapekey datablocks
1734  * - Animation/Drivers affecting the parameters of the geometry are made to
1735  *   trigger updates on the obdata geometry component, which then trigger
1736  *   downstream re-evaluation of the individual instances of this geometry.
1737  */
1738 void DepsgraphRelationBuilder::build_object_data_geometry(Object *object)
1739 {
1740         ID *obdata = (ID *)object->data;
1741         /* Init operation of object-level geometry evaluation. */
1742         OperationKey geom_init_key(&object->id,
1743                                    DEG_NODE_TYPE_GEOMETRY,
1744                                    DEG_OPCODE_PLACEHOLDER,
1745                                    "Eval Init");
1746         /* Get nodes for result of obdata's evaluation, and geometry evaluation
1747          * on object.
1748          */
1749         ComponentKey obdata_geom_key(obdata, DEG_NODE_TYPE_GEOMETRY);
1750         ComponentKey geom_key(&object->id, DEG_NODE_TYPE_GEOMETRY);
1751         /* Link components to each other. */
1752         add_relation(obdata_geom_key, geom_key, "Object Geometry Base Data");
1753         OperationKey obdata_ubereval_key(&object->id,
1754                                          DEG_NODE_TYPE_GEOMETRY,
1755                                          DEG_OPCODE_GEOMETRY_UBEREVAL);
1756         /* Special case: modifiers evaluation queries scene for various things like
1757          * data mask to be used. We add relation here to ensure object is never
1758          * evaluated prior to Scene's CoW is ready.
1759          */
1760         OperationKey scene_key(&scene_->id,
1761                                DEG_NODE_TYPE_LAYER_COLLECTIONS,
1762                                DEG_OPCODE_VIEW_LAYER_EVAL);
1763         DepsRelation *rel = add_relation(scene_key, obdata_ubereval_key, "CoW Relation");
1764         rel->flag |= DEPSREL_FLAG_NO_FLUSH;
1765         /* Modifiers */
1766         if (object->modifiers.first != NULL) {
1767                 ModifierUpdateDepsgraphContext ctx = {};
1768                 ctx.scene = scene_;
1769                 ctx.object = object;
1770                 LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
1771                         const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type);
1772                         if (mti->updateDepsgraph) {
1773                                 DepsNodeHandle handle = create_node_handle(obdata_ubereval_key);
1774                                 ctx.node = reinterpret_cast< ::DepsNodeHandle* >(&handle);
1775                                 mti->updateDepsgraph(md, &ctx);
1776                         }
1777                         if (BKE_object_modifier_use_time(object, md)) {
1778                                 TimeSourceKey time_src_key;
1779                                 add_relation(time_src_key, obdata_ubereval_key, "Time Source");
1780                         }
1781                         if (md->type == eModifierType_Cloth) {
1782                                 build_cloth(object, md);
1783                         }
1784                 }
1785         }
1786         /* Materials. */
1787         if (object->totcol) {
1788                 for (int a = 1; a <= object->totcol; a++) {
1789                         Material *ma = give_current_material(object, a);
1790                         if (ma != NULL) {
1791                                 build_material(ma);
1792
1793                                 if (object->type == OB_MESH) {
1794                                         OperationKey material_key(&ma->id,
1795                                                                   DEG_NODE_TYPE_SHADING,
1796                                                                   DEG_OPCODE_MATERIAL_UPDATE);
1797                                         OperationKey shading_key(&object->id,
1798                                                                  DEG_NODE_TYPE_SHADING,
1799                                                                  DEG_OPCODE_SHADING);
1800                                         add_relation(material_key, shading_key, "Material Update");
1801                                 }
1802                         }
1803                 }
1804         }
1805         /* Geometry collision. */
1806         if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1807                 // add geometry collider relations
1808         }
1809         /* Make sure uber update is the last in the dependencies.
1810          *
1811          * TODO(sergey): Get rid of this node.
1812          */
1813         if (object->type != OB_ARMATURE) {
1814                 /* Armatures does no longer require uber node. */
1815                 OperationKey obdata_ubereval_key(&object->id,
1816                                                  DEG_NODE_TYPE_GEOMETRY,
1817                                                  DEG_OPCODE_GEOMETRY_UBEREVAL);
1818                 add_relation(geom_init_key,
1819                              obdata_ubereval_key,
1820                              "Object Geometry UberEval");
1821         }
1822         if (object->type == OB_MBALL) {
1823                 Object *mom = BKE_mball_basis_find(scene_, object);
1824                 ComponentKey mom_geom_key(&mom->id, DEG_NODE_TYPE_GEOMETRY);
1825                 /* motherball - mom depends on children! */
1826                 if (mom == object) {
1827                         ComponentKey mom_transform_key(&mom->id,
1828                                                        DEG_NODE_TYPE_TRANSFORM);
1829                         add_relation(mom_transform_key,
1830                                      mom_geom_key,
1831                                      "Metaball Motherball Transform -> Geometry");
1832                 }
1833                 else {
1834                         ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1835                         add_relation(geom_key, mom_geom_key, "Metaball Motherball");
1836                         add_relation(transform_key, mom_geom_key, "Metaball Motherball");
1837                 }
1838         }
1839         /* NOTE: This is compatibility code to support particle systems
1840          *
1841          * for viewport being properly rendered in final render mode.
1842          * This relation is similar to what dag_object_time_update_flags()
1843          * was doing for mesh objects with particle system.
1844          *
1845          * Ideally we need to get rid of this relation.
1846          */
1847         if (object_particles_depends_on_time(object)) {
1848                 TimeSourceKey time_key;
1849                 OperationKey obdata_ubereval_key(&object->id,
1850                                                  DEG_NODE_TYPE_GEOMETRY,
1851                                                  DEG_OPCODE_GEOMETRY_UBEREVAL);
1852                 add_relation(time_key, obdata_ubereval_key, "Legacy particle time");
1853         }
1854         /* Object data datablock. */
1855         build_object_data_geometry_datablock((ID *)object->data);
1856         Key *key = BKE_key_from_object(object);
1857         if (key != NULL) {
1858                 if (key->adt != NULL) {
1859                         if (key->adt->action || key->adt->nla_tracks.first) {
1860                                 ComponentKey obdata_key((ID *)object->data,
1861                                                         DEG_NODE_TYPE_GEOMETRY);
1862                                 ComponentKey adt_key(&key->id, DEG_NODE_TYPE_ANIMATION);
1863                                 add_relation(adt_key, obdata_key, "Animation");
1864                         }
1865                 }
1866         }
1867 }
1868
1869 void DepsgraphRelationBuilder::build_object_data_geometry_datablock(ID *obdata)
1870 {
1871         if (built_map_.checkIsBuiltAndTag(obdata)) {
1872                 return;
1873         }
1874         /* Animation. */
1875         build_animdata(obdata);
1876         /* ShapeKeys. */
1877         Key *key = BKE_key_from_id(obdata);
1878         if (key != NULL) {
1879                 build_shapekeys(key);
1880         }
1881         /* Link object data evaluation node to exit operation. */
1882         OperationKey obdata_geom_eval_key(obdata,
1883                                           DEG_NODE_TYPE_GEOMETRY,
1884                                           DEG_OPCODE_PLACEHOLDER,
1885                                           "Geometry Eval");
1886         OperationKey obdata_geom_done_key(obdata,
1887                                           DEG_NODE_TYPE_GEOMETRY,
1888                                           DEG_OPCODE_PLACEHOLDER,
1889                                           "Eval Done");
1890         add_relation(obdata_geom_eval_key,
1891                      obdata_geom_done_key,
1892                      "ObData Geom Eval Done");
1893         /* Type-specific links. */
1894         const ID_Type id_type = GS(obdata->name);
1895         switch (id_type) {
1896                 case ID_ME:
1897                         break;
1898                 case ID_MB:
1899                         break;
1900                 case ID_CU:
1901                 {
1902                         Curve *cu = (Curve *)obdata;
1903                         if (cu->bevobj != NULL) {
1904                                 ComponentKey bevob_geom_key(&cu->bevobj->id,
1905                                                             DEG_NODE_TYPE_GEOMETRY);
1906                                 add_relation(bevob_geom_key,
1907                                              obdata_geom_eval_key,
1908                                              "Curve Bevel Geometry");
1909                                 ComponentKey bevob_key(&cu->bevobj->id,
1910                                                        DEG_NODE_TYPE_TRANSFORM);
1911                                 add_relation(bevob_key,
1912                                              obdata_geom_eval_key,
1913                                              "Curve Bevel Transform");
1914                                 build_object(NULL, cu->bevobj);
1915                         }
1916                         if (cu->taperobj != NULL) {
1917                                 ComponentKey taperob_key(&cu->taperobj->id,
1918                                                          DEG_NODE_TYPE_GEOMETRY);
1919                                 add_relation(taperob_key, obdata_geom_eval_key, "Curve Taper");
1920                                 build_object(NULL, cu->taperobj);
1921                         }
1922                         if (cu->textoncurve != NULL) {
1923                                 ComponentKey textoncurve_key(&cu->textoncurve->id,
1924                                                              DEG_NODE_TYPE_GEOMETRY);
1925                                 add_relation(textoncurve_key,
1926                                              obdata_geom_eval_key,
1927                                              "Text on Curve");
1928                                 build_object(NULL, cu->textoncurve);
1929                         }
1930                         break;
1931                 }
1932                 case ID_LT:
1933                         break;
1934                 default:
1935                         BLI_assert(!"Should not happen");
1936                         break;
1937         }
1938 }
1939
1940 void DepsgraphRelationBuilder::build_armature(bArmature *armature)
1941 {
1942         if (built_map_.checkIsBuiltAndTag(armature)) {
1943                 return;
1944         }
1945         build_animdata(&armature->id);
1946 }
1947
1948 void DepsgraphRelationBuilder::build_camera(Camera *camera)
1949 {
1950         if (built_map_.checkIsBuiltAndTag(camera)) {
1951                 return;
1952         }
1953         if (camera->dof_ob != NULL) {
1954                 ComponentKey camera_parameters_key(&camera->id, DEG_NODE_TYPE_PARAMETERS);
1955                 ComponentKey dof_ob_key(&camera->dof_ob->id, DEG_NODE_TYPE_TRANSFORM);
1956                 add_relation(dof_ob_key, camera_parameters_key, "Camera DOF");
1957         }
1958 }
1959
1960 /* Lamps */
1961 void DepsgraphRelationBuilder::build_lamp(Lamp *lamp)
1962 {
1963         if (built_map_.checkIsBuiltAndTag(lamp)) {
1964                 return;
1965         }
1966         /* lamp's nodetree */
1967         if (lamp->nodetree != NULL) {
1968                 build_nodetree(lamp->nodetree);
1969                 ComponentKey lamp_parameters_key(&lamp->id, DEG_NODE_TYPE_PARAMETERS);
1970                 ComponentKey nodetree_key(&lamp->nodetree->id, DEG_NODE_TYPE_SHADING);
1971                 add_relation(nodetree_key, lamp_parameters_key, "NTree->Light Parameters");
1972                 build_nested_nodetree(&lamp->id, lamp->nodetree);
1973         }
1974 }
1975
1976 void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
1977 {
1978         if (ntree == NULL) {
1979                 return;
1980         }
1981         if (built_map_.checkIsBuiltAndTag(ntree)) {
1982                 return;
1983         }
1984         build_animdata(&ntree->id);
1985         ComponentKey shading_key(&ntree->id, DEG_NODE_TYPE_SHADING);
1986         /* nodetree's nodes... */
1987         LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) {
1988                 ID *id = bnode->id;
1989                 if (id == NULL) {
1990                         continue;
1991                 }
1992                 ID_Type id_type = GS(id->name);
1993                 if (id_type == ID_MA) {
1994                         build_material((Material *)bnode->id);
1995                 }
1996                 else if (id_type == ID_TE) {
1997                         build_texture((Tex *)bnode->id);
1998                 }
1999                 else if (id_type == ID_IM) {
2000                         /* nothing for now. */
2001                 }
2002                 else if (id_type == ID_OB) {
2003                         build_object(NULL, (Object *)id);
2004                 }
2005                 else if (id_type == ID_SCE) {
2006                         /* Scenes are used by compositor trees, and handled by render
2007                          * pipeline. No need to build dependencies for them here.
2008                          */
2009                 }
2010                 else if (id_type == ID_TXT) {
2011                         /* Ignore script nodes. */
2012                 }
2013                 else if (bnode->type == NODE_GROUP) {
2014                         bNodeTree *group_ntree = (bNodeTree *)id;
2015                         build_nodetree(group_ntree);
2016                         ComponentKey group_shading_key(&group_ntree->id,
2017                                                        DEG_NODE_TYPE_SHADING);
2018                         add_relation(group_shading_key, shading_key, "Group Node");
2019                 }
2020                 else {
2021                         BLI_assert(!"Unknown ID type used for node");
2022                 }
2023         }
2024
2025         OperationKey shading_update_key(&ntree->id,
2026                                         DEG_NODE_TYPE_SHADING,
2027                                         DEG_OPCODE_MATERIAL_UPDATE);
2028         OperationKey shading_parameters_key(&ntree->id,
2029                                             DEG_NODE_TYPE_SHADING_PARAMETERS,
2030                                             DEG_OPCODE_MATERIAL_UPDATE);
2031         add_relation(shading_parameters_key, shading_update_key, "NTree Shading Parameters");
2032
2033         if (check_id_has_anim_component(&ntree->id)) {
2034                 ComponentKey animation_key(&ntree->id, DEG_NODE_TYPE_ANIMATION);
2035                 add_relation(animation_key, shading_parameters_key, "NTree Shading Parameters");
2036         }
2037 }
2038
2039 /* Recursively build graph for material */
2040 void DepsgraphRelationBuilder::build_material(Material *material)
2041 {
2042         if (built_map_.checkIsBuiltAndTag(material)) {
2043                 return;
2044         }
2045         /* animation */
2046         build_animdata(&material->id);
2047         /* material's nodetree */
2048         if (material->nodetree != NULL) {
2049                 build_nodetree(material->nodetree);
2050                 OperationKey ntree_key(&material->nodetree->id,
2051                                        DEG_NODE_TYPE_SHADING,
2052                                        DEG_OPCODE_MATERIAL_UPDATE);
2053                 OperationKey material_key(&material->id,
2054                                           DEG_NODE_TYPE_SHADING,
2055                                           DEG_OPCODE_MATERIAL_UPDATE);
2056                 add_relation(ntree_key, material_key, "Material's NTree");
2057                 build_nested_nodetree(&material->id, material->nodetree);
2058         }
2059 }
2060
2061 /* Recursively build graph for texture */
2062 void DepsgraphRelationBuilder::build_texture(Tex *texture)
2063 {
2064         if (built_map_.checkIsBuiltAndTag(texture)) {
2065                 return;
2066         }
2067         /* texture itself */
2068         build_animdata(&texture->id);
2069         /* texture's nodetree */
2070         build_nodetree(texture->nodetree);
2071         build_nested_nodetree(&texture->id, texture->nodetree);
2072 }
2073
2074 void DepsgraphRelationBuilder::build_compositor(Scene *scene)
2075 {
2076         /* For now, just a plain wrapper? */
2077         build_nodetree(scene->nodetree);
2078 }
2079
2080 void DepsgraphRelationBuilder::build_gpencil(bGPdata *gpd)
2081 {
2082         if (built_map_.checkIsBuiltAndTag(gpd)) {
2083                 return;
2084         }
2085         /* animation */
2086         build_animdata(&gpd->id);
2087
2088         // TODO: parent object (when that feature is implemented)
2089 }
2090
2091 void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file)
2092 {
2093         if (built_map_.checkIsBuiltAndTag(cache_file)) {
2094                 return;
2095         }
2096         /* Animation. */
2097         build_animdata(&cache_file->id);
2098 }
2099
2100 void DepsgraphRelationBuilder::build_mask(Mask *mask)
2101 {
2102         if (built_map_.checkIsBuiltAndTag(mask)) {
2103                 return;
2104         }
2105         ID *mask_id = &mask->id;
2106         /* F-Curve animation. */
2107         build_animdata(mask_id);
2108         /* Own mask animation. */
2109         OperationKey mask_animation_key(mask_id,
2110                                         DEG_NODE_TYPE_ANIMATION,
2111                                         DEG_OPCODE_MASK_ANIMATION);
2112         TimeSourceKey time_src_key;
2113         add_relation(time_src_key, mask_animation_key, "TimeSrc -> Mask Animation");
2114         /* Final mask evaluation. */
2115         ComponentKey parameters_key(mask_id, DEG_NODE_TYPE_PARAMETERS);
2116         add_relation(mask_animation_key, parameters_key, "Mask Animation -> Mask Eval");
2117 }
2118
2119 void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip)
2120 {
2121         if (built_map_.checkIsBuiltAndTag(clip)) {
2122                 return;
2123         }
2124         /* Animation. */
2125         build_animdata(&clip->id);
2126 }
2127
2128 void DepsgraphRelationBuilder::build_lightprobe(LightProbe *probe)
2129 {
2130         if (built_map_.checkIsBuiltAndTag(probe)) {
2131                 return;
2132         }
2133         build_animdata(&probe->id);
2134 }
2135
2136 void DepsgraphRelationBuilder::build_speaker(Speaker *speaker)
2137 {
2138         if (built_map_.checkIsBuiltAndTag(speaker)) {
2139                 return;
2140         }
2141         build_animdata(&speaker->id);
2142 }
2143
2144 void DepsgraphRelationBuilder::build_copy_on_write_relations()
2145 {
2146         foreach (IDDepsNode *id_node, graph_->id_nodes) {
2147                 build_copy_on_write_relations(id_node);
2148         }
2149 }
2150
2151 /* Nested datablocks (node trees, shape keys) requires special relation to
2152  * ensure owner's datablock remapping happens after node tree itself is ready.
2153  *
2154  * This is similar to what happens in ntree_hack_remap_pointers().
2155  */
2156 void DepsgraphRelationBuilder::build_nested_datablock(ID *owner, ID *id)
2157 {
2158         OperationKey owner_copy_on_write_key(owner,
2159                                              DEG_NODE_TYPE_COPY_ON_WRITE,
2160                                              DEG_OPCODE_COPY_ON_WRITE);
2161         OperationKey id_copy_on_write_key(id,
2162                                           DEG_NODE_TYPE_COPY_ON_WRITE,
2163                                           DEG_OPCODE_COPY_ON_WRITE);
2164         add_relation(id_copy_on_write_key,
2165                      owner_copy_on_write_key,
2166                      "Eval Order");
2167 }
2168
2169 void DepsgraphRelationBuilder::build_nested_nodetree(ID *owner,
2170                                                      bNodeTree *ntree)
2171 {
2172         if (ntree == NULL) {
2173                 return;
2174         }
2175         build_nested_datablock(owner, &ntree->id);
2176 }
2177
2178 void DepsgraphRelationBuilder::build_nested_shapekey(ID *owner, Key *key)
2179 {
2180         if (key == NULL) {
2181                 return;
2182         }
2183         build_nested_datablock(owner, &key->id);
2184 }
2185
2186 void DepsgraphRelationBuilder::build_copy_on_write_relations(IDDepsNode *id_node)
2187 {
2188         ID *id_orig = id_node->id_orig;
2189         const ID_Type id_type = GS(id_orig->name);
2190         TimeSourceKey time_source_key;
2191         OperationKey copy_on_write_key(id_orig,
2192                                        DEG_NODE_TYPE_COPY_ON_WRITE,
2193                                        DEG_OPCODE_COPY_ON_WRITE);
2194         /* XXX: This is a quick hack to make Alt-A to work. */
2195         // add_relation(time_source_key, copy_on_write_key, "Fluxgate capacitor hack");
2196         /* Resat of code is using rather low level trickery, so need to get some
2197          * explicit pointers.
2198          */
2199         DepsNode *node_cow = find_node(copy_on_write_key);
2200         OperationDepsNode *op_cow = node_cow->get_exit_operation();
2201         /* Plug any other components to this one. */
2202         GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, id_node->components)
2203         {
2204                 if (comp_node->type == DEG_NODE_TYPE_COPY_ON_WRITE) {
2205                         /* Copy-on-write component never depends on itself. */
2206                         continue;
2207                 }
2208                 if (!comp_node->depends_on_cow()) {
2209                         /* Component explicitly requests to not add relation. */
2210                         continue;
2211                 }
2212                 int rel_flag = DEPSREL_FLAG_NO_FLUSH;
2213                 if (id_type == ID_ME && comp_node->type == DEG_NODE_TYPE_GEOMETRY) {
2214                         rel_flag &= ~DEPSREL_FLAG_NO_FLUSH;
2215                 }
2216                 /* All entry operations of each component should wait for a proper
2217                  * copy of ID.
2218                  */
2219                 OperationDepsNode *op_entry = comp_node->get_entry_operation();
2220                 if (op_entry != NULL) {
2221                         DepsRelation *rel = graph_->add_new_relation(
2222                                 op_cow, op_entry, "CoW Dependency");
2223                         rel->flag |= rel_flag;
2224                 }
2225                 /* All dangling operations should also be executed after copy-on-write. */
2226                 GHASH_FOREACH_BEGIN(OperationDepsNode *, op_node, comp_node->operations_map)
2227                 {
2228                         if (op_node == op_entry) {
2229                                 continue;
2230                         }
2231                         if (op_node->inlinks.size() == 0) {
2232                                 DepsRelation *rel = graph_->add_new_relation(
2233                                         op_cow, op_node, "CoW Dependency");
2234                                 rel->flag |= rel_flag;
2235                         }
2236                         else {
2237                                 bool has_same_comp_dependency = false;
2238                                 foreach (DepsRelation *rel_current, op_node->inlinks) {
2239                                         if (rel_current->from->type != DEG_NODE_TYPE_OPERATION) {
2240                                                 continue;
2241                                         }
2242                                         OperationDepsNode *op_node_from =
2243                                                 (OperationDepsNode *)rel_current->from;
2244                                         if (op_node_from->owner == op_node->owner) {
2245                                                 has_same_comp_dependency = true;
2246                                                 break;
2247                                         }
2248                                 }
2249                                 if (!has_same_comp_dependency) {
2250                                         DepsRelation *rel = graph_->add_new_relation(
2251                                                 op_cow, op_node, "CoW Dependency");
2252                                         rel->flag |= rel_flag;
2253                                 }
2254                         }
2255                 }
2256                 GHASH_FOREACH_END();
2257                 /* NOTE: We currently ignore implicit relations to an external
2258                  * datablocks for copy-on-write operations. This means, for example,
2259                  * copy-on-write component of Object will not wait for copy-on-write
2260                  * component of it's Mesh. This is because pointers are all known
2261                  * already so remapping will happen all correct. And then If some object
2262                  * evaluation step needs geometry, it will have transitive dependency
2263                  * to Mesh copy-on-write already.
2264                  */
2265         }
2266         GHASH_FOREACH_END();
2267         /* TODO(sergey): This solves crash for now, but causes too many
2268          * updates potentially.
2269          */
2270         if (GS(id_orig->name) == ID_OB) {
2271                 Object *object = (Object *)id_orig;
2272                 ID *object_data_id = (ID *)object->data;
2273                 if (object_data_id != NULL) {
2274                         OperationKey data_copy_on_write_key(object_data_id,
2275                                                             DEG_NODE_TYPE_COPY_ON_WRITE,
2276                                                             DEG_OPCODE_COPY_ON_WRITE);
2277                         add_relation(data_copy_on_write_key, copy_on_write_key, "Eval Order");
2278                 }
2279                 else {
2280                         BLI_assert(object->type == OB_EMPTY);
2281                 }
2282         }
2283 }
2284
2285 /* **** ID traversal callbacks functions **** */
2286
2287 void DepsgraphRelationBuilder::modifier_walk(void *user_data,
2288                                              struct Object * /*object*/,
2289                                              struct ID **idpoin,
2290                                              int /*cb_flag*/)
2291 {
2292         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
2293         ID *id = *idpoin;
2294         if (id == NULL) {
2295                 return;
2296         }
2297         switch (GS(id->name)) {
2298                 case ID_OB:
2299                         data->builder->build_object(NULL, (Object *)id);
2300                         break;
2301                 case ID_TE:
2302                         data->builder->build_texture((Tex *)id);
2303                         break;
2304                 default:
2305                         /* pass */
2306                         break;
2307         }
2308 }
2309
2310 void DepsgraphRelationBuilder::constraint_walk(bConstraint * /*con*/,
2311                                                ID **idpoin,
2312                                                bool /*is_reference*/,
2313                                                void *user_data)
2314 {
2315         BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
2316         if (*idpoin) {
2317                 ID *id = *idpoin;
2318                 if (GS(id->name) == ID_OB) {
2319                         data->builder->build_object(NULL, (Object *)id);
2320                 }
2321         }
2322 }
2323
2324 }  // namespace DEG