From c9b578eac8a3c0e246e9679e2333a1788d5c4031 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Tue, 1 Feb 2022 16:27:29 -0600 Subject: [PATCH] Geometry Nodes: Remove object transform dependency in some cases The geometry nodes modifier currently always adds a dependency relation from the evaluated geometry to the object transform. However, that can be avoided unless there is a collection or object info node in "Relative" mode. In order to avoid requiring dependency graph relations updates often when editing a node tree, this patch doesn't check if the node is muted or if the data-block sockets are empty before adding the dependency. Fixes T95265 Differential Revision: https://developer.blender.org/D13973 --- source/blender/makesrna/intern/rna_nodetree.c | 4 +- source/blender/modifiers/intern/MOD_nodes.cc | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 38a447a9657..13c8444de1d 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -10524,7 +10524,7 @@ static void def_geo_object_info(StructRNA *srna) RNA_def_property_enum_items(prop, rna_node_geometry_object_info_transform_space_items); RNA_def_property_ui_text( prop, "Transform Space", "The transformation of the vector and geometry outputs"); - RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update_relations"); } static void def_geo_legacy_points_to_volume(StructRNA *srna) @@ -10608,7 +10608,7 @@ static void def_geo_collection_info(StructRNA *srna) prop = RNA_def_property(srna, "transform_space", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, rna_node_geometry_collection_info_transform_space_items); RNA_def_property_ui_text(prop, "Transform Space", "The transformation of the geometry output"); - RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update_relations"); } static void def_geo_legacy_attribute_proximity(StructRNA *srna) diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 83775be8c9e..ac72478782f 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -176,7 +176,32 @@ static void add_used_ids_from_sockets(const ListBase &sockets, Set &ids) } } -static void find_used_ids_from_nodes(const bNodeTree &tree, Set &ids) +/** + * \note We can only check properties here that cause the dependency graph to update relations when + * they are changed, otherwise there may be a missing relation after editing. So this could check + * more properties like whether the node is muted, but we would have to accept the cost of updating + * relations when those properties are changed. + */ +static bool node_needs_own_transform_relation(const bNode &node) +{ + if (node.type == GEO_NODE_COLLECTION_INFO) { + const NodeGeometryCollectionInfo &storage = *static_cast( + node.storage); + return storage.transform_space == GEO_NODE_TRANSFORM_SPACE_RELATIVE; + } + + if (node.type == GEO_NODE_OBJECT_INFO) { + const NodeGeometryObjectInfo &storage = *static_cast( + node.storage); + return storage.transform_space == GEO_NODE_TRANSFORM_SPACE_RELATIVE; + } + + return false; +} + +static void process_nodes_for_depsgraph(const bNodeTree &tree, + Set &ids, + bool &needs_own_transform_relation) { Set handled_groups; @@ -187,9 +212,10 @@ static void find_used_ids_from_nodes(const bNodeTree &tree, Set &ids) if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { const bNodeTree *group = (bNodeTree *)node->id; if (group != nullptr && handled_groups.add(group)) { - find_used_ids_from_nodes(*group, ids); + process_nodes_for_depsgraph(*group, ids, needs_own_transform_relation); } } + needs_own_transform_relation |= node_needs_own_transform_relation(*node); } } @@ -243,12 +269,12 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte return; } - DEG_add_modifier_to_transform_relation(ctx->node, "Nodes Modifier"); DEG_add_node_tree_output_relation(ctx->node, nmd->node_group, "Nodes Modifier"); + bool needs_own_transform_relation = false; Set used_ids; find_used_ids_from_settings(nmd->settings, used_ids); - find_used_ids_from_nodes(*nmd->node_group, used_ids); + process_nodes_for_depsgraph(*nmd->node_group, used_ids, needs_own_transform_relation); for (ID *id : used_ids) { switch ((ID_Type)GS(id->name)) { case ID_OB: { @@ -272,6 +298,10 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte } } } + + if (needs_own_transform_relation) { + DEG_add_modifier_to_transform_relation(ctx->node, "Nodes Modifier"); + } } static bool check_tree_for_time_node(const bNodeTree &tree,