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 | 167 |
1 files changed, 137 insertions, 30 deletions
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 40fbfbc2b99..f5a131a1731 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -28,14 +28,12 @@ #include <cstring> /* required for STREQ later on. */ #include <stdio.h> #include <stdlib.h> -#include <unordered_set> #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" #include "BLI_utildefines.h" -extern "C" { #include "DNA_action_types.h" #include "DNA_anim_types.h" #include "DNA_armature_types.h" @@ -62,6 +60,7 @@ extern "C" { #include "DNA_rigidbody_types.h" #include "DNA_scene_types.h" #include "DNA_sequence_types.h" +#include "DNA_simulation_types.h" #include "DNA_sound_types.h" #include "DNA_speaker_types.h" #include "DNA_texture_types.h" @@ -69,15 +68,16 @@ extern "C" { #include "DNA_world_types.h" #include "BKE_action.h" -#include "BKE_animsys.h" +#include "BKE_anim_data.h" #include "BKE_armature.h" #include "BKE_collection.h" #include "BKE_collision.h" #include "BKE_constraint.h" #include "BKE_curve.h" #include "BKE_effect.h" -#include "BKE_fcurve.h" +#include "BKE_fcurve_driver.h" #include "BKE_gpencil_modifier.h" +#include "BKE_idprop.h" #include "BKE_image.h" #include "BKE_key.h" #include "BKE_layer.h" @@ -98,7 +98,6 @@ extern "C" { #include "RNA_access.h" #include "RNA_types.h" -} /* extern "C" */ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" @@ -121,8 +120,6 @@ extern "C" { namespace DEG { -using std::unordered_set; - /* ***************** */ /* Relations Builder */ @@ -436,7 +433,7 @@ void DepsgraphRelationBuilder::add_particle_forcefield_relations(const Operation } /* Smoke flow relations. */ - if (relation->pd->forcefield == PFIELD_SMOKEFLOW && relation->pd->f_source) { + if (relation->pd->forcefield == PFIELD_FLUIDFLOW && relation->pd->f_source) { ComponentKey trf_key(&relation->pd->f_source->id, NodeType::TRANSFORM); add_relation(trf_key, key, "Smoke Force Domain"); ComponentKey eff_key(&relation->pd->f_source->id, NodeType::GEOMETRY); @@ -558,6 +555,9 @@ void DepsgraphRelationBuilder::build_id(ID *id) case ID_SCE: build_scene_parameters((Scene *)id); break; + case ID_SIM: + build_simulation((Simulation *)id); + break; default: fprintf(stderr, "Unhandled ID %s\n", id->name); BLI_assert(!"Should never happen"); @@ -565,6 +565,18 @@ void DepsgraphRelationBuilder::build_id(ID *id) } } +static void build_idproperties_callback(IDProperty *id_property, void *user_data) +{ + DepsgraphRelationBuilder *builder = reinterpret_cast<DepsgraphRelationBuilder *>(user_data); + BLI_assert(id_property->type == IDP_ID); + builder->build_id(reinterpret_cast<ID *>(id_property->data.pointer)); +} + +void DepsgraphRelationBuilder::build_idproperties(IDProperty *id_property) +{ + IDP_foreach_property(id_property, IDP_TYPE_FILTER_ID, build_idproperties_callback, this); +} + void DepsgraphRelationBuilder::build_collection(LayerCollection *from_layer_collection, Object *object, Collection *collection) @@ -578,6 +590,7 @@ void DepsgraphRelationBuilder::build_collection(LayerCollection *from_layer_coll * recurses into all the nested objects and collections. */ return; } + build_idproperties(collection->id.properties); const bool group_done = built_map_.checkIsBuiltAndTag(collection); OperationKey object_transform_final_key(object != nullptr ? &object->id : nullptr, NodeType::TRANSFORM, @@ -645,19 +658,19 @@ void DepsgraphRelationBuilder::build_object(Base *base, Object *object) if (object->modifiers.first != nullptr) { BuilderWalkUserData data; data.builder = this; - modifiers_foreachIDLink(object, modifier_walk, &data); + BKE_modifiers_foreach_ID_link(object, modifier_walk, &data); } /* Grease Pencil Modifiers. */ if (object->greasepencil_modifiers.first != nullptr) { BuilderWalkUserData data; data.builder = this; - BKE_gpencil_modifiers_foreachIDLink(object, modifier_walk, &data); + BKE_gpencil_modifiers_foreach_ID_link(object, modifier_walk, &data); } /* Shader FX. */ if (object->shader_fx.first != nullptr) { BuilderWalkUserData data; data.builder = this; - BKE_shaderfx_foreachIDLink(object, modifier_walk, &data); + BKE_shaderfx_foreach_ID_link(object, modifier_walk, &data); } /* Constraints. */ if (object->constraints.first != nullptr) { @@ -691,6 +704,7 @@ void DepsgraphRelationBuilder::build_object(Base *base, Object *object) final_transform_key, "Simulation -> Final Transform"); } + build_idproperties(object->id.properties); /* Animation data */ build_animdata(&object->id); /* Object data. */ @@ -1219,6 +1233,12 @@ void DepsgraphRelationBuilder::build_animdata(ID *id) build_animdata_curves(id); /* Drivers. */ build_animdata_drivers(id); + + if (check_id_has_anim_component(id)) { + ComponentKey animation_key(id, NodeType::ANIMATION); + ComponentKey parameters_key(id, NodeType::PARAMETERS); + add_relation(animation_key, parameters_key, "Animation -> Parameters"); + } } void DepsgraphRelationBuilder::build_animdata_curves(ID *id) @@ -1367,6 +1387,7 @@ void DepsgraphRelationBuilder::build_action(bAction *action) if (built_map_.checkIsBuiltAndTag(action)) { return; } + build_idproperties(action->id.properties); if (!BLI_listbase_is_empty(&action->curves)) { TimeSourceKey time_src_key; ComponentKey animation_key(&action->id, NodeType::ANIMATION); @@ -1479,7 +1500,10 @@ void DepsgraphRelationBuilder::build_driver_data(ID *id, FCurve *fcu) } } if (property_entry_key.prop != nullptr && RNA_property_is_idprop(property_entry_key.prop)) { - RNAPathKey property_exit_key(id, rna_path, RNAPointerSource::EXIT); + RNAPathKey property_exit_key(property_entry_key.id, + property_entry_key.ptr, + property_entry_key.prop, + RNAPointerSource::EXIT); OperationKey parameters_key(id, NodeType::PARAMETERS, OperationCode::PARAMETERS_EVAL); add_relation(property_exit_key, parameters_key, "Driven Property -> Properties"); } @@ -1612,6 +1636,7 @@ void DepsgraphRelationBuilder::build_world(World *world) if (built_map_.checkIsBuiltAndTag(world)) { return; } + build_idproperties(world->id.properties); /* animation */ build_animdata(&world->id); build_parameters(&world->id); @@ -1789,7 +1814,7 @@ void DepsgraphRelationBuilder::build_particle_systems(Object *object) } } /* Keyed particle targets. */ - if (part->phystype == PART_PHYS_KEYED) { + if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) { LISTBASE_FOREACH (ParticleTarget *, particle_target, &psys->targets) { if (particle_target->ob == nullptr || particle_target->ob == object) { continue; @@ -1854,8 +1879,9 @@ void DepsgraphRelationBuilder::build_particle_settings(ParticleSettings *part) ComponentKey texture_key(&mtex->tex->id, NodeType::GENERIC_DATABLOCK); add_relation(texture_key, particle_settings_reset_key, - "Particle Texture", + "Particle Texture -> Particle Reset", RELATION_FLAG_FLUSH_USER_EDIT_ONLY); + add_relation(texture_key, particle_settings_eval_key, "Particle Texture -> Particle Eval"); /* TODO(sergey): Consider moving texture space handling to an own * function. */ if (mtex->texco == TEXCO_OBJECT && mtex->object != nullptr) { @@ -1890,6 +1916,7 @@ void DepsgraphRelationBuilder::build_shapekeys(Key *key) if (built_map_.checkIsBuiltAndTag(key)) { return; } + build_idproperties(key->id.properties); /* Attach animdata to geometry. */ build_animdata(&key->id); build_parameters(&key->id); @@ -1947,7 +1974,7 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) ctx.scene = scene_; ctx.object = object; LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) { - const ModifierTypeInfo *mti = modifierType_getInfo((ModifierType)md->type); + const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)md->type); if (mti->updateDepsgraph) { DepsNodeHandle handle = create_node_handle(obdata_ubereval_key); ctx.node = reinterpret_cast<::DepsNodeHandle *>(&handle); @@ -1965,7 +1992,7 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) ctx.scene = scene_; ctx.object = object; LISTBASE_FOREACH (GpencilModifierData *, md, &object->greasepencil_modifiers) { - const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo( + const GpencilModifierTypeInfo *mti = BKE_gpencil_modifier_get_info( (GpencilModifierType)md->type); if (mti->updateDepsgraph) { DepsNodeHandle handle = create_node_handle(obdata_ubereval_key); @@ -1984,7 +2011,7 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) ctx.scene = scene_; ctx.object = object; LISTBASE_FOREACH (ShaderFxData *, fx, &object->shader_fx) { - const ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo((ShaderFxType)fx->type); + const ShaderFxTypeInfo *fxi = BKE_shaderfx_get_info((ShaderFxType)fx->type); if (fxi->updateDepsgraph) { DepsNodeHandle handle = create_node_handle(obdata_ubereval_key); ctx.node = reinterpret_cast<::DepsNodeHandle *>(&handle); @@ -2069,6 +2096,7 @@ void DepsgraphRelationBuilder::build_object_data_geometry_datablock(ID *obdata) if (built_map_.checkIsBuiltAndTag(obdata)) { return; } + build_idproperties(obdata->properties); /* Animation. */ build_animdata(obdata); build_parameters(obdata); @@ -2181,8 +2209,18 @@ void DepsgraphRelationBuilder::build_armature(bArmature *armature) if (built_map_.checkIsBuiltAndTag(armature)) { return; } + build_idproperties(armature->id.properties); build_animdata(&armature->id); build_parameters(&armature->id); + build_armature_bones(&armature->bonebase); +} + +void DepsgraphRelationBuilder::build_armature_bones(ListBase *bones) +{ + LISTBASE_FOREACH (Bone *, bone, bones) { + build_idproperties(bone->prop); + build_armature_bones(&bone->childbase); + } } void DepsgraphRelationBuilder::build_camera(Camera *camera) @@ -2190,6 +2228,7 @@ void DepsgraphRelationBuilder::build_camera(Camera *camera) if (built_map_.checkIsBuiltAndTag(camera)) { return; } + build_idproperties(camera->id.properties); build_animdata(&camera->id); build_parameters(&camera->id); if (camera->dof.focus_object != nullptr) { @@ -2206,16 +2245,23 @@ void DepsgraphRelationBuilder::build_light(Light *lamp) if (built_map_.checkIsBuiltAndTag(lamp)) { return; } + build_idproperties(lamp->id.properties); build_animdata(&lamp->id); build_parameters(&lamp->id); + + ComponentKey lamp_parameters_key(&lamp->id, NodeType::PARAMETERS); + /* light's nodetree */ if (lamp->nodetree != nullptr) { build_nodetree(lamp->nodetree); - ComponentKey lamp_parameters_key(&lamp->id, NodeType::PARAMETERS); ComponentKey nodetree_key(&lamp->nodetree->id, NodeType::SHADING); add_relation(nodetree_key, lamp_parameters_key, "NTree->Light Parameters"); build_nested_nodetree(&lamp->id, lamp->nodetree); } + + /* For allowing drivers on lamp properties. */ + ComponentKey shading_key(&lamp->id, NodeType::SHADING); + add_relation(lamp_parameters_key, shading_key, "Light Shading Parameters"); } void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree) @@ -2226,11 +2272,20 @@ void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree) if (built_map_.checkIsBuiltAndTag(ntree)) { return; } + build_idproperties(ntree->id.properties); build_animdata(&ntree->id); build_parameters(&ntree->id); ComponentKey shading_key(&ntree->id, NodeType::SHADING); /* nodetree's nodes... */ LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) { + build_idproperties(bnode->prop); + LISTBASE_FOREACH (bNodeSocket *, socket, &bnode->inputs) { + build_idproperties(socket->prop); + } + LISTBASE_FOREACH (bNodeSocket *, socket, &bnode->outputs) { + build_idproperties(socket->prop); + } + ID *id = bnode->id; if (id == nullptr) { continue; @@ -2295,6 +2350,13 @@ void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree) } } + LISTBASE_FOREACH (bNodeSocket *, socket, &ntree->inputs) { + build_idproperties(socket->prop); + } + LISTBASE_FOREACH (bNodeSocket *, socket, &ntree->outputs) { + build_idproperties(socket->prop); + } + OperationKey shading_update_key(&ntree->id, NodeType::SHADING, OperationCode::MATERIAL_UPDATE); OperationKey shading_parameters_key( &ntree->id, NodeType::SHADING_PARAMETERS, OperationCode::MATERIAL_UPDATE); @@ -2314,6 +2376,7 @@ void DepsgraphRelationBuilder::build_material(Material *material) if (built_map_.checkIsBuiltAndTag(material)) { return; } + build_idproperties(material->id.properties); /* animation */ build_animdata(&material->id); build_parameters(&material->id); @@ -2345,21 +2408,33 @@ void DepsgraphRelationBuilder::build_texture(Tex *texture) return; } /* texture itself */ + ComponentKey texture_key(&texture->id, NodeType::GENERIC_DATABLOCK); + build_idproperties(texture->id.properties); build_animdata(&texture->id); build_parameters(&texture->id); + /* texture's nodetree */ build_nodetree(texture->nodetree); + build_nested_nodetree(&texture->id, texture->nodetree); + /* Special cases for different IDs which texture uses. */ if (texture->type == TEX_IMAGE) { if (texture->ima != nullptr) { build_image(texture->ima); + + ComponentKey image_key(&texture->ima->id, NodeType::GENERIC_DATABLOCK); + add_relation(image_key, texture_key, "Texture Image"); } } - build_nested_nodetree(&texture->id, texture->nodetree); + if (check_id_has_anim_component(&texture->id)) { ComponentKey animation_key(&texture->id, NodeType::ANIMATION); - ComponentKey datablock_key(&texture->id, NodeType::GENERIC_DATABLOCK); - add_relation(animation_key, datablock_key, "Datablock Animation"); + add_relation(animation_key, texture_key, "Datablock Animation"); + } + + if (BKE_image_user_id_has_animation(&texture->id)) { + ComponentKey image_animation_key(&texture->id, NodeType::IMAGE_ANIMATION); + add_relation(image_animation_key, texture_key, "Datablock Image Animation"); } } @@ -2368,6 +2443,7 @@ void DepsgraphRelationBuilder::build_image(Image *image) if (built_map_.checkIsBuiltAndTag(image)) { return; } + build_idproperties(image->id.properties); build_parameters(&image->id); } @@ -2388,6 +2464,7 @@ void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file) if (built_map_.checkIsBuiltAndTag(cache_file)) { return; } + build_idproperties(cache_file->id.properties); /* Animation. */ build_animdata(&cache_file->id); build_parameters(&cache_file->id); @@ -2417,6 +2494,7 @@ void DepsgraphRelationBuilder::build_mask(Mask *mask) return; } ID *mask_id = &mask->id; + build_idproperties(mask_id->properties); /* F-Curve animation. */ build_animdata(mask_id); build_parameters(mask_id); @@ -2455,6 +2533,7 @@ void DepsgraphRelationBuilder::build_freestyle_linestyle(FreestyleLineStyle *lin ID *linestyle_id = &linestyle->id; build_parameters(linestyle_id); + build_idproperties(linestyle_id->properties); build_animdata(linestyle_id); build_nodetree(linestyle->nodetree); } @@ -2465,6 +2544,7 @@ void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip) return; } /* Animation. */ + build_idproperties(clip->id.properties); build_animdata(&clip->id); build_parameters(&clip->id); } @@ -2474,6 +2554,7 @@ void DepsgraphRelationBuilder::build_lightprobe(LightProbe *probe) if (built_map_.checkIsBuiltAndTag(probe)) { return; } + build_idproperties(probe->id.properties); build_animdata(&probe->id); build_parameters(&probe->id); } @@ -2483,6 +2564,7 @@ void DepsgraphRelationBuilder::build_speaker(Speaker *speaker) if (built_map_.checkIsBuiltAndTag(speaker)) { return; } + build_idproperties(speaker->id.properties); build_animdata(&speaker->id); build_parameters(&speaker->id); if (speaker->sound != nullptr) { @@ -2498,10 +2580,25 @@ void DepsgraphRelationBuilder::build_sound(bSound *sound) if (built_map_.checkIsBuiltAndTag(sound)) { return; } + build_idproperties(sound->id.properties); build_animdata(&sound->id); build_parameters(&sound->id); } +void DepsgraphRelationBuilder::build_simulation(Simulation *simulation) +{ + if (built_map_.checkIsBuiltAndTag(simulation)) { + return; + } + build_animdata(&simulation->id); + build_parameters(&simulation->id); + + OperationKey simulation_update_key( + &simulation->id, NodeType::SIMULATION, OperationCode::SIMULATION_EVAL); + TimeSourceKey time_src_key; + add_relation(time_src_key, simulation_update_key, "TimeSrc -> Simulation"); +} + void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene) { if (scene->ed == nullptr) { @@ -2514,6 +2611,7 @@ void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene) Sequence *seq; bool has_audio_strips = false; SEQ_BEGIN (scene->ed, seq) { + build_idproperties(seq->prop); if (seq->sound != nullptr) { build_sound(seq->sound); ComponentKey sound_key(&seq->sound->id, NodeType::AUDIO); @@ -2544,8 +2642,16 @@ void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene) } } -void DepsgraphRelationBuilder::build_scene_audio(Scene * /*scene*/) +void DepsgraphRelationBuilder::build_scene_audio(Scene *scene) { + OperationKey scene_audio_volume_key(&scene->id, NodeType::AUDIO, OperationCode::AUDIO_VOLUME); + OperationKey scene_sound_eval_key(&scene->id, NodeType::AUDIO, OperationCode::SOUND_EVAL); + add_relation(scene_audio_volume_key, scene_sound_eval_key, "Audio Volume -> Sound"); + + if (scene->audio.flag & AUDIO_VOLUME_ANIMATED) { + ComponentKey scene_anim_key(&scene->id, NodeType::ANIMATION); + add_relation(scene_anim_key, scene_audio_volume_key, "Animation -> Audio Volume"); + } } void DepsgraphRelationBuilder::build_scene_speakers(Scene * /*scene*/, ViewLayer *view_layer) @@ -2608,7 +2714,7 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node) Node *node_cow = find_node(copy_on_write_key); OperationNode *op_cow = node_cow->get_exit_operation(); /* Plug any other components to this one. */ - GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) { + for (ComponentNode *comp_node : id_node->components.values()) { if (comp_node->type == NodeType::COPY_ON_WRITE) { /* Copy-on-write component never depends on itself. */ continue; @@ -2651,11 +2757,11 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node) rel->flag |= rel_flag; } /* All dangling operations should also be executed after copy-on-write. */ - GHASH_FOREACH_BEGIN (OperationNode *, op_node, comp_node->operations_map) { + for (OperationNode *op_node : comp_node->operations_map->values()) { if (op_node == op_entry) { continue; } - if (op_node->inlinks.size() == 0) { + if (op_node->inlinks.is_empty()) { Relation *rel = graph_->add_new_relation(op_cow, op_node, "CoW Dependency"); rel->flag |= rel_flag; } @@ -2677,7 +2783,6 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node) } } } - GHASH_FOREACH_END(); /* NOTE: We currently ignore implicit relations to an external * data-blocks for copy-on-write operations. This means, for example, * copy-on-write component of Object will not wait for copy-on-write @@ -2686,7 +2791,6 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node) * evaluation step needs geometry, it will have transitive dependency * to Mesh copy-on-write already. */ } - GHASH_FOREACH_END(); /* TODO(sergey): This solves crash for now, but causes too many * updates potentially. */ if (GS(id_orig->name) == ID_OB) { @@ -2735,7 +2839,7 @@ static bool is_reachable(const Node *const from, const Node *const to) // Perform a graph walk from 'to' towards its incoming connections. // Walking from 'from' towards its outgoing connections is 10x slower on the Spring rig. deque<const Node *> queue; - unordered_set<const Node *> seen; + Set<const Node *> seen; queue.push_back(to); while (!queue.empty()) { // Visit the next node to inspect. @@ -2749,7 +2853,7 @@ static bool is_reachable(const Node *const from, const Node *const to) // Queue all incoming relations that we haven't seen before. for (Relation *relation : visit->inlinks) { const Node *prev_node = relation->from; - if (seen.insert(prev_node).second) { + if (seen.add(prev_node)) { queue.push_back(prev_node); } } @@ -2788,6 +2892,9 @@ void DepsgraphRelationBuilder::build_driver_relations(IDNode *id_node) DriverGroupMap driver_groups; LISTBASE_FOREACH (FCurve *, fcu, &adt->drivers) { + if (fcu->rna_path == nullptr) { + continue; + } // Get the RNA path except the part after the last dot. char *last_dot = strrchr(fcu->rna_path, '.'); string rna_prefix; @@ -2838,7 +2945,7 @@ void DepsgraphRelationBuilder::build_driver_relations(IDNode *id_node) } } } -} +} // namespace DEG /* **** ID traversal callbacks functions **** */ |