2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2013 Blender Foundation.
19 * All rights reserved.
21 * Original Author: Joshua Leung
22 * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/depsgraph/intern/builder/deg_builder_relations.cc
30 * Methods for constructing depsgraph
33 #include "intern/builder/deg_builder_relations.h"
39 #include "MEM_guardedalloc.h"
42 #include "BLI_blenlib.h"
43 #include "BLI_string.h"
44 #include "BLI_utildefines.h"
46 #include "DNA_action_types.h"
47 #include "DNA_anim_types.h"
48 #include "DNA_armature_types.h"
49 #include "DNA_camera_types.h"
50 #include "DNA_cachefile_types.h"
51 #include "DNA_constraint_types.h"
52 #include "DNA_curve_types.h"
53 #include "DNA_effect_types.h"
54 #include "DNA_gpencil_types.h"
55 #include "DNA_group_types.h"
56 #include "DNA_key_types.h"
57 #include "DNA_lamp_types.h"
58 #include "DNA_material_types.h"
59 #include "DNA_mesh_types.h"
60 #include "DNA_meta_types.h"
61 #include "DNA_node_types.h"
62 #include "DNA_particle_types.h"
63 #include "DNA_object_types.h"
64 #include "DNA_rigidbody_types.h"
65 #include "DNA_scene_types.h"
66 #include "DNA_texture_types.h"
67 #include "DNA_world_types.h"
68 #include "DNA_object_force.h"
70 #include "BKE_action.h"
71 #include "BKE_armature.h"
72 #include "BKE_animsys.h"
73 #include "BKE_constraint.h"
74 #include "BKE_curve.h"
75 #include "BKE_effect.h"
76 #include "BKE_collision.h"
77 #include "BKE_fcurve.h"
78 #include "BKE_group.h"
80 #include "BKE_library.h"
82 #include "BKE_material.h"
83 #include "BKE_mball.h"
84 #include "BKE_modifier.h"
86 #include "BKE_object.h"
87 #include "BKE_particle.h"
88 #include "BKE_rigidbody.h"
89 #include "BKE_sound.h"
90 #include "BKE_texture.h"
91 #include "BKE_tracking.h"
92 #include "BKE_world.h"
94 #include "DEG_depsgraph.h"
95 #include "DEG_depsgraph_build.h"
97 #include "RNA_access.h"
98 #include "RNA_types.h"
101 #include "intern/builder/deg_builder.h"
102 #include "intern/builder/deg_builder_pchanmap.h"
104 #include "intern/nodes/deg_node.h"
105 #include "intern/nodes/deg_node_component.h"
106 #include "intern/nodes/deg_node_operation.h"
108 #include "intern/depsgraph_intern.h"
109 #include "intern/depsgraph_types.h"
111 #include "util/deg_util_foreach.h"
115 /* ***************** */
116 /* Relations Builder */
118 /* TODO(sergey): This is somewhat weak, but we don't want neither false-positive
119 * time dependencies nor special exceptions in the depsgraph evaluation.
121 static bool python_driver_depends_on_time(ChannelDriver *driver)
123 if (driver->expression[0] == '\0') {
124 /* Empty expression depends on nothing. */
127 if (strchr(driver->expression, '(') != NULL) {
128 /* Function calls are considered dependent on a time. */
131 if (strstr(driver->expression, "time") != NULL) {
132 /* Variable `time` depends on time. */
133 /* TODO(sergey): This is a bit weak, but not sure about better way of
138 /* Possible indirect time relation s should be handled via variable
144 /* **** General purpose functions **** */
146 RNAPathKey::RNAPathKey(ID *id, const char *path) :
149 /* create ID pointer for root of path lookup */
151 RNA_id_pointer_create(id, &id_ptr);
152 /* try to resolve path... */
154 if (!RNA_path_resolve_full(&id_ptr, path, &this->ptr, &this->prop, &index)) {
155 this->ptr = PointerRNA_NULL;
160 DepsgraphRelationBuilder::DepsgraphRelationBuilder(Depsgraph *graph) :
165 RootDepsNode *DepsgraphRelationBuilder::find_node(const RootKey &key) const
168 BLI_assert(!"Doesn't seem to be correct");
169 return m_graph->root_node;
172 TimeSourceDepsNode *DepsgraphRelationBuilder::find_node(
173 const TimeSourceKey &key) const
180 return m_graph->root_node->time_source;
184 ComponentDepsNode *DepsgraphRelationBuilder::find_node(
185 const ComponentKey &key) const
187 IDDepsNode *id_node = m_graph->find_id_node(key.id);
189 fprintf(stderr, "find_node component: Could not find ID %s\n",
190 (key.id != NULL) ? key.id->name : "<null>");
194 ComponentDepsNode *node = id_node->find_component(key.type, key.name);
198 OperationDepsNode *DepsgraphRelationBuilder::find_node(
199 const OperationKey &key) const
201 IDDepsNode *id_node = m_graph->find_id_node(key.id);
203 fprintf(stderr, "find_node operation: Could not find ID\n");
207 ComponentDepsNode *comp_node = id_node->find_component(key.component_type,
210 fprintf(stderr, "find_node operation: Could not find component\n");
214 OperationDepsNode *op_node = comp_node->find_operation(key.opcode, key.name);
216 fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
217 DEG_OPNAMES[key.opcode], key.name.c_str());
222 DepsNode *DepsgraphRelationBuilder::find_node(const RNAPathKey &key) const
224 return m_graph->find_node_from_pointer(&key.ptr, key.prop);
227 OperationDepsNode *DepsgraphRelationBuilder::has_node(
228 const OperationKey &key) const
230 IDDepsNode *id_node = m_graph->find_id_node(key.id);
234 ComponentDepsNode *comp_node = id_node->find_component(key.component_type,
239 return comp_node->has_operation(key.opcode, key.name);
242 void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc,
244 const char *description)
246 if (timesrc && node_to) {
247 m_graph->add_new_relation(timesrc, node_to, DEPSREL_TYPE_TIME, description);
250 DEG_DEBUG_PRINTF("add_time_relation(%p = %s, %p = %s, %s) Failed\n",
251 timesrc, (timesrc) ? timesrc->identifier().c_str() : "<None>",
252 node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
257 void DepsgraphRelationBuilder::add_operation_relation(
258 OperationDepsNode *node_from,
259 OperationDepsNode *node_to,
260 eDepsRelation_Type type,
261 const char *description)
263 if (node_from && node_to) {
264 m_graph->add_new_relation(node_from, node_to, type, description);
267 DEG_DEBUG_PRINTF("add_operation_relation(%p = %s, %p = %s, %d, %s) Failed\n",
268 node_from, (node_from) ? node_from->identifier().c_str() : "<None>",
269 node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
274 void DepsgraphRelationBuilder::add_collision_relations(const OperationKey &key, Scene *scene, Object *ob, Group *group, int layer, bool dupli, const char *name)
276 unsigned int numcollobj;
277 Object **collobjs = get_collisionobjects_ext(scene, ob, group, layer, &numcollobj, eModifierType_Collision, dupli);
279 for (unsigned int i = 0; i < numcollobj; i++)
281 Object *ob1 = collobjs[i];
283 ComponentKey trf_key(&ob1->id, DEPSNODE_TYPE_TRANSFORM);
284 add_relation(trf_key, key, DEPSREL_TYPE_STANDARD, name);
286 ComponentKey coll_key(&ob1->id, DEPSNODE_TYPE_GEOMETRY);
287 add_relation(coll_key, key, DEPSREL_TYPE_STANDARD, name);
294 void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key, Scene *scene, Object *ob, ParticleSystem *psys, EffectorWeights *eff, bool add_absorption, const char *name)
296 ListBase *effectors = pdInitEffectors(scene, ob, psys, eff, false);
299 for (EffectorCache *eff = (EffectorCache *)effectors->first; eff; eff = eff->next) {
301 ComponentKey eff_key(&eff->ob->id, DEPSNODE_TYPE_TRANSFORM);
302 add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name);
307 ComponentKey eff_key(&eff->ob->id, DEPSNODE_TYPE_EVAL_PARTICLES);
308 add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name);
310 /* TODO: remove this when/if EVAL_PARTICLES is sufficient for up to date particles */
311 ComponentKey mod_key(&eff->ob->id, DEPSNODE_TYPE_GEOMETRY);
312 add_relation(mod_key, key, DEPSREL_TYPE_STANDARD, name);
314 else if (eff->psys != psys) {
315 OperationKey eff_key(&eff->ob->id, DEPSNODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, eff->psys->name);
316 add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name);
320 if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) {
321 ComponentKey trf_key(&eff->pd->f_source->id, DEPSNODE_TYPE_TRANSFORM);
322 add_relation(trf_key, key, DEPSREL_TYPE_STANDARD, "Smoke Force Domain");
324 ComponentKey eff_key(&eff->pd->f_source->id, DEPSNODE_TYPE_GEOMETRY);
325 add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, "Smoke Force Domain");
328 if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) {
329 add_collision_relations(key, scene, ob, NULL, eff->ob->lay, true, "Force Absorption");
334 pdEndEffectors(&effectors);
337 /* **** Functions to build relations between entities **** */
339 void DepsgraphRelationBuilder::build_scene(Main *bmain, Scene *scene)
341 /* LIB_TAG_DOIT is used to indicate whether node for given ID was already
344 BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
345 /* XXX nested node trees are not included in tag-clearing above,
346 * so we need to do this manually.
348 FOREACH_NODETREE(bmain, nodetree, id) {
349 if (id != (ID *)nodetree)
350 nodetree->id.tag &= ~LIB_TAG_DOIT;
351 } FOREACH_NODETREE_END
354 // TODO: link set to scene, especially our timesource...
358 for (Base *base = (Base *)scene->base.first; base; base = base->next) {
359 Object *ob = base->object;
362 build_object(bmain, scene, ob);
364 /* object that this is a proxy for */
366 ob->proxy->proxy_from = ob;
367 build_object(bmain, scene, ob->proxy);
368 /* TODO(sergey): This is an inverted relation, matches old depsgraph
369 * behavior and need to be investigated if it still need to be inverted.
371 ComponentKey ob_pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE);
372 ComponentKey proxy_pose_key(&ob->proxy->id, DEPSNODE_TYPE_EVAL_POSE);
373 add_relation(ob_pose_key, proxy_pose_key, DEPSREL_TYPE_TRANSFORM, "Proxy");
376 /* Object dupligroup. */
378 build_group(bmain, scene, ob, ob->dup_group);
383 if (scene->rigidbody_world) {
384 build_rigidbody(scene);
387 /* scene's animation and drivers */
389 build_animdata(&scene->id);
394 build_world(scene->world);
398 if (scene->nodetree) {
399 build_compositor(scene);
404 build_gpencil(&scene->id, scene->gpd);
407 for (Depsgraph::OperationNodes::const_iterator it_op = m_graph->operations.begin();
408 it_op != m_graph->operations.end();
411 OperationDepsNode *node = *it_op;
412 IDDepsNode *id_node = node->owner->owner;
413 ID *id = id_node->id;
414 if (GS(id->name) == ID_OB) {
415 Object *object = (Object *)id;
416 object->customdata_mask |= node->customdata_mask;
421 void DepsgraphRelationBuilder::build_group(Main *bmain,
426 ID *group_id = &group->id;
427 bool group_done = (group_id->tag & LIB_TAG_DOIT) != 0;
428 OperationKey object_local_transform_key(&object->id,
429 DEPSNODE_TYPE_TRANSFORM,
430 DEG_OPCODE_TRANSFORM_LOCAL);
431 for (GroupObject *go = (GroupObject *)group->gobject.first;
436 build_object(bmain, scene, go->ob);
438 ComponentKey dupli_transform_key(&go->ob->id, DEPSNODE_TYPE_TRANSFORM);
439 add_relation(dupli_transform_key,
440 object_local_transform_key,
441 DEPSREL_TYPE_TRANSFORM,
444 group_id->tag |= LIB_TAG_DOIT;
447 void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *ob)
449 if (ob->id.tag & LIB_TAG_DOIT) {
453 /* Object Transforms */
454 eDepsOperation_Code base_op = (ob->parent) ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL;
455 OperationKey base_op_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, base_op);
457 OperationKey local_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL);
458 OperationKey parent_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT);
459 OperationKey final_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
461 OperationKey ob_ubereval_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_OBJECT_UBEREVAL);
465 /* parent relationship */
466 build_object_parent(ob);
468 /* local -> parent */
469 add_relation(local_transform_key, parent_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObLocal -> ObParent]");
472 /* object constraints */
473 if (ob->constraints.first) {
474 OperationKey constraint_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_CONSTRAINTS);
476 /* constraint relations */
477 // TODO: provide base op
478 // XXX: this is broken
479 build_constraints(scene, &ob->id, DEPSNODE_TYPE_TRANSFORM, "", &ob->constraints, NULL);
481 /* operation order */
482 add_relation(base_op_key, constraint_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObBase-> Constraint Stack]");
483 add_relation(constraint_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObConstraints -> Done]");
486 add_relation(constraint_key, ob_ubereval_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval");
487 add_relation(ob_ubereval_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval");
490 /* operation order */
491 add_relation(base_op_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "Object Transform");
494 add_relation(base_op_key, ob_ubereval_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval");
495 add_relation(ob_ubereval_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval");
500 build_animdata(&ob->id);
502 // XXX: This should be hooked up by the build_animdata code
503 if (ob->adt && (ob->adt->action || ob->adt->nla_tracks.first)) {
504 ComponentKey adt_key(&ob->id, DEPSNODE_TYPE_ANIMATION);
505 add_relation(adt_key, local_transform_key, DEPSREL_TYPE_OPERATION, "Object Animation");
511 ID *obdata_id = (ID *)ob->data;
513 /* ob data animation */
514 build_animdata(obdata_id);
516 /* type-specific data... */
518 case OB_MESH: /* Geometry */
525 build_obdata_geom(bmain, scene, ob);
529 case OB_ARMATURE: /* Pose */
530 if (ID_IS_LINKED_DATABLOCK(ob) && ob->proxy_from != NULL) {
534 build_rig(scene, ob);
538 case OB_LAMP: /* Lamp */
542 case OB_CAMERA: /* Camera */
547 Key *key = BKE_key_from_object(ob);
549 ComponentKey geometry_key((ID *)ob->data, DEPSNODE_TYPE_GEOMETRY);
550 ComponentKey key_key(&key->id, DEPSNODE_TYPE_GEOMETRY);
551 add_relation(key_key, geometry_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Shapekeys");
555 /* particle systems */
556 if (ob->particlesystem.first) {
557 build_particles(scene, ob);
562 build_gpencil(&ob->id, ob->gpd);
566 void DepsgraphRelationBuilder::build_object_parent(Object *ob)
568 /* XXX: for now, need to use the component key (not just direct to the parent op), or else the matrix doesn't get reset */
569 // XXX: @sergey - it would be good if we got that backwards flushing working when tagging for updates
570 //OperationKey ob_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT);
571 ComponentKey ob_key(&ob->id, DEPSNODE_TYPE_TRANSFORM);
573 /* type-specific links */
574 switch (ob->partype) {
575 case PARSKEL: /* Armature Deform (Virtual Modifier) */
577 ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM);
578 add_relation(parent_key, ob_key, DEPSREL_TYPE_STANDARD, "Armature Deform Parent");
582 case PARVERT1: /* Vertex Parent */
585 ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY);
586 add_relation(parent_key, ob_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Vertex Parent");
588 /* XXX not sure what this is for or how you could be done properly - lukas */
589 OperationDepsNode *parent_node = find_operation_node(parent_key);
590 if (parent_node != NULL) {
591 parent_node->customdata_mask |= CD_MASK_ORIGINDEX;
594 ComponentKey transform_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM);
595 add_relation(transform_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Vertex Parent TFM");
599 case PARBONE: /* Bone Parent */
601 ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_BONE, ob->parsubstr);
602 add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Bone Parent");
608 if (ob->parent->type == OB_LATTICE) {
609 /* Lattice Deform Parent - Virtual Modifier */
610 // XXX: no virtual modifiers should be left!
611 ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM);
612 ComponentKey geom_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY);
614 add_relation(parent_key, ob_key, DEPSREL_TYPE_STANDARD, "Lattice Deform Parent");
615 add_relation(geom_key, ob_key, DEPSREL_TYPE_STANDARD, "Lattice Deform Parent Geom");
617 else if (ob->parent->type == OB_CURVE) {
618 Curve *cu = (Curve *)ob->parent->data;
620 if (cu->flag & CU_PATH) {
622 ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY);
623 add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Follow Parent");
625 ComponentKey transform_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM);
626 add_relation(transform_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Follow TFM");
629 /* Standard Parent */
630 ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM);
631 add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Parent");
635 /* Standard Parent */
636 ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM);
637 add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Parent");
643 /* exception case: parent is duplivert */
644 if ((ob->type == OB_MBALL) && (ob->parent->transflag & OB_DUPLIVERTS)) {
645 //dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert");
649 void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode_Type component_type, const char *component_subdata,
650 ListBase *constraints, RootPChanMap *root_map)
652 OperationKey constraint_op_key(id, component_type, component_subdata,
653 (component_type == DEPSNODE_TYPE_BONE) ? DEG_OPCODE_BONE_CONSTRAINTS : DEG_OPCODE_TRANSFORM_CONSTRAINTS);
655 /* add dependencies for each constraint in turn */
656 for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) {
657 const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
659 /* invalid constraint type... */
663 /* special case for camera tracking -- it doesn't use targets to define relations */
664 // TODO: we can now represent dependencies in a much richer manner, so review how this is done...
665 if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) {
666 bool depends_on_camera = false;
668 if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
669 bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
671 if (((data->clip) || (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0])
672 depends_on_camera = true;
674 if (data->depth_ob) {
675 // DAG_RL_DATA_OB | DAG_RL_OB_OB
676 ComponentKey depth_key(&data->depth_ob->id, DEPSNODE_TYPE_TRANSFORM);
677 add_relation(depth_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
680 else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
681 depends_on_camera = true;
684 if (depends_on_camera && scene->camera) {
685 // DAG_RL_DATA_OB | DAG_RL_OB_OB
686 ComponentKey camera_key(&scene->camera->id, DEPSNODE_TYPE_TRANSFORM);
687 add_relation(camera_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
690 /* TODO(sergey): This is more a TimeSource -> MovieClip -> Constraint dependency chain. */
691 TimeSourceKey time_src_key;
692 add_relation(time_src_key, constraint_op_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]");
694 else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
695 /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint dependency chain. */
696 TimeSourceKey time_src_key;
697 add_relation(time_src_key, constraint_op_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]");
699 bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data;
701 if (data->cache_file) {
702 ComponentKey cache_key(&data->cache_file->id, DEPSNODE_TYPE_CACHE);
703 add_relation(cache_key, constraint_op_key, DEPSREL_TYPE_CACHE, cti->name);
706 else if (cti->get_constraint_targets) {
707 ListBase targets = {NULL, NULL};
708 cti->get_constraint_targets(con, &targets);
710 for (bConstraintTarget *ct = (bConstraintTarget *)targets.first; ct; ct = ct->next) {
714 if (ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK)) {
715 /* ignore IK constraints - these are handled separately (on pose level) */
717 else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO)) {
718 /* these constraints require path geometry data... */
719 ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY);
720 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_GEOMETRY_EVAL, cti->name); // XXX: type = geom_transform
721 // TODO: path dependency
723 else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) {
725 if (&ct->tar->id == id) {
727 eDepsOperation_Code target_key_opcode;
729 /* Using "done" here breaks in-chain deps, while using "ready" here breaks most production rigs instead...
730 * So, we do a compromise here, and only do this when an IK chain conflict may occur
732 if (root_map->has_common_root(component_subdata, ct->subtarget)) {
733 target_key_opcode = DEG_OPCODE_BONE_READY;
736 target_key_opcode = DEG_OPCODE_BONE_DONE;
739 OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_BONE, ct->subtarget, target_key_opcode);
740 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
743 /* different armature - we can safely use the result of that */
744 OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_BONE, ct->subtarget, DEG_OPCODE_BONE_DONE);
745 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
748 else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) {
750 /* NOTE: for now, we don't need to represent vertex groups separately... */
751 ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY);
752 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_GEOMETRY_EVAL, cti->name);
754 if (ct->tar->type == OB_MESH) {
755 OperationDepsNode *node2 = find_operation_node(target_key);
757 node2->customdata_mask |= CD_MASK_MDEFORMVERT;
761 else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
762 /* Constraints which requires the target object surface. */
763 ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY);
764 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
766 /* NOTE: obdata eval now doesn't necessarily depend on the object's transform... */
767 ComponentKey target_transform_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM);
768 add_relation(target_transform_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
771 /* standard object relation */
772 // TODO: loc vs rot vs scale?
773 if (&ct->tar->id == id) {
774 /* Constraint targetting own object:
775 * - This case is fine IFF we're dealing with a bone constraint pointing to
776 * its own armature. In that case, it's just transform -> bone.
777 * - If however it is a real self targetting case, just make it depend on the
778 * previous constraint (or the pre-constraint state)...
780 if ((ct->tar->type == OB_ARMATURE) && (component_type == DEPSNODE_TYPE_BONE)) {
781 OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
782 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
785 OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL);
786 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
790 /* normal object dependency */
791 OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
792 add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
796 /* Constraints which needs world's matrix for transform.
797 * TODO(sergey): More constraints here?
800 CONSTRAINT_TYPE_ROTLIKE,
801 CONSTRAINT_TYPE_SIZELIKE,
802 CONSTRAINT_TYPE_LOCLIKE,
803 CONSTRAINT_TYPE_TRANSLIKE))
805 /* TODO(sergey): Add used space check. */
806 ComponentKey target_transform_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM);
807 add_relation(target_transform_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name);
812 if (cti->flush_constraint_targets)
813 cti->flush_constraint_targets(con, &targets, 1);
818 void DepsgraphRelationBuilder::build_animdata(ID *id)
820 AnimData *adt = BKE_animdata_from_id(id);
825 ComponentKey adt_key(id, DEPSNODE_TYPE_ANIMATION);
828 if (adt->action || adt->nla_tracks.first) {
829 /* wire up dependency to time source */
830 TimeSourceKey time_src_key;
831 add_relation(time_src_key, adt_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]");
833 // XXX: Hook up specific update callbacks for special properties which may need it...
835 // XXX: animdata "hierarchy" - top-level overrides need to go after lower-down
839 for (FCurve *fcu = (FCurve *)adt->drivers.first; fcu; fcu = fcu->next) {
840 OperationKey driver_key(id, DEPSNODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, deg_fcurve_id_name(fcu));
842 /* create the driver's relations to targets */
843 build_driver(id, fcu);
845 /* prevent driver from occurring before own animation... */
846 if (adt->action || adt->nla_tracks.first) {
847 add_relation(adt_key, driver_key, DEPSREL_TYPE_OPERATION,
848 "[AnimData Before Drivers]");
853 void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
855 ChannelDriver *driver = fcu->driver;
856 OperationKey driver_key(id, DEPSNODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, deg_fcurve_id_name(fcu));
857 bPoseChannel *pchan = NULL;
859 /* create dependency between driver and data affected by it */
860 /* - direct property relationship... */
861 //RNAPathKey affected_key(id, fcu->rna_path);
862 //add_relation(driver_key, affected_key, DEPSREL_TYPE_DRIVER, "[Driver -> Data] DepsRel");
864 /* driver -> data components (for interleaved evaluation - bones/constraints/modifiers) */
865 // XXX: this probably should probably be moved out into a separate function
866 if (strstr(fcu->rna_path, "pose.bones[") != NULL) {
867 /* interleaved drivers during bone eval */
868 // TODO: ideally, if this is for a constraint, it goes to said constraint
869 Object *ob = (Object *)id;
872 bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
873 pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
876 MEM_freeN(bone_name);
881 OperationKey bone_key(id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL);
882 add_relation(driver_key, bone_key, DEPSREL_TYPE_DRIVER, "[Driver -> Bone]");
886 "Couldn't find bone name for driver path - '%s'\n",
890 else if (GS(id->name) == ID_AR && strstr(fcu->rna_path, "bones[")) {
891 /* drivers on armature-level bone settings (i.e. bbone stuff),
892 * which will affect the evaluation of corresponding pose bones
894 IDDepsNode *arm_node = m_graph->find_id_node(id);
895 char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "bones[");
897 if (arm_node && bone_name) {
898 /* find objects which use this, and make their eval callbacks depend on this */
899 foreach (DepsRelation *rel, arm_node->outlinks) {
900 IDDepsNode *to_node = (IDDepsNode *)rel->to;
902 /* we only care about objects with pose data which use this... */
903 if (GS(to_node->id->name) == ID_OB) {
904 Object *ob = (Object *)to_node->id;
905 bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name); // NOTE: ob->pose may be NULL
908 OperationKey bone_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL);
909 add_relation(driver_key, bone_key, DEPSREL_TYPE_DRIVER, "[Arm Bone -> Driver -> Bone]");
915 MEM_freeN(bone_name);
920 "Couldn't find armature bone name for driver path - '%s'\n",
924 else if (GS(id->name) == ID_OB && strstr(fcu->rna_path, "modifiers[")) {
925 /* modifier driver - connect directly to the modifier */
926 char *modifier_name = BLI_str_quoted_substrN(fcu->rna_path, "modifiers[");
928 OperationKey modifier_key(id,
929 DEPSNODE_TYPE_GEOMETRY,
930 DEG_OPCODE_GEOMETRY_MODIFIER,
932 if (has_node(modifier_key)) {
933 add_relation(driver_key, modifier_key, DEPSREL_TYPE_DRIVER, "[Driver -> Modifier]");
936 printf("Unexisting driver RNA path: %s\n", fcu->rna_path);
939 MEM_freeN(modifier_name);
942 else if (GS(id->name) == ID_KE && strstr(fcu->rna_path, "key_blocks[")) {
943 /* shape key driver - hook into the base geometry operation */
944 // XXX: double check where this points
945 Key *shape_key = (Key *)id;
947 ComponentKey geometry_key(shape_key->from, DEPSNODE_TYPE_GEOMETRY);
948 add_relation(driver_key, geometry_key, DEPSREL_TYPE_DRIVER, "[Driver -> ShapeKey Geom]");
950 else if (strstr(fcu->rna_path, "key_blocks[")) {
951 ComponentKey geometry_key(id, DEPSNODE_TYPE_GEOMETRY);
952 add_relation(driver_key, geometry_key, DEPSREL_TYPE_DRIVER, "[Driver -> ShapeKey Geom]");
955 if (GS(id->name) == ID_OB) {
956 /* assume that driver affects a transform... */
957 OperationKey local_transform_key(id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL);
958 add_relation(driver_key, local_transform_key, DEPSREL_TYPE_OPERATION, "[Driver -> Transform]");
960 else if (GS(id->name) == ID_KE) {
961 ComponentKey geometry_key(id, DEPSNODE_TYPE_GEOMETRY);
962 add_relation(driver_key, geometry_key, DEPSREL_TYPE_GEOMETRY_EVAL, "[Driver -> Shapekey Geometry]");
966 /* ensure that affected prop's update callbacks will be triggered once done */
967 // TODO: implement this once the functionality to add these links exists in RNA
968 // XXX: the data itself could also set this, if it were to be truly initialised later?
970 /* loop over variables to get the target relationships */
971 for (DriverVar *dvar = (DriverVar *)driver->variables.first; dvar; dvar = dvar->next) {
972 /* only used targets */
973 DRIVER_TARGETS_USED_LOOPER(dvar)
975 if (dtar->id == NULL)
978 /* special handling for directly-named bones */
979 if ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) {
980 Object *ob = (Object *)dtar->id;
981 bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name);
982 if (target_pchan != NULL) {
983 /* get node associated with bone */
984 // XXX: watch the space!
985 /* Some cases can't use final bone transform, for example:
986 * - Driving the bone with itself (addressed here)
987 * - Relations inside an IK chain (TODO?)
989 if (dtar->id == id &&
991 STREQ(pchan->name, target_pchan->name))
995 OperationKey target_key(dtar->id, DEPSNODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_DONE);
996 add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[Bone Target -> Driver]");
999 else if (dtar->flag & DTAR_FLAG_STRUCT_REF) {
1000 /* get node associated with the object's transforms */
1001 OperationKey target_key(dtar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
1002 add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[Target -> Driver]");
1004 else if (dtar->rna_path && strstr(dtar->rna_path, "pose.bones[")) {
1005 /* workaround for ensuring that local bone transforms don't end up
1006 * having to wait for pose eval to finish (to prevent cycles)
1008 Object *ob = (Object *)dtar->id;
1009 char *bone_name = BLI_str_quoted_substrN(dtar->rna_path, "pose.bones[");
1010 bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
1012 MEM_freeN(bone_name);
1016 if (dtar->id == id &&
1018 STREQ(pchan->name, target_pchan->name))
1022 OperationKey bone_key(dtar->id, DEPSNODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_LOCAL);
1023 add_relation(bone_key, driver_key, DEPSREL_TYPE_DRIVER, "[RNA Bone -> Driver]");
1027 if (dtar->id == id) {
1028 /* Ignore input dependency if we're driving properties of the same ID,
1029 * otherwise we'll be ending up in a cyclic dependency here.
1033 /* resolve path to get node */
1034 RNAPathKey target_key(dtar->id, dtar->rna_path ? dtar->rna_path : "");
1035 add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[RNA Target -> Driver]");
1038 DRIVER_TARGETS_LOOPER_END
1041 /* It's quite tricky to detect if the driver actually depends on time or not,
1042 * so for now we'll be quite conservative here about optimization and consider
1043 * all python drivers to be depending on time.
1045 if ((driver->type == DRIVER_TYPE_PYTHON) &&
1046 python_driver_depends_on_time(driver))
1048 TimeSourceKey time_src_key;
1049 add_relation(time_src_key, driver_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Driver]");
1053 void DepsgraphRelationBuilder::build_world(World *world)
1055 ID *world_id = &world->id;
1056 if (world_id->tag & LIB_TAG_DOIT) {
1059 world_id->tag |= LIB_TAG_DOIT;
1061 build_animdata(world_id);
1063 /* TODO: other settings? */
1066 build_texture_stack(world_id, world->mtex);
1068 /* world's nodetree */
1069 build_nodetree(world_id, world->nodetree);
1072 void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
1074 RigidBodyWorld *rbw = scene->rigidbody_world;
1076 OperationKey init_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD);
1077 OperationKey sim_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM);
1079 /* rel between the two sim-nodes */
1080 add_relation(init_key, sim_key, DEPSREL_TYPE_OPERATION, "Rigidbody [Init -> SimStep]");
1082 /* set up dependencies between these operations and other builtin nodes --------------- */
1084 /* time dependency */
1085 TimeSourceKey time_src_key;
1086 add_relation(time_src_key, init_key, DEPSREL_TYPE_TIME, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)");
1087 add_relation(time_src_key, sim_key, DEPSREL_TYPE_TIME, "TimeSrc -> Rigidbody Sim Step");
1089 /* objects - simulation participants */
1091 for (GroupObject *go = (GroupObject *)rbw->group->gobject.first; go; go = go->next) {
1092 Object *ob = go->ob;
1093 if (!ob || ob->type != OB_MESH)
1096 /* hook up evaluation order...
1097 * 1) flushing rigidbody results follows base transforms being applied
1098 * 2) rigidbody flushing can only be performed after simulation has been run
1100 * 3) simulation needs to know base transforms to figure out what to do
1101 * XXX: there's probably a difference between passive and active
1102 * - passive don't change, so may need to know full transform...
1104 OperationKey rbo_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY);
1106 eDepsOperation_Code trans_opcode = ob->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL;
1107 OperationKey trans_op(&ob->id, DEPSNODE_TYPE_TRANSFORM, trans_opcode);
1109 add_relation(trans_op, rbo_key, DEPSREL_TYPE_OPERATION, "Base Ob Transform -> RBO Sync");
1110 add_relation(sim_key, rbo_key, DEPSREL_TYPE_COMPONENT_ORDER, "Rigidbody Sim Eval -> RBO Sync");
1112 /* if constraints exist, those depend on the result of the rigidbody sim
1113 * - This allows constraints to modify the result of the sim (i.e. clamping)
1114 * while still allowing the sim to depend on some changes to the objects.
1115 * Also, since constraints are hooked up to the final nodes, this link
1116 * means that we can also fit in there too...
1117 * - Later, it might be good to include a constraint in the stack allowing us
1118 * to control whether rigidbody eval gets interleaved into the constraint stack
1120 if (ob->constraints.first) {
1121 OperationKey constraint_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_CONSTRAINTS);
1122 add_relation(rbo_key, constraint_key, DEPSREL_TYPE_COMPONENT_ORDER, "RBO Sync -> Ob Constraints");
1125 /* final object transform depends on rigidbody */
1126 OperationKey done_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL);
1127 add_relation(rbo_key, done_key, DEPSREL_TYPE_COMPONENT_ORDER, "RBO Sync -> Done");
1129 // XXX: ubereval will be removed eventually, but we still need it in the meantime
1130 OperationKey uber_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_OBJECT_UBEREVAL);
1131 add_relation(rbo_key, uber_key, DEPSREL_TYPE_COMPONENT_ORDER, "RBO Sync -> Uber (Temp)");
1135 /* needed to get correct base values */
1136 add_relation(trans_op, sim_key, DEPSREL_TYPE_OPERATION, "Base Ob Transform -> Rigidbody Sim Eval");
1141 if (rbw->constraints) {
1142 for (GroupObject *go = (GroupObject *)rbw->constraints->gobject.first; go; go = go->next) {
1143 Object *ob = go->ob;
1144 if (!ob || !ob->rigidbody_constraint)
1147 RigidBodyCon *rbc = ob->rigidbody_constraint;
1149 /* final result of the constraint object's transform controls how the
1150 * constraint affects the physics sim for these objects
1152 ComponentKey trans_key(&ob->id, DEPSNODE_TYPE_TRANSFORM);
1153 OperationKey ob1_key(&rbc->ob1->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY);
1154 OperationKey ob2_key(&rbc->ob2->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY);
1156 /* - constrained-objects sync depends on the constraint-holder */
1157 add_relation(trans_key, ob1_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_1");
1158 add_relation(trans_key, ob2_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_2");
1160 /* - ensure that sim depends on this constraint's transform */
1161 add_relation(trans_key, sim_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint Transform -> RB Simulation");
1166 void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob)
1168 TimeSourceKey time_src_key;
1169 OperationKey obdata_ubereval_key(&ob->id,
1170 DEPSNODE_TYPE_GEOMETRY,
1171 DEG_OPCODE_GEOMETRY_UBEREVAL);
1173 /* particle systems */
1174 for (ParticleSystem *psys = (ParticleSystem *)ob->particlesystem.first; psys; psys = psys->next) {
1175 ParticleSettings *part = psys->part;
1177 /* particle settings */
1178 build_animdata(&part->id);
1180 /* this particle system */
1181 OperationKey psys_key(&ob->id, DEPSNODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, psys->name);
1183 /* XXX: if particle system is later re-enabled, we must do full rebuild? */
1184 if (!psys_check_enabled(ob, psys, G.is_rendering))
1187 /* TODO(sergey): Are all particle systems depends on time?
1188 * Hair without dynamics i.e.
1190 add_relation(time_src_key, psys_key,
1194 /* TODO(sergey): Currently particle update is just a placeholder,
1195 * hook it to the ubereval node so particle system is getting updated
1198 add_relation(psys_key,
1199 obdata_ubereval_key,
1200 DEPSREL_TYPE_OPERATION,
1201 "PSys -> UberEval");
1204 if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) {
1207 for (pt = psys->targets.first; pt; pt = pt->next) {
1208 if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys - 1)) {
1209 node2 = dag_get_node(dag, pt->ob);
1210 dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Targets");
1215 if (part->ren_as == PART_DRAW_OB && part->dup_ob) {
1216 node2 = dag_get_node(dag, part->dup_ob);
1217 /* note that this relation actually runs in the wrong direction, the problem
1218 * is that dupli system all have this (due to parenting), and the render
1219 * engine instancing assumes particular ordering of objects in list */
1220 dag_add_relation(dag, node, node2, DAG_RL_OB_OB, "Particle Object Visualization");
1221 if (part->dup_ob->type == OB_MBALL)
1222 dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA, "Particle Object Visualization");
1225 if (part->ren_as == PART_DRAW_GR && part->dup_group) {
1226 for (go = part->dup_group->gobject.first; go; go = go->next) {
1227 node2 = dag_get_node(dag, go->ob);
1228 dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Particle Group Visualization");
1234 if (part->type != PART_HAIR) {
1235 add_collision_relations(psys_key, scene, ob, part->collision_group, ob->lay, true, "Particle Collision");
1239 add_forcefield_relations(psys_key, scene, ob, psys, part->effector_weights, part->type == PART_HAIR, "Particle Field");
1243 BoidRule *rule = NULL;
1244 BoidState *state = NULL;
1246 for (state = (BoidState *)part->boids->states.first; state; state = state->next) {
1247 for (rule = (BoidRule *)state->rules.first; rule; rule = rule->next) {
1248 Object *ruleob = NULL;
1249 if (rule->type == eBoidRuleType_Avoid)
1250 ruleob = ((BoidRuleGoalAvoid *)rule)->ob;
1251 else if (rule->type == eBoidRuleType_FollowLeader)
1252 ruleob = ((BoidRuleFollowLeader *)rule)->ob;
1255 ComponentKey ruleob_key(&ruleob->id, DEPSNODE_TYPE_TRANSFORM);
1256 add_relation(ruleob_key, psys_key, DEPSREL_TYPE_TRANSFORM, "Boid Rule");
1262 if (part->ren_as == PART_DRAW_OB && part->dup_ob) {
1263 ComponentKey dup_ob_key(&part->dup_ob->id, DEPSNODE_TYPE_TRANSFORM);
1264 add_relation(dup_ob_key,
1266 DEPSREL_TYPE_TRANSFORM,
1267 "Particle Object Visualization");
1271 /* Particle depends on the object transform, so that channel is to be ready
1274 * TODO(sergey): This relation should be altered once real granular update
1277 ComponentKey transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM);
1278 add_relation(transform_key,
1279 obdata_ubereval_key,
1280 DEPSREL_TYPE_GEOMETRY_EVAL,
1287 /* IK Solver Eval Steps */
1288 void DepsgraphRelationBuilder::build_ik_pose(Object *ob,
1289 bPoseChannel *pchan,
1291 RootPChanMap *root_map)
1293 bKinematicConstraint *data = (bKinematicConstraint *)con->data;
1295 /* attach owner to IK Solver too
1296 * - assume that owner is always part of chain
1297 * - see notes on direction of rel below...
1299 bPoseChannel *rootchan = BKE_armature_ik_solver_find_root(pchan, data);
1300 OperationKey solver_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_IK_SOLVER);
1303 // XXX: this should get handled as part of the constraint code
1304 if (data->tar != NULL) {
1305 /* TODO(sergey): For until we'll store partial matricies in the depsgraph,
1306 * we create dependency between target object and pose eval component.
1308 * This way we ensuring the whole subtree is updated from scratch without
1309 * need of intermediate matricies. This is an overkill, but good enough for
1310 * testing IK solver.
1312 // FIXME: geometry targets...
1313 ComponentKey pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE);
1314 if ((data->tar->type == OB_ARMATURE) && (data->subtarget[0])) {
1315 /* TODO(sergey): This is only for until granular update stores intermediate result. */
1316 if (data->tar != ob) {
1317 /* different armature - can just read the results */
1318 ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_BONE, data->subtarget);
1319 add_relation(target_key, pose_key, DEPSREL_TYPE_TRANSFORM, con->name);
1322 /* same armature - we'll use the ready state only, just in case this bone is in the chain we're solving */
1323 OperationKey target_key(&data->tar->id, DEPSNODE_TYPE_BONE, data->subtarget, DEG_OPCODE_BONE_DONE);
1324 add_relation(target_key, solver_key, DEPSREL_TYPE_TRANSFORM, con->name);
1327 else if (ELEM(data->tar->type, OB_MESH, OB_LATTICE) && (data->subtarget[0])) {
1328 /* vertex group target */
1329 /* NOTE: for now, we don't need to represent vertex groups separately... */
1330 ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_GEOMETRY);
1331 add_relation(target_key, solver_key, DEPSREL_TYPE_GEOMETRY_EVAL, con->name);
1333 if (data->tar->type == OB_MESH) {
1334 OperationDepsNode *node2 = find_operation_node(target_key);
1335 if (node2 != NULL) {
1336 node2->customdata_mask |= CD_MASK_MDEFORMVERT;
1341 /* Standard Object Target */
1342 ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_TRANSFORM);
1343 add_relation(target_key, pose_key, DEPSREL_TYPE_TRANSFORM, con->name);
1346 if ((data->tar == ob) && (data->subtarget[0])) {
1347 /* Prevent target's constraints from linking to anything from same
1348 * chain that it controls.
1350 root_map->add_bone(data->subtarget, rootchan->name);
1355 // XXX: this should get handled as part of the constraint code
1356 if (data->poletar != NULL) {
1357 if ((data->poletar->type == OB_ARMATURE) && (data->polesubtarget[0])) {
1358 // XXX: same armature issues - ready vs done?
1359 ComponentKey target_key(&data->poletar->id, DEPSNODE_TYPE_BONE, data->subtarget);
1360 add_relation(target_key, solver_key, DEPSREL_TYPE_TRANSFORM, con->name);
1362 else if (ELEM(data->poletar->type, OB_MESH, OB_LATTICE) && (data->subtarget[0])) {
1363 /* vertex group target */
1364 /* NOTE: for now, we don't need to represent vertex groups separately... */
1365 ComponentKey target_key(&data->poletar->id, DEPSNODE_TYPE_GEOMETRY);
1366 add_relation(target_key, solver_key, DEPSREL_TYPE_GEOMETRY_EVAL, con->name);
1368 if (data->poletar->type == OB_MESH) {
1369 OperationDepsNode *node2 = find_operation_node(target_key);
1370 if (node2 != NULL) {
1371 node2->customdata_mask |= CD_MASK_MDEFORMVERT;
1376 ComponentKey target_key(&data->poletar->id, DEPSNODE_TYPE_TRANSFORM);
1377 add_relation(target_key, solver_key, DEPSREL_TYPE_TRANSFORM, con->name);
1381 DEG_DEBUG_PRINTF("\nStarting IK Build: pchan = %s, target = (%s, %s), segcount = %d\n",
1382 pchan->name, data->tar->id.name, data->subtarget, data->rootbone);
1384 bPoseChannel *parchan = pchan;
1385 /* exclude tip from chain? */
1386 if (!(data->flag & CONSTRAINT_IK_TIP)) {
1387 OperationKey tip_transforms_key(&ob->id, DEPSNODE_TYPE_BONE,
1388 parchan->name, DEG_OPCODE_BONE_LOCAL);
1389 add_relation(solver_key, tip_transforms_key,
1390 DEPSREL_TYPE_TRANSFORM, "IK Solver Result");
1391 parchan = pchan->parent;
1394 root_map->add_bone(parchan->name, rootchan->name);
1396 OperationKey parchan_transforms_key(&ob->id, DEPSNODE_TYPE_BONE,
1397 parchan->name, DEG_OPCODE_BONE_READY);
1398 add_relation(parchan_transforms_key, solver_key,
1399 DEPSREL_TYPE_TRANSFORM, "IK Solver Owner");
1401 /* Walk to the chain's root */
1402 //size_t segcount = 0;
1406 /* Make IK-solver dependent on this bone's result,
1407 * since it can only run after the standard results
1408 * of the bone are know. Validate links step on the
1409 * bone will ensure that users of this bone only
1410 * grab the result with IK solver results...
1412 if (parchan != pchan) {
1413 OperationKey parent_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY);
1414 add_relation(parent_key, solver_key, DEPSREL_TYPE_TRANSFORM, "IK Chain Parent");
1416 OperationKey done_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE);
1417 add_relation(solver_key, done_key, DEPSREL_TYPE_TRANSFORM, "IK Chain Result");
1420 OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE);
1421 add_relation(solver_key, final_transforms_key, DEPSREL_TYPE_TRANSFORM, "IK Solver Result");
1423 parchan->flag |= POSE_DONE;
1426 root_map->add_bone(parchan->name, rootchan->name);
1428 /* continue up chain, until we reach target number of items... */
1429 DEG_DEBUG_PRINTF(" %d = %s\n", segcount, parchan->name);
1431 if ((segcount == data->rootbone) || (segcount > 255)) break; /* 255 is weak */
1433 parchan = parchan->parent;
1436 OperationKey flush_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
1437 add_relation(solver_key, flush_key, DEPSREL_TYPE_OPERATION, "PoseEval Result-Bone Link");
1440 /* Spline IK Eval Steps */
1441 void DepsgraphRelationBuilder::build_splineik_pose(Object *ob,
1442 bPoseChannel *pchan,
1444 RootPChanMap *root_map)
1446 bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
1447 bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
1448 OperationKey transforms_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY);
1449 OperationKey solver_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, rootchan->name, DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
1451 /* attach owner to IK Solver too
1452 * - assume that owner is always part of chain
1453 * - see notes on direction of rel below...
1455 add_relation(transforms_key, solver_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Solver Owner");
1457 /* attach path dependency to solver */
1459 /* TODO(sergey): For until we'll store partial matricies in the depsgraph,
1460 * we create dependency between target object and pose eval component.
1461 * See IK pose for a bit more information.
1463 // TODO: the bigggest point here is that we need the curve PATH and not just the general geometry...
1464 ComponentKey target_key(&data->tar->id, DEPSNODE_TYPE_GEOMETRY);
1465 ComponentKey pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE);
1466 add_relation(target_key, pose_key, DEPSREL_TYPE_TRANSFORM, "[Curve.Path -> Spline IK] DepsRel");
1469 pchan->flag |= POSE_DONE;
1470 OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
1471 add_relation(solver_key, final_transforms_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Result");
1473 root_map->add_bone(pchan->name, rootchan->name);
1475 /* Walk to the chain's root */
1476 //size_t segcount = 0;
1479 for (bPoseChannel *parchan = pchan->parent; parchan; parchan = parchan->parent) {
1480 /* Make Spline IK solver dependent on this bone's result,
1481 * since it can only run after the standard results
1482 * of the bone are know. Validate links step on the
1483 * bone will ensure that users of this bone only
1484 * grab the result with IK solver results...
1486 if (parchan != pchan) {
1487 OperationKey parent_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_READY);
1488 add_relation(parent_key, solver_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Solver Update");
1490 OperationKey done_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE);
1491 add_relation(solver_key, done_key, DEPSREL_TYPE_TRANSFORM, "IK Chain Result");
1493 parchan->flag |= POSE_DONE;
1495 OperationKey final_transforms_key(&ob->id, DEPSNODE_TYPE_BONE, parchan->name, DEG_OPCODE_BONE_DONE);
1496 add_relation(solver_key, final_transforms_key, DEPSREL_TYPE_TRANSFORM, "Spline IK Solver Result");
1498 root_map->add_bone(parchan->name, rootchan->name);
1500 /* continue up chain, until we reach target number of items... */
1502 if ((segcount == data->chainlen) || (segcount > 255)) break; /* 255 is weak */
1505 OperationKey flush_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
1506 add_relation(solver_key, flush_key, DEPSREL_TYPE_OPERATION, "PoseEval Result-Bone Link");
1509 /* Pose/Armature Bones Graph */
1510 void DepsgraphRelationBuilder::build_rig(Scene *scene, Object *ob)
1513 bArmature *arm = (bArmature *)ob->data;
1515 // TODO: selection status?
1517 /* attach links between pose operations */
1518 OperationKey init_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
1519 OperationKey flush_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
1521 add_relation(init_key, flush_key, DEPSREL_TYPE_COMPONENT_ORDER, "[Pose Init -> Pose Cleanup]");
1523 /* Make sure pose is up-to-date with armature updates. */
1524 OperationKey armature_key(&arm->id,
1525 DEPSNODE_TYPE_PARAMETERS,
1526 DEG_OPCODE_PLACEHOLDER,
1528 add_relation(armature_key, init_key, DEPSREL_TYPE_COMPONENT_ORDER, "Data dependency");
1530 if (ob->adt && (ob->adt->action || ob->adt->nla_tracks.first)) {
1531 ComponentKey animation_key(&ob->id, DEPSNODE_TYPE_ANIMATION);
1532 add_relation(animation_key, init_key, DEPSREL_TYPE_OPERATION, "Rig Animation");
1536 * - These require separate processing steps are pose-level
1537 * to be executed between chains of bones (i.e. once the
1538 * base transforms of a bunch of bones is done)
1540 * - We build relations for these before the dependencies
1541 * between ops in the same component as it is necessary
1542 * to check whether such bones are in the same IK chain
1543 * (or else we get weird issues with either in-chain
1544 * references, or with bones being parented to IK'd bones)
1547 * - Care is needed to ensure that multi-headed trees work out the same as in ik-tree building
1548 * - Animated chain-lengths are a problem...
1550 RootPChanMap root_map;
1551 bool pose_depends_on_local_transform = false;
1552 for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1553 for (bConstraint *con = (bConstraint *)pchan->constraints.first; con; con = con->next) {
1554 switch (con->type) {
1555 case CONSTRAINT_TYPE_KINEMATIC:
1556 build_ik_pose(ob, pchan, con, &root_map);
1557 pose_depends_on_local_transform = true;
1560 case CONSTRAINT_TYPE_SPLINEIK:
1561 build_splineik_pose(ob, pchan, con, &root_map);
1562 pose_depends_on_local_transform = true;
1565 /* Constraints which needs world's matrix for transform.
1566 * TODO(sergey): More constraints here?
1568 case CONSTRAINT_TYPE_ROTLIKE:
1569 case CONSTRAINT_TYPE_SIZELIKE:
1570 case CONSTRAINT_TYPE_LOCLIKE:
1571 case CONSTRAINT_TYPE_TRANSLIKE:
1572 /* TODO(sergey): Add used space check. */
1573 pose_depends_on_local_transform = true;
1581 //root_map.print_debug();
1583 if (pose_depends_on_local_transform) {
1584 /* TODO(sergey): Once partial updates are possible use relation between
1585 * object transform and solver itself in it's build function.
1587 ComponentKey pose_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE);
1588 ComponentKey local_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM);
1589 add_relation(local_transform_key, pose_key, DEPSREL_TYPE_TRANSFORM, "Local Transforms");
1593 /* links between operations for each bone */
1594 for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) {
1595 OperationKey bone_local_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL);
1596 OperationKey bone_pose_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_POSE_PARENT);
1597 OperationKey bone_ready_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY);
1598 OperationKey bone_done_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
1600 pchan->flag &= ~POSE_DONE;
1602 /* pose init to bone local */
1603 add_relation(init_key, bone_local_key, DEPSREL_TYPE_OPERATION, "PoseEval Source-Bone Link");
1605 /* local to pose parenting operation */
1606 add_relation(bone_local_key, bone_pose_key, DEPSREL_TYPE_OPERATION, "Bone Local - PoseSpace Link");
1608 /* parent relation */
1609 if (pchan->parent != NULL) {
1610 eDepsOperation_Code parent_key_opcode;
1612 /* NOTE: this difference in handling allows us to prevent lockups while ensuring correct poses for separate chains */
1613 if (root_map.has_common_root(pchan->name, pchan->parent->name)) {
1614 parent_key_opcode = DEG_OPCODE_BONE_READY;
1617 parent_key_opcode = DEG_OPCODE_BONE_DONE;
1620 OperationKey parent_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->parent->name, parent_key_opcode);
1621 add_relation(parent_key, bone_pose_key, DEPSREL_TYPE_TRANSFORM, "[Parent Bone -> Child Bone]");
1625 if (pchan->constraints.first != NULL) {
1626 /* constraints stack and constraint dependencies */
1627 build_constraints(scene, &ob->id, DEPSNODE_TYPE_BONE, pchan->name, &pchan->constraints, &root_map);
1629 /* pose -> constraints */
1630 OperationKey constraints_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_CONSTRAINTS);
1631 add_relation(bone_pose_key, constraints_key, DEPSREL_TYPE_OPERATION, "Constraints Stack");
1633 /* constraints -> ready */
1634 // TODO: when constraint stack is exploded, this step should occur before the first IK solver
1635 add_relation(constraints_key, bone_ready_key, DEPSREL_TYPE_OPERATION, "Constraints -> Ready");
1639 add_relation(bone_pose_key, bone_ready_key, DEPSREL_TYPE_OPERATION, "Pose -> Ready");
1642 /* bone ready -> done
1643 * NOTE: For bones without IK, this is all that's needed.
1644 * For IK chains however, an additional rel is created from IK to done,
1645 * with transitive reduction removing this one...
1647 add_relation(bone_ready_key, bone_done_key, DEPSREL_TYPE_OPERATION, "Ready -> Done");
1649 /* assume that all bones must be done for the pose to be ready (for deformers) */
1650 add_relation(bone_done_key, flush_key, DEPSREL_TYPE_OPERATION, "PoseEval Result-Bone Link");
1654 void DepsgraphRelationBuilder::build_proxy_rig(Object *ob)
1656 OperationKey pose_init_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_INIT);
1657 OperationKey pose_done_key(&ob->id, DEPSNODE_TYPE_EVAL_POSE, DEG_OPCODE_POSE_DONE);
1658 for (bPoseChannel *pchan = (bPoseChannel *)ob->pose->chanbase.first;
1660 pchan = pchan->next)
1662 OperationKey bone_local_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL);
1663 OperationKey bone_ready_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY);
1664 OperationKey bone_done_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
1665 add_relation(pose_init_key, bone_local_key, DEPSREL_TYPE_OPERATION, "Pose Init -> Bone Local");
1666 add_relation(bone_local_key, bone_ready_key, DEPSREL_TYPE_OPERATION, "Local -> Ready");
1667 add_relation(bone_ready_key, bone_done_key, DEPSREL_TYPE_OPERATION, "Ready -> Done");
1668 add_relation(bone_done_key, pose_done_key, DEPSREL_TYPE_OPERATION, "Bone Done -> Pose Done");
1673 void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key)
1675 ComponentKey obdata_key(obdata, DEPSNODE_TYPE_GEOMETRY);
1677 /* attach animdata to geometry */
1678 build_animdata(&key->id);
1681 // TODO: this should really be handled in build_animdata, since many of these cases will need it
1682 if (key->adt->action || key->adt->nla_tracks.first) {
1683 ComponentKey adt_key(&key->id, DEPSNODE_TYPE_ANIMATION);
1684 add_relation(adt_key, obdata_key, DEPSREL_TYPE_OPERATION, "Animation");
1687 /* NOTE: individual shapekey drivers are handled above already */
1690 /* attach to geometry */
1691 // XXX: aren't shapekeys now done as a pseudo-modifier on object?
1692 //ComponentKey key_key(&key->id, DEPSNODE_TYPE_GEOMETRY); // FIXME: this doesn't exist
1693 //add_relation(key_key, obdata_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Shapekeys");
1697 * ObData Geometry Evaluation
1698 * ==========================
1700 * The evaluation of geometry on objects is as follows:
1701 * - The actual evaluated of the derived geometry (e.g. DerivedMesh, DispList, etc.)
1702 * occurs in the Geometry component of the object which references this. This includes
1703 * modifiers, and the temporary "ubereval" for geometry.
1704 * - Therefore, each user of a piece of shared geometry data ends up evaluating its own
1705 * version of the stuff, complete with whatever modifiers it may use.
1707 * - The datablocks for the geometry data - "obdata" (e.g. ID_ME, ID_CU, ID_LT, etc.) are used for
1708 * 1) calculating the bounding boxes of the geometry data,
1709 * 2) aggregating inward links from other objects (e.g. for text on curve, etc.)
1710 * and also for the links coming from the shapekey datablocks
1711 * - Animation/Drivers affecting the parameters of the geometry are made to trigger
1712 * updates on the obdata geometry component, which then trigger downstream
1713 * re-evaluation of the individual instances of this geometry.
1715 // TODO: Materials and lighting should probably get their own component, instead of being lumped under geometry?
1716 void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Object *ob)
1718 ID *obdata = (ID *)ob->data;
1720 /* Init operation of object-level geometry evaluation. */
1721 OperationKey geom_init_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Init");
1723 /* get nodes for result of obdata's evaluation, and geometry evaluation on object */
1724 ComponentKey obdata_geom_key(obdata, DEPSNODE_TYPE_GEOMETRY);
1725 ComponentKey geom_key(&ob->id, DEPSNODE_TYPE_GEOMETRY);
1727 /* link components to each other */
1728 add_relation(obdata_geom_key, geom_key, DEPSREL_TYPE_DATABLOCK, "Object Geometry Base Data");
1731 if (ob->modifiers.first) {
1733 OperationKey prev_mod_key;
1735 for (md = (ModifierData *)ob->modifiers.first; md; md = md->next) {
1736 const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type);
1737 OperationKey mod_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_MODIFIER, md->name);
1740 /* Stack relation: modifier depends on previous modifier in the stack */
1741 add_relation(prev_mod_key, mod_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Modifier Stack");
1744 /* Stack relation: first modifier depends on the geometry. */
1745 add_relation(geom_init_key, mod_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Modifier Stack");
1748 if (mti->updateDepsgraph) {
1749 DepsNodeHandle handle = create_node_handle(mod_key);
1750 mti->updateDepsgraph(
1755 reinterpret_cast< ::DepsNodeHandle* >(&handle));
1758 if (BKE_object_modifier_use_time(ob, md)) {
1759 TimeSourceKey time_src_key;
1760 add_relation(time_src_key, mod_key, DEPSREL_TYPE_TIME, "Time Source");
1762 /* Hacky fix for T45633 (Animated modifiers aren't updated)
1764 * This check works because BKE_object_modifier_use_time() tests
1765 * for either the modifier needing time, or that it is animated.
1767 /* XXX: Remove this hack when these links are added as part of build_animdata() instead */
1768 if (modifier_dependsOnTime(md) == false) {
1769 ComponentKey animation_key(&ob->id, DEPSNODE_TYPE_ANIMATION);
1770 add_relation(animation_key, mod_key, DEPSREL_TYPE_OPERATION, "Modifier Animation");
1774 prev_mod_key = mod_key;
1782 for (a = 1; a <= ob->totcol; a++) {
1783 Material *ma = give_current_material(ob, a);
1786 build_material(&ob->id, ma);
1790 /* geometry collision */
1791 if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1792 // add geometry collider relations
1795 /* Make sure uber update is the last in the dependencies.
1797 * TODO(sergey): Get rid of this node.
1799 if (ob->type != OB_ARMATURE) {
1800 /* Armatures does no longer require uber node. */
1801 OperationKey obdata_ubereval_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL);
1802 if (ob->modifiers.last) {
1803 ModifierData *md = (ModifierData *)ob->modifiers.last;
1804 OperationKey mod_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_MODIFIER, md->name);
1805 add_relation(mod_key, obdata_ubereval_key, DEPSREL_TYPE_OPERATION, "Object Geometry UberEval");
1808 add_relation(geom_init_key, obdata_ubereval_key, DEPSREL_TYPE_OPERATION, "Object Geometry UberEval");
1812 if (obdata->tag & LIB_TAG_DOIT) {
1815 obdata->tag |= LIB_TAG_DOIT;
1817 /* Link object data evaluation node to exit operation. */
1818 OperationKey obdata_geom_eval_key(obdata, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
1819 OperationKey obdata_geom_done_key(obdata, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Done");
1820 add_relation(obdata_geom_eval_key, obdata_geom_done_key, DEPSREL_TYPE_DATABLOCK, "ObData Geom Eval Done");
1822 /* type-specific node/links */
1829 Object *mom = BKE_mball_basis_find(scene, ob);
1831 /* motherball - mom depends on children! */
1833 /* non-motherball -> cannot be directly evaluated! */
1834 ComponentKey mom_key(&mom->id, DEPSNODE_TYPE_GEOMETRY);
1835 ComponentKey transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM);
1836 add_relation(geom_key, mom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Metaball Motherball");
1837 add_relation(transform_key, mom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Metaball Motherball");
1845 Curve *cu = (Curve *)obdata;
1847 /* curve's dependencies */
1848 // XXX: these needs geom data, but where is geom stored?
1850 ComponentKey bevob_key(&cu->bevobj->id, DEPSNODE_TYPE_GEOMETRY);
1851 add_relation(bevob_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Curve Bevel");
1854 ComponentKey taperob_key(&cu->taperobj->id, DEPSNODE_TYPE_GEOMETRY);
1855 add_relation(taperob_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Curve Taper");
1857 if (ob->type == OB_FONT) {
1858 if (cu->textoncurve) {
1859 ComponentKey textoncurve_key(&cu->taperobj->id, DEPSNODE_TYPE_GEOMETRY);
1860 add_relation(textoncurve_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Text on Curve");
1866 case OB_SURF: /* Nurbs Surface */
1871 case OB_LATTICE: /* Lattice */
1878 Key *key = BKE_key_from_object(ob);
1880 build_shapekeys(obdata, key);
1883 if (needs_animdata_node(obdata)) {
1884 ComponentKey animation_key(obdata, DEPSNODE_TYPE_ANIMATION);
1885 ComponentKey parameters_key(obdata, DEPSNODE_TYPE_PARAMETERS);
1886 add_relation(animation_key, parameters_key,
1887 DEPSREL_TYPE_COMPONENT_ORDER, "Geom Parameters");
1888 /* Evaluation usually depends on animation.
1889 * TODO(sergey): Need to re-hook it after granular update is implemented..
1891 add_relation(animation_key, obdata_geom_eval_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Animation");
1896 // TODO: Link scene-camera links in somehow...
1897 void DepsgraphRelationBuilder::build_camera(Object *ob)
1899 Camera *cam = (Camera *)ob->data;
1900 ID *camera_id = &cam->id;
1901 if (camera_id->tag & LIB_TAG_DOIT) {
1904 camera_id->tag |= LIB_TAG_DOIT;
1906 ComponentKey parameters_key(camera_id, DEPSNODE_TYPE_PARAMETERS);
1908 if (needs_animdata_node(camera_id)) {
1909 ComponentKey animation_key(camera_id, DEPSNODE_TYPE_ANIMATION);
1910 add_relation(animation_key, parameters_key,
1911 DEPSREL_TYPE_COMPONENT_ORDER, "Camera Parameters");
1916 ComponentKey ob_param_key(&ob->id, DEPSNODE_TYPE_PARAMETERS);
1917 ComponentKey dof_ob_key(&cam->dof_ob->id, DEPSNODE_TYPE_TRANSFORM);
1918 add_relation(dof_ob_key, ob_param_key, DEPSREL_TYPE_TRANSFORM, "Camera DOF");
1923 void DepsgraphRelationBuilder::build_lamp(Object *ob)
1925 Lamp *la = (Lamp *)ob->data;
1926 ID *lamp_id = &la->id;
1927 if (lamp_id->tag & LIB_TAG_DOIT) {
1930 lamp_id->tag |= LIB_TAG_DOIT;
1932 ComponentKey parameters_key(lamp_id, DEPSNODE_TYPE_PARAMETERS);
1934 if (needs_animdata_node(lamp_id)) {
1935 ComponentKey animation_key(lamp_id, DEPSNODE_TYPE_ANIMATION);
1936 add_relation(animation_key, parameters_key,
1937 DEPSREL_TYPE_COMPONENT_ORDER, "Lamp Parameters");
1940 /* lamp's nodetree */
1942 build_nodetree(lamp_id, la->nodetree);
1943 ComponentKey nodetree_key(&la->nodetree->id, DEPSNODE_TYPE_PARAMETERS);
1944 add_relation(nodetree_key, parameters_key,
1945 DEPSREL_TYPE_COMPONENT_ORDER, "NTree->Lamp Parameters");
1949 build_texture_stack(lamp_id, la->mtex);
1952 void DepsgraphRelationBuilder::build_nodetree(ID *owner, bNodeTree *ntree)
1957 ID *ntree_id = &ntree->id;
1959 build_animdata(ntree_id);
1961 OperationKey parameters_key(ntree_id,
1962 DEPSNODE_TYPE_PARAMETERS,
1963 DEG_OPCODE_PLACEHOLDER,
1966 /* nodetree's nodes... */
1967 for (bNode *bnode = (bNode *)ntree->nodes.first; bnode; bnode = bnode->next) {
1969 if (GS(bnode->id->name) == ID_MA) {
1970 build_material(owner, (Material *)bnode->id);
1972 else if (bnode->type == ID_TE) {
1973 build_texture(owner, (Tex *)bnode->id);
1975 else if (bnode->type == NODE_GROUP) {
1976 bNodeTree *group_ntree = (bNodeTree *)bnode->id;
1977 if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) {
1978 build_nodetree(owner, group_ntree);
1979 group_ntree->id.tag |= LIB_TAG_DOIT;
1981 OperationKey group_parameters_key(&group_ntree->id,
1982 DEPSNODE_TYPE_PARAMETERS,
1983 DEG_OPCODE_PLACEHOLDER,
1985 add_relation(group_parameters_key, parameters_key,
1986 DEPSREL_TYPE_COMPONENT_ORDER, "Group Node");
1991 if (needs_animdata_node(ntree_id)) {
1992 ComponentKey animation_key(ntree_id, DEPSNODE_TYPE_ANIMATION);
1993 add_relation(animation_key, parameters_key,
1994 DEPSREL_TYPE_COMPONENT_ORDER, "NTree Parameters");
1997 // TODO: link from nodetree to owner_component?
2000 /* Recursively build graph for material */
2001 void DepsgraphRelationBuilder::build_material(ID *owner, Material *ma)
2003 ID *ma_id = &ma->id;
2004 if (ma_id->tag & LIB_TAG_DOIT) {
2007 ma_id->tag |= LIB_TAG_DOIT;
2010 build_animdata(ma_id);
2013 build_texture_stack(owner, ma->mtex);
2015 /* material's nodetree */
2016 build_nodetree(owner, ma->nodetree);
2019 /* Recursively build graph for texture */
2020 void DepsgraphRelationBuilder::build_texture(ID *owner, Tex *tex)
2022 ID *tex_id = &tex->id;
2023 if (tex_id->tag & LIB_TAG_DOIT) {
2026 tex_id->tag |= LIB_TAG_DOIT;
2028 /* texture itself */
2029 build_animdata(tex_id);
2031 /* texture's nodetree */
2032 build_nodetree(owner, tex->nodetree);
2035 /* Texture-stack attached to some shading datablock */
2036 void DepsgraphRelationBuilder::build_texture_stack(ID *owner, MTex **texture_stack)
2040 /* for now assume that all texture-stacks have same number of max items */
2041 for (i = 0; i < MAX_MTEX; i++) {
2042 MTex *mtex = texture_stack[i];
2043 if (mtex && mtex->tex)
2044 build_texture(owner, mtex->tex);
2048 void DepsgraphRelationBuilder::build_compositor(Scene *scene)
2050 /* For now, just a plain wrapper? */
2051 build_nodetree(&scene->id, scene->nodetree);
2054 void DepsgraphRelationBuilder::build_gpencil(ID *UNUSED(owner), bGPdata *gpd)
2057 build_animdata(&gpd->id);
2059 // TODO: parent object (when that feature is implemented)
2062 bool DepsgraphRelationBuilder::needs_animdata_node(ID *id)
2064 AnimData *adt = BKE_animdata_from_id(id);
2066 return adt->action != NULL;