diff options
Diffstat (limited to 'source/blender/depsgraph/intern/builder/deg_builder_relations.cc')
-rw-r--r-- | source/blender/depsgraph/intern/builder/deg_builder_relations.cc | 1943 |
1 files changed, 1043 insertions, 900 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 94cff521edc..066c9868876 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -38,10 +38,10 @@ #include "MEM_guardedalloc.h" -extern "C" { -#include "BLI_blenlib.h" #include "BLI_utildefines.h" +#include "BLI_blenlib.h" +extern "C" { #include "DNA_action_types.h" #include "DNA_anim_types.h" #include "DNA_armature_types.h" @@ -66,7 +66,7 @@ extern "C" { #include "DNA_scene_types.h" #include "DNA_texture_types.h" #include "DNA_world_types.h" -#include "DNA_object_force.h" +#include "DNA_object_force_types.h" #include "BKE_action.h" #include "BKE_armature.h" @@ -88,23 +88,24 @@ extern "C" { #include "BKE_particle.h" #include "BKE_rigidbody.h" #include "BKE_sound.h" -#include "BKE_texture.h" #include "BKE_tracking.h" #include "BKE_world.h" -#include "DEG_depsgraph.h" -#include "DEG_depsgraph_build.h" - #include "RNA_access.h" #include "RNA_types.h" } /* extern "C" */ +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" + #include "intern/builder/deg_builder.h" #include "intern/builder/deg_builder_pchanmap.h" #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" +#include "intern/nodes/deg_node_id.h" #include "intern/nodes/deg_node_operation.h" +#include "intern/nodes/deg_node_time.h" #include "intern/depsgraph_intern.h" #include "intern/depsgraph_types.h" @@ -142,35 +143,42 @@ static bool python_driver_depends_on_time(ChannelDriver *driver) return false; } -/* **** General purpose functions **** */ - -RNAPathKey::RNAPathKey(ID *id, const char *path) : - id(id) +static bool particle_system_depends_on_time(ParticleSystem *psys) { - /* create ID pointer for root of path lookup */ - PointerRNA id_ptr; - RNA_id_pointer_create(id, &id_ptr); - /* try to resolve path... */ - int index; - if (!RNA_path_resolve_full(&id_ptr, path, &this->ptr, &this->prop, &index)) { - this->ptr = PointerRNA_NULL; - this->prop = NULL; + ParticleSettings *part = psys->part; + /* Non-hair particles we always consider dependent on time. */ + if (part->type != PART_HAIR) { + return true; } + /* Dynamics always depends on time. */ + if (psys->flag & PSYS_HAIR_DYNAMICS) { + return true; + } + /* TODO(sergey): Check what else makes hair dependent on time. */ + return false; } -DepsgraphRelationBuilder::DepsgraphRelationBuilder(Depsgraph *graph) : - m_graph(graph) +static bool object_particles_depends_on_time(Object *object) { + LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) { + if (particle_system_depends_on_time(psys)) { + return true; + } + } + return false; } -RootDepsNode *DepsgraphRelationBuilder::find_node(const RootKey &key) const +/* **** General purpose functions **** */ + +DepsgraphRelationBuilder::DepsgraphRelationBuilder(Main *bmain, + Depsgraph *graph) + : bmain_(bmain), + graph_(graph), + scene_(NULL) { - (void)key; - BLI_assert(!"Doesn't seem to be correct"); - return m_graph->root_node; } -TimeSourceDepsNode *DepsgraphRelationBuilder::find_node( +TimeSourceDepsNode *DepsgraphRelationBuilder::get_node( const TimeSourceKey &key) const { if (key.id) { @@ -178,14 +186,14 @@ TimeSourceDepsNode *DepsgraphRelationBuilder::find_node( return NULL; } else { - return m_graph->root_node->time_source; + return graph_->time_source; } } -ComponentDepsNode *DepsgraphRelationBuilder::find_node( +ComponentDepsNode *DepsgraphRelationBuilder::get_node( const ComponentKey &key) const { - IDDepsNode *id_node = m_graph->find_id_node(key.id); + IDDepsNode *id_node = graph_->find_id_node(key.id); if (!id_node) { fprintf(stderr, "find_node component: Could not find ID %s\n", (key.id != NULL) ? key.id->name : "<null>"); @@ -196,41 +204,26 @@ ComponentDepsNode *DepsgraphRelationBuilder::find_node( return node; } -OperationDepsNode *DepsgraphRelationBuilder::find_node( +OperationDepsNode *DepsgraphRelationBuilder::get_node( const OperationKey &key) const { - IDDepsNode *id_node = m_graph->find_id_node(key.id); - if (!id_node) { - fprintf(stderr, "find_node operation: Could not find ID\n"); - return NULL; - } - - ComponentDepsNode *comp_node = id_node->find_component(key.component_type, - key.component_name); - if (!comp_node) { - fprintf(stderr, "find_node operation: Could not find component\n"); - return NULL; - } - - OperationDepsNode *op_node = comp_node->find_operation(key.opcode, - key.name, - key.name_tag); - if (!op_node) { + OperationDepsNode *op_node = find_node(key); + if (op_node == NULL) { fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n", DEG_OPNAMES[key.opcode], key.name); } return op_node; } -DepsNode *DepsgraphRelationBuilder::find_node(const RNAPathKey &key) const +DepsNode *DepsgraphRelationBuilder::get_node(const RNAPathKey &key) const { - return m_graph->find_node_from_pointer(&key.ptr, key.prop); + return graph_->find_node_from_pointer(&key.ptr, key.prop); } -OperationDepsNode *DepsgraphRelationBuilder::has_node( +OperationDepsNode *DepsgraphRelationBuilder::find_node( const OperationKey &key) const { - IDDepsNode *id_node = m_graph->find_id_node(key.id); + IDDepsNode *id_node = graph_->find_id_node(key.id); if (!id_node) { return NULL; } @@ -239,97 +232,137 @@ OperationDepsNode *DepsgraphRelationBuilder::has_node( if (!comp_node) { return NULL; } - return comp_node->has_operation(key.opcode, key.name, key.name_tag); + return comp_node->find_operation(key.opcode, key.name, key.name_tag); +} + +bool DepsgraphRelationBuilder::has_node(const OperationKey &key) const +{ + return find_node(key) != NULL; } -void DepsgraphRelationBuilder::add_time_relation(TimeSourceDepsNode *timesrc, - DepsNode *node_to, - const char *description) +DepsRelation *DepsgraphRelationBuilder::add_time_relation( + TimeSourceDepsNode *timesrc, + DepsNode *node_to, + const char *description, + bool check_unique) { if (timesrc && node_to) { - m_graph->add_new_relation(timesrc, node_to, DEPSREL_TYPE_TIME, description); + return graph_->add_new_relation(timesrc, node_to, description, check_unique); } else { - DEG_DEBUG_PRINTF("add_time_relation(%p = %s, %p = %s, %s) Failed\n", + DEG_DEBUG_PRINTF(BUILD, "add_time_relation(%p = %s, %p = %s, %s) Failed\n", timesrc, (timesrc) ? timesrc->identifier().c_str() : "<None>", node_to, (node_to) ? node_to->identifier().c_str() : "<None>", description); } + return NULL; } -void DepsgraphRelationBuilder::add_operation_relation( +DepsRelation *DepsgraphRelationBuilder::add_operation_relation( OperationDepsNode *node_from, OperationDepsNode *node_to, - eDepsRelation_Type type, - const char *description) + const char *description, + bool check_unique) { if (node_from && node_to) { - m_graph->add_new_relation(node_from, node_to, type, description); + return graph_->add_new_relation(node_from, + node_to, + description, + check_unique); } else { - DEG_DEBUG_PRINTF("add_operation_relation(%p = %s, %p = %s, %d, %s) Failed\n", + DEG_DEBUG_PRINTF(BUILD, "add_operation_relation(%p = %s, %p = %s, %s) Failed\n", node_from, (node_from) ? node_from->identifier().c_str() : "<None>", node_to, (node_to) ? node_to->identifier().c_str() : "<None>", - type, description); + description); } + return NULL; } -void DepsgraphRelationBuilder::add_collision_relations(const OperationKey &key, Scene *scene, Object *ob, Group *group, int layer, bool dupli, const char *name) +void DepsgraphRelationBuilder::add_collision_relations( + const OperationKey &key, + Scene *scene, + Object *object, + Group *group, + int layer, + bool dupli, + const char *name) { unsigned int numcollobj; - Object **collobjs = get_collisionobjects_ext(scene, ob, group, layer, &numcollobj, eModifierType_Collision, dupli); - - for (unsigned int i = 0; i < numcollobj; i++) - { + Object **collobjs = get_collisionobjects_ext( + scene, + object, + group, + layer, + &numcollobj, + eModifierType_Collision, + dupli); + for (unsigned int i = 0; i < numcollobj; i++) { Object *ob1 = collobjs[i]; - ComponentKey trf_key(&ob1->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(trf_key, key, DEPSREL_TYPE_STANDARD, name); + ComponentKey trf_key(&ob1->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(trf_key, key, name); - ComponentKey coll_key(&ob1->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(coll_key, key, DEPSREL_TYPE_STANDARD, name); + ComponentKey coll_key(&ob1->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(coll_key, key, name); } - - if (collobjs) + if (collobjs != NULL) { MEM_freeN(collobjs); + } } -void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key, Scene *scene, Object *ob, ParticleSystem *psys, EffectorWeights *eff, bool add_absorption, const char *name) +void DepsgraphRelationBuilder::add_forcefield_relations( + const OperationKey &key, + Scene *scene, + Object *object, + ParticleSystem *psys, + EffectorWeights *eff, + bool add_absorption, + const char *name) { - ListBase *effectors = pdInitEffectors(scene, ob, psys, eff, false); - - if (effectors) { - for (EffectorCache *eff = (EffectorCache *)effectors->first; eff; eff = eff->next) { - if (eff->ob != ob) { - ComponentKey eff_key(&eff->ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name); + ListBase *effectors = pdInitEffectors(scene, object, psys, eff, false); + if (effectors != NULL) { + LISTBASE_FOREACH(EffectorCache *, eff, effectors) { + if (eff->ob != object) { + ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(eff_key, key, name); } + if (eff->psys != NULL) { + if (eff->ob != object) { + ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_EVAL_PARTICLES); + add_relation(eff_key, key, name); - if (eff->psys) { - if (eff->ob != ob) { - ComponentKey eff_key(&eff->ob->id, DEPSNODE_TYPE_EVAL_PARTICLES); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name); - - /* TODO: remove this when/if EVAL_PARTICLES is sufficient for up to date particles */ - ComponentKey mod_key(&eff->ob->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(mod_key, key, DEPSREL_TYPE_STANDARD, name); + /* TODO: remove this when/if EVAL_PARTICLES is sufficient + * for up to date particles. + */ + ComponentKey mod_key(&eff->ob->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(mod_key, key, name); } else if (eff->psys != psys) { - OperationKey eff_key(&eff->ob->id, DEPSNODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, eff->psys->name); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, name); + OperationKey eff_key(&eff->ob->id, + DEG_NODE_TYPE_EVAL_PARTICLES, + DEG_OPCODE_PARTICLE_SYSTEM_EVAL, + eff->psys->name); + add_relation(eff_key, key, name); } } - if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) { - ComponentKey trf_key(&eff->pd->f_source->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(trf_key, key, DEPSREL_TYPE_STANDARD, "Smoke Force Domain"); + ComponentKey trf_key(&eff->pd->f_source->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(trf_key, key, "Smoke Force Domain"); - ComponentKey eff_key(&eff->pd->f_source->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(eff_key, key, DEPSREL_TYPE_STANDARD, "Smoke Force Domain"); + ComponentKey eff_key(&eff->pd->f_source->id, + DEG_NODE_TYPE_GEOMETRY); + add_relation(eff_key, key, "Smoke Force Domain"); } - if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) { - add_collision_relations(key, scene, ob, NULL, eff->ob->lay, true, "Force Absorption"); + add_collision_relations(key, + scene, + object, + NULL, + eff->ob->lay, + true, + "Force Absorption"); } } } @@ -337,199 +370,205 @@ void DepsgraphRelationBuilder::add_forcefield_relations(const OperationKey &key, pdEndEffectors(&effectors); } +Depsgraph *DepsgraphRelationBuilder::getGraph() +{ + return graph_; +} + /* **** Functions to build relations between entities **** */ -void DepsgraphRelationBuilder::begin_build(Main *bmain) +void DepsgraphRelationBuilder::begin_build() { - /* LIB_TAG_DOIT is used to indicate whether node for given ID was already - * created or not. - */ - BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); - /* XXX nested node trees are notr included in tag-clearing above, - * so we need to do this manually. - */ - FOREACH_NODETREE(bmain, nodetree, id) { - if (id != (ID *)nodetree) { - nodetree->id.tag &= ~LIB_TAG_DOIT; - } - } FOREACH_NODETREE_END } -void DepsgraphRelationBuilder::build_group(Main *bmain, - Scene *scene, - Object *object, - Group *group) +void DepsgraphRelationBuilder::build_group(Object *object, Group *group) { - ID *group_id = &group->id; - bool group_done = (group_id->tag & LIB_TAG_DOIT) != 0; - OperationKey object_local_transform_key(&object->id, - DEPSNODE_TYPE_TRANSFORM, + const bool group_done = built_map_.checkIsBuiltAndTag(group); + OperationKey object_local_transform_key(object != NULL ? &object->id : NULL, + DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - LINKLIST_FOREACH (GroupObject *, go, &group->gobject) { + LISTBASE_FOREACH (GroupObject *, go, &group->gobject) { if (!group_done) { - build_object(bmain, scene, go->ob); + build_object(go->ob); + } + if (object != NULL) { + ComponentKey dupli_transform_key(&go->ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(dupli_transform_key, object_local_transform_key, "Dupligroup"); } - ComponentKey dupli_transform_key(&go->ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(dupli_transform_key, - object_local_transform_key, - DEPSREL_TYPE_TRANSFORM, - "Dupligroup"); } - group_id->tag |= LIB_TAG_DOIT; } -void DepsgraphRelationBuilder::build_object(Main *bmain, Scene *scene, Object *ob) +void DepsgraphRelationBuilder::build_object(Object *object) { - if (ob->id.tag & LIB_TAG_DOIT) { + if (built_map_.checkIsBuiltAndTag(object)) { return; } - ob->id.tag |= LIB_TAG_DOIT; - /* Object Transforms */ - eDepsOperation_Code base_op = (ob->parent) ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL; - OperationKey base_op_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, base_op); - - OperationKey local_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - OperationKey parent_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT); - OperationKey final_transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - - OperationKey ob_ubereval_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_OBJECT_UBEREVAL); - - /* parenting */ - if (ob->parent) { - /* parent relationship */ - build_object_parent(ob); - - /* local -> parent */ - add_relation(local_transform_key, parent_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObLocal -> ObParent]"); - } - - /* object constraints */ - if (ob->constraints.first) { - OperationKey constraint_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_CONSTRAINTS); - - /* constraint relations */ - // TODO: provide base op - // XXX: this is broken - build_constraints(scene, &ob->id, DEPSNODE_TYPE_TRANSFORM, "", &ob->constraints, NULL); - + eDepsOperation_Code base_op = (object->parent) ? DEG_OPCODE_TRANSFORM_PARENT + : DEG_OPCODE_TRANSFORM_LOCAL; + OperationKey base_op_key(&object->id, DEG_NODE_TYPE_TRANSFORM, base_op); + OperationKey local_transform_key(&object->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_LOCAL); + OperationKey parent_transform_key(&object->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_PARENT); + OperationKey final_transform_key(&object->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + OperationKey ob_ubereval_key(&object->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL); + /* Parenting. */ + if (object->parent != NULL) { + /* Make sure parent object's relations are built. */ + build_object(object->parent); + /* Parent relationship. */ + build_object_parent(object); + /* Local -> parent. */ + add_relation(local_transform_key, + parent_transform_key, + "ObLocal -> ObParent"); + } + /* Modifiers. */ + if (object->modifiers.first != NULL) { + BuilderWalkUserData data; + data.builder = this; + modifiers_foreachIDLink(object, modifier_walk, &data); + } + /* Constraints. */ + if (object->constraints.first != NULL) { + BuilderWalkUserData data; + data.builder = this; + BKE_constraints_id_loop(&object->constraints, constraint_walk, &data); + } + /* Object constraints. */ + if (object->constraints.first != NULL) { + OperationKey constraint_key(&object->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_CONSTRAINTS); + /* Constraint relations. */ + build_constraints(&object->id, + DEG_NODE_TYPE_TRANSFORM, + "", + &object->constraints, + NULL); /* operation order */ - add_relation(base_op_key, constraint_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObBase-> Constraint Stack]"); - add_relation(constraint_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "[ObConstraints -> Done]"); - + add_relation(base_op_key, constraint_key, "ObBase-> Constraint Stack"); + add_relation(constraint_key, final_transform_key, "ObConstraints -> Done"); // XXX - add_relation(constraint_key, ob_ubereval_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval"); - add_relation(ob_ubereval_key, final_transform_key, DEPSREL_TYPE_COMPONENT_ORDER, "Temp Ubereval"); + add_relation(constraint_key, ob_ubereval_key, "Temp Ubereval"); + add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval"); } else { /* NOTE: Keep an eye here, we skip some relations here to "streamline" * dependencies and avoid transitive relations which causes overhead. * But once we get rid of uber eval node this will need reconsideration. */ - if (ob->rigidbody_object == NULL) { + if (object->rigidbody_object == NULL) { /* Rigid body will hook up another node inbetween, so skip * relation here to avoid transitive relation. */ - add_relation(base_op_key, - ob_ubereval_key, - DEPSREL_TYPE_COMPONENT_ORDER, - "Temp Ubereval"); + add_relation(base_op_key, ob_ubereval_key, "Temp Ubereval"); } - add_relation(ob_ubereval_key, - final_transform_key, - DEPSREL_TYPE_COMPONENT_ORDER, - "Temp Ubereval"); + add_relation(ob_ubereval_key, final_transform_key, "Temp Ubereval"); + } + /* Animation data */ + build_animdata(&object->id); + /* Object data. */ + build_object_data(object); + /* Particle systems. */ + if (object->particlesystem.first != NULL) { + build_particles(object); + } + /* Grease pencil. */ + if (object->gpd != NULL) { + build_gpencil(object->gpd); + } + /* Object that this is a proxy for. */ + if (object->proxy != NULL) { + object->proxy->proxy_from = object; + build_object(object->proxy); + /* TODO(sergey): This is an inverted relation, matches old depsgraph + * behavior and need to be investigated if it still need to be inverted. + */ + ComponentKey ob_pose_key(&object->id, DEG_NODE_TYPE_EVAL_POSE); + ComponentKey proxy_pose_key(&object->proxy->id, DEG_NODE_TYPE_EVAL_POSE); + add_relation(ob_pose_key, proxy_pose_key, "Proxy"); } - - - /* AnimData */ - build_animdata(&ob->id); - - // XXX: This should be hooked up by the build_animdata code - if (needs_animdata_node(&ob->id)) { - ComponentKey adt_key(&ob->id, DEPSNODE_TYPE_ANIMATION); - add_relation(adt_key, local_transform_key, DEPSREL_TYPE_OPERATION, "Object Animation"); + /* Object dupligroup. */ + if (object->dup_group != NULL) { + build_group(object, object->dup_group); } +} - - /* object data */ - if (ob->data) { - ID *obdata_id = (ID *)ob->data; - - /* ob data animation */ - build_animdata(obdata_id); - - /* type-specific data... */ - switch (ob->type) { - case OB_MESH: /* Geometry */ - case OB_CURVE: - case OB_FONT: - case OB_SURF: - case OB_MBALL: - case OB_LATTICE: - { - build_obdata_geom(bmain, scene, ob); - break; - } - - case OB_ARMATURE: /* Pose */ - if (ID_IS_LINKED_DATABLOCK(ob) && ob->proxy_from != NULL) { - build_proxy_rig(ob); - } - else { - build_rig(scene, ob); - } - break; - - case OB_LAMP: /* Lamp */ - build_lamp(ob); - break; - - case OB_CAMERA: /* Camera */ - build_camera(ob); - break; - } - - Key *key = BKE_key_from_object(ob); - if (key != NULL) { - ComponentKey geometry_key((ID *)ob->data, DEPSNODE_TYPE_GEOMETRY); - ComponentKey key_key(&key->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(key_key, geometry_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Shapekeys"); - } +void DepsgraphRelationBuilder::build_object_data(Object *object) +{ + if (object->data == NULL) { + return; } - - /* particle systems */ - if (ob->particlesystem.first) { - build_particles(scene, ob); + ID *obdata_id = (ID *)object->data; + /* Object data animation. */ + build_animdata(obdata_id); + /* type-specific data. */ + switch (object->type) { + case OB_MESH: + case OB_CURVE: + case OB_FONT: + case OB_SURF: + case OB_MBALL: + case OB_LATTICE: + { + build_obdata_geom(object); + break; + } + case OB_ARMATURE: + if (ID_IS_LINKED(object) && object->proxy_from != NULL) { + build_proxy_rig(object); + } + else { + build_rig(object); + } + break; + case OB_LAMP: + build_lamp(object); + break; + case OB_CAMERA: + build_camera(object); + break; } - - /* grease pencil */ - if (ob->gpd) { - build_gpencil(ob->gpd); + Key *key = BKE_key_from_object(object); + if (key != NULL) { + ComponentKey geometry_key((ID *)object->data, DEG_NODE_TYPE_GEOMETRY); + ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(key_key, geometry_key, "Shapekeys"); } } -void DepsgraphRelationBuilder::build_object_parent(Object *ob) +void DepsgraphRelationBuilder::build_object_parent(Object *object) { - /* XXX: for now, need to use the component key (not just direct to the parent op), or else the matrix doesn't get reset */ - // XXX: @sergey - it would be good if we got that backwards flushing working when tagging for updates - //OperationKey ob_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT); - ComponentKey ob_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); + /* XXX: for now, need to use the component key (not just direct to the parent op), + * or else the matrix doesn't get reset/ + */ + // XXX: @sergey - it would be good if we got that backwards flushing working + // when tagging for updates. + //OperationKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_PARENT); + ComponentKey ob_key(&object->id, DEG_NODE_TYPE_TRANSFORM); /* type-specific links */ - switch (ob->partype) { + switch (object->partype) { case PARSKEL: /* Armature Deform (Virtual Modifier) */ { - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(parent_key, ob_key, DEPSREL_TYPE_STANDARD, "Armature Deform Parent"); + ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(parent_key, ob_key, "Armature Deform Parent"); break; } case PARVERT1: /* Vertex Parent */ case PARVERT3: { - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(parent_key, ob_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Vertex Parent"); + ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(parent_key, ob_key, "Vertex Parent"); /* XXX not sure what this is for or how you could be done properly - lukas */ OperationDepsNode *parent_node = find_operation_node(parent_key); @@ -537,179 +576,210 @@ void DepsgraphRelationBuilder::build_object_parent(Object *ob) parent_node->customdata_mask |= CD_MASK_ORIGINDEX; } - ComponentKey transform_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(transform_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Vertex Parent TFM"); + ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(transform_key, ob_key, "Vertex Parent TFM"); break; } case PARBONE: /* Bone Parent */ { - ComponentKey parent_bone_key(&ob->parent->id, - DEPSNODE_TYPE_BONE, - ob->parsubstr); - OperationKey parent_transform_key(&ob->parent->id, - DEPSNODE_TYPE_TRANSFORM, + ComponentKey parent_bone_key(&object->parent->id, + DEG_NODE_TYPE_BONE, + object->parsubstr); + OperationKey parent_transform_key(&object->parent->id, + DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(parent_bone_key, - ob_key, - DEPSREL_TYPE_TRANSFORM, - "Bone Parent"); - add_relation(parent_transform_key, - ob_key, - DEPSREL_TYPE_TRANSFORM, - "Armature Parent"); + add_relation(parent_bone_key, ob_key, "Bone Parent"); + add_relation(parent_transform_key, ob_key, "Armature Parent"); break; } default: { - if (ob->parent->type == OB_LATTICE) { + if (object->parent->type == OB_LATTICE) { /* Lattice Deform Parent - Virtual Modifier */ // XXX: no virtual modifiers should be left! - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - ComponentKey geom_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY); + ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM); + ComponentKey geom_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY); - add_relation(parent_key, ob_key, DEPSREL_TYPE_STANDARD, "Lattice Deform Parent"); - add_relation(geom_key, ob_key, DEPSREL_TYPE_STANDARD, "Lattice Deform Parent Geom"); + add_relation(parent_key, ob_key, "Lattice Deform Parent"); + add_relation(geom_key, ob_key, "Lattice Deform Parent Geom"); } - else if (ob->parent->type == OB_CURVE) { - Curve *cu = (Curve *)ob->parent->data; + else if (object->parent->type == OB_CURVE) { + Curve *cu = (Curve *)object->parent->data; if (cu->flag & CU_PATH) { /* Follow Path */ - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Follow Parent"); + ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(parent_key, ob_key, "Curve Follow Parent"); - ComponentKey transform_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(transform_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Follow TFM"); + ComponentKey transform_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(transform_key, ob_key, "Curve Follow TFM"); } else { /* Standard Parent */ - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Curve Parent"); + ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(parent_key, ob_key, "Curve Parent"); } } else { /* Standard Parent */ - ComponentKey parent_key(&ob->parent->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(parent_key, ob_key, DEPSREL_TYPE_TRANSFORM, "Parent"); + ComponentKey parent_key(&object->parent->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(parent_key, ob_key, "Parent"); } break; } } /* exception case: parent is duplivert */ - if ((ob->type == OB_MBALL) && (ob->parent->transflag & OB_DUPLIVERTS)) { + if ((object->type == OB_MBALL) && (object->parent->transflag & OB_DUPLIVERTS)) { //dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert"); } } -void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode_Type component_type, const char *component_subdata, - ListBase *constraints, RootPChanMap *root_map) +void DepsgraphRelationBuilder::build_constraints(ID *id, + eDepsNode_Type component_type, + const char *component_subdata, + ListBase *constraints, + RootPChanMap *root_map) { - OperationKey constraint_op_key(id, component_type, component_subdata, - (component_type == DEPSNODE_TYPE_BONE) ? DEG_OPCODE_BONE_CONSTRAINTS : DEG_OPCODE_TRANSFORM_CONSTRAINTS); - - /* add dependencies for each constraint in turn */ + OperationKey constraint_op_key( + id, + component_type, + component_subdata, + (component_type == DEG_NODE_TYPE_BONE) + ? DEG_OPCODE_BONE_CONSTRAINTS + : DEG_OPCODE_TRANSFORM_CONSTRAINTS); + /* Add dependencies for each constraint in turn. */ for (bConstraint *con = (bConstraint *)constraints->first; con; con = con->next) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); - - /* invalid constraint type... */ - if (cti == NULL) + /* Invalid constraint type. */ + if (cti == NULL) { continue; - - /* special case for camera tracking -- it doesn't use targets to define relations */ - // TODO: we can now represent dependencies in a much richer manner, so review how this is done... - if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER, CONSTRAINT_TYPE_OBJECTSOLVER)) { + } + /* Special case for camera tracking -- it doesn't use targets to + * define relations. + */ + /* TODO: we can now represent dependencies in a much richer manner, + * so review how this is done. + */ + if (ELEM(cti->type, + CONSTRAINT_TYPE_FOLLOWTRACK, + CONSTRAINT_TYPE_CAMERASOLVER, + CONSTRAINT_TYPE_OBJECTSOLVER)) + { bool depends_on_camera = false; - if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) { bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data; - - if (((data->clip) || (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0]) + if (((data->clip) || + (data->flag & FOLLOWTRACK_ACTIVECLIP)) && data->track[0]) + { depends_on_camera = true; - + } if (data->depth_ob) { - // DAG_RL_DATA_OB | DAG_RL_OB_OB - ComponentKey depth_key(&data->depth_ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(depth_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + ComponentKey depth_transform_key(&data->depth_ob->id, + DEG_NODE_TYPE_TRANSFORM); + ComponentKey depth_geometry_key(&data->depth_ob->id, + DEG_NODE_TYPE_GEOMETRY); + add_relation(depth_transform_key, constraint_op_key, cti->name); + add_relation(depth_geometry_key, constraint_op_key, cti->name); } } else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) { depends_on_camera = true; } - - if (depends_on_camera && scene->camera) { - // DAG_RL_DATA_OB | DAG_RL_OB_OB - ComponentKey camera_key(&scene->camera->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(camera_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + if (depends_on_camera && scene_->camera != NULL) { + ComponentKey camera_key(&scene_->camera->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(camera_key, constraint_op_key, cti->name); } - - /* TODO(sergey): This is more a TimeSource -> MovieClip -> Constraint dependency chain. */ + /* TODO(sergey): This is more a TimeSource -> MovieClip -> + * Constraint dependency chain. + */ TimeSourceKey time_src_key; - add_relation(time_src_key, constraint_op_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]"); + add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation"); } else if (cti->type == CONSTRAINT_TYPE_TRANSFORM_CACHE) { - /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint dependency chain. */ + /* TODO(kevin): This is more a TimeSource -> CacheFile -> Constraint + * dependency chain. + */ TimeSourceKey time_src_key; - add_relation(time_src_key, constraint_op_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]"); - + add_relation(time_src_key, constraint_op_key, "TimeSrc -> Animation"); bTransformCacheConstraint *data = (bTransformCacheConstraint *)con->data; - if (data->cache_file) { - ComponentKey cache_key(&data->cache_file->id, DEPSNODE_TYPE_CACHE); - add_relation(cache_key, constraint_op_key, DEPSREL_TYPE_CACHE, cti->name); + ComponentKey cache_key(&data->cache_file->id, DEG_NODE_TYPE_CACHE); + add_relation(cache_key, constraint_op_key, cti->name); } } else if (cti->get_constraint_targets) { ListBase targets = {NULL, NULL}; cti->get_constraint_targets(con, &targets); - - LINKLIST_FOREACH (bConstraintTarget *, ct, &targets) { + LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { if (ct->tar == NULL) { continue; } - - if (ELEM(con->type, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_SPLINEIK)) { - /* ignore IK constraints - these are handled separately (on pose level) */ + if (ELEM(con->type, + CONSTRAINT_TYPE_KINEMATIC, + CONSTRAINT_TYPE_SPLINEIK)) + { + /* Ignore IK constraints - these are handled separately + * (on pose level). + */ } - else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO)) { - /* these constraints require path geometry data... */ - ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_GEOMETRY_EVAL, cti->name); // XXX: type = geom_transform - // TODO: path dependency + else if (ELEM(con->type, + CONSTRAINT_TYPE_FOLLOWPATH, + CONSTRAINT_TYPE_CLAMPTO)) + { + /* These constraints require path geometry data. */ + ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, constraint_op_key, cti->name); + ComponentKey target_transform_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(target_transform_key, constraint_op_key, cti->name); } else if ((ct->tar->type == OB_ARMATURE) && (ct->subtarget[0])) { /* bone */ if (&ct->tar->id == id) { /* same armature */ eDepsOperation_Code target_key_opcode; - - /* Using "done" here breaks in-chain deps, while using "ready" here breaks most production rigs instead... - * So, we do a compromise here, and only do this when an IK chain conflict may occur + /* Using "done" here breaks in-chain deps, while using + * "ready" here breaks most production rigs instead. + * So, we do a compromise here, and only do this when an + * IK chain conflict may occur. */ - if (root_map->has_common_root(component_subdata, ct->subtarget)) { + if (root_map->has_common_root(component_subdata, + ct->subtarget)) + { target_key_opcode = DEG_OPCODE_BONE_READY; } else { target_key_opcode = DEG_OPCODE_BONE_DONE; } - - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_BONE, ct->subtarget, target_key_opcode); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_BONE, + ct->subtarget, + target_key_opcode); + add_relation(target_key, constraint_op_key, cti->name); } else { - /* different armature - we can safely use the result of that */ - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_BONE, ct->subtarget, DEG_OPCODE_BONE_DONE); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + /* Different armature - we can safely use the result + * of that. + */ + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_BONE, + ct->subtarget, + DEG_OPCODE_BONE_DONE); + add_relation(target_key, constraint_op_key, cti->name); } } - else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) { - /* vertex group */ - /* NOTE: for now, we don't need to represent vertex groups separately... */ - ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_GEOMETRY_EVAL, cti->name); - + else if (ELEM(ct->tar->type, OB_MESH, OB_LATTICE) && + (ct->subtarget[0])) + { + /* Vertex group. */ + /* NOTE: for now, we don't need to represent vertex groups + * separately. + */ + ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, constraint_op_key, cti->name); if (ct->tar->type == OB_MESH) { OperationDepsNode *node2 = find_operation_node(target_key); if (node2 != NULL) { @@ -719,39 +789,50 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode } else if (con->type == CONSTRAINT_TYPE_SHRINKWRAP) { /* Constraints which requires the target object surface. */ - ComponentKey target_key(&ct->tar->id, DEPSNODE_TYPE_GEOMETRY); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); - - /* NOTE: obdata eval now doesn't necessarily depend on the object's transform... */ - ComponentKey target_transform_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(target_transform_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + ComponentKey target_key(&ct->tar->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(target_key, constraint_op_key, cti->name); + /* NOTE: obdata eval now doesn't necessarily depend on the + * object's transform. + */ + ComponentKey target_transform_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(target_transform_key, constraint_op_key, cti->name); } else { - /* standard object relation */ + /* Standard object relation. */ // TODO: loc vs rot vs scale? if (&ct->tar->id == id) { /* Constraint targetting own object: - * - This case is fine IFF we're dealing with a bone constraint pointing to - * its own armature. In that case, it's just transform -> bone. - * - If however it is a real self targetting case, just make it depend on the - * previous constraint (or the pre-constraint state)... + * - This case is fine IFF we're dealing with a bone + * constraint pointing to its own armature. In that + * case, it's just transform -> bone. + * - If however it is a real self targetting case, just + * make it depend on the previous constraint (or the + * pre-constraint state). */ - if ((ct->tar->type == OB_ARMATURE) && (component_type == DEPSNODE_TYPE_BONE)) { - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + if ((ct->tar->type == OB_ARMATURE) && + (component_type == DEG_NODE_TYPE_BONE)) + { + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + add_relation(target_key, constraint_op_key, cti->name); } else { - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_LOCAL); + add_relation(target_key, constraint_op_key, cti->name); } } else { - /* normal object dependency */ - OperationKey target_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(target_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + /* Normal object dependency. */ + OperationKey target_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + add_relation(target_key, constraint_op_key, cti->name); } } - /* Constraints which needs world's matrix for transform. * TODO(sergey): More constraints here? */ @@ -762,44 +843,130 @@ void DepsgraphRelationBuilder::build_constraints(Scene *scene, ID *id, eDepsNode CONSTRAINT_TYPE_TRANSLIKE)) { /* TODO(sergey): Add used space check. */ - ComponentKey target_transform_key(&ct->tar->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(target_transform_key, constraint_op_key, DEPSREL_TYPE_TRANSFORM, cti->name); + ComponentKey target_transform_key(&ct->tar->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(target_transform_key, constraint_op_key, cti->name); } - } - - if (cti->flush_constraint_targets) + if (cti->flush_constraint_targets) { cti->flush_constraint_targets(con, &targets, 1); + } } } } void DepsgraphRelationBuilder::build_animdata(ID *id) { - AnimData *adt = BKE_animdata_from_id(id); + /* Animation curves and NLA. */ + build_animdata_curves(id); + /* Drivers. */ + build_animdata_drivers(id); +} - if (adt == NULL) +void DepsgraphRelationBuilder::build_animdata_curves(ID *id) +{ + AnimData *adt = BKE_animdata_from_id(id); + if (adt == NULL) { return; + } + if (adt->action == NULL && adt->nla_tracks.first == NULL) { + return; + } + /* Wire up dependency to time source. */ + ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION); + TimeSourceKey time_src_key; + add_relation(time_src_key, adt_key, "TimeSrc -> Animation"); + /* Get source operations. */ + DepsNode *node_from = get_node(adt_key); + BLI_assert(node_from != NULL); + if (node_from == NULL) { + return; + } + OperationDepsNode *operation_from = node_from->get_exit_operation(); + BLI_assert(operation_from != NULL); + /* Build relations from animation operation to properties it changes. */ + if (adt->action != NULL) { + build_animdata_curves_targets(id, adt_key, + operation_from, + &adt->action->curves); + } + LISTBASE_FOREACH(NlaTrack *, nlt, &adt->nla_tracks) { + build_animdata_nlastrip_targets(id, adt_key, + operation_from, + &nlt->strips); + } +} - ComponentKey adt_key(id, DEPSNODE_TYPE_ANIMATION); - - /* animation */ - if (adt->action || adt->nla_tracks.first) { - /* wire up dependency to time source */ - TimeSourceKey time_src_key; - add_relation(time_src_key, adt_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Animation]"); - - // XXX: Hook up specific update callbacks for special properties which may need it... +void DepsgraphRelationBuilder::build_animdata_curves_targets( + ID *id, ComponentKey &adt_key, + OperationDepsNode *operation_from, + ListBase *curves) +{ + /* Iterate over all curves and build relations. */ + PointerRNA id_ptr; + RNA_id_pointer_create(id, &id_ptr); + LISTBASE_FOREACH(FCurve *, fcu, curves) { + PointerRNA ptr; + PropertyRNA *prop; + int index; + if (!RNA_path_resolve_full(&id_ptr, fcu->rna_path, + &ptr, &prop, &index)) + { + continue; + } + DepsNode *node_to = graph_->find_node_from_pointer(&ptr, prop); + if (node_to == NULL) { + continue; + } + OperationDepsNode *operation_to = node_to->get_entry_operation(); + /* NOTE: Special case for bones, avoid relation from animation to + * each of the bones. Bone evaluation could only start from pose + * init anyway. + */ + if (operation_to->opcode == DEG_OPCODE_BONE_LOCAL) { + OperationKey pose_init_key(id, + DEG_NODE_TYPE_EVAL_POSE, + DEG_OPCODE_POSE_INIT); + add_relation(adt_key, pose_init_key, "Animation -> Prop", true); + continue; + } + graph_->add_new_relation(operation_from, operation_to, + "Animation -> Prop", + true); + } +} - // XXX: animdata "hierarchy" - top-level overrides need to go after lower-down +void DepsgraphRelationBuilder::build_animdata_nlastrip_targets( + ID *id, ComponentKey &adt_key, + OperationDepsNode *operation_from, + ListBase *strips) +{ + LISTBASE_FOREACH(NlaStrip *, strip, strips) { + if (strip->act != NULL) { + build_animdata_curves_targets(id, adt_key, + operation_from, + &strip->act->curves); + } + else if (strip->strips.first != NULL) { + build_animdata_nlastrip_targets(id, adt_key, + operation_from, + &strip->strips); + } } +} - /* drivers */ - LINKLIST_FOREACH (FCurve *, fcu, &adt->drivers) { +void DepsgraphRelationBuilder::build_animdata_drivers(ID *id) +{ + AnimData *adt = BKE_animdata_from_id(id); + if (adt == NULL) { + return; + } + ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION); + LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) { OperationKey driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); /* create the driver's relations to targets */ @@ -819,9 +986,10 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) */ if (fcu->array_index > 0) { FCurve *fcu_prev = NULL; - LINKLIST_FOREACH (FCurve *, fcu_candidate, &adt->drivers) { + LISTBASE_FOREACH (FCurve *, fcu_candidate, &adt->drivers) { /* Writing to different RNA paths is */ - if (!STREQ(fcu_candidate->rna_path, fcu->rna_path)) { + const char *rna_path = fcu->rna_path ? fcu->rna_path : ""; + if (!STREQ(fcu_candidate->rna_path, rna_path)) { continue; } /* We only do relation from previous fcurve to previous one. */ @@ -837,26 +1005,22 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) } if (fcu_prev != NULL) { OperationKey prev_driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu_prev->rna_path, + fcu_prev->rna_path ? fcu_prev->rna_path : "", fcu_prev->array_index); OperationKey driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); - add_relation(prev_driver_key, - driver_key, - DEPSREL_TYPE_OPERATION, - "[Driver Order]"); + add_relation(prev_driver_key, driver_key, "Driver Order"); } } /* prevent driver from occurring before own animation... */ if (adt->action || adt->nla_tracks.first) { - add_relation(adt_key, driver_key, DEPSREL_TYPE_OPERATION, - "[AnimData Before Drivers]"); + add_relation(adt_key, driver_key, "AnimData Before Drivers"); } } } @@ -865,249 +1029,224 @@ void DepsgraphRelationBuilder::build_driver(ID *id, FCurve *fcu) { ChannelDriver *driver = fcu->driver; OperationKey driver_key(id, - DEPSNODE_TYPE_PARAMETERS, + DEG_NODE_TYPE_PARAMETERS, DEG_OPCODE_DRIVER, - fcu->rna_path, + fcu->rna_path ? fcu->rna_path : "", fcu->array_index); - bPoseChannel *pchan = NULL; - - /* create dependency between driver and data affected by it */ - /* - direct property relationship... */ - //RNAPathKey affected_key(id, fcu->rna_path); - //add_relation(driver_key, affected_key, DEPSREL_TYPE_DRIVER, "[Driver -> Data] DepsRel"); - - /* driver -> data components (for interleaved evaluation - bones/constraints/modifiers) */ - // XXX: this probably should probably be moved out into a separate function - if (strstr(fcu->rna_path, "pose.bones[") != NULL) { - /* interleaved drivers during bone eval */ - // TODO: ideally, if this is for a constraint, it goes to said constraint - Object *ob = (Object *)id; - char *bone_name; - - bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones["); - pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - - if (bone_name) { - MEM_freeN(bone_name); - bone_name = NULL; - } - - if (pchan) { - OperationKey bone_key(id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); - add_relation(driver_key, bone_key, DEPSREL_TYPE_DRIVER, "[Driver -> Bone]"); - } - else { - fprintf(stderr, - "Couldn't find bone name for driver path - '%s'\n", - fcu->rna_path); - } + /* Driver -> data components (for interleaved evaluation + * bones/constraints/modifiers). + */ + build_driver_data(id, fcu); + /* Loop over variables to get the target relationships. */ + build_driver_variables(id, fcu); + /* It's quite tricky to detect if the driver actually depends on time or + * not, so for now we'll be quite conservative here about optimization and + * consider all python drivers to be depending on time. + */ + if ((driver->type == DRIVER_TYPE_PYTHON) && + python_driver_depends_on_time(driver)) + { + TimeSourceKey time_src_key; + add_relation(time_src_key, driver_key, "TimeSrc -> Driver"); } - else if (GS(id->name) == ID_AR && strstr(fcu->rna_path, "bones[")) { - /* drivers on armature-level bone settings (i.e. bbone stuff), - * which will affect the evaluation of corresponding pose bones - */ - IDDepsNode *arm_node = m_graph->find_id_node(id); - char *bone_name = BLI_str_quoted_substrN(fcu->rna_path, "bones["); +} +void DepsgraphRelationBuilder::build_driver_data(ID *id, FCurve *fcu) +{ + OperationKey driver_key(id, + DEG_NODE_TYPE_PARAMETERS, + DEG_OPCODE_DRIVER, + fcu->rna_path ? fcu->rna_path : "", + fcu->array_index); + const char *rna_path = fcu->rna_path ? fcu->rna_path : ""; + const RNAPathKey self_key(id, rna_path); + if (GS(id->name) == ID_AR && strstr(rna_path, "bones[")) { + /* Drivers on armature-level bone settings (i.e. bbone stuff), + * which will affect the evaluation of corresponding pose bones. + */ + IDDepsNode *arm_node = graph_->find_id_node(id); + char *bone_name = BLI_str_quoted_substrN(rna_path, "bones["); if (arm_node && bone_name) { - /* find objects which use this, and make their eval callbacks depend on this */ + /* Find objects which use this, and make their eval callbacks + * depend on this. + */ foreach (DepsRelation *rel, arm_node->outlinks) { IDDepsNode *to_node = (IDDepsNode *)rel->to; - - /* we only care about objects with pose data which use this... */ + /* We only care about objects with pose data which use this. */ if (GS(to_node->id->name) == ID_OB) { - Object *ob = (Object *)to_node->id; - bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, bone_name); // NOTE: ob->pose may be NULL - - if (pchan) { - OperationKey bone_key(&ob->id, DEPSNODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_LOCAL); - add_relation(driver_key, bone_key, DEPSREL_TYPE_DRIVER, "[Arm Bone -> Driver -> Bone]"); + Object *object = (Object *)to_node->id; + /* NOTE: object->pose may be NULL. */ + bPoseChannel *pchan = BKE_pose_channel_find_name( + object->pose, bone_name); + if (pchan != NULL) { + OperationKey bone_key(&object->id, + DEG_NODE_TYPE_BONE, + pchan->name, + DEG_OPCODE_BONE_LOCAL); + add_relation(driver_key, + bone_key, + "Arm Bone -> Driver -> Bone"); } } } - - /* free temp data */ + /* Free temp data. */ MEM_freeN(bone_name); bone_name = NULL; } else { fprintf(stderr, "Couldn't find armature bone name for driver path - '%s'\n", - fcu->rna_path); - } - } - else if (GS(id->name) == ID_OB && strstr(fcu->rna_path, "modifiers[")) { - /* modifier driver - connect directly to the modifier */ - char *modifier_name = BLI_str_quoted_substrN(fcu->rna_path, "modifiers["); - if (modifier_name) { - OperationKey modifier_key(id, - DEPSNODE_TYPE_GEOMETRY, - DEG_OPCODE_GEOMETRY_MODIFIER, - modifier_name); - if (has_node(modifier_key)) { - add_relation(driver_key, modifier_key, DEPSREL_TYPE_DRIVER, "[Driver -> Modifier]"); - } - else { - printf("Unexisting driver RNA path: %s\n", fcu->rna_path); - } - - MEM_freeN(modifier_name); + rna_path); } } - else if (GS(id->name) == ID_KE && strstr(fcu->rna_path, "key_blocks[")) { - /* shape key driver - hook into the base geometry operation */ - // XXX: double check where this points - Key *shape_key = (Key *)id; - - ComponentKey geometry_key(shape_key->from, DEPSNODE_TYPE_GEOMETRY); - add_relation(driver_key, geometry_key, DEPSREL_TYPE_DRIVER, "[Driver -> ShapeKey Geom]"); - } - else if (strstr(fcu->rna_path, "key_blocks[")) { - ComponentKey geometry_key(id, DEPSNODE_TYPE_GEOMETRY); - add_relation(driver_key, geometry_key, DEPSREL_TYPE_DRIVER, "[Driver -> ShapeKey Geom]"); - } else { - if (GS(id->name) == ID_OB) { - /* assume that driver affects a transform... */ - OperationKey local_transform_key(id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_LOCAL); - add_relation(driver_key, local_transform_key, DEPSREL_TYPE_OPERATION, "[Driver -> Transform]"); + RNAPathKey target_key(id, rna_path); + if (RNA_pointer_is_null(&target_key.ptr)) { + /* TODO(sergey): This would only mean that driver is broken. + * so we can't create relation anyway. However, we need to avoid + * adding drivers which are known to be buggy to a dependency + * graph, in order to save computational power. + */ } - else if (GS(id->name) == ID_KE) { - ComponentKey geometry_key(id, DEPSNODE_TYPE_GEOMETRY); - add_relation(driver_key, geometry_key, DEPSREL_TYPE_GEOMETRY_EVAL, "[Driver -> Shapekey Geometry]"); + else { + if (target_key.prop != NULL && + RNA_property_is_idprop(target_key.prop)) + { + OperationKey parameters_key(id, + DEG_NODE_TYPE_PARAMETERS, + DEG_OPCODE_PARAMETERS_EVAL); + add_relation(target_key, + parameters_key, + "Driver Target -> Properties"); + } + add_relation(driver_key, target_key, "Driver -> Target"); } } +} - /* ensure that affected prop's update callbacks will be triggered once done */ - // TODO: implement this once the functionality to add these links exists in RNA - // XXX: the data itself could also set this, if it were to be truly initialised later? +void DepsgraphRelationBuilder::build_driver_variables(ID *id, FCurve *fcu) +{ + ChannelDriver *driver = fcu->driver; + OperationKey driver_key(id, + DEG_NODE_TYPE_PARAMETERS, + DEG_OPCODE_DRIVER, + fcu->rna_path ? fcu->rna_path : "", + fcu->array_index); + const char *rna_path = fcu->rna_path ? fcu->rna_path : ""; + const RNAPathKey self_key(id, rna_path); - /* loop over variables to get the target relationships */ - LINKLIST_FOREACH (DriverVar *, dvar, &driver->variables) { - /* only used targets */ + LISTBASE_FOREACH (DriverVar *, dvar, &driver->variables) { + /* Only used targets. */ DRIVER_TARGETS_USED_LOOPER(dvar) { - if (dtar->id == NULL) + if (dtar->id == NULL) { continue; - - /* special handling for directly-named bones */ - if ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) { - Object *ob = (Object *)dtar->id; - bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, dtar->pchan_name); - if (target_pchan != NULL) { - /* get node associated with bone */ - // XXX: watch the space! - /* Some cases can't use final bone transform, for example: - * - Driving the bone with itself (addressed here) - * - Relations inside an IK chain (TODO?) - */ - if (dtar->id == id && - pchan != NULL && - STREQ(pchan->name, target_pchan->name)) - { - continue; - } - OperationKey target_key(dtar->id, DEPSNODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_DONE); - add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[Bone Target -> Driver]"); + } + /* Special handling for directly-named bones. */ + if ((dtar->flag & DTAR_FLAG_STRUCT_REF) && + (((Object *)dtar->id)->type == OB_ARMATURE) && + (dtar->pchan_name[0])) + { + Object *object = (Object *)dtar->id; + bPoseChannel *target_pchan = + BKE_pose_channel_find_name(object->pose, + dtar->pchan_name); + if (target_pchan == NULL) { + continue; + } + OperationKey variable_key(dtar->id, + DEG_NODE_TYPE_BONE, + target_pchan->name, + DEG_OPCODE_BONE_DONE); + if (is_same_bone_dependency(variable_key, self_key)) { + continue; } + add_relation(variable_key, driver_key, "Bone Target -> Driver"); } else if (dtar->flag & DTAR_FLAG_STRUCT_REF) { - /* get node associated with the object's transforms */ - OperationKey target_key(dtar->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_FINAL); - add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[Target -> Driver]"); + /* Get node associated with the object's transforms. */ + if (dtar->id == id) { + /* Ignore input dependency if we're driving properties of + * the same ID, otherwise we'll be ending up in a cyclic + * dependency here. + */ + continue; + } + OperationKey target_key(dtar->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_FINAL); + add_relation(target_key, driver_key, "Target -> Driver"); } - else if (dtar->rna_path && strstr(dtar->rna_path, "pose.bones[")) { - /* workaround for ensuring that local bone transforms don't end up - * having to wait for pose eval to finish (to prevent cycles) - */ - Object *ob = (Object *)dtar->id; - char *bone_name = BLI_str_quoted_substrN(dtar->rna_path, "pose.bones["); - bPoseChannel *target_pchan = BKE_pose_channel_find_name(ob->pose, bone_name); - if (bone_name) { - MEM_freeN(bone_name); - bone_name = NULL; + else if (dtar->rna_path) { + RNAPathKey variable_key(dtar->id, dtar->rna_path); + if (RNA_pointer_is_null(&variable_key.ptr)) { + continue; } - if (target_pchan) { - if (dtar->id == id && - pchan != NULL && - STREQ(pchan->name, target_pchan->name)) - { - continue; - } - OperationKey bone_key(dtar->id, DEPSNODE_TYPE_BONE, target_pchan->name, DEG_OPCODE_BONE_LOCAL); - add_relation(bone_key, driver_key, DEPSREL_TYPE_DRIVER, "[RNA Bone -> Driver]"); + if (is_same_bone_dependency(variable_key, self_key) || + is_same_nodetree_node_dependency(variable_key, self_key) || + is_same_shapekey_dependency(variable_key, self_key)) + { + continue; } + add_relation(variable_key, driver_key, "RNA Target -> Driver"); } else { if (dtar->id == id) { - /* Ignore input dependency if we're driving properties of the same ID, - * otherwise we'll be ending up in a cyclic dependency here. + /* Ignore input dependency if we're driving properties of + * the same ID, otherwise we'll be ending up in a cyclic + * dependency here. */ continue; } - /* resolve path to get node */ - RNAPathKey target_key(dtar->id, dtar->rna_path ? dtar->rna_path : ""); - add_relation(target_key, driver_key, DEPSREL_TYPE_DRIVER_TARGET, "[RNA Target -> Driver]"); + /* Resolve path to get node. */ + RNAPathKey target_key(dtar->id, + dtar->rna_path ? dtar->rna_path : ""); + add_relation(target_key, driver_key, "RNA Target -> Driver"); } } DRIVER_TARGETS_LOOPER_END } - - /* It's quite tricky to detect if the driver actually depends on time or not, - * so for now we'll be quite conservative here about optimization and consider - * all python drivers to be depending on time. - */ - if ((driver->type == DRIVER_TYPE_PYTHON) && - python_driver_depends_on_time(driver)) - { - TimeSourceKey time_src_key; - add_relation(time_src_key, driver_key, DEPSREL_TYPE_TIME, "[TimeSrc -> Driver]"); - } } void DepsgraphRelationBuilder::build_world(World *world) { - ID *world_id = &world->id; - if (world_id->tag & LIB_TAG_DOIT) { + if (built_map_.checkIsBuiltAndTag(world)) { return; } - world_id->tag |= LIB_TAG_DOIT; - - build_animdata(world_id); - + build_animdata(&world->id); /* TODO: other settings? */ - /* textures */ build_texture_stack(world->mtex); - /* world's nodetree */ - build_nodetree(world->nodetree); + if (world->nodetree != NULL) { + build_nodetree(world->nodetree); + ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_PARAMETERS); + ComponentKey world_key(&world->id, DEG_NODE_TYPE_PARAMETERS); + add_relation(ntree_key, world_key, "NTree->World Parameters"); + } } void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) { RigidBodyWorld *rbw = scene->rigidbody_world; - OperationKey init_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD); - OperationKey sim_key(&scene->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM); + OperationKey init_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_REBUILD); + OperationKey sim_key(&scene->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_SIM); /* rel between the two sim-nodes */ - add_relation(init_key, sim_key, DEPSREL_TYPE_OPERATION, "Rigidbody [Init -> SimStep]"); + add_relation(init_key, sim_key, "Rigidbody [Init -> SimStep]"); /* set up dependencies between these operations and other builtin nodes --------------- */ /* time dependency */ TimeSourceKey time_src_key; - add_relation(time_src_key, - init_key, - DEPSREL_TYPE_TIME, - "TimeSrc -> Rigidbody Reset/Rebuild (Optional)"); + add_relation(time_src_key, init_key, "TimeSrc -> Rigidbody Reset/Rebuild (Optional)"); /* objects - simulation participants */ if (rbw->group) { - LINKLIST_FOREACH (GroupObject *, go, &rbw->group->gobject) { - Object *ob = go->ob; - if (ob == NULL || ob->type != OB_MESH) { + LISTBASE_FOREACH (GroupObject *, go, &rbw->group->gobject) { + Object *object = go->ob; + if (object == NULL || object->type != OB_MESH) { continue; } @@ -1119,12 +1258,12 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) * XXX: there's probably a difference between passive and active * - passive don't change, so may need to know full transform... */ - OperationKey rbo_key(&ob->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); + OperationKey rbo_key(&object->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY); - eDepsOperation_Code trans_opcode = ob->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL; - OperationKey trans_op(&ob->id, DEPSNODE_TYPE_TRANSFORM, trans_opcode); + eDepsOperation_Code trans_opcode = object->parent ? DEG_OPCODE_TRANSFORM_PARENT : DEG_OPCODE_TRANSFORM_LOCAL; + OperationKey trans_op(&object->id, DEG_NODE_TYPE_TRANSFORM, trans_opcode); - add_relation(sim_key, rbo_key, DEPSREL_TYPE_COMPONENT_ORDER, "Rigidbody Sim Eval -> RBO Sync"); + add_relation(sim_key, rbo_key, "Rigidbody Sim Eval -> RBO Sync"); /* if constraints exist, those depend on the result of the rigidbody sim * - This allows constraints to modify the result of the sim (i.e. clamping) @@ -1134,14 +1273,11 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) * - Later, it might be good to include a constraint in the stack allowing us * to control whether rigidbody eval gets interleaved into the constraint stack */ - if (ob->constraints.first) { - OperationKey constraint_key(&ob->id, - DEPSNODE_TYPE_TRANSFORM, + if (object->constraints.first) { + OperationKey constraint_key(&object->id, + DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_CONSTRAINTS); - add_relation(rbo_key, - constraint_key, - DEPSREL_TYPE_COMPONENT_ORDER, - "RBO Sync -> Ob Constraints"); + add_relation(rbo_key, constraint_key, "RBO Sync -> Ob Constraints"); } else { /* Final object transform depends on rigidbody. @@ -1149,150 +1285,140 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene) * NOTE: Currently we consider final here an ubereval node. * If it is gone we'll need to reconsider relation here. */ - OperationKey uber_key(&ob->id, - DEPSNODE_TYPE_TRANSFORM, - DEG_OPCODE_OBJECT_UBEREVAL); - add_relation(rbo_key, - uber_key, - DEPSREL_TYPE_COMPONENT_ORDER, - "RBO Sync -> Uber (Temp)"); + OperationKey uber_key(&object->id, + DEG_NODE_TYPE_TRANSFORM, + DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL); + add_relation(rbo_key, uber_key, "RBO Sync -> Uber (Temp)"); } /* Needed to get correct base values. */ - add_relation(trans_op, - sim_key, - DEPSREL_TYPE_OPERATION, - "Base Ob Transform -> Rigidbody Sim Eval"); + add_relation(trans_op, sim_key, "Base Ob Transform -> Rigidbody Sim Eval"); } } /* constraints */ if (rbw->constraints) { - LINKLIST_FOREACH (GroupObject *, go, &rbw->constraints->gobject) { - Object *ob = go->ob; - if (ob == NULL || !ob->rigidbody_constraint) { + LISTBASE_FOREACH (GroupObject *, go, &rbw->constraints->gobject) { + Object *object = go->ob; + if (object == NULL || !object->rigidbody_constraint) { continue; } - RigidBodyCon *rbc = ob->rigidbody_constraint; + RigidBodyCon *rbc = object->rigidbody_constraint; /* final result of the constraint object's transform controls how the * constraint affects the physics sim for these objects */ - ComponentKey trans_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); - OperationKey ob1_key(&rbc->ob1->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); - OperationKey ob2_key(&rbc->ob2->id, DEPSNODE_TYPE_TRANSFORM, DEG_OPCODE_TRANSFORM_RIGIDBODY); + ComponentKey trans_key(&object->id, DEG_NODE_TYPE_TRANSFORM); + OperationKey ob1_key(&rbc->ob1->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY); + OperationKey ob2_key(&rbc->ob2->id, DEG_NODE_TYPE_TRANSFORM, DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY); /* - constrained-objects sync depends on the constraint-holder */ - add_relation(trans_key, ob1_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_1"); - add_relation(trans_key, ob2_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint -> RBC.Object_2"); + add_relation(trans_key, ob1_key, "RigidBodyConstraint -> RBC.Object_1"); + add_relation(trans_key, ob2_key, "RigidBodyConstraint -> RBC.Object_2"); /* - ensure that sim depends on this constraint's transform */ - add_relation(trans_key, sim_key, DEPSREL_TYPE_TRANSFORM, "RigidBodyConstraint Transform -> RB Simulation"); + add_relation(trans_key, sim_key, "RigidBodyConstraint Transform -> RB Simulation"); } } } -void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) +void DepsgraphRelationBuilder::build_particles(Object *object) { TimeSourceKey time_src_key; - OperationKey obdata_ubereval_key(&ob->id, - DEPSNODE_TYPE_GEOMETRY, + OperationKey obdata_ubereval_key(&object->id, + DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL); + OperationKey eval_init_key(&object->id, + DEG_NODE_TYPE_EVAL_PARTICLES, + DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT); - /* particle systems */ - LINKLIST_FOREACH (ParticleSystem *, psys, &ob->particlesystem) { + /* Particle systems. */ + LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) { ParticleSettings *part = psys->part; - - /* particle settings */ + /* Animation of particle settings, */ build_animdata(&part->id); - - /* this particle system */ - OperationKey psys_key(&ob->id, DEPSNODE_TYPE_EVAL_PARTICLES, DEG_OPCODE_PSYS_EVAL, psys->name); - - /* XXX: if particle system is later re-enabled, we must do full rebuild? */ - if (!psys_check_enabled(ob, psys, G.is_rendering)) - continue; - - /* TODO(sergey): Are all particle systems depends on time? - * Hair without dynamics i.e. - */ - add_relation(time_src_key, psys_key, - DEPSREL_TYPE_TIME, - "TimeSrc -> PSys"); - + /* This particle system. */ + OperationKey psys_key(&object->id, + DEG_NODE_TYPE_EVAL_PARTICLES, + DEG_OPCODE_PARTICLE_SYSTEM_EVAL, + psys->name); + add_relation(eval_init_key, psys_key, "Init -> PSys"); /* TODO(sergey): Currently particle update is just a placeholder, * hook it to the ubereval node so particle system is getting updated * on playback. */ - add_relation(psys_key, - obdata_ubereval_key, - DEPSREL_TYPE_OPERATION, - "PSys -> UberEval"); - -#if 0 - if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) { - LINKLIST_FOREACH (ParticleTarget *, pt, &psys->targets) { - if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys - 1)) { - node2 = dag_get_node(dag, pt->ob); - dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Targets"); - } - } - } - - if (part->ren_as == PART_DRAW_OB && part->dup_ob) { - node2 = dag_get_node(dag, part->dup_ob); - /* note that this relation actually runs in the wrong direction, the problem - * is that dupli system all have this (due to parenting), and the render - * engine instancing assumes particular ordering of objects in list */ - dag_add_relation(dag, node, node2, DAG_RL_OB_OB, "Particle Object Visualization"); - if (part->dup_ob->type == OB_MBALL) - dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA, "Particle Object Visualization"); - } - - if (part->ren_as == PART_DRAW_GR && part->dup_group) { - LINKLIST_FOREACH (GroupObject *, go, &part->dup_group->gobject) { - node2 = dag_get_node(dag, go->ob); - dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Particle Group Visualization"); - } - } -#endif - - /* collisions */ + add_relation(psys_key, obdata_ubereval_key, "PSys -> UberEval"); + /* Collisions */ if (part->type != PART_HAIR) { - add_collision_relations(psys_key, scene, ob, part->collision_group, ob->lay, true, "Particle Collision"); + add_collision_relations(psys_key, + scene_, + object, + part->collision_group, + object->lay, + true, + "Particle Collision"); } - else if ((psys->flag & PSYS_HAIR_DYNAMICS) && psys->clmd && psys->clmd->coll_parms) { - add_collision_relations(psys_key, scene, ob, psys->clmd->coll_parms->group, ob->lay | scene->lay, true, "Hair Collision"); + else if ((psys->flag & PSYS_HAIR_DYNAMICS) && + psys->clmd && psys->clmd->coll_parms) + { + add_collision_relations(psys_key, + scene_, + object, + psys->clmd->coll_parms->group, + object->lay | scene_->lay, + true, + "Hair Collision"); } - - /* effectors */ - add_forcefield_relations(psys_key, scene, ob, psys, part->effector_weights, part->type == PART_HAIR, "Particle Field"); - - /* boids */ + /* Effectors. */ + add_forcefield_relations(psys_key, + scene_, + object, + psys, + part->effector_weights, + part->type == PART_HAIR, + "Particle Field"); + /* Boids. */ if (part->boids) { - LINKLIST_FOREACH (BoidState *, state, &part->boids->states) { - LINKLIST_FOREACH (BoidRule *, rule, &state->rules) { + LISTBASE_FOREACH (BoidState *, state, &part->boids->states) { + LISTBASE_FOREACH (BoidRule *, rule, &state->rules) { Object *ruleob = NULL; - if (rule->type == eBoidRuleType_Avoid) + if (rule->type == eBoidRuleType_Avoid) { ruleob = ((BoidRuleGoalAvoid *)rule)->ob; - else if (rule->type == eBoidRuleType_FollowLeader) + } + else if (rule->type == eBoidRuleType_FollowLeader) { ruleob = ((BoidRuleFollowLeader *)rule)->ob; - + } if (ruleob) { - ComponentKey ruleob_key(&ruleob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(ruleob_key, psys_key, DEPSREL_TYPE_TRANSFORM, "Boid Rule"); + ComponentKey ruleob_key(&ruleob->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(ruleob_key, psys_key, "Boid Rule"); } } } } - if (part->ren_as == PART_DRAW_OB && part->dup_ob) { - ComponentKey dup_ob_key(&part->dup_ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(dup_ob_key, - psys_key, - DEPSREL_TYPE_TRANSFORM, - "Particle Object Visualization"); + switch (part->ren_as) { + case PART_DRAW_OB: + if (part->dup_ob != NULL) { + /* Make sure object's relations are all built. */ + build_object(part->dup_ob); + /* Build relation for the particle visualization. */ + build_particles_visualization_object(object, + psys, + part->dup_ob); + } + break; + case PART_DRAW_GR: + if (part->dup_group != NULL) { + build_group(NULL, part->dup_group); + LISTBASE_FOREACH (GroupObject *, go, &part->dup_group->gobject) { + build_particles_visualization_object(object, + psys, + go->ob); + } + } + break; } } @@ -1302,20 +1428,52 @@ void DepsgraphRelationBuilder::build_particles(Scene *scene, Object *ob) * TODO(sergey): This relation should be altered once real granular update * is implemented. */ - ComponentKey transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(transform_key, - obdata_ubereval_key, - DEPSREL_TYPE_GEOMETRY_EVAL, - "Partcile Eval"); + ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(transform_key, obdata_ubereval_key, "Partcile Eval"); /* pointcache */ // TODO... } +void DepsgraphRelationBuilder::build_particles_visualization_object( + Object *object, + ParticleSystem *psys, + Object *draw_object) +{ + OperationKey psys_key(&object->id, + DEG_NODE_TYPE_EVAL_PARTICLES, + DEG_OPCODE_PARTICLE_SYSTEM_EVAL, + psys->name); + OperationKey obdata_ubereval_key(&object->id, + DEG_NODE_TYPE_GEOMETRY, + DEG_OPCODE_GEOMETRY_UBEREVAL); + ComponentKey dup_ob_key(&draw_object->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(dup_ob_key, psys_key, "Particle Object Visualization"); + if (draw_object->type == OB_MBALL) { + ComponentKey dup_geometry_key(&draw_object->id, DEG_NODE_TYPE_GEOMETRY); + add_relation(obdata_ubereval_key, + dup_geometry_key, + "Particle MBall Visualization"); + } +} + +void DepsgraphRelationBuilder::build_cloth(Object *object, + ModifierData * /*md*/) +{ + OperationKey cache_key(&object->id, + DEG_NODE_TYPE_CACHE, + DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER); + /* Cache component affects on modifier. */ + OperationKey modifier_key(&object->id, + DEG_NODE_TYPE_GEOMETRY, + DEG_OPCODE_GEOMETRY_UBEREVAL); + add_relation(cache_key, modifier_key, "Cloth Cache -> Cloth"); +} + /* Shapekeys */ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) { - ComponentKey obdata_key(obdata, DEPSNODE_TYPE_GEOMETRY); + ComponentKey obdata_key(obdata, DEG_NODE_TYPE_GEOMETRY); /* attach animdata to geometry */ build_animdata(&key->id); @@ -1323,8 +1481,8 @@ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) if (key->adt) { // TODO: this should really be handled in build_animdata, since many of these cases will need it if (key->adt->action || key->adt->nla_tracks.first) { - ComponentKey adt_key(&key->id, DEPSNODE_TYPE_ANIMATION); - add_relation(adt_key, obdata_key, DEPSREL_TYPE_OPERATION, "Animation"); + ComponentKey adt_key(&key->id, DEG_NODE_TYPE_ANIMATION); + add_relation(adt_key, obdata_key, "Animation"); } /* NOTE: individual shapekey drivers are handled above already */ @@ -1332,8 +1490,8 @@ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) /* attach to geometry */ // XXX: aren't shapekeys now done as a pseudo-modifier on object? - //ComponentKey key_key(&key->id, DEPSNODE_TYPE_GEOMETRY); // FIXME: this doesn't exist - //add_relation(key_key, obdata_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Shapekeys"); + //ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY); // FIXME: this doesn't exist + //add_relation(key_key, obdata_key, "Shapekeys"); } /** @@ -1356,86 +1514,58 @@ void DepsgraphRelationBuilder::build_shapekeys(ID *obdata, Key *key) * re-evaluation of the individual instances of this geometry. */ // TODO: Materials and lighting should probably get their own component, instead of being lumped under geometry? -void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Object *ob) +void DepsgraphRelationBuilder::build_obdata_geom(Object *object) { - ID *obdata = (ID *)ob->data; + ID *obdata = (ID *)object->data; /* Init operation of object-level geometry evaluation. */ - OperationKey geom_init_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Init"); + OperationKey geom_init_key(&object->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Init"); /* get nodes for result of obdata's evaluation, and geometry evaluation on object */ - ComponentKey obdata_geom_key(obdata, DEPSNODE_TYPE_GEOMETRY); - ComponentKey geom_key(&ob->id, DEPSNODE_TYPE_GEOMETRY); + ComponentKey obdata_geom_key(obdata, DEG_NODE_TYPE_GEOMETRY); + ComponentKey geom_key(&object->id, DEG_NODE_TYPE_GEOMETRY); /* link components to each other */ - add_relation(obdata_geom_key, geom_key, DEPSREL_TYPE_DATABLOCK, "Object Geometry Base Data"); + add_relation(obdata_geom_key, geom_key, "Object Geometry Base Data"); /* Modifiers */ - if (ob->modifiers.first) { - OperationKey prev_mod_key; - - LINKLIST_FOREACH (ModifierData *, md, &ob->modifiers) { + if (object->modifiers.first != NULL) { + OperationKey obdata_ubereval_key(&object->id, + DEG_NODE_TYPE_GEOMETRY, + DEG_OPCODE_GEOMETRY_UBEREVAL); + ModifierUpdateDepsgraphContext ctx = {}; + ctx.scene = scene_; + ctx.object = object; + + LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) { const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type); - OperationKey mod_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_MODIFIER, md->name); - - if (md->prev) { - /* Stack relation: modifier depends on previous modifier in the stack */ - add_relation(prev_mod_key, mod_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Modifier Stack"); - } - else { - /* Stack relation: first modifier depends on the geometry. */ - add_relation(geom_init_key, mod_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Modifier Stack"); - } - if (mti->updateDepsgraph) { - DepsNodeHandle handle = create_node_handle(mod_key); - mti->updateDepsgraph( - md, - bmain, - scene, - ob, - reinterpret_cast< ::DepsNodeHandle* >(&handle)); + DepsNodeHandle handle = create_node_handle(obdata_ubereval_key); + ctx.node = reinterpret_cast< ::DepsNodeHandle* >(&handle); + mti->updateDepsgraph(md, &ctx); } - - if (BKE_object_modifier_use_time(ob, md)) { + if (BKE_object_modifier_use_time(object, md)) { TimeSourceKey time_src_key; - add_relation(time_src_key, mod_key, DEPSREL_TYPE_TIME, "Time Source"); - - /* Hacky fix for T45633 (Animated modifiers aren't updated) - * - * This check works because BKE_object_modifier_use_time() tests - * for either the modifier needing time, or that it is animated. - */ - /* XXX: Remove this hack when these links are added as part of build_animdata() instead */ - if (modifier_dependsOnTime(md) == false && needs_animdata_node(&ob->id)) { - ComponentKey animation_key(&ob->id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, mod_key, DEPSREL_TYPE_OPERATION, "Modifier Animation"); - } + add_relation(time_src_key, obdata_ubereval_key, "Time Source"); + } + if (md->type == eModifierType_Cloth) { + build_cloth(object, md); } - - prev_mod_key = mod_key; } } /* materials */ - if (ob->totcol != 0) { - ComponentKey object_shading_key(&ob->id, DEPSNODE_TYPE_SHADING); - for (int a = 1; a <= ob->totcol; a++) { - Material *ma = give_current_material(ob, a); + if (object->totcol) { + for (int a = 1; a <= object->totcol; a++) { + Material *ma = give_current_material(object, a); if (ma != NULL) { build_material(ma); - ComponentKey material_shading_key(&ma->id, - DEPSNODE_TYPE_SHADING); - add_relation(material_shading_key, - object_shading_key, - DEPSREL_TYPE_UPDATE, - "Object Shading"); } } } /* geometry collision */ - if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_LATTICE)) { + if (ELEM(object->type, OB_MESH, OB_CURVE, OB_LATTICE)) { // add geometry collider relations } @@ -1443,45 +1573,57 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje * * TODO(sergey): Get rid of this node. */ - if (ob->type != OB_ARMATURE) { + if (object->type != OB_ARMATURE) { /* Armatures does no longer require uber node. */ - OperationKey obdata_ubereval_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL); - if (ob->modifiers.last) { - ModifierData *md = (ModifierData *)ob->modifiers.last; - OperationKey mod_key(&ob->id, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_MODIFIER, md->name); - add_relation(mod_key, obdata_ubereval_key, DEPSREL_TYPE_OPERATION, "Object Geometry UberEval"); - } - else { - add_relation(geom_init_key, obdata_ubereval_key, DEPSREL_TYPE_OPERATION, "Object Geometry UberEval"); - } + OperationKey obdata_ubereval_key(&object->id, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_GEOMETRY_UBEREVAL); + add_relation(geom_init_key, obdata_ubereval_key, "Object Geometry UberEval"); } - if (obdata->tag & LIB_TAG_DOIT) { + if (built_map_.checkIsBuiltAndTag(obdata)) { return; } - obdata->tag |= LIB_TAG_DOIT; /* Link object data evaluation node to exit operation. */ - OperationKey obdata_geom_eval_key(obdata, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Geometry Eval"); - OperationKey obdata_geom_done_key(obdata, DEPSNODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Done"); - add_relation(obdata_geom_eval_key, obdata_geom_done_key, DEPSREL_TYPE_DATABLOCK, "ObData Geom Eval Done"); + OperationKey obdata_geom_eval_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Geometry Eval"); + OperationKey obdata_geom_done_key(obdata, DEG_NODE_TYPE_GEOMETRY, DEG_OPCODE_PLACEHOLDER, "Eval Done"); + add_relation(obdata_geom_eval_key, obdata_geom_done_key, "ObData Geom Eval Done"); /* type-specific node/links */ - switch (ob->type) { + switch (object->type) { case OB_MESH: + /* NOTE: This is compatibility code to support particle systems + * + * for viewport being properly rendered in final render mode. + * This relation is similar to what dag_object_time_update_flags() + * was doing for mesh objects with particle system. + * + * Ideally we need to get rid of this relation. + */ + if (object_particles_depends_on_time(object)) { + TimeSourceKey time_key; + OperationKey obdata_ubereval_key(&object->id, + DEG_NODE_TYPE_GEOMETRY, + DEG_OPCODE_GEOMETRY_UBEREVAL); + add_relation(time_key, obdata_ubereval_key, "Legacy particle time"); + } break; case OB_MBALL: { - Object *mom = BKE_mball_basis_find(scene, ob); - + Object *mom = BKE_mball_basis_find(scene_, object); + ComponentKey mom_geom_key(&mom->id, DEG_NODE_TYPE_GEOMETRY); /* motherball - mom depends on children! */ - if (mom != ob) { - /* non-motherball -> cannot be directly evaluated! */ - ComponentKey mom_key(&mom->id, DEPSNODE_TYPE_GEOMETRY); - ComponentKey transform_key(&ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(geom_key, mom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Metaball Motherball"); - add_relation(transform_key, mom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Metaball Motherball"); + if (mom == object) { + ComponentKey mom_transform_key(&mom->id, + DEG_NODE_TYPE_TRANSFORM); + add_relation(mom_transform_key, + mom_geom_key, + "Metaball Motherball Transform -> Geometry"); + } + else { + ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(geom_key, mom_geom_key, "Metaball Motherball"); + add_relation(transform_key, mom_geom_key, "Metaball Motherball"); } break; } @@ -1494,20 +1636,20 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje /* curve's dependencies */ // XXX: these needs geom data, but where is geom stored? if (cu->bevobj) { - ComponentKey bevob_key(&cu->bevobj->id, DEPSNODE_TYPE_GEOMETRY); - build_object(bmain, scene, cu->bevobj); - add_relation(bevob_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Curve Bevel"); + ComponentKey bevob_key(&cu->bevobj->id, DEG_NODE_TYPE_GEOMETRY); + build_object(cu->bevobj); + add_relation(bevob_key, geom_key, "Curve Bevel"); } if (cu->taperobj) { - ComponentKey taperob_key(&cu->taperobj->id, DEPSNODE_TYPE_GEOMETRY); - build_object(bmain, scene, cu->taperobj); - add_relation(taperob_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Curve Taper"); + ComponentKey taperob_key(&cu->taperobj->id, DEG_NODE_TYPE_GEOMETRY); + build_object(cu->taperobj); + add_relation(taperob_key, geom_key, "Curve Taper"); } - if (ob->type == OB_FONT) { + if (object->type == OB_FONT) { if (cu->textoncurve) { - ComponentKey textoncurve_key(&cu->textoncurve->id, DEPSNODE_TYPE_GEOMETRY); - build_object(bmain, scene, cu->textoncurve); - add_relation(textoncurve_key, geom_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Text on Curve"); + ComponentKey textoncurve_key(&cu->textoncurve->id, DEG_NODE_TYPE_GEOMETRY); + build_object(cu->textoncurve); + add_relation(textoncurve_key, geom_key, "Text on Curve"); } } break; @@ -1525,180 +1667,140 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje } /* ShapeKeys */ - Key *key = BKE_key_from_object(ob); + Key *key = BKE_key_from_object(object); if (key) { build_shapekeys(obdata, key); } - - if (needs_animdata_node(obdata)) { - ComponentKey animation_key(obdata, DEPSNODE_TYPE_ANIMATION); - ComponentKey parameters_key(obdata, DEPSNODE_TYPE_PARAMETERS); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Geom Parameters"); - /* Evaluation usually depends on animation. - * TODO(sergey): Need to re-hook it after granular update is implemented.. - */ - add_relation(animation_key, obdata_geom_eval_key, DEPSREL_TYPE_GEOMETRY_EVAL, "Animation"); - } } /* Cameras */ // TODO: Link scene-camera links in somehow... -void DepsgraphRelationBuilder::build_camera(Object *ob) +void DepsgraphRelationBuilder::build_camera(Object *object) { - Camera *cam = (Camera *)ob->data; - ID *camera_id = &cam->id; - if (camera_id->tag & LIB_TAG_DOIT) { + Camera *camera = (Camera *)object->data; + if (built_map_.checkIsBuiltAndTag(camera)) { return; } - camera_id->tag |= LIB_TAG_DOIT; - - ComponentKey parameters_key(camera_id, DEPSNODE_TYPE_PARAMETERS); - - if (needs_animdata_node(camera_id)) { - ComponentKey animation_key(camera_id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Camera Parameters"); - } - /* DOF */ - if (cam->dof_ob) { - ComponentKey ob_param_key(&ob->id, DEPSNODE_TYPE_PARAMETERS); - ComponentKey dof_ob_key(&cam->dof_ob->id, DEPSNODE_TYPE_TRANSFORM); - add_relation(dof_ob_key, ob_param_key, DEPSREL_TYPE_TRANSFORM, "Camera DOF"); + if (camera->dof_ob) { + ComponentKey ob_param_key(&object->id, DEG_NODE_TYPE_PARAMETERS); + ComponentKey dof_ob_key(&camera->dof_ob->id, DEG_NODE_TYPE_TRANSFORM); + add_relation(dof_ob_key, ob_param_key, "Camera DOF"); } } /* Lamps */ -void DepsgraphRelationBuilder::build_lamp(Object *ob) +void DepsgraphRelationBuilder::build_lamp(Object *object) { - Lamp *la = (Lamp *)ob->data; - ID *lamp_id = &la->id; - if (lamp_id->tag & LIB_TAG_DOIT) { + Lamp *lamp = (Lamp *)object->data; + if (built_map_.checkIsBuiltAndTag(lamp)) { return; } - lamp_id->tag |= LIB_TAG_DOIT; - - ComponentKey parameters_key(lamp_id, DEPSNODE_TYPE_PARAMETERS); - - if (needs_animdata_node(lamp_id)) { - ComponentKey animation_key(lamp_id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Lamp Parameters"); - } - /* lamp's nodetree */ - if (la->nodetree) { - build_nodetree(la->nodetree); - ComponentKey nodetree_key(&la->nodetree->id, DEPSNODE_TYPE_PARAMETERS); - add_relation(nodetree_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "NTree->Lamp Parameters"); + if (lamp->nodetree != NULL) { + build_nodetree(lamp->nodetree); + ComponentKey parameters_key(&lamp->id, DEG_NODE_TYPE_PARAMETERS); + ComponentKey nodetree_key(&lamp->nodetree->id, DEG_NODE_TYPE_PARAMETERS); + add_relation(nodetree_key, parameters_key, "NTree->Lamp Parameters"); } - /* textures */ - build_texture_stack(la->mtex); + build_texture_stack(lamp->mtex); } void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree) { - if (!ntree) + if (ntree == NULL) { return; - - ID *ntree_id = &ntree->id; - - build_animdata(ntree_id); - - OperationKey parameters_key(ntree_id, - DEPSNODE_TYPE_PARAMETERS, - DEG_OPCODE_PLACEHOLDER, - "Parameters Eval"); - + } + if (built_map_.checkIsBuiltAndTag(ntree)) { + return; + } + build_animdata(&ntree->id); + OperationKey parameters_key(&ntree->id, + DEG_NODE_TYPE_PARAMETERS, + DEG_OPCODE_PARAMETERS_EVAL); /* nodetree's nodes... */ - LINKLIST_FOREACH (bNode *, bnode, &ntree->nodes) { - if (bnode->id) { - if (GS(bnode->id->name) == ID_MA) { - build_material((Material *)bnode->id); - } - else if (bnode->type == ID_TE) { - build_texture((Tex *)bnode->id); - } - else if (bnode->type == NODE_GROUP) { - bNodeTree *group_ntree = (bNodeTree *)bnode->id; - if ((group_ntree->id.tag & LIB_TAG_DOIT) == 0) { - build_nodetree(group_ntree); - group_ntree->id.tag |= LIB_TAG_DOIT; - } - OperationKey group_parameters_key(&group_ntree->id, - DEPSNODE_TYPE_PARAMETERS, - DEG_OPCODE_PLACEHOLDER, - "Parameters Eval"); - add_relation(group_parameters_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "Group Node"); - } + LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) { + ID *id = bnode->id; + if (id == NULL) { + continue; + } + ID_Type id_type = GS(id->name); + if (id_type == ID_MA) { + build_material((Material *)bnode->id); + } + else if (id_type == ID_TE) { + build_texture((Tex *)bnode->id); + } + else if (id_type == ID_IM) { + /* nothing for now. */ + } + else if (id_type == ID_OB) { + build_object((Object *)id); + } + else if (id_type == ID_SCE) { + /* Scenes are used by compositor trees, and handled by render + * pipeline. No need to build dependencies for them here. + */ + } + else if (id_type == ID_TXT) { + /* Ignore script nodes. */ + } + else if (bnode->type == NODE_GROUP) { + bNodeTree *group_ntree = (bNodeTree *)id; + build_nodetree(group_ntree); + OperationKey group_parameters_key(&group_ntree->id, + DEG_NODE_TYPE_PARAMETERS, + DEG_OPCODE_PARAMETERS_EVAL); + add_relation(group_parameters_key, parameters_key, "Group Node"); + } + else { + BLI_assert(!"Unknown ID type used for node"); } - } - - if (needs_animdata_node(ntree_id)) { - ComponentKey animation_key(ntree_id, DEPSNODE_TYPE_ANIMATION); - add_relation(animation_key, parameters_key, - DEPSREL_TYPE_COMPONENT_ORDER, "NTree Parameters"); } } /* Recursively build graph for material */ -void DepsgraphRelationBuilder::build_material(Material *ma) +void DepsgraphRelationBuilder::build_material(Material *material) { - ID *ma_id = &ma->id; - if (ma_id->tag & LIB_TAG_DOIT) { + if (built_map_.checkIsBuiltAndTag(material)) { return; } - ma_id->tag |= LIB_TAG_DOIT; - /* animation */ - build_animdata(ma_id); - + build_animdata(&material->id); /* textures */ - build_texture_stack(ma->mtex); - + build_texture_stack(material->mtex); /* material's nodetree */ - if (ma->nodetree != NULL) { - build_nodetree(ma->nodetree); - OperationKey ntree_key(&ma->nodetree->id, - DEPSNODE_TYPE_PARAMETERS, - DEG_OPCODE_PLACEHOLDER, - "Parameters Eval"); - OperationKey material_key(&ma->id, - DEPSNODE_TYPE_SHADING, + if (material->nodetree != NULL) { + build_nodetree(material->nodetree); + OperationKey ntree_key(&material->nodetree->id, + DEG_NODE_TYPE_PARAMETERS, + DEG_OPCODE_PARAMETERS_EVAL); + OperationKey material_key(&material->id, + DEG_NODE_TYPE_SHADING, DEG_OPCODE_PLACEHOLDER, "Material Update"); - add_relation(ntree_key, material_key, - DEPSREL_TYPE_UPDATE, "Material's NTree"); + add_relation(ntree_key, material_key, "Material's NTree"); } } /* Recursively build graph for texture */ -void DepsgraphRelationBuilder::build_texture(Tex *tex) +void DepsgraphRelationBuilder::build_texture(Tex *texture) { - ID *tex_id = &tex->id; - if (tex_id->tag & LIB_TAG_DOIT) { + if (built_map_.checkIsBuiltAndTag(texture)) { return; } - tex_id->tag |= LIB_TAG_DOIT; - /* texture itself */ - build_animdata(tex_id); - + build_animdata(&texture->id); /* texture's nodetree */ - build_nodetree(tex->nodetree); + build_nodetree(texture->nodetree); } /* Texture-stack attached to some shading datablock */ void DepsgraphRelationBuilder::build_texture_stack(MTex **texture_stack) { - int i; - /* for now assume that all texture-stacks have same number of max items */ - for (i = 0; i < MAX_MTEX; i++) { + for (int i = 0; i < MAX_MTEX; i++) { MTex *mtex = texture_stack[i]; if (mtex && mtex->tex) build_texture(mtex->tex); @@ -1719,24 +1821,26 @@ void DepsgraphRelationBuilder::build_gpencil(bGPdata *gpd) // TODO: parent object (when that feature is implemented) } -bool DepsgraphRelationBuilder::needs_animdata_node(ID *id) +void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file) { - AnimData *adt = BKE_animdata_from_id(id); - if (adt != NULL) { - return (adt->action != NULL) || (adt->nla_tracks.first != NULL); - } - return false; -} - -void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file) { /* Animation. */ build_animdata(&cache_file->id); } void DepsgraphRelationBuilder::build_mask(Mask *mask) { - /* Animation. */ - build_animdata(&mask->id); + ID *mask_id = &mask->id; + /* F-Curve animation. */ + build_animdata(mask_id); + /* Own mask animation. */ + OperationKey mask_animation_key(mask_id, + DEG_NODE_TYPE_ANIMATION, + DEG_OPCODE_MASK_ANIMATION); + TimeSourceKey time_src_key; + add_relation(time_src_key, mask_animation_key, "TimeSrc -> Mask Animation"); + /* Final mask evaluation. */ + ComponentKey parameters_key(mask_id, DEG_NODE_TYPE_PARAMETERS); + add_relation(mask_animation_key, parameters_key, "Mask Animation -> Mask Eval"); } void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip) @@ -1745,4 +1849,43 @@ void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip) build_animdata(&clip->id); } +/* **** ID traversal callbacks functions **** */ + +void DepsgraphRelationBuilder::modifier_walk(void *user_data, + struct Object * /*object*/, + struct ID **idpoin, + int /*cb_flag*/) +{ + BuilderWalkUserData *data = (BuilderWalkUserData *)user_data; + ID *id = *idpoin; + if (id == NULL) { + return; + } + switch (GS(id->name)) { + case ID_OB: + data->builder->build_object((Object *)id); + break; + case ID_TE: + data->builder->build_texture((Tex *)id); + break; + default: + /* pass */ + break; + } +} + +void DepsgraphRelationBuilder::constraint_walk(bConstraint * /*con*/, + ID **idpoin, + bool /*is_reference*/, + void *user_data) +{ + BuilderWalkUserData *data = (BuilderWalkUserData *)user_data; + if (*idpoin) { + ID *id = *idpoin; + if (GS(id->name) == ID_OB) { + data->builder->build_object((Object *)id); + } + } +} + } // namespace DEG |