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_texture.h"
92 #include "BKE_tracking.h"
93 #include "BKE_world.h"
95 #include "RNA_access.h"
96 #include "RNA_types.h"
99 #include "DEG_depsgraph.h"
100 #include "DEG_depsgraph_build.h"
102 #include "intern/builder/deg_builder.h"
103 #include "intern/builder/deg_builder_pchanmap.h"
105 #include "intern/nodes/deg_node.h"
106 #include "intern/nodes/deg_node_component.h"
107 #include "intern/nodes/deg_node_operation.h"
109 #include "intern/depsgraph_intern.h"
110 #include "intern/depsgraph_types.h"
112 #include "util/deg_util_foreach.h"
118 struct BuilderWalkUserData {
119 DepsgraphRelationBuilder *builder;
122 void modifier_walk(void *user_data,
123 struct Object * /*object*/,
124 struct Object **obpoin,
127 BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
129 data->builder->build_object(*obpoin);
133 void constraint_walk(bConstraint * /*con*/,
135 bool /*is_reference*/,
138 BuilderWalkUserData *data = (BuilderWalkUserData *)user_data;
141 if (GS(id->name) == ID_OB) {
142 data->builder->build_object((Object *)id);
149 /* ***************** */
150 /* Relations Builder */
152 /* TODO(sergey): This is somewhat weak, but we don't want neither false-positive
153 * time dependencies nor special exceptions in the depsgraph evaluation.
155 static bool python_driver_depends_on_time(ChannelDriver *driver)
157 if (driver->expression[0] == '\0') {
158 /* Empty expression depends on nothing. */
161 if (strchr(driver->expression, '(') != NULL) {
162 /* Function calls are considered dependent on a time. */
165 if (strstr(driver->expression, "frame") != NULL) {
166 /* Variable `frame` depends on time. */
167 /* TODO(sergey): This is a bit weak, but not sure about better way of
172 /* Possible indirect time relation s should be handled via variable
178 static bool particle_system_depends_on_time(ParticleSystem *psys)
180 ParticleSettings *part = psys->part;
181 /* Non-hair particles we always consider dependent on time. */
182 if (part->type != PART_HAIR) {
185 /* Dynamics always depends on time. */
186 if (psys->flag & PSYS_HAIR_DYNAMICS) {
189 /* TODO(sergey): Check what else makes hair dependent on time. */
193 static bool object_particles_depends_on_time(Object *object)
195 LINKLIST_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
196 if (particle_system_depends_on_time(psys)) {
203 /* **** General purpose functions **** */
205 DepsgraphRelationBuilder::DepsgraphRelationBuilder(Main *bmain,
213 TimeSourceDepsNode *DepsgraphRelationBuilder::get_node(
214 const TimeSourceKey &key) const
221 return graph_->time_source;
225 ComponentDepsNode *DepsgraphRelationBuilder::get_node(
226 const ComponentKey &key) const
228 IDDepsNode *id_node = graph_->find_id_node(key.id);
230 fprintf(stderr, "find_node component: Could not find ID %s\n",
231 (key.id != NULL) ? key.id->name : "<null>");
235 ComponentDepsNode *node = id_node->find_component(key.type, key.name);
239 OperationDepsNode *DepsgraphRelationBuilder::get_node(
240 const OperationKey &key) const
242 OperationDepsNode *op_node = find_node(key);
243 if (op_node == NULL) {
244 fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
245 DEG_OPNAMES[key.opcode], key.name);
250 DepsNode *DepsgraphRelationBuilder::get_node(const RNAPathKey &key) const
252 return graph_->find_node_from_pointer(&key.ptr, key.prop);
255 OperationDepsNode *DepsgraphRelationBuilder::find_node(
256 const OperationKey &key) const
258 IDDepsNode *id_node = graph_->find_id_node(key.id);
262 ComponentDepsNode *comp_node = id_node->find_component(key.component_type,
267 return comp_node->find_operation(key.opcode, key.name, key.name_tag);
270 bool DepsgraphRelationBuilder::has_node(const OperationKey &key) const
272 return find_node(key) != NULL;
275 void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc,
277 const char *description,
280 if (timesrc && node_to) {
281 graph_->add_new_relation(timesrc, node_to, description, check_unique);
284 DEG_DEBUG_PRINTF("add_time_relation(%p = %s, %p = %s, %s) Failed\n",
285 timesrc, (timesrc) ? timesrc->identifier().c_str() : "<None>",
286 node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
291 void DepsgraphRelationBuilder::add_operation_relation(
292 OperationDepsNode *node_from,
293 OperationDepsNode *node_to,
294 const char *description,
297 if (node_from && node_to) {
298 graph_->add_new_relation(node_from, node_to, description, check_unique);
301 DEG_DEBUG_PRINTF("add_operation_relation(%p = %s, %p = %s, %s) Failed\n",
302 node_from, (node_from) ? node_from->identifier().c_str() : "<None>",
303 node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
308 void DepsgraphRelationBuilder::add_collision_relations(
309 const OperationKey &key,
317 unsigned int numcollobj;
318 Object **collobjs = get_collisionobjects_ext(
324 eModifierType_Collision,
326 for (unsigned int i = 0; i < numcollobj; i++) {
327 Object *ob1 = collobjs[i];
329 ComponentKey trf_key(&ob1->id, DEG_NODE_TYPE_TRANSFORM);
330 add_relation(trf_key, key, name);
332 ComponentKey coll_key(&ob1->id, DEG_NODE_TYPE_GEOMETRY);
333 add_relation(coll_key, key, name);
335 if (collobjs != NULL) {
340 void DepsgraphRelationBuilder::add_forcefield_relations(
341 const OperationKey &key,
344 ParticleSystem *psys,
345 EffectorWeights *eff,
349 ListBase *effectors = pdInitEffectors(scene, object, psys, eff, false);
350 if (effectors != NULL) {
351 LINKLIST_FOREACH(EffectorCache *, eff, effectors) {
352 if (eff->ob != object) {
353 ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_TRANSFORM);
354 add_relation(eff_key, key, name);
356 if (eff->psys != NULL) {
357 if (eff->ob != object) {
358 ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES);
359 add_relation(eff_key, key, name);
361 /* TODO: remove this when/if EVAL_PARTICLES is sufficient
362 * for up to date particles.
364 ComponentKey mod_key(&eff->ob->id, DEG_NODE_TYPE_GEOMETRY);
365 add_relation(mod_key, key, name);
367 else if (eff->psys != psys) {
368 OperationKey eff_key(&eff->ob->id,
369 DEG_NODE_TYPE_EVAL_PARTICLES,
370 DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
372 add_relation(eff_key, key, name);
375 if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) {
376 ComponentKey trf_key(&eff->pd->f_source->id,
377 DEG_NODE_TYPE_TRANSFORM);
378 add_relation(trf_key, key, "Smoke Force Domain");
380 ComponentKey eff_key(&eff->pd->f_source->id,
381 DEG_NODE_TYPE_GEOMETRY);
382 add_relation(eff_key, key, "Smoke Force Domain");
384 if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) {
385 add_collision_relations(key,
396 pdEndEffectors(&effectors);
399 Depsgraph *DepsgraphRelationBuilder::getGraph()
404 /* **** Functions to build relations between entities **** */
406 void DepsgraphRelationBuilder::begin_build()
408 /* LIB_TAG_DOIT is used to indicate whether node for given ID was already
411 BKE_main_id_tag_all(bmain_, LIB_TAG_DOIT, false);
412 /* XXX nested node trees are notr included in tag-clearing above,
413 * so we need to do this manually.
415 FOREACH_NODETREE(bmain_, nodetree, id)
417 if (id != (ID *)nodetree) {
418 nodetree->id.tag &= ~LIB_TAG_DOIT;
421 FOREACH_NODETREE_END;
424 void DepsgraphRelationBuilder::build_group(Object *object, Group *group)
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 DEG_NODE_TYPE_TRANSFORM,
430 DEG_OPCODE_TRANSFORM_LOCAL);
431 LINKLIST_FOREACH (GroupObject *, go, &group->gobject) {
433 build_object(go->ob);
435 ComponentKey dupli_transform_key(&go->ob->id, DEG_NODE_TYPE_TRANSFORM);
436 add_relation(dupli_transform_key, object_local_transform_key, "Dupligroup");
438 group_id->tag |= LIB_TAG_DOIT;
441 void DepsgraphRelationBuilder::build_object(Object *object)
443 if (object->id.tag & LIB_TAG_DOIT) {
446 object->id.tag |= LIB_TAG_DOIT;
447 /* Object Transforms */
448 eDepsOperation_Code base_op = (object->parent) ? DEG_OPCODE_TRANSFORM_PARENT
449 : DEG_OPCODE_TRANSFORM_LOCAL;
450 OperationKey base_op_key(&object->id, DEG_NODE_TYPE_TRANSFORM, base_op);
451 OperationKey local_transform_key(&object->id,
452 DEG_NODE_TYPE_TRANSFORM,
453 DEG_OPCODE_TRANSFORM_LOCAL);
454 OperationKey parent_transform_key(&object->id,
455 DEG_NODE_TYPE_TRANSFORM,
456 DEG_OPCODE_TRANSFORM_PARENT);
457 OperationKey final_transform_key(&object->id,
458 DEG_NODE_TYPE_TRANSFORM,
459 DEG_OPCODE_TRANSFORM_FINAL);
460 OperationKey ob_ubereval_key(&object->id,
461 DEG_NODE_TYPE_TRANSFORM,
462 DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
464 if (object->parent != NULL) {
465 /* Parent relationship. */
466 build_object_parent(object);
467 /* Local -> parent. */
468 add_relation(local_transform_key,
469 parent_transform_key,
470 "ObLocal -> ObParent");
473 if (object->modifiers.first != NULL) {
474 BuilderWalkUserData data;
476 modifiers_foreachObjectLink(object, modifier_walk, &data);
479 if (object->constraints.first != NULL) {
480 BuilderWalkUserData data;
482 BKE_constraints_id_loop(&object->constraints, constraint_walk, &data);
484 /* Object constraints. */
485 if (object->constraints.first != NULL) {
486 OperationKey constraint_key(&object->id,
487 DEG_NODE_TYPE_TRANSFORM,
488 DEG_OPCODE_TRANSFORM_CONSTRAINTS);
489 /* Constraint relations. */
490 build_constraints(&object->id,
491 DEG_NODE_TYPE_TRANSFORM,
493 &object->constraints,
495 /* operation order */
496 add_relation(base_op_key, constraint_key, "ObBase-> Constraint Stack");
497 add_relation(constraint_key, final_transform_key, "ObConstraints -> Done");
499 add_relation(constraint_key, ob_ubereval_key, "Temp Ubereval");
500 add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval");
503 /* NOTE: Keep an eye here, we skip some relations here to "streamline"
504 * dependencies and avoid transitive relations which causes overhead.
505 * But once we get rid of uber eval node this will need reconsideration.
507 if (object->rigidbody_object == NULL) {
508 /* Rigid body will hook up another node inbetween, so skip
509 * relation here to avoid transitive relation.
511 add_relation(base_op_key, ob_ubereval_key, "Temp Ubereval");
513 add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval");
516 build_animdata(&object->id);
518 build_object_data(object);
519 /* Particle systems. */
520 if (object->particlesystem.first != NULL) {
521 build_particles(object);
524 if (object->gpd != NULL) {
525 build_gpencil(object->gpd);
527 /* Object that this is a proxy for. */
528 if (object->proxy != NULL) {
529 object->proxy->proxy_from = object;
530 build_object(object->proxy);
531 /* TODO(sergey): This is an inverted relation, matches old depsgraph
532 * behavior and need to be investigated if it still need to be inverted.
534 ComponentKey ob_pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE);
535 ComponentKey proxy_pose_key(&object->proxy->id, DEG_NODE_TYPE_EVAL_POSE);
536 add_relation(ob_pose_key, proxy_pose_key, "Proxy");
538 /* Object dupligroup. */
539 if (object->dup_group != NULL) {
540 build_group(object, object->dup_group);
544 void DepsgraphRelationBuilder::build_object_data(Object *object)
546 if (object->data == NULL) {
549 ID *obdata_id = (ID *)object->data;
550 /* Object data animation. */
551 build_animdata(obdata_id);
552 /* type-specific data. */
553 switch (object->type) {
561 build_obdata_geom(object);
565 if (ID_IS_LINKED(object) && object->proxy_from != NULL) {
566 build_proxy_rig(object);
576 build_camera(object);
579 Key *key = BKE_key_from_object(object);
581 ComponentKey geometry_key((ID *)object->data, DEG_NODE_TYPE_GEOMETRY);
582 ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY);
583 add_relation(key_key, geometry_key, "Shapekeys");
587 void DepsgraphRelationBuilder::build_object_parent(Object *object)
589 /* XXX: for now, need to use the component key (not just direct to the parent op),
590 * or else the matrix doesn't get reset/
592 // XXX: @sergey - it would be good if we got that backwards flushing working
593 // when tagging for updates.
594 //OperationKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT);
595 ComponentKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
597 /* type-specific links */
598 switch (object->partype) {
599 case PARSKEL: /* Armature Deform (Virtual Modifier) */
601 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
602 add_relation(parent_key, ob_key, "Armature Deform Parent");
606 case PARVERT1: /* Vertex Parent */
609 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
610 add_relation(parent_key, ob_key, "Vertex Parent");
612 /* XXX not sure what this is for or how you could be done properly - lukas */
613 OperationDepsNode *parent_node = find_operation_node(parent_key);
614 if (parent_node != NULL) {
615 parent_node->customdata_mask |= CD_MASK_ORIGINDEX;
618 ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
619 add_relation(transform_key, ob_key, "Vertex Parent TFM");
623 case PARBONE: /* Bone Parent */
625 ComponentKey parent_bone_key(&object->parent->id,
628 OperationKey parent_transform_key(&object->parent->id,
629 DEG_NODE_TYPE_TRANSFORM,
630 DEG_OPCODE_TRANSFORM_FINAL);
631 add_relation(parent_bone_key, ob_key, "Bone Parent");
632 add_relation(parent_transform_key, ob_key, "Armature Parent");
638 if (object->parent->type == OB_LATTICE) {
639 /* Lattice Deform Parent - Virtual Modifier */
640 // XXX: no virtual modifiers should be left!
641 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
642 ComponentKey geom_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
644 add_relation(parent_key, ob_key, "Lattice Deform Parent");
645 add_relation(geom_key, ob_key, "Lattice Deform Parent Geom");
647 else if (object->parent->type == OB_CURVE) {
648 Curve *cu = (Curve *)object->parent->data;
650 if (cu->flag & CU_PATH) {
652 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY);
653 add_relation(parent_key, ob_key, "Curve Follow Parent");
655 ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
656 add_relation(transform_key, ob_key, "Curve Follow TFM");
659 /* Standard Parent */
660 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
661 add_relation(parent_key, ob_key, "Curve Parent");
665 /* Standard Parent */
666 ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM);
667 add_relation(parent_key, ob_key, "Parent");
673 /* exception case: parent is duplivert */
674 if ((object->type == OB_MBALL) && (object->parent->transflag & OB_DUPLIVERTS)) {
675 //dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert");
679 void DepsgraphRelationBuilder::build_constraints(ID *id,
680 eDepsNode_Type component_type,
681 const char *component_subdata,
682 ListBase *constraints,
683 RootPChanMap *root_map)
685 OperationKey constraint_op_key(
689 (component_type == DEG_NODE_TYPE_BONE)
690 ? DEG_OPCODE_BONE_CONSTRAINTS
691 : DEG_OPCODE_TRANSFORM_CONSTRAINTS);
692 /* Add dependencies for each constraint in turn. */
693 for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) {
694 const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
695 /* Invalid constraint type. */
699 /* Special case for camera tracking -- it doesn't use targets to
702 /* TODO: we can now represent dependencies in a much richer manner,
703 * so review how this is done.
706 CONSTRAINT_TYPE_FOLLOWTRACK,
707 CONSTRAINT_TYPE_CAMERASOLVER,
708 CONSTRAINT_TYPE_OBJECTSOLVER))
710 bool depends_on_camera = false;
711 if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
712 bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
714 (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0])
716 depends_on_camera = true;
718 if (data->depth_ob) {
719 ComponentKey depth_transform_key(&data->depth_ob->id,
720 DEG_NODE_TYPE_TRANSFORM);
721 ComponentKey depth_geometry_key(&data->depth_ob->id,
722 DEG_NODE_TYPE_GEOMETRY);
723 add_relation(depth_transform_key, constraint_op_key, cti->name);
724 add_relation(depth_geometry_key, constraint_op_key, cti->name);
727 else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
728 depends_on_camera = true;
730 if (depends_on_camera && scene_->camera != NULL) {
731 ComponentKey camera_key(&scene_->camera->id, DEG_NODE_TYPE_TRANSFORM);
732 add_relation(camera_key, constraint_op_key, cti->name);
734 /* TODO(sergey): This is more a TimeSource -> MovieClip ->
735 * Constraint dependency chain.
737 TimeSourceKey time_src_key;
738 add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation");
740 else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) {
741 /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint
744 TimeSourceKey time_src_key;
745 add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation");
746 bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data;
747 if (data->cache_file) {
748 ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE);
749 add_relation(cache_key, constraint_op_key, cti->name);
752 else if (cti->get_constraint_targets) {
753 ListBase targets = {NULL, NULL};
754 cti->get_constraint_targets(con, &targets);
755 LINKLIST_FOREACH (bConstraintTarget *, ct, &targets) {
756 if (ct->tar == NULL) {
760 CONSTRAINT_TYPE_KINEMATIC,
761 CONSTRAINT_TYPE_SPLINEIK))
763 /* Ignore IK constraints - these are handled separately
767 else if (ELEM(con->type,
768 CONSTRAINT_TYPE_FOLLOWPATH,
769 CONSTRAINT_TYPE_CLAMPTO))
771 /* These constraints require path geometry data. */
772 ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
773 add_relation(target_key, constraint_op_key, cti->name);
774 ComponentKey target_transform_key(&ct->tar->id,
775 DEG_NODE_TYPE_TRANSFORM);
776 add_relation(target_transform_key, constraint_op_key, cti->name);
778 else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) {
780 if (&ct->tar->id == id) {
782 eDepsOperation_Code target_key_opcode;
783 /* Using "done" here breaks in-chain deps, while using
784 * "ready" here breaks most production rigs instead.
785 * So, we do a compromise here, and only do this when an
786 * IK chain conflict may occur.
788 if (root_map->has_common_root(component_subdata,
791 target_key_opcode = DEG_OPCODE_BONE_READY;
794 target_key_opcode = DEG_OPCODE_BONE_DONE;
796 OperationKey target_key(&ct->tar->id,
800 add_relation(target_key, constraint_op_key, cti->name);
803 /* Different armature - we can safely use the result
806 OperationKey target_key(&ct->tar->id,
809 DEG_OPCODE_BONE_DONE);
810 add_relation(target_key, constraint_op_key, cti->name);
813 else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) &&
817 /* NOTE: for now, we don't need to represent vertex groups
820 ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
821 add_relation(target_key, constraint_op_key, cti->name);
822 if (ct->tar->type == OB_MESH) {
823 OperationDepsNode *node2 = find_operation_node(target_key);
825 node2->customdata_mask |= CD_MASK_MDEFORMVERT;
829 else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) {
830 /* Constraints which requires the target object surface. */
831 ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY);
832 add_relation(target_key, constraint_op_key, cti->name);
833 /* NOTE: obdata eval now doesn't necessarily depend on the
834 * object's transform.
836 ComponentKey target_transform_key(&ct->tar->id,
837 DEG_NODE_TYPE_TRANSFORM);
838 add_relation(target_transform_key, constraint_op_key, cti->name);
841 /* Standard object relation. */
842 // TODO: loc vs rot vs scale?
843 if (&ct->tar->id == id) {
844 /* Constraint targetting own object:
845 * - This case is fine IFF we're dealing with a bone
846 * constraint pointing to its own armature. In that
847 * case, it's just transform -> bone.
848 * - If however it is a real self targetting case, just
849 * make it depend on the previous constraint (or the
850 * pre-constraint state).
852 if ((ct->tar->type == OB_ARMATURE) &&
853 (component_type == DEG_NODE_TYPE_BONE))
855 OperationKey target_key(&ct->tar->id,
856 DEG_NODE_TYPE_TRANSFORM,
857 DEG_OPCODE_TRANSFORM_FINAL);
858 add_relation(target_key, constraint_op_key, cti->name);
861 OperationKey target_key(&ct->tar->id,
862 DEG_NODE_TYPE_TRANSFORM,
863 DEG_OPCODE_TRANSFORM_LOCAL);
864 add_relation(target_key, constraint_op_key, cti->name);
868 /* Normal object dependency. */
869 OperationKey target_key(&ct->tar->id,
870 DEG_NODE_TYPE_TRANSFORM,
871 DEG_OPCODE_TRANSFORM_FINAL);
872 add_relation(target_key, constraint_op_key, cti->name);
875 /* Constraints which needs world's matrix for transform.
876 * TODO(sergey): More constraints here?
879 CONSTRAINT_TYPE_ROTLIKE,
880 CONSTRAINT_TYPE_SIZELIKE,
881 CONSTRAINT_TYPE_LOCLIKE,
882 CONSTRAINT_TYPE_TRANSLIKE))
884 /* TODO(sergey): Add used space check. */
885 ComponentKey target_transform_key(&ct->tar->id,
886 DEG_NODE_TYPE_TRANSFORM);
887 add_relation(target_transform_key, constraint_op_key, cti->name);
890 if (cti->flush_constraint_targets) {
891 cti->flush_constraint_targets(con, &targets, 1);
897 void DepsgraphRelationBuilder::build_animdata(ID *id)
899 /* Animation curves and NLA. */
900 build_animdata_curves(id);
902 build_animdata_drievrs(id);
905 void DepsgraphRelationBuilder::build_animdata_curves(ID *id)
907 AnimData *adt = BKE_animdata_from_id(id);
911 if (adt->action == NULL && adt->nla_tracks.first == NULL) {
914 /* Wire up dependency to time source. */
915 ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
916 TimeSourceKey time_src_key;
917 add_relation(time_src_key, adt_key, "TimeSrc -> Animation");
918 /* Build relations from animation operation to properties it changes. */
919 build_animdata_curves_targets(id);
922 void DepsgraphRelationBuilder::build_animdata_curves_targets(ID *id)
924 AnimData *adt = BKE_animdata_from_id(id);
925 if (adt == NULL || adt->action == NULL) {
928 /* Get source operation. */
929 ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
930 DepsNode *node_from = get_node(adt_key);
931 BLI_assert(node_from != NULL);
932 if (node_from == NULL) {
935 OperationDepsNode *operation_from = node_from->get_exit_operation();
936 BLI_assert(operation_from != NULL);
937 /* Iterate over all curves and build relations. */
939 RNA_id_pointer_create(id, &id_ptr);
940 LINKLIST_FOREACH(FCurve *, fcu, &adt->action->curves) {
944 if (!RNA_path_resolve_full(&id_ptr, fcu->rna_path,
945 &ptr, &prop, &index))
949 DepsNode *node_to = graph_->find_node_from_pointer(&ptr, prop);
950 if (node_to == NULL) {
953 OperationDepsNode *operation_to = node_to->get_entry_operation();
954 /* NOTE: Special case for bones, avoid relation from animation to
955 * each of the bones. Bone evaluation could only start from pose
958 if (operation_to->opcode == DEG_OPCODE_BONE_LOCAL) {
959 OperationKey pose_init_key(id,
960 DEG_NODE_TYPE_EVAL_POSE,
961 DEG_OPCODE_POSE_INIT);
962 add_relation(adt_key, pose_init_key, "Animation -> Prop", true);
965 graph_->add_new_relation(operation_from, operation_to,
971 void DepsgraphRelationBuilder::build_animdata_drievrs(ID *id)
973 AnimData *adt = BKE_animdata_from_id(id);
977 ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
978 LINKLIST_FOREACH (FCurve *, fcu, &adt->drivers) {
979 OperationKey driver_key(id,
980 DEG_NODE_TYPE_PARAMETERS,
982 fcu->rna_path ? fcu->rna_path : "",
985 /* create the driver's relations to targets */
986 build_driver(id, fcu);
988 /* Special case for array drivers: we can not multithread them because
989 * of the way how they work internally: animation system will write the
990 * whole array back to RNA even when changing individual array value.
992 * Some tricky things here:
993 * - array_index is -1 for single channel drivers, meaning we only have
994 * to do some magic when array_index is not -1.
995 * - We do relation from next array index to a previous one, so we don't
996 * have to deal with array index 0.
998 * TODO(sergey): Avoid liner lookup somehow.
1000 if (fcu->array_index > 0) {
1001 FCurve *fcu_prev = NULL;
1002 LINKLIST_FOREACH (FCurve *, fcu_candidate, &adt->drivers) {
1003 /* Writing to different RNA paths is */
1004 const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1005 if (!STREQ(fcu_candidate->rna_path, rna_path)) {
1008 /* We only do relation from previous fcurve to previous one. */
1009 if (fcu_candidate->array_index >= fcu->array_index) {
1012 /* Choose fcurve with highest possible array index. */
1013 if (fcu_prev == NULL ||
1014 fcu_candidate->array_index > fcu_prev->array_index)
1016 fcu_prev = fcu_candidate;
1019 if (fcu_prev != NULL) {
1020 OperationKey prev_driver_key(id,
1021 DEG_NODE_TYPE_PARAMETERS,
1023 fcu_prev->rna_path ? fcu_prev->rna_path : "",
1024 fcu_prev->array_index);
1025 OperationKey driver_key(id,
1026 DEG_NODE_TYPE_PARAMETERS,
1028 fcu->rna_path ? fcu->rna_path : "",
1030 add_relation(prev_driver_key, driver_key, "Driver Order");
1034 /* prevent driver from occurring before own animation... */
1035 if (adt->action || adt->nla_tracks.first) {
1036 add_relation(adt_key, driver_key, "AnimData Before Drivers");
1041 void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu)
1043 ChannelDriver *driver = fcu->driver;
1044 OperationKey driver_key(id,
1045 DEG_NODE_TYPE_PARAMETERS,
1047 fcu->rna_path ? fcu->rna_path : "",
1049 /* Driver -> data components (for interleaved evaluation
1050 * bones/constraints/modifiers).
1052 build_driver_data(id, fcu);
1053 /* Loop over variables to get the target relationships. */
1054 build_driver_variables(id, fcu);
1055 /* It's quite tricky to detect if the driver actually depends on time or
1056 * not, so for now we'll be quite conservative here about optimization and
1057 * consider all python drivers to be depending on time.
1059 if ((driver->type == DRIVER_TYPE_PYTHON) &&
1060 python_driver_depends_on_time(driver))
1062 TimeSourceKey time_src_key;
1063 add_relation(time_src_key, driver_key, "TimeSrc -> Driver");
1067 void DepsgraphRelationBuilder::build_driver_data(ID *id, FCurve *fcu)
1069 OperationKey driver_key(id,
1070 DEG_NODE_TYPE_PARAMETERS,
1072 fcu->rna_path ? fcu->rna_path : "",
1074 const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1075 const RNAPathKey self_key(id, rna_path);
1076 if (GS(id->name) == ID_AR && strstr(rna_path, "bones[")) {
1077 /* Drivers on armature-level bone settings (i.e. bbone stuff),
1078 * which will affect the evaluation of corresponding pose bones.
1080 IDDepsNode *arm_node = graph_->find_id_node(id);
1081 char *bone_name = BLI_str_quoted_substrN(rna_path, "bones[");
1082 if (arm_node && bone_name) {
1083 /* Find objects which use this, and make their eval callbacks
1086 foreach (DepsRelation *rel, arm_node->outlinks) {
1087 IDDepsNode *to_node = (IDDepsNode *)rel->to;
1088 /* We only care about objects with pose data which use this. */
1089 if (GS(to_node->id->name) == ID_OB) {
1090 Object *object = (Object *)to_node->id;
1091 /* NOTE: object->pose may be NULL. */
1092 bPoseChannel *pchan = BKE_pose_channel_find_name(
1093 object->pose, bone_name);
1094 if (pchan != NULL) {
1095 OperationKey bone_key(&object->id,
1098 DEG_OPCODE_BONE_LOCAL);
1099 add_relation(driver_key,
1101 "Arm Bone -> Driver -> Bone");
1105 /* Free temp data. */
1106 MEM_freeN(bone_name);
1111 "Couldn't find armature bone name for driver path - '%s'\n",
1116 RNAPathKey target_key(id, rna_path);
1117 add_relation(driver_key, target_key, "Driver -> Target");
1121 void DepsgraphRelationBuilder::build_driver_variables(ID *id, FCurve *fcu)
1123 ChannelDriver *driver = fcu->driver;
1124 OperationKey driver_key(id,
1125 DEG_NODE_TYPE_PARAMETERS,
1127 fcu->rna_path ? fcu->rna_path : "",
1129 const char *rna_path = fcu->rna_path ? fcu->rna_path : "";
1130 const RNAPathKey self_key(id, rna_path);
1132 LINKLIST_FOREACH (DriverVar *, dvar, &driver->variables) {
1133 /* Only used targets. */
1134 DRIVER_TARGETS_USED_LOOPER(dvar)
1136 if (dtar->id == NULL) {
1139 /* Special handling for directly-named bones. */
1140 if ((dtar->flag & DTAR_FLAG_STRUCT_REF) &&
1141 (((Object *)dtar->id)->type == OB_ARMATURE) &&
1142 (dtar->pchan_name[0]))
1144 Object *object = (Object *)dtar->id;
1145 bPoseChannel *target_pchan =
1146 BKE_pose_channel_find_name(object->pose,
1148 if (target_pchan == NULL) {
1151 OperationKey variable_key(dtar->id,
1154 DEG_OPCODE_BONE_DONE);
1155 if (is_same_bone_dependency(variable_key, self_key)) {
1158 add_relation(variable_key, driver_key, "Bone Target -> Driver");
1160 else if (dtar->flag & DTAR_FLAG_STRUCT_REF) {
1161 /* Get node associated with the object's transforms. */
1162 if (dtar->id == id) {
1163 /* Ignore input dependency if we're driving properties of
1164 * the same ID, otherwise we'll be ending up in a cyclic
1169 OperationKey target_key(dtar->id,
1170 DEG_NODE_TYPE_TRANSFORM,
1171 DEG_OPCODE_TRANSFORM_FINAL);
1172 add_relation(target_key, driver_key, "Target -> Driver");
1174 else if (dtar->rna_path) {
1175 RNAPathKey variable_key(dtar->id, dtar->rna_path);
1176 if (RNA_pointer_is_null(&variable_key.ptr)) {
1179 if (is_same_bone_dependency(variable_key, self_key)) {
1182 add_relation(variable_key, driver_key, "RNA Bone -> Driver");
1185 if (dtar->id == id) {
1186 /* Ignore input dependency if we're driving properties of
1187 * the same ID, otherwise we'll be ending up in a cyclic
1192 /* Resolve path to get node. */
1193 RNAPathKey target_key(dtar->id,
1194 dtar->rna_path ? dtar->rna_path : "");
1195 add_relation(target_key, driver_key, "RNA Target -> Driver");
1198 DRIVER_TARGETS_LOOPER_END
1202 void DepsgraphRelationBuilder::build_world(World *world)
1204 ID *world_id = &world->id;
1205 if (world_id->tag & LIB_TAG_DOIT) {
1208 world_id->tag |= LIB_TAG_DOIT;
1210 build_animdata(world_id);
1212 /* TODO: other settings? */
1215 build_texture_stack(world->mtex);
1217 /* world's nodetree */
1218 if (world->nodetree != NULL) {
1219 build_nodetree(world->nodetree);
1220 ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
1221 ComponentKey world_key(world_id, DEG_NODE_TYPE_PARAMETERS);
1222 add_relation(ntree_key, world_key, "NTree->World Parameters");
1226 void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
1228 RigidBodyWorld *rbw = scene->rigidbody_world;
1230 OperationKey init_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD);
1231 OperationKey sim_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM);
1233 /* rel between the two sim-nodes */
1234 add_relation(init_key, sim_key, "Rigidbody [Init -> SimStep]");
1236 /* set up dependencies between these operations and other builtin nodes --------------- */
1238 /* time dependency */
1239 TimeSourceKey time_src_key;
1240 add_relation(time_src_key, init_key, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)");
1242 /* objects - simulation participants */
1244 LINKLIST_FOREACH (GroupObject *, go, &rbw->group->gobject) {
1245 Object *object = go->ob;
1246 if (object == NULL || object->type != OB_MESH) {
1250 /* hook up evaluation order...
1251 * 1) flushing rigidbody results follows base transforms being applied
1252 * 2) rigidbody flushing can only be performed after simulation has been run
1254 * 3) simulation needs to know base transforms to figure out what to do
1255 * XXX: there's probably a difference between passive and active
1256 * - passive don't change, so may need to know full transform...
1258 OperationKey rbo_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1260 eDepsOperation_Code trans_opcode = object->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL;
1261 OperationKey trans_op(&object->id, DEG_NODE_TYPE_TRANSFORM, trans_opcode);
1263 add_relation(sim_key, rbo_key, "Rigidbody Sim Eval -> RBO Sync");
1265 /* if constraints exist, those depend on the result of the rigidbody sim
1266 * - This allows constraints to modify the result of the sim (i.e. clamping)
1267 * while still allowing the sim to depend on some changes to the objects.
1268 * Also, since constraints are hooked up to the final nodes, this link
1269 * means that we can also fit in there too...
1270 * - Later, it might be good to include a constraint in the stack allowing us
1271 * to control whether rigidbody eval gets interleaved into the constraint stack
1273 if (object->constraints.first) {
1274 OperationKey constraint_key(&object->id,
1275 DEG_NODE_TYPE_TRANSFORM,
1276 DEG_OPCODE_TRANSFORM_CONSTRAINTS);
1277 add_relation(rbo_key, constraint_key, "RBO Sync -> Ob Constraints");
1280 /* Final object transform depends on rigidbody.
1282 * NOTE: Currently we consider final here an ubereval node.
1283 * If it is gone we'll need to reconsider relation here.
1285 OperationKey uber_key(&object->id,
1286 DEG_NODE_TYPE_TRANSFORM,
1287 DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
1288 add_relation(rbo_key, uber_key, "RBO Sync -> Uber (Temp)");
1291 /* Needed to get correct base values. */
1292 add_relation(trans_op, sim_key, "Base Ob Transform -> Rigidbody Sim Eval");
1297 if (rbw->constraints) {
1298 LINKLIST_FOREACH (GroupObject *, go, &rbw->constraints->gobject) {
1299 Object *object = go->ob;
1300 if (object == NULL || !object->rigidbody_constraint) {
1304 RigidBodyCon *rbc = object->rigidbody_constraint;
1306 /* final result of the constraint object's transform controls how the
1307 * constraint affects the physics sim for these objects
1309 ComponentKey trans_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1310 OperationKey ob1_key(&rbc->ob1->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1311 OperationKey ob2_key(&rbc->ob2->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
1313 /* - constrained-objects sync depends on the constraint-holder */
1314 add_relation(trans_key, ob1_key, "RigidBodyConstraint -> RBC.Object_1");
1315 add_relation(trans_key, ob2_key, "RigidBodyConstraint -> RBC.Object_2");
1317 /* - ensure that sim depends on this constraint's transform */
1318 add_relation(trans_key, sim_key, "RigidBodyConstraint Transform -> RB Simulation");
1323 void DepsgraphRelationBuilder::build_particles(Object *object)
1325 TimeSourceKey time_src_key;
1326 OperationKey obdata_ubereval_key(&object->id,
1327 DEG_NODE_TYPE_GEOMETRY,
1328 DEG_OPCODE_GEOMETRY_UBEREVAL);
1329 OperationKey eval_init_key(&object->id,
1330 DEG_NODE_TYPE_EVAL_PARTICLES,
1331 DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
1332 if (object_particles_depends_on_time(object)) {
1333 add_relation(time_src_key, eval_init_key, "TimeSrc -> PSys");
1336 /* particle systems */
1337 LINKLIST_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
1338 ParticleSettings *part = psys->part;
1340 /* particle settings */
1341 build_animdata(&part->id);
1343 /* this particle system */
1344 OperationKey psys_key(&object->id, DEG_NODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PARTICLE_SYSTEM_EVAL, psys->name);
1346 /* XXX: if particle system is later re-enabled, we must do full rebuild? */
1347 if (!psys_check_enabled(object, psys, G.is_rendering))
1350 add_relation(eval_init_key, psys_key, "Init -> PSys");
1352 /* TODO(sergey): Currently particle update is just a placeholder,
1353 * hook it to the ubereval node so particle system is getting updated
1356 add_relation(psys_key, obdata_ubereval_key, "PSys -> UberEval");
1359 if (part->type != PART_HAIR) {
1360 add_collision_relations(psys_key, scene_, object, part->collision_group, object->lay, true, "Particle Collision");
1362 else if ((psys->flag & PSYS_HAIR_DYNAMICS) && psys->clmd && psys->clmd->coll_parms) {
1363 add_collision_relations(psys_key, scene_, object, psys->clmd->coll_parms->group, object->lay | scene_->lay, true, "Hair Collision");
1367 add_forcefield_relations(psys_key, scene_, object, psys, part->effector_weights, part->type == PART_HAIR, "Particle Field");
1371 LINKLIST_FOREACH (BoidState *, state, &part->boids->states) {
1372 LINKLIST_FOREACH (BoidRule *, rule, &state->rules) {
1373 Object *ruleob = NULL;
1374 if (rule->type == eBoidRuleType_Avoid)
1375 ruleob = ((BoidRuleGoalAvoid *)rule)->ob;
1376 else if (rule->type == eBoidRuleType_FollowLeader)
1377 ruleob = ((BoidRuleFollowLeader *)rule)->ob;
1380 ComponentKey ruleob_key(&ruleob->id, DEG_NODE_TYPE_TRANSFORM);
1381 add_relation(ruleob_key, psys_key, "Boid Rule");
1387 if (part->ren_as == PART_DRAW_OB && part->dup_ob) {
1388 ComponentKey dup_ob_key(&part->dup_ob->id, DEG_NODE_TYPE_TRANSFORM);
1389 add_relation(dup_ob_key, psys_key, "Particle Object Visualization");
1393 /* Particle depends on the object transform, so that channel is to be ready
1396 * TODO(sergey): This relation should be altered once real granular update
1399 ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1400 add_relation(transform_key, obdata_ubereval_key, "Partcile Eval");
1406 void DepsgraphRelationBuilder::build_cloth(Object *object,
1407 ModifierData * /*md*/)
1409 OperationKey cache_key(&object->id,
1410 DEG_NODE_TYPE_CACHE,
1411 DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER);
1412 /* Cache component affects on modifier. */
1413 OperationKey modifier_key(&object->id,
1414 DEG_NODE_TYPE_GEOMETRY,
1415 DEG_OPCODE_GEOMETRY_UBEREVAL);
1416 add_relation(cache_key, modifier_key, "Cloth Cache -> Cloth");
1420 void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key)
1422 ComponentKey obdata_key(obdata, DEG_NODE_TYPE_GEOMETRY);
1424 /* attach animdata to geometry */
1425 build_animdata(&key->id);
1428 // TODO: this should really be handled in build_animdata, since many of these cases will need it
1429 if (key->adt->action || key->adt->nla_tracks.first) {
1430 ComponentKey adt_key(&key->id, DEG_NODE_TYPE_ANIMATION);
1431 add_relation(adt_key, obdata_key, "Animation");
1434 /* NOTE: individual shapekey drivers are handled above already */
1437 /* attach to geometry */
1438 // XXX: aren't shapekeys now done as a pseudo-modifier on object?
1439 //ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY); // FIXME: this doesn't exist
1440 //add_relation(key_key, obdata_key, "Shapekeys");
1444 * ObData Geometry Evaluation
1445 * ==========================
1447 * The evaluation of geometry on objects is as follows:
1448 * - The actual evaluated of the derived geometry (e.g. DerivedMesh, DispList, etc.)
1449 * occurs in the Geometry component of the object which references this. This includes
1450 * modifiers, and the temporary "ubereval" for geometry.
1451 * - Therefore, each user of a piece of shared geometry data ends up evaluating its own
1452 * version of the stuff, complete with whatever modifiers it may use.
1454 * - The datablocks for the geometry data - "obdata" (e.g. ID_ME, ID_CU, ID_LT, etc.) are used for
1455 * 1) calculating the bounding boxes of the geometry data,
1456 * 2) aggregating inward links from other objects (e.g. for text on curve, etc.)
1457 * and also for the links coming from the shapekey datablocks
1458 * - Animation/Drivers affecting the parameters of the geometry are made to trigger
1459 * updates on the obdata geometry component, which then trigger downstream
1460 * re-evaluation of the individual instances of this geometry.
1462 // TODO: Materials and lighting should probably get their own component, instead of being lumped under geometry?
1463 void DepsgraphRelationBuilder::build_obdata_geom(Object *object)
1465 ID *obdata = (ID *)object->data;
1467 /* Init operation of object-level geometry evaluation. */
1468 OperationKey geom_init_key(&object->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Init");
1470 /* get nodes for result of obdata's evaluation, and geometry evaluation on object */
1471 ComponentKey obdata_geom_key(obdata, DEG_NODE_TYPE_GEOMETRY);
1472 ComponentKey geom_key(&object->id, DEG_NODE_TYPE_GEOMETRY);
1474 /* link components to each other */
1475 add_relation(obdata_geom_key, geom_key, "Object Geometry Base Data");
1478 if (object->modifiers.first != NULL) {
1479 OperationKey obdata_ubereval_key(&object->id,
1480 DEG_NODE_TYPE_GEOMETRY,
1481 DEG_OPCODE_GEOMETRY_UBEREVAL);
1483 LINKLIST_FOREACH (ModifierData *, md, &object->modifiers) {
1484 const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type);
1485 if (mti->updateDepsgraph) {
1486 DepsNodeHandle handle = create_node_handle(obdata_ubereval_key);
1487 mti->updateDepsgraph(
1492 reinterpret_cast< ::DepsNodeHandle* >(&handle));
1494 if (BKE_object_modifier_use_time(object, md)) {
1495 TimeSourceKey time_src_key;
1496 add_relation(time_src_key, obdata_ubereval_key, "Time Source");
1498 if (md->type == eModifierType_Cloth) {
1499 build_cloth(object, md);
1505 if (object->totcol) {
1506 for (int a = 1; a <= object->totcol; a++) {
1507 Material *ma = give_current_material(object, a);
1514 /* geometry collision */
1515 if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) {
1516 // add geometry collider relations
1519 /* Make sure uber update is the last in the dependencies.
1521 * TODO(sergey): Get rid of this node.
1523 if (object->type != OB_ARMATURE) {
1524 /* Armatures does no longer require uber node. */
1525 OperationKey obdata_ubereval_key(&object->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL);
1526 add_relation(geom_init_key, obdata_ubereval_key, "Object Geometry UberEval");
1529 if (obdata->tag & LIB_TAG_DOIT) {
1532 obdata->tag |= LIB_TAG_DOIT;
1534 /* Link object data evaluation node to exit operation. */
1535 OperationKey obdata_geom_eval_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Geometry Eval");
1536 OperationKey obdata_geom_done_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Done");
1537 add_relation(obdata_geom_eval_key, obdata_geom_done_key, "ObData Geom Eval Done");
1539 /* type-specific node/links */
1540 switch (object->type) {
1542 /* NOTE: This is compatibility code to support particle systems
1544 * for viewport being properly rendered in final render mode.
1545 * This relation is similar to what dag_object_time_update_flags()
1546 * was doing for mesh objects with particle system.
1548 * Ideally we need to get rid of this relation.
1550 if (object_particles_depends_on_time(object)) {
1551 TimeSourceKey time_key;
1552 OperationKey obdata_ubereval_key(&object->id,
1553 DEG_NODE_TYPE_GEOMETRY,
1554 DEG_OPCODE_GEOMETRY_UBEREVAL);
1555 add_relation(time_key, obdata_ubereval_key, "Legacy particle time");
1561 Object *mom = BKE_mball_basis_find(scene_, object);
1562 ComponentKey mom_geom_key(&mom->id, DEG_NODE_TYPE_GEOMETRY);
1563 /* motherball - mom depends on children! */
1564 if (mom == object) {
1565 ComponentKey mom_transform_key(&mom->id,
1566 DEG_NODE_TYPE_TRANSFORM);
1567 add_relation(mom_transform_key,
1569 "Metaball Motherball Transform -> Geometry");
1572 ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
1573 add_relation(geom_key, mom_geom_key, "Metaball Motherball");
1574 add_relation(transform_key, mom_geom_key, "Metaball Motherball");
1582 Curve *cu = (Curve *)obdata;
1584 /* curve's dependencies */
1585 // XXX: these needs geom data, but where is geom stored?
1587 ComponentKey bevob_key(&cu->bevobj->id, DEG_NODE_TYPE_GEOMETRY);
1588 build_object(cu->bevobj);
1589 add_relation(bevob_key, geom_key, "Curve Bevel");
1592 ComponentKey taperob_key(&cu->taperobj->id, DEG_NODE_TYPE_GEOMETRY);
1593 build_object(cu->taperobj);
1594 add_relation(taperob_key, geom_key, "Curve Taper");
1596 if (object->type == OB_FONT) {
1597 if (cu->textoncurve) {
1598 ComponentKey textoncurve_key(&cu->textoncurve->id, DEG_NODE_TYPE_GEOMETRY);
1599 build_object(cu->textoncurve);
1600 add_relation(textoncurve_key, geom_key, "Text on Curve");
1606 case OB_SURF: /* Nurbs Surface */
1611 case OB_LATTICE: /* Lattice */
1618 Key *key = BKE_key_from_object(object);
1620 build_shapekeys(obdata, key);
1625 // TODO: Link scene-camera links in somehow...
1626 void DepsgraphRelationBuilder::build_camera(Object *object)
1628 Camera *cam = (Camera *)object->data;
1629 ID *camera_id = &cam->id;
1630 if (camera_id->tag & LIB_TAG_DOIT) {
1633 camera_id->tag |= LIB_TAG_DOIT;
1636 ComponentKey ob_param_key(&object->id, DEG_NODE_TYPE_PARAMETERS);
1637 ComponentKey dof_ob_key(&cam->dof_ob->id, DEG_NODE_TYPE_TRANSFORM);
1638 add_relation(dof_ob_key, ob_param_key, "Camera DOF");
1643 void DepsgraphRelationBuilder::build_lamp(Object *object)
1645 Lamp *la = (Lamp *)object->data;
1646 ID *lamp_id = &la->id;
1647 if (lamp_id->tag & LIB_TAG_DOIT) {
1650 lamp_id->tag |= LIB_TAG_DOIT;
1651 /* lamp's nodetree */
1652 if (la->nodetree != NULL) {
1653 build_nodetree(la->nodetree);
1654 ComponentKey parameters_key(lamp_id, DEG_NODE_TYPE_PARAMETERS);
1655 ComponentKey nodetree_key(&la->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
1656 add_relation(nodetree_key, parameters_key, "NTree->Lamp Parameters");
1659 build_texture_stack(la->mtex);
1662 void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
1667 ID *ntree_id = &ntree->id;
1669 build_animdata(ntree_id);
1671 OperationKey parameters_key(ntree_id,
1672 DEG_NODE_TYPE_PARAMETERS,
1673 DEG_OPCODE_PARAMETERS_EVAL);
1675 /* nodetree's nodes... */
1676 LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) {
1681 ID_Type id_type = GS(id->name);
1682 if (id_type == ID_MA) {
1683 build_material((Material *)bnode->id);
1685 else if (id_type == ID_TE) {
1686 build_texture((Tex *)bnode->id);
1688 else if (id_type == ID_IM) {
1689 /* nothing for now. */
1691 else if (id_type == ID_OB) {
1692 build_object((Object *)id);
1694 else if (id_type == ID_SCE) {
1695 /* Scenes are used by compositor trees, and handled by render
1696 * pipeline. No need to build dependencies for them here.
1699 else if (id_type == ID_TXT) {
1700 /* Ignore script nodes. */
1702 else if (bnode->type == NODE_GROUP) {
1703 bNodeTree *group_ntree = (bNodeTree *)id;
1704 if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) {
1705 build_nodetree(group_ntree);
1706 group_ntree->id.tag |= LIB_TAG_DOIT;
1708 OperationKey group_parameters_key(&group_ntree->id,
1709 DEG_NODE_TYPE_PARAMETERS,
1710 DEG_OPCODE_PARAMETERS_EVAL);
1711 add_relation(group_parameters_key, parameters_key, "Group Node");
1714 BLI_assert(!"Unknown ID type used for node");
1719 /* Recursively build graph for material */
1720 void DepsgraphRelationBuilder::build_material(Material *ma)
1722 ID *ma_id = &ma->id;
1723 if (ma_id->tag & LIB_TAG_DOIT) {
1726 ma_id->tag |= LIB_TAG_DOIT;
1729 build_animdata(ma_id);
1732 build_texture_stack(ma->mtex);
1734 /* material's nodetree */
1735 if (ma->nodetree != NULL) {
1736 build_nodetree(ma->nodetree);
1737 OperationKey ntree_key(&ma->nodetree->id,
1738 DEG_NODE_TYPE_PARAMETERS,
1739 DEG_OPCODE_PARAMETERS_EVAL);
1740 OperationKey material_key(&ma->id,
1741 DEG_NODE_TYPE_SHADING,
1742 DEG_OPCODE_PLACEHOLDER,
1744 add_relation(ntree_key, material_key, "Material's NTree");
1748 /* Recursively build graph for texture */
1749 void DepsgraphRelationBuilder::build_texture(Tex *tex)
1751 ID *tex_id = &tex->id;
1752 if (tex_id->tag & LIB_TAG_DOIT) {
1755 tex_id->tag |= LIB_TAG_DOIT;
1757 /* texture itself */
1758 build_animdata(tex_id);
1760 /* texture's nodetree */
1761 build_nodetree(tex->nodetree);
1764 /* Texture-stack attached to some shading datablock */
1765 void DepsgraphRelationBuilder::build_texture_stack(MTex **texture_stack)
1769 /* for now assume that all texture-stacks have same number of max items */
1770 for (i = 0; i < MAX_MTEX; i++) {
1771 MTex *mtex = texture_stack[i];
1772 if (mtex && mtex->tex)
1773 build_texture(mtex->tex);
1777 void DepsgraphRelationBuilder::build_compositor(Scene *scene)
1779 /* For now, just a plain wrapper? */
1780 build_nodetree(scene->nodetree);
1783 void DepsgraphRelationBuilder::build_gpencil(bGPdata *gpd)
1786 build_animdata(&gpd->id);
1788 // TODO: parent object (when that feature is implemented)
1791 void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file) {
1793 build_animdata(&cache_file->id);
1796 void DepsgraphRelationBuilder::build_mask(Mask *mask)
1798 ID *mask_id = &mask->id;
1799 /* F-Curve animation. */
1800 build_animdata(mask_id);
1801 /* Own mask animation. */
1802 OperationKey mask_animation_key(mask_id,
1803 DEG_NODE_TYPE_ANIMATION,
1804 DEG_OPCODE_MASK_ANIMATION);
1805 TimeSourceKey time_src_key;
1806 add_relation(time_src_key, mask_animation_key, "TimeSrc -> Mask Animation");
1807 /* Final mask evaluation. */
1808 ComponentKey parameters_key(mask_id, DEG_NODE_TYPE_PARAMETERS);
1809 add_relation(mask_animation_key, parameters_key, "Mask Animation -> Mask Eval");
1812 void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip)
1815 build_animdata(&clip->id);