[Bf-blender-cvs] [797c8f6d75b] geometry-nodes: Geomtetry Nodes: Set node editor context from the active modifier

Hans Goudey noreply at git.blender.org
Fri Nov 20 20:30:01 CET 2020


Commit: 797c8f6d75bc4249b8d5ebcda1c428d00febec56
Author: Hans Goudey
Date:   Fri Nov 20 14:29:52 2020 -0500
Branches: geometry-nodes
https://developer.blender.org/rB797c8f6d75bc4249b8d5ebcda1c428d00febec56

Geomtetry Nodes: Set node editor context from the active modifier

Similar to how the node editor context works for materials, this commit
makes the node group displayed in the node editor depend on the active
object and its active modifier. To keep the node group from changing,
just pin the node group in the header.

There are still missing updates when switching the modifier's node group.

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

M	source/blender/nodes/geometry/node_geometry_tree.cc

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

diff --git a/source/blender/nodes/geometry/node_geometry_tree.cc b/source/blender/nodes/geometry/node_geometry_tree.cc
index d4a9805f311..4bc12625fb8 100644
--- a/source/blender/nodes/geometry/node_geometry_tree.cc
+++ b/source/blender/nodes/geometry/node_geometry_tree.cc
@@ -20,16 +20,49 @@
 
 #include "NOD_geometry.h"
 
+#include "BKE_context.h"
 #include "BKE_node.h"
+#include "BKE_object.h"
 
 #include "BLT_translation.h"
 
+#include "DNA_modifier_types.h"
 #include "DNA_node_types.h"
 
 #include "RNA_access.h"
 
 bNodeTreeType *ntreeType_Geometry;
 
+static void geometry_node_tree_get_from_context(const bContext *C,
+                                                bNodeTreeType *UNUSED(treetype),
+                                                bNodeTree **r_ntree,
+                                                ID **r_id,
+                                                ID **r_from)
+{
+  ViewLayer *view_layer = CTX_data_view_layer(C);
+  Object *ob = OBACT(view_layer);
+
+  if (ob == NULL) {
+    return;
+  }
+
+  const ModifierData *md = BKE_object_active_modifier(ob);
+
+  if (md == NULL) {
+    return;
+  }
+
+  if (md->type == eModifierType_Nodes) {
+    NodesModifierData *nmd = (NodesModifierData *)md;
+    if (nmd->node_group != NULL) {
+      *r_from = &ob->id;
+      *r_id = &ob->id;
+      // *r_id = &nmd->node_group->id;
+      *r_ntree = nmd->node_group;
+    }
+  }
+}
+
 void register_node_tree_type_geo(void)
 {
   bNodeTreeType *tt = ntreeType_Geometry = static_cast<bNodeTreeType *>(
@@ -41,5 +74,7 @@ void register_node_tree_type_geo(void)
   strcpy(tt->ui_description, N_("Geometry nodes"));
   tt->rna_ext.srna = &RNA_GeometryNodeTree;
 
+  tt->get_from_context = geometry_node_tree_get_from_context;
+
   ntreeTypeAdd(tt);
 }



More information about the Bf-blender-cvs mailing list