[Bf-blender-cvs] [c9b578eac8a] master: Geometry Nodes: Remove object transform dependency in some cases

Hans Goudey noreply at git.blender.org
Tue Feb 1 23:27:39 CET 2022


Commit: c9b578eac8a3c0e246e9679e2333a1788d5c4031
Author: Hans Goudey
Date:   Tue Feb 1 16:27:29 2022 -0600
Branches: master
https://developer.blender.org/rBc9b578eac8a3c0e246e9679e2333a1788d5c4031

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

===================================================================

M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/modifiers/intern/MOD_nodes.cc

===================================================================

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<ID *> &ids)
   }
 }
 
-static void find_used_ids_from_nodes(const bNodeTree &tree, Set<ID *> &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<const NodeGeometryCollectionInfo *>(
+        node.storage);
+    return storage.transform_space == GEO_NODE_TRANSFORM_SPACE_RELATIVE;
+  }
+
+  if (node.type == GEO_NODE_OBJECT_INFO) {
+    const NodeGeometryObjectInfo &storage = *static_cast<const NodeGeometryObjectInfo *>(
+        node.storage);
+    return storage.transform_space == GEO_NODE_TRANSFORM_SPACE_RELATIVE;
+  }
+
+  return false;
+}
+
+static void process_nodes_for_depsgraph(const bNodeTree &tree,
+                                        Set<ID *> &ids,
+                                        bool &needs_own_transform_relation)
 {
   Set<const bNodeTree *> handled_groups;
 
@@ -187,9 +212,10 @@ static void find_used_ids_from_nodes(const bNodeTree &tree, Set<ID *> &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<ID *> 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,



More information about the Bf-blender-cvs mailing list