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"
37 #include <cstring> /* required for STREQ later on. */
39 #include "MEM_guardedalloc.h"
41 #include "BLI_utildefines.h"
42 #include "BLI_blenlib.h"
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_object_types.h"
65 #include "DNA_rigidbody_types.h"
66 #include "DNA_scene_types.h"
67 #include "DNA_texture_types.h"
68 #include "DNA_world_types.h"
69 #include "DNA_object_force.h"
71 #include "BKE_action.h"
72 #include "BKE_armature.h"
73 #include "BKE_animsys.h"
74 #include "BKE_constraint.h"
75 #include "BKE_curve.h"
76 #include "BKE_effect.h"
77 #include "BKE_collision.h"
78 #include "BKE_fcurve.h"
79 #include "BKE_group.h"
81 #include "BKE_library.h"
83 #include "BKE_material.h"
84 #include "BKE_mball.h"
85 #include "BKE_modifier.h"
87 #include "BKE_object.h"
88 #include "BKE_particle.h"
89 #include "BKE_rigidbody.h"
90 #include "BKE_sound.h"
91 #include "BKE_tracking.h"
92 #include "BKE_world.h"
94 #include "RNA_access.h"
95 #include "RNA_types.h"
98 #include "DEG_depsgraph.h"
99 #include "DEG_depsgraph_build.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_id.h"
107 #include "intern/nodes/deg_node_operation.h"
108 #include "intern/nodes/deg_node_time.h"
110 #include "intern/depsgraph_intern.h"
111 #include "intern/depsgraph_types.h"
113 #include "util/deg_util_foreach.h"
119 struct BuilderWalkUserData {
120 DepsgraphRelationBuilder *builder;
123 void modifier_walk(void *user_data,
124 struct Object * /*object*/,
125 struct Object **obpoin,
128 BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
130 data->builder->build_object(*obpoin);
134 void constraint_walk(bConstraint * /*con*/,
136 bool /*is_reference*/,
139 BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
142 if (GS(id->name) == ID_OB) {
143 data->builder->build_object((Object *)id);
150 /* ***************** */
151 /* Relations Builder */
153 /* TODO(sergey): This is somewhat weak, but we don't want neither false-positive
154 * time dependencies nor special exceptions in the depsgraph evaluation.
156 static bool python_driver_depends_on_time(ChannelDriver *driver)
158 if (driver->expression[0] == '\0') {
159 /* Empty expression depends on nothing. */
162 if (strchr(driver->expression, '(') != NULL) {
163 /* Function calls are considered dependent on a time. */
166 if (strstr(driver->expression, "frame") != NULL) {
167 /* Variable `frame` depends on time. */
168 /* TODO(sergey): This is a bit weak, but not sure about better way of
173 /* Possible indirect time relation s should be handled via variable
179 static bool particle_system_depends_on_time(ParticleSystem *psys)
181 ParticleSettings *part = psys->part;
182 /* Non-hair particles we always consider dependent on time. */
183 if (part->type != PART_HAIR) {
186 /* Dynamics always depends on time. */
187 if (psys->flag & PSYS_HAIR_DYNAMICS) {
190 /* TODO(sergey): Check what else makes hair dependent on time. */
194 static bool object_particles_depends_on_time(Object *object)
197 BLI_LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
198 if (particle_system_depends_on_time(psys)) {
205 /* **** General purpose functions **** */
207 DepsgraphRelationBuilder::DepsgraphRelationBuilder(Main *bmain,
215 TimeSourceDepsNode *DepsgraphRelationBuilder::get_node(
216 const TimeSourceKey &key) const
223 return graph_->time_source;
227 ComponentDepsNode *DepsgraphRelationBuilder::get_node(
228 const ComponentKey &key) const
230 IDDepsNode *id_node = graph_->find_id_node(key.id);
232 fprintf(stderr, "find_node component: Could not find ID %s\n",
233 (key.id != NULL) ? key.id->name : "<null>");
237 ComponentDepsNode *node = id_node->find_component(key.type, key.name);
241 OperationDepsNode *DepsgraphRelationBuilder::get_node(
242 const OperationKey &key) const
244 OperationDepsNode *op_node = find_node(key);
245 if (op_node == NULL) {
246 fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
247 DEG_OPNAMES[key.opcode], key.name);
252 DepsNode *DepsgraphRelationBuilder::get_node(const RNAPathKey &key) const
254 return graph_->find_node_from_pointer(&key.ptr, key.prop);
257 OperationDepsNode *DepsgraphRelationBuilder::find_node(
258 const OperationKey &key) const
260 IDDepsNode *id_node = graph_->find_id_node(key.id);
264 ComponentDepsNode *comp_node = id_node->find_component(key.component_type,
269 return comp_node->find_operation(key.opcode, key.name, key.name_tag);
272 bool DepsgraphRelationBuilder::has_node(const OperationKey &key) const
274 return find_node(key) != NULL;
277 void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc,
279 const char *description,
282 if (timesrc && node_to) {
283 graph_->add_new_relation(timesrc, node_to, description, check_unique);
286 DEG_DEBUG_PRINTF("add_time_relation(%p = %s, %p = %s, %s) Failed\n",
287 timesrc, (timesrc) ? timesrc->identifier().c_str() : "<None>",
288 node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
293 void DepsgraphRelationBuilder::add_operation_relation(
294 OperationDepsNode *node_from,
295 OperationDepsNode *node_to,
296 const char *description,
299 if (node_from && node_to) {
300 graph_->add_new_relation(node_from, node_to, description, check_unique);
303 DEG_DEBUG_PRINTF("add_operation_relation(%p = %s, %p = %s, %s) Failed\n",
304 node_from, (node_from) ? node_from->identifier().c_str() : "<None>",
305 node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
310 void DepsgraphRelationBuilder::add_collision_relations(
311 const OperationKey &key,
319 unsigned int numcollobj;
320 Object **collobjs = get_collisionobjects_ext(
326 eModifierType_Collision,
328 for (unsigned int i = 0; i < numcollobj; i++) {
329 Object *ob1 = collobjs[i];
331 ComponentKey trf_key(&ob1->id, DEG_NODE_TYPE_TRANSFORM);
332 add_relation(trf_key, key, name);
334 ComponentKey coll_key(&ob1->id, DEG_NODE_TYPE_GEOMETRY);
335 add_relation(coll_key, key, name);
337 if (collobjs != NULL) {
342 void DepsgraphRelationBuilder::add_forcefield_relations(
343 const OperationKey &key,
346 ParticleSystem *psys,
347 EffectorWeights *eff,
351 ListBase *effectors = pdInitEffectors(scene, object, psys, eff, false);
352 if (effectors != NULL) {
353 BLI_LISTBASE_FOREACH(EffectorCache *, eff, effectors) {
354 if (eff->ob != object) {
355 ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_TRANSFORM);
356 add_relation(eff_key, key, name);
358 if (eff->psys != NULL) {
359 if (eff->ob != object) {
360 ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES);
361 add_relation(eff_key, key, name);
363 /* TODO: remove this when/if EVAL_PARTICLES is sufficient
364 * for up to date particles.
366 ComponentKey mod_key(&eff->ob->id, DEG_NODE_TYPE_GEOMETRY);
367 add_relation(mod_key, key, name);
369 else if (eff->psys != psys) {
370 OperationKey eff_key(&eff->ob->id,
371 DEG_NODE_TYPE_EVAL_PARTICLES,
372 DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
374 add_relation(eff_key, key, name);
377 if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) {
378 ComponentKey trf_key(&eff->pd->f_source->id,
379 DEG_NODE_TYPE_TRANSFORM);
380 add_relation(trf_key, key, "Smoke Force Domain");
382 ComponentKey eff_key(&eff->pd->f_source->id,
383 DEG_NODE_TYPE_GEOMETRY);
384 add_relation(eff_key, key, "Smoke Force Domain");
386 if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) {
387 add_collision_relations(key,
398 pdEndEffectors(&effectors);
401 Depsgraph *DepsgraphRelationBuilder::getGraph()
406 /* **** Functions to build relations between entities **** */
408 void DepsgraphRelationBuilder::begin_build()
410 /* LIB_TAG_DOIT is used to indicate whether node for given ID was already
413 BKE_main_id_tag_all(bmain_, LIB_TAG_DOIT, false);
414 /* XXX nested node trees are notr included in tag-clearing above,
415 * so we need to do this manually.
417 FOREACH_NODETREE(bmain_, nodetree, id)
419 if (id != (ID *)nodetree) {
420 nodetree->id.tag &= ~LIB_TAG_DOIT;
423 FOREACH_NODETREE_END;
426 void DepsgraphRelationBuilder::build_group(Object *object, Group *group)
428 ID *group_id = &group->id;
429 bool group_done = (group_id->tag & LIB_TAG_DOIT) != 0;
430 OperationKey object_local_transform_key(object != NULL ? &object->id : NULL,
431 DEG_NODE_TYPE_TRANSFORM,
432 DEG_OPCODE_TRANSFORM_LOCAL);
433 BLI_LISTBASE_FOREACH (GroupObject *, go, &group->gobject) {
435 build_object(go->ob);
437 if (object != NULL) {
438 ComponentKey dupli_transform_key(&go->ob->id, DEG_NODE_TYPE_TRANSFORM);
439 add_relation(dupli_transform_key, object_local_transform_key, "Dupligroup");
442 group_id->tag |= LIB_TAG_DOIT;
445 void DepsgraphRelationBuilder::build_object(Object *object)
447 if (object->id.tag & LIB_TAG_DOIT) {
450 object->id.tag |= LIB_TAG_DOIT;
451 /* Object Transforms */
452 eDepsOperation_Code base_op = (object->parent) ? DEG_OPCODE_TRANSFORM_PARENT
453 : DEG_OPCODE_TRANSFORM_LOCAL;
454 OperationKey base_op_key(&object->id, DEG_NODE_TYPE_TRANSFORM, base_op);
455 OperationKey local_transform_key(&object->id,
456 DEG_NODE_TYPE_TRANSFORM,
457 DEG_OPCODE_TRANSFORM_LOCAL);
458 OperationKey parent_transform_key(&object->id,
459 DEG_NODE_TYPE_TRANSFORM,
460 DEG_OPCODE_TRANSFORM_PARENT);
461 OperationKey final_transform_key(&object->id,
462 DEG_NODE_TYPE_TRANSFORM,
463 DEG_OPCODE_TRANSFORM_FINAL);
464 OperationKey ob_ubereval_key(&object->id,
465 DEG_NODE_TYPE_TRANSFORM,
466 DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
468 if (object->parent != NULL) {
469 /* Parent relationship. */
470 build_object_parent(object);
471 /* Local -> parent. */
472 add_relation(local_transform_key,
473 parent_transform_key,
474 "ObLocal -> ObParent");
477 if (object->modifiers.first != NULL) {
478 BuilderWalkUserData data;
480 modifiers_foreachObjectLink(object, modifier_walk, &data);
483 if (object->constraints.first != NULL) {
484 BuilderWalkUserData data;
486 BKE_constraints_id_loop(&object->constraints, constraint_walk, &data);
488 /* Object constraints. */
489 if (object->constraints.first != NULL) {
490 OperationKey constraint_key(&object->id,
491 DEG_NODE_TYPE_TRANSFORM,
492 DEG_OPCODE_TRANSFORM_CONSTRAINTS);
493 /* Constraint relations. */
494 build_constraints(&object->id,
495 DEG_NODE_TYPE_TRANSFORM,
497 &object->constraints,
499 /* operation order */
500 add_relation(base_op_key, constraint_key, "ObBase-> Constraint Stack");
501 add_relation(constraint_key, final_transform_key, "ObConstraints -> Done");
503 add_relation(constraint_key, ob_ubereval_key, "Temp Ubereval");
504 add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval");
507 /* NOTE: Keep an eye here, we skip some relations here to "streamline"
508 * dependencies and avoid transitive relations which causes overhead.
509 * But once we get rid of uber eval node this will need reconsideration.
511 if (object->rigidbody_object == NULL) {
512 /* Rigid body will hook up another node inbetween, so skip
513 * relation here to avoid transitive relation.
515 add_relation(base_op_key, ob_ubereval_key, "Temp Ubereval");
517 add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval");
520 build_animdata(&object->id);
522 build_object_data(object);
523 /* Particle systems. */
524 if (object->particlesystem.first != NULL) {
525 build_particles(object);
528 if (object->gpd != NULL) {
529 build_gpencil(object->gpd);
531 /* Object that this is a proxy for. */
532 if (object->proxy != NULL) {
533 object->proxy->proxy_from = object;
534 build_object(object->proxy);
535 /* TODO(sergey): This is an inverted relation, matches old depsgraph
536 * behavior and need to be investigated if it still need to be inverted.
538 ComponentKey ob_pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
539 ComponentKey proxy_pose_key(&object->proxy->id, DEG_NODE_TYPE_EVAL_POSE);
540 add_relation(ob_pose_key, proxy_pose_key, "Proxy");
542 /* Object dupligroup. */
543 if (object->dup_group != NULL) {
544 build_group(object, object->dup_group);
548 void DepsgraphRelationBuilder::build_object_data(Object *object)
550 if (object->data == NULL) {
553 ID *obdata_id = (ID *)object->data;
554 /* Object data animation. */
555 build_animdata(obdata_id);
556 /* type-specific data. */
557 switch (object->type) {
565 build_obdata_geom(object);
569 if (ID_IS_LINKED(object) && object->proxy_from != NULL) {
570 build_proxy_rig(object);
580 build_camera(object);
583 Key *key = BKE_key_from_object(object);
585 ComponentKey geometry_key((ID *)object->data, DEG_NODE_TYPE_GEOMETRY);
586 ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY);
587 add_relation(key_key, geometry_key, "Shapekeys");
591 void DepsgraphRelationBuilder::build_object_parent(Object *object)
593 /* XXX: for now, need to use the component key (not just direct to the parent op),
594 * or else the matrix doesn't get reset/
596 // XXX: @sergey - it would be good if we got that backwards flushing working
597 // when tagging for updates.
598 //OperationKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT);
599 ComponentKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
601 /* type-specific links */
602 switch (object->partype) {
603 case PARSKEL: /* Armature Deform (Virtual Modifier) */
605 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
606 add_relation(parent_key, ob_key, "Armature Deform Parent");
610 case PARVERT1: /* Vertex Parent */
613 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
614 add_relation(parent_key, ob_key, "Vertex Parent");
616 /* XXX not sure what this is for or how you could be done properly - lukas */
617 OperationDepsNode *parent_node = find_operation_node(parent_key);
618 if (parent_node != NULL) {
619 parent_node->customdata_mask |= CD_MASK_ORIGINDEX;
622 ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
623 add_relation(transform_key, ob_key, "Vertex Parent TFM");
627 case PARBONE: /* Bone Parent */
629 ComponentKey parent_bone_key(&object->parent->id,
632 OperationKey parent_transform_key(&object->parent->id,
633 DEG_NODE_TYPE_TRANSFORM,
634 DEG_OPCODE_TRANSFORM_FINAL);
635 add_relation(parent_bone_key, ob_key, "Bone Parent");
636 add_relation(parent_transform_key, ob_key, "Armature Parent");
642 if (object->parent->type == OB_LATTICE) {
643 /* Lattice Deform Parent - Virtual Modifier */
644 // XXX: no virtual modifiers should be left!
645 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
646 ComponentKey geom_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
648 add_relation(parent_key, ob_key, "Lattice Deform Parent");
649 add_relation(geom_key, ob_key, "Lattice Deform Parent Geom");
651 else if (object->parent->type == OB_CURVE) {
652 Curve *cu = (Curve *)object->parent->data;
654 if (cu->flag & CU_PATH) {
656 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
657 add_relation(parent_key, ob_key, "Curve Follow Parent");
659 ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
660 add_relation(transform_key, ob_key, "Curve Follow TFM");
663 /* Standard Parent */
664 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
665 add_relation(parent_key, ob_key, "Curve Parent");
669 /* Standard Parent */
670 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
671 add_relation(parent_key, ob_key, "Parent");
677 /* exception case: parent is duplivert */
678 if ((object->type == OB_MBALL) && (object->parent->transflag & OB_DUPLIVERTS)) {
679 //dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert");
683 void DepsgraphRelationBuilder::build_constraints(ID *id,
684 eDepsNode_Type component_type,
685 const char *component_subdata,
686 ListBase *constraints,
687 RootPChanMap *root_map)
689 OperationKey constraint_op_key(
693 (component_type == DEG_NODE_TYPE_BONE)
694 ? DEG_OPCODE_BONE_CONSTRAINTS
695 : DEG_OPCODE_TRANSFORM_CONSTRAINTS);
696 /* Add dependencies for each constraint in turn. */
697 for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) {
698 const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
699 /* Invalid constraint type. */
703 /* Special case for camera tracking -- it doesn't use targets to
706 /* TODO: we can now represent dependencies in a much richer manner,
707 * so review how this is done.
710 CONSTRAINT_TYPE_FOLLOWTRACK,
711 CONSTRAINT_TYPE_CAMERASOLVER,
712 CONSTRAINT_TYPE_OBJECTSOLVER))
714 bool depends_on_camera = false;
715 if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
716 bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
718 (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0])
720 depends_on_camera = true;
722 if (data->depth_ob) {
723 ComponentKey depth_transform_key(&data->depth_ob->id,
724 DEG_NODE_TYPE_TRANSFORM);
725 ComponentKey depth_geometry_key(&data->depth_ob->id,
726 DEG_NODE_TYPE_GEOMETRY);
727 add_relation(depth_transform_key, constraint_op_key, cti->name);
728 add_relation(depth_geometry_key, constraint_op_key, cti->name);
731 else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
732 depends_on_camera = true;
734 if (depends_on_camera && scene_->camera != NULL) {
735 ComponentKey camera_key(&scene_->camera->id, DEG_NODE_TYPE_TRANSFORM);
736 add_relation(camera_key, constraint_op_key, cti->name);
738 /* TODO(sergey): This is more a TimeSource -> MovieClip ->
739 * Constraint dependency chain.
741 TimeSourceKey time_src_key;
742 add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation");
744 else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
745 /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint
748 TimeSourceKey time_src_key;
749 add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation");
750 bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data;
751 if (data->cache_file) {
752 ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE);
753 add_relation(cache_key, constraint_op_key, cti->name);
756 else if (cti->get_constraint_targets) {
757 ListBase targets = {NULL, NULL};
758 cti->get_constraint_targets(con, &targets);
759 BLI_LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) {
760 if (ct->tar == NULL) {
764 CONSTRAINT_TYPE_KINEMATIC,
765 CONSTRAINT_TYPE_SPLINEIK))
767 /* Ignore IK constraints - these are handled separately
771 else if (ELEM(con->type,
772 CONSTRAINT_TYPE_FOLLOWPATH,
773 CONSTRAINT_TYPE_CLAMPTO))
775 /* These constraints require path geometry data. */
776 ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
777 add_relation(target_key, constraint_op_key, cti->name);
778 ComponentKey target_transform_key(&ct->tar->id,
779 DEG_NODE_TYPE_TRANSFORM);
780 add_relation(target_transform_key, constraint_op_key, cti->name);
782 else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) {
784 if (&ct->tar->id == id) {
786 eDepsOperation_Code target_key_opcode;
787 /* Using "done" here breaks in-chain deps, while using
788 * "ready" here breaks most production rigs instead.
789 * So, we do a compromise here, and only do this when an
790 * IK chain conflict may occur.
792 if (root_map->has_common_root(component_subdata,
795 target_key_opcode = DEG_OPCODE_BONE_READY;
798 target_key_opcode = DEG_OPCODE_BONE_DONE;
800 OperationKey target_key(&ct->tar->id,
804 add_relation(target_key, constraint_op_key, cti->name);
807 /* Different armature - we can safely use the result
810 OperationKey target_key(&ct->tar->id,
813 DEG_OPCODE_BONE_DONE);
814 add_relation(target_key, constraint_op_key, cti->name);
817 else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) &&
821 /* NOTE: for now, we don't need to represent vertex groups
824 ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
825 add_relation(target_key, constraint_op_key, cti->name);
826 if (ct->tar->type == OB_MESH) {
827 OperationDepsNode *node2 = find_operation_node(target_key);
829 node2->customdata_mask |= CD_MASK_MDEFORMVERT;
833 else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
834 /* Constraints which requires the target object surface. */
835 ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
836 add_relation(target_key, constraint_op_key, cti->name);
837 /* NOTE: obdata eval now doesn't necessarily depend on the
838 * object's transform.
840 ComponentKey target_transform_key(&ct->tar->id,
841 DEG_NODE_TYPE_TRANSFORM);
842 add_relation(target_transform_key, constraint_op_key, cti->name);
845 /* Standard object relation. */
846 // TODO: loc vs rot vs scale?
847 if (&ct->tar->id == id) {
848 /* Constraint targetting own object:
849 * - This case is fine IFF we're dealing with a bone
850 * constraint pointing to its own armature. In that
851 * case, it's just transform -> bone.
852 * - If however it is a real self targetting case, just
853 * make it depend on the previous constraint (or the
854 * pre-constraint state).
856 if ((ct->tar->type == OB_ARMATURE) &&
857 (component_type == DEG_NODE_TYPE_BONE))
859 OperationKey target_key(&ct->tar->id,
860 DEG_NODE_TYPE_TRANSFORM,
861 DEG_OPCODE_TRANSFORM_FINAL);
862 add_relation(target_key, constraint_op_key, cti->name);
865 OperationKey target_key(&ct->tar->id,
866 DEG_NODE_TYPE_TRANSFORM,
867 DEG_OPCODE_TRANSFORM_LOCAL);
868 add_relation(target_key, constraint_op_key, cti->name);
872 /* Normal object dependency. */
873 OperationKey target_key(&ct->tar->id,
874 DEG_NODE_TYPE_TRANSFORM,
875 DEG_OPCODE_TRANSFORM_FINAL);
876 add_relation(target_key, constraint_op_key, cti->name);
879 /* Constraints which needs world's matrix for transform.
880 * TODO(sergey): More constraints here?
883 CONSTRAINT_TYPE_ROTLIKE,
884 CONSTRAINT_TYPE_SIZELIKE,
885 CONSTRAINT_TYPE_LOCLIKE,
886 CONSTRAINT_TYPE_TRANSLIKE))
888 /* TODO(sergey): Add used space check. */
889 ComponentKey target_transform_key(&ct->tar->id,
890 DEG_NODE_TYPE_TRANSFORM);
891 add_relation(target_transform_key, constraint_op_key, cti->name);
894 if (cti->flush_constraint_targets) {
895 cti->flush_constraint_targets(con, &targets, 1);
901 void DepsgraphRelationBuilder::build_animdata(ID *id)
903 /* Animation curves and NLA. */
904 build_animdata_curves(id);
906 build_animdata_drivers(id);
909 void DepsgraphRelationBuilder::build_animdata_curves(ID *id)
911 AnimData *adt = BKE_animdata_from_id(id);
915 if (adt->action == NULL && adt->nla_tracks.first == NULL) {
918 /* Wire up dependency to time source. */
919 ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
920 TimeSourceKey time_src_key;
921 add_relation(time_src_key, adt_key, "TimeSrc -> Animation");
922 /* Get source operations. */
923 DepsNode *node_from = get_node(adt_key);
924 BLI_assert(node_from != NULL);
925 if (node_from == NULL) {
928 OperationDepsNode *operation_from = node_from->get_exit_operation();
929 BLI_assert(operation_from != NULL);
930 /* Build relations from animation operation to properties it changes. */
931 if (adt->action != NULL) {
932 build_animdata_curves_targets(id, adt_key,
934 &adt->action->curves);
936 BLI_LISTBASE_FOREACH(NlaTrack *, nlt, &adt->nla_tracks) {
937 build_animdata_nlastrip_targets(id, adt_key,
943 void DepsgraphRelationBuilder::build_animdata_curves_targets(
944 ID *id, ComponentKey &adt_key,
945 OperationDepsNode *operation_from,
948 /* Iterate over all curves and build relations. */
950 RNA_id_pointer_create(id, &id_ptr);
951 BLI_LISTBASE_FOREACH(FCurve *, fcu, curves) {
955 if (!RNA_path_resolve_full(&id_ptr, fcu->rna_path,
956 &ptr, &prop, &index))
960 DepsNode *node_to = graph_->find_node_from_pointer(&ptr, prop);
961 if (node_to == NULL) {
964 OperationDepsNode *operation_to = node_to->get_entry_operation();
965 /* NOTE: Special case for bones, avoid relation from animation to
966 * each of the bones. Bone evaluation could only start from pose
969 if (operation_to->opcode == DEG_OPCODE_BONE_LOCAL) {
970 OperationKey pose_init_key(id,
971 DEG_NODE_TYPE_EVAL_POSE,
972 DEG_OPCODE_POSE_INIT);
973 add_relation(adt_key, pose_init_key, "Animation -> Prop", true);
976 graph_->add_new_relation(operation_from, operation_to,
982 void DepsgraphRelationBuilder::build_animdata_nlastrip_targets(
983 ID *id, ComponentKey &adt_key,
984 OperationDepsNode *operation_from,
987 BLI_LISTBASE_FOREACH(NlaStrip *, strip, strips) {
988 if (strip->act != NULL) {
989 build_animdata_curves_targets(id, adt_key,
991 &strip->act->curves);
993 else if (strip->strips.first != NULL) {
994 build_animdata_nlastrip_targets(id, adt_key,
1001 void DepsgraphRelationBuilder::build_animdata_drivers(ID *id)
1003 AnimData *adt = BKE_animdata_from_id(id);
1007 ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
1008 BLI_LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) {
1009 OperationKey driver_key(id,
1010 DEG_NODE_TYPE_PARAMETERS,
1012 fcu->rna_path ? fcu->rna_path : "",
1015 /* create the driver's relations to targets */
1016 build_driver(id, fcu);
1018 /* Special case for array drivers: we can not multithread them because
1019 * of the way how they work internally: animation system will write the
1020 * whole array back to RNA even when changing individual array value.
1022 * Some tricky things here:
1023 * - array_index is -1 for single channel drivers, meaning we only have
1024 * to do some magic when array_index is not -1.
1025 * - We do relation from next array index to a previous one, so we don't
1026 * have to deal with array index 0.
1028 * TODO(sergey): Avoid liner lookup somehow.
1030 if (fcu->array_index > 0) {
1031 FCurve *fcu_prev = NULL;
1032 BLI_LISTBASE_FOREACH (FCurve *, fcu_candidate, &adt->drivers) {
1033 /* Writing to different RNA paths is */
1034 const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1035 if (!STREQ(fcu_candidate->rna_path, rna_path)) {
1038 /* We only do relation from previous fcurve to previous one. */
1039 if (fcu_candidate->array_index >= fcu->array_index) {
1042 /* Choose fcurve with highest possible array index. */
1043 if (fcu_prev == NULL ||
1044 fcu_candidate->array_index > fcu_prev->array_index)
1046 fcu_prev = fcu_candidate;
1049 if (fcu_prev != NULL) {
1050 OperationKey prev_driver_key(id,
1051 DEG_NODE_TYPE_PARAMETERS,
1053 fcu_prev->rna_path ? fcu_prev->rna_path : "",
1054 fcu_prev->array_index);
1055 OperationKey driver_key(id,
1056 DEG_NODE_TYPE_PARAMETERS,
1058 fcu->rna_path ? fcu->rna_path : "",
1060 add_relation(prev_driver_key, driver_key, "Driver Order");
1064 /* prevent driver from occurring before own animation... */
1065 if (adt->action || adt->nla_tracks.first) {
1066 add_relation(adt_key, driver_key, "AnimData Before Drivers");
1071 void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
1073 ChannelDriver *driver = fcu->driver;
1074 OperationKey driver_key(id,
1075 DEG_NODE_TYPE_PARAMETERS,
1077 fcu->rna_path ? fcu->rna_path : "",
1079 /* Driver -> data components (for interleaved evaluation
1080 * bones/constraints/modifiers).
1082 build_driver_data(id, fcu);
1083 /* Loop over variables to get the target relationships. */
1084 build_driver_variables(id, fcu);
1085 /* It's quite tricky to detect if the driver actually depends on time or
1086 * not, so for now we'll be quite conservative here about optimization and
1087 * consider all python drivers to be depending on time.
1089 if ((driver->type == DRIVER_TYPE_PYTHON) &&
1090 python_driver_depends_on_time(driver))
1092 TimeSourceKey time_src_key;
1093 add_relation(time_src_key, driver_key, "TimeSrc -> Driver");
1097 void DepsgraphRelationBuilder::build_driver_data(ID *id, FCurve *fcu)
1099 OperationKey driver_key(id,
1100 DEG_NODE_TYPE_PARAMETERS,
1102 fcu->rna_path ? fcu->rna_path : "",
1104 const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1105 const RNAPathKey self_key(id, rna_path);
1106 if (GS(id->name) == ID_AR && strstr(rna_path, "bones[")) {
1107 /* Drivers on armature-level bone settings (i.e. bbone stuff),
1108 * which will affect the evaluation of corresponding pose bones.
1110 IDDepsNode *arm_node = graph_->find_id_node(id);
1111 char *bone_name = BLI_str_quoted_substrN(rna_path, "bones[");
1112 if (arm_node && bone_name) {
1113 /* Find objects which use this, and make their eval callbacks
1116 foreach (DepsRelation *rel, arm_node->outlinks) {
1117 IDDepsNode *to_node = (IDDepsNode *)rel->to;
1118 /* We only care about objects with pose data which use this. */
1119 if (GS(to_node->id->name) == ID_OB) {
1120 Object *object = (Object *)to_node->id;
1121 /* NOTE: object->pose may be NULL. */
1122 bPoseChannel *pchan = BKE_pose_channel_find_name(
1123 object->pose, bone_name);
1124 if (pchan != NULL) {
1125 OperationKey bone_key(&object->id,
1128 DEG_OPCODE_BONE_LOCAL);
1129 add_relation(driver_key,
1131 "Arm Bone -> Driver -> Bone");
1135 /* Free temp data. */
1136 MEM_freeN(bone_name);
1141 "Couldn't find armature bone name for driver path - '%s'\n",
1146 RNAPathKey target_key(id, rna_path);
1147 add_relation(driver_key, target_key, "Driver -> Target");
1151 void DepsgraphRelationBuilder::build_driver_variables(ID *id, FCurve *fcu)
1153 ChannelDriver *driver = fcu->driver;
1154 OperationKey driver_key(id,
1155 DEG_NODE_TYPE_PARAMETERS,
1157 fcu->rna_path ? fcu->rna_path : "",
1159 const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1160 const RNAPathKey self_key(id, rna_path);
1162 BLI_LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) {
1163 /* Only used targets. */
1164 DRIVER_TARGETS_USED_LOOPER(dvar)
1166 if (dtar->id == NULL) {
1169 /* Special handling for directly-named bones. */
1170 if ((dtar->flag & DTAR_FLAG_STRUCT_REF) &&
1171 (((Object *)dtar->id)->type == OB_ARMATURE) &&
1172 (dtar->pchan_name[0]))
1174 Object *object = (Object *)dtar->id;
1175 bPoseChannel *target_pchan =
1176 BKE_pose_channel_find_name(object->pose,
1178 if (target_pchan == NULL) {
1181 OperationKey variable_key(dtar->id,
1184 DEG_OPCODE_BONE_DONE);
1185 if (is_same_bone_dependency(variable_key, self_key)) {
1188 add_relation(variable_key, driver_key, "Bone Target -> Driver");
1190 else if (dtar->flag & DTAR_FLAG_STRUCT_REF) {
1191 /* Get node associated with the object's transforms. */
1192 if (dtar->id == id) {
1193 /* Ignore input dependency if we're driving properties of
1194 * the same ID, otherwise we'll be ending up in a cyclic
1199 OperationKey target_key(dtar->id,
1200 DEG_NODE_TYPE_TRANSFORM,
1201 DEG_OPCODE_TRANSFORM_FINAL);
1202 add_relation(target_key, driver_key, "Target -> Driver");
1204 else if (dtar->rna_path) {
1205 RNAPathKey variable_key(dtar->id, dtar->rna_path);
1206 if (RNA_pointer_is_null(&variable_key.ptr)) {
1209 if (is_same_bone_dependency(variable_key, self_key) ||
1210 is_same_nodetree_node_dependency(variable_key, self_key) ||
1211 is_same_shapekey_dependency(variable_key, self_key))
1215 add_relation(variable_key, driver_key, "RNA Target -> Driver");
1218 if (dtar->id == id) {
1219 /* Ignore input dependency if we're driving properties of
1220 * the same ID, otherwise we'll be ending up in a cyclic
1225 /* Resolve path to get node. */
1226 RNAPathKey target_key(dtar->id,
1227 dtar->rna_path ? dtar->rna_path : "");
1228 add_relation(target_key, driver_key, "RNA Target -> Driver");
1231 DRIVER_TARGETS_LOOPER_END
1235 void DepsgraphRelationBuilder::build_world(World *world)
1237 ID *world_id = &world->id;
1238 if (world_id->tag & LIB_TAG_DOIT) {
1241 world_id->tag |= LIB_TAG_DOIT;
1243 build_animdata(world_id);
1245 /* TODO: other settings? */
1248 build_texture_stack(world->mtex);
1250 /* world's nodetree */
1251 if (world->nodetree != NULL) {
1252 build_nodetree(world->nodetree);
1253 ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
1254 ComponentKey world_key(world_id, DEG_NODE_TYPE_PARAMETERS);
1255 add_relation(ntree_key, world_key, "NTree->World Parameters");
1259 void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
1261 RigidBodyWorld *rbw = scene->rigidbody_world;
1263 OperationKey init_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD);
1264 OperationKey sim_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM);
1266 /* rel between the two sim-nodes */
1267 add_relation(init_key, sim_key, "Rigidbody [Init -> SimStep]");
1269 /* set up dependencies between these operations and other builtin nodes --------------- */
1271 /* time dependency */
1272 TimeSourceKey time_src_key;
1273 add_relation(time_src_key, init_key, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)");
1275 /* objects - simulation participants */
1277 BLI_LISTBASE_FOREACH (GroupObject *, go, &rbw->group->gobject) {
1278 Object *object = go->ob;
1279 if (object == NULL || object->type != OB_MESH) {
1283 /* hook up evaluation order...
1284 * 1) flushing rigidbody results follows base transforms being applied
1285 * 2) rigidbody flushing can only be performed after simulation has been run
1287 * 3) simulation needs to know base transforms to figure out what to do
1288 * XXX: there's probably a difference between passive and active
1289 * - passive don't change, so may need to know full transform...
1291 OperationKey rbo_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1293 eDepsOperation_Code trans_opcode = object->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL;
1294 OperationKey trans_op(&object->id, DEG_NODE_TYPE_TRANSFORM, trans_opcode);
1296 add_relation(sim_key, rbo_key, "Rigidbody Sim Eval -> RBO Sync");
1298 /* if constraints exist, those depend on the result of the rigidbody sim
1299 * - This allows constraints to modify the result of the sim (i.e. clamping)
1300 * while still allowing the sim to depend on some changes to the objects.
1301 * Also, since constraints are hooked up to the final nodes, this link
1302 * means that we can also fit in there too...
1303 * - Later, it might be good to include a constraint in the stack allowing us
1304 * to control whether rigidbody eval gets interleaved into the constraint stack
1306 if (object->constraints.first) {
1307 OperationKey constraint_key(&object->id,
1308 DEG_NODE_TYPE_TRANSFORM,
1309 DEG_OPCODE_TRANSFORM_CONSTRAINTS);
1310 add_relation(rbo_key, constraint_key, "RBO Sync -> Ob Constraints");
1313 /* Final object transform depends on rigidbody.
1315 * NOTE: Currently we consider final here an ubereval node.
1316 * If it is gone we'll need to reconsider relation here.
1318 OperationKey uber_key(&object->id,
1319 DEG_NODE_TYPE_TRANSFORM,
1320 DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
1321 add_relation(rbo_key, uber_key, "RBO Sync -> Uber (Temp)");
1324 /* Needed to get correct base values. */
1325 add_relation(trans_op, sim_key, "Base Ob Transform -> Rigidbody Sim Eval");
1330 if (rbw->constraints) {
1331 BLI_LISTBASE_FOREACH (GroupObject *, go, &rbw->constraints->gobject) {
1332 Object *object = go->ob;
1333 if (object == NULL || !object->rigidbody_constraint) {
1337 RigidBodyCon *rbc = object->rigidbody_constraint;
1339 /* final result of the constraint object's transform controls how the
1340 * constraint affects the physics sim for these objects
1342 ComponentKey trans_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1343 OperationKey ob1_key(&rbc->ob1->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1344 OperationKey ob2_key(&rbc->ob2->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1346 /* - constrained-objects sync depends on the constraint-holder */
1347 add_relation(trans_key, ob1_key, "RigidBodyConstraint -> RBC.Object_1");
1348 add_relation(trans_key, ob2_key, "RigidBodyConstraint -> RBC.Object_2");
1350 /* - ensure that sim depends on this constraint's transform */
1351 add_relation(trans_key, sim_key, "RigidBodyConstraint Transform -> RB Simulation");
1356 void DepsgraphRelationBuilder::build_particles(Object *object)
1358 TimeSourceKey time_src_key;
1359 OperationKey obdata_ubereval_key(&object->id,
1360 DEG_NODE_TYPE_GEOMETRY,
1361 DEG_OPCODE_GEOMETRY_UBEREVAL);
1362 OperationKey eval_init_key(&object->id,
1363 DEG_NODE_TYPE_EVAL_PARTICLES,
1364 DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
1366 /* Particle systems. */
1367 BLI_LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
1368 ParticleSettings *part = psys->part;
1369 /* Animation of particle settings, */
1370 build_animdata(&part->id);
1371 /* This particle system. */
1372 OperationKey psys_key(&object->id,
1373 DEG_NODE_TYPE_EVAL_PARTICLES,
1374 DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
1376 add_relation(eval_init_key, psys_key, "Init -> PSys");
1377 /* TODO(sergey): Currently particle update is just a placeholder,
1378 * hook it to the ubereval node so particle system is getting updated
1381 add_relation(psys_key, obdata_ubereval_key, "PSys -> UberEval");
1383 if (part->type != PART_HAIR) {
1384 add_collision_relations(psys_key,
1387 part->collision_group,
1390 "Particle Collision");
1392 else if ((psys->flag & PSYS_HAIR_DYNAMICS) &&
1393 psys->clmd && psys->clmd->coll_parms)
1395 add_collision_relations(psys_key,
1398 psys->clmd->coll_parms->group,
1399 object->lay | scene_->lay,
1404 add_forcefield_relations(psys_key,
1408 part->effector_weights,
1409 part->type == PART_HAIR,
1413 BLI_LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
1414 BLI_LISTBASE_FOREACH (BoidRule *, rule, &state->rules) {
1415 Object *ruleob = NULL;
1416 if (rule->type == eBoidRuleType_Avoid) {
1417 ruleob = ((BoidRuleGoalAvoid *)rule)->ob;
1419 else if (rule->type == eBoidRuleType_FollowLeader) {
1420 ruleob = ((BoidRuleFollowLeader *)rule)->ob;
1423 ComponentKey ruleob_key(&ruleob->id,
1424 DEG_NODE_TYPE_TRANSFORM);
1425 add_relation(ruleob_key, psys_key, "Boid Rule");
1431 switch (part->ren_as) {
1433 if (part->dup_ob != NULL) {
1434 /* Make sure object's relations are all built. */
1435 build_object(part->dup_ob);
1436 /* Build relation for the particle visualization. */
1437 build_particles_visualization_object(object,
1443 if (part->dup_group != NULL) {
1444 build_group(NULL, part->dup_group);
1445 BLI_LISTBASE_FOREACH (GroupObject *, go, &part->dup_group->gobject) {
1446 build_particles_visualization_object(object,
1455 /* Particle depends on the object transform, so that channel is to be ready
1458 * TODO(sergey): This relation should be altered once real granular update
1461 ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1462 add_relation(transform_key, obdata_ubereval_key, "Partcile Eval");
1468 void DepsgraphRelationBuilder::build_particles_visualization_object(
1470 ParticleSystem *psys,
1471 Object *draw_object)
1473 OperationKey psys_key(&object->id,
1474 DEG_NODE_TYPE_EVAL_PARTICLES,
1475 DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
1477 OperationKey obdata_ubereval_key(&object->id,
1478 DEG_NODE_TYPE_GEOMETRY,
1479 DEG_OPCODE_GEOMETRY_UBEREVAL);
1480 ComponentKey dup_ob_key(&draw_object->id, DEG_NODE_TYPE_TRANSFORM);
1481 add_relation(dup_ob_key, psys_key, "Particle Object Visualization");
1482 if (draw_object->type == OB_MBALL) {
1483 ComponentKey dup_geometry_key(&draw_object->id, DEG_NODE_TYPE_GEOMETRY);
1484 add_relation(obdata_ubereval_key,
1486 "Particle MBall Visualization");
1490 void DepsgraphRelationBuilder::build_cloth(Object *object,
1491 ModifierData * /*md*/)
1493 OperationKey cache_key(&object->id,
1494 DEG_NODE_TYPE_CACHE,
1495 DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER);
1496 /* Cache component affects on modifier. */
1497 OperationKey modifier_key(&object->id,
1498 DEG_NODE_TYPE_GEOMETRY,
1499 DEG_OPCODE_GEOMETRY_UBEREVAL);
1500 add_relation(cache_key, modifier_key, "Cloth Cache -> Cloth");
1504 void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key)
1506 ComponentKey obdata_key(obdata, DEG_NODE_TYPE_GEOMETRY);
1508 /* attach animdata to geometry */
1509 build_animdata(&key->id);
1512 // TODO: this should really be handled in build_animdata, since many of these cases will need it
1513 if (key->adt->action || key->adt->nla_tracks.first) {
1514 ComponentKey adt_key(&key->id, DEG_NODE_TYPE_ANIMATION);
1515 add_relation(adt_key, obdata_key, "Animation");
1518 /* NOTE: individual shapekey drivers are handled above already */
1521 /* attach to geometry */
1522 // XXX: aren't shapekeys now done as a pseudo-modifier on object?
1523 //ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY); // FIXME: this doesn't exist
1524 //add_relation(key_key, obdata_key, "Shapekeys");
1528 * ObData Geometry Evaluation
1529 * ==========================
1531 * The evaluation of geometry on objects is as follows:
1532 * - The actual evaluated of the derived geometry (e.g. DerivedMesh, DispList, etc.)
1533 * occurs in the Geometry component of the object which references this. This includes
1534 * modifiers, and the temporary "ubereval" for geometry.
1535 * - Therefore, each user of a piece of shared geometry data ends up evaluating its own
1536 * version of the stuff, complete with whatever modifiers it may use.
1538 * - The datablocks for the geometry data - "obdata" (e.g. ID_ME, ID_CU, ID_LT, etc.) are used for
1539 * 1) calculating the bounding boxes of the geometry data,
1540 * 2) aggregating inward links from other objects (e.g. for text on curve, etc.)
1541 * and also for the links coming from the shapekey datablocks
1542 * - Animation/Drivers affecting the parameters of the geometry are made to trigger
1543 * updates on the obdata geometry component, which then trigger downstream
1544 * re-evaluation of the individual instances of this geometry.
1546 // TODO: Materials and lighting should probably get their own component, instead of being lumped under geometry?
1547 void DepsgraphRelationBuilder::build_obdata_geom(Object *object)
1549 ID *obdata = (ID *)object->data;
1551 /* Init operation of object-level geometry evaluation. */
1552 OperationKey geom_init_key(&object->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Init");
1554 /* get nodes for result of obdata's evaluation, and geometry evaluation on object */
1555 ComponentKey obdata_geom_key(obdata, DEG_NODE_TYPE_GEOMETRY);
1556 ComponentKey geom_key(&object->id, DEG_NODE_TYPE_GEOMETRY);
1558 /* link components to each other */
1559 add_relation(obdata_geom_key, geom_key, "Object Geometry Base Data");
1562 if (object->modifiers.first != NULL) {
1563 OperationKey obdata_ubereval_key(&object->id,
1564 DEG_NODE_TYPE_GEOMETRY,
1565 DEG_OPCODE_GEOMETRY_UBEREVAL);
1567 BLI_LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
1568 const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type);
1569 if (mti->updateDepsgraph) {
1570 DepsNodeHandle handle = create_node_handle(obdata_ubereval_key);
1571 mti->updateDepsgraph(
1576 reinterpret_cast< ::DepsNodeHandle* >(&handle));
1578 if (BKE_object_modifier_use_time(object, md)) {
1579 TimeSourceKey time_src_key;
1580 add_relation(time_src_key, obdata_ubereval_key, "Time Source");
1582 if (md->type == eModifierType_Cloth) {
1583 build_cloth(object, md);
1589 if (object->totcol) {
1590 for (int a = 1; a <= object->totcol; a++) {
1591 Material *ma = give_current_material(object, a);
1598 /* geometry collision */
1599 if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1600 // add geometry collider relations
1603 /* Make sure uber update is the last in the dependencies.
1605 * TODO(sergey): Get rid of this node.
1607 if (object->type != OB_ARMATURE) {
1608 /* Armatures does no longer require uber node. */
1609 OperationKey obdata_ubereval_key(&object->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL);
1610 add_relation(geom_init_key, obdata_ubereval_key, "Object Geometry UberEval");
1613 if (obdata->tag & LIB_TAG_DOIT) {
1616 obdata->tag |= LIB_TAG_DOIT;
1618 /* Link object data evaluation node to exit operation. */
1619 OperationKey obdata_geom_eval_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
1620 OperationKey obdata_geom_done_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Done");
1621 add_relation(obdata_geom_eval_key, obdata_geom_done_key, "ObData Geom Eval Done");
1623 /* type-specific node/links */
1624 switch (object->type) {
1626 /* NOTE: This is compatibility code to support particle systems
1628 * for viewport being properly rendered in final render mode.
1629 * This relation is similar to what dag_object_time_update_flags()
1630 * was doing for mesh objects with particle system.
1632 * Ideally we need to get rid of this relation.
1634 if (object_particles_depends_on_time(object)) {
1635 TimeSourceKey time_key;
1636 OperationKey obdata_ubereval_key(&object->id,
1637 DEG_NODE_TYPE_GEOMETRY,
1638 DEG_OPCODE_GEOMETRY_UBEREVAL);
1639 add_relation(time_key, obdata_ubereval_key, "Legacy particle time");
1645 Object *mom = BKE_mball_basis_find(scene_, object);
1646 ComponentKey mom_geom_key(&mom->id, DEG_NODE_TYPE_GEOMETRY);
1647 /* motherball - mom depends on children! */
1648 if (mom == object) {
1649 ComponentKey mom_transform_key(&mom->id,
1650 DEG_NODE_TYPE_TRANSFORM);
1651 add_relation(mom_transform_key,
1653 "Metaball Motherball Transform -> Geometry");
1656 ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1657 add_relation(geom_key, mom_geom_key, "Metaball Motherball");
1658 add_relation(transform_key, mom_geom_key, "Metaball Motherball");
1666 Curve *cu = (Curve *)obdata;
1668 /* curve's dependencies */
1669 // XXX: these needs geom data, but where is geom stored?
1671 ComponentKey bevob_key(&cu->bevobj->id, DEG_NODE_TYPE_GEOMETRY);
1672 build_object(cu->bevobj);
1673 add_relation(bevob_key, geom_key, "Curve Bevel");
1676 ComponentKey taperob_key(&cu->taperobj->id, DEG_NODE_TYPE_GEOMETRY);
1677 build_object(cu->taperobj);
1678 add_relation(taperob_key, geom_key, "Curve Taper");
1680 if (object->type == OB_FONT) {
1681 if (cu->textoncurve) {
1682 ComponentKey textoncurve_key(&cu->textoncurve->id, DEG_NODE_TYPE_GEOMETRY);
1683 build_object(cu->textoncurve);
1684 add_relation(textoncurve_key, geom_key, "Text on Curve");
1690 case OB_SURF: /* Nurbs Surface */
1695 case OB_LATTICE: /* Lattice */
1702 Key *key = BKE_key_from_object(object);
1704 build_shapekeys(obdata, key);
1709 // TODO: Link scene-camera links in somehow...
1710 void DepsgraphRelationBuilder::build_camera(Object *object)
1712 Camera *cam = (Camera *)object->data;
1713 ID *camera_id = &cam->id;
1714 if (camera_id->tag & LIB_TAG_DOIT) {
1717 camera_id->tag |= LIB_TAG_DOIT;
1720 ComponentKey ob_param_key(&object->id, DEG_NODE_TYPE_PARAMETERS);
1721 ComponentKey dof_ob_key(&cam->dof_ob->id, DEG_NODE_TYPE_TRANSFORM);
1722 add_relation(dof_ob_key, ob_param_key, "Camera DOF");
1727 void DepsgraphRelationBuilder::build_lamp(Object *object)
1729 Lamp *la = (Lamp *)object->data;
1730 ID *lamp_id = &la->id;
1731 if (lamp_id->tag & LIB_TAG_DOIT) {
1734 lamp_id->tag |= LIB_TAG_DOIT;
1735 /* lamp's nodetree */
1736 if (la->nodetree != NULL) {
1737 build_nodetree(la->nodetree);
1738 ComponentKey parameters_key(lamp_id, DEG_NODE_TYPE_PARAMETERS);
1739 ComponentKey nodetree_key(&la->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
1740 add_relation(nodetree_key, parameters_key, "NTree->Lamp Parameters");
1743 build_texture_stack(la->mtex);
1746 void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
1751 ID *ntree_id = &ntree->id;
1753 build_animdata(ntree_id);
1755 OperationKey parameters_key(ntree_id,
1756 DEG_NODE_TYPE_PARAMETERS,
1757 DEG_OPCODE_PARAMETERS_EVAL);
1759 /* nodetree's nodes... */
1760 BLI_LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) {
1765 ID_Type id_type = GS(id->name);
1766 if (id_type == ID_MA) {
1767 build_material((Material *)bnode->id);
1769 else if (id_type == ID_TE) {
1770 build_texture((Tex *)bnode->id);
1772 else if (id_type == ID_IM) {
1773 /* nothing for now. */
1775 else if (id_type == ID_OB) {
1776 build_object((Object *)id);
1778 else if (id_type == ID_SCE) {
1779 /* Scenes are used by compositor trees, and handled by render
1780 * pipeline. No need to build dependencies for them here.
1783 else if (id_type == ID_TXT) {
1784 /* Ignore script nodes. */
1786 else if (bnode->type == NODE_GROUP) {
1787 bNodeTree *group_ntree = (bNodeTree *)id;
1788 if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) {
1789 build_nodetree(group_ntree);
1790 group_ntree->id.tag |= LIB_TAG_DOIT;
1792 OperationKey group_parameters_key(&group_ntree->id,
1793 DEG_NODE_TYPE_PARAMETERS,
1794 DEG_OPCODE_PARAMETERS_EVAL);
1795 add_relation(group_parameters_key, parameters_key, "Group Node");
1798 BLI_assert(!"Unknown ID type used for node");
1803 /* Recursively build graph for material */
1804 void DepsgraphRelationBuilder::build_material(Material *ma)
1806 ID *ma_id = &ma->id;
1807 if (ma_id->tag & LIB_TAG_DOIT) {
1810 ma_id->tag |= LIB_TAG_DOIT;
1813 build_animdata(ma_id);
1816 build_texture_stack(ma->mtex);
1818 /* material's nodetree */
1819 if (ma->nodetree != NULL) {
1820 build_nodetree(ma->nodetree);
1821 OperationKey ntree_key(&ma->nodetree->id,
1822 DEG_NODE_TYPE_PARAMETERS,
1823 DEG_OPCODE_PARAMETERS_EVAL);
1824 OperationKey material_key(&ma->id,
1825 DEG_NODE_TYPE_SHADING,
1826 DEG_OPCODE_PLACEHOLDER,
1828 add_relation(ntree_key, material_key, "Material's NTree");
1832 /* Recursively build graph for texture */
1833 void DepsgraphRelationBuilder::build_texture(Tex *tex)
1835 ID *tex_id = &tex->id;
1836 if (tex_id->tag & LIB_TAG_DOIT) {
1839 tex_id->tag |= LIB_TAG_DOIT;
1841 /* texture itself */
1842 build_animdata(tex_id);
1844 /* texture's nodetree */
1845 build_nodetree(tex->nodetree);
1848 /* Texture-stack attached to some shading datablock */
1849 void DepsgraphRelationBuilder::build_texture_stack(MTex **texture_stack)
1853 /* for now assume that all texture-stacks have same number of max items */
1854 for (i = 0; i < MAX_MTEX; i++) {
1855 MTex *mtex = texture_stack[i];
1856 if (mtex && mtex->tex)
1857 build_texture(mtex->tex);
1861 void DepsgraphRelationBuilder::build_compositor(Scene *scene)
1863 /* For now, just a plain wrapper? */
1864 build_nodetree(scene->nodetree);
1867 void DepsgraphRelationBuilder::build_gpencil(bGPdata *gpd)
1870 build_animdata(&gpd->id);
1872 // TODO: parent object (when that feature is implemented)
1875 void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file)
1878 build_animdata(&cache_file->id);
1881 void DepsgraphRelationBuilder::build_mask(Mask *mask)
1883 ID *mask_id = &mask->id;
1884 /* F-Curve animation. */
1885 build_animdata(mask_id);
1886 /* Own mask animation. */
1887 OperationKey mask_animation_key(mask_id,
1888 DEG_NODE_TYPE_ANIMATION,
1889 DEG_OPCODE_MASK_ANIMATION);
1890 TimeSourceKey time_src_key;
1891 add_relation(time_src_key, mask_animation_key, "TimeSrc -> Mask Animation");
1892 /* Final mask evaluation. */
1893 ComponentKey parameters_key(mask_id, DEG_NODE_TYPE_PARAMETERS);
1894 add_relation(mask_animation_key, parameters_key, "Mask Animation -> Mask Eval");
1897 void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip)
1900 build_animdata(&clip->id);