[Bf-blender-cvs] [e0aab87f543] spreadsheet-active-node: initial node group support

Jacques Lucke noreply at git.blender.org
Thu Apr 1 13:55:18 CEST 2021


Commit: e0aab87f543885817379b001d1efa398e81bee52
Author: Jacques Lucke
Date:   Thu Apr 1 10:07:59 2021 +0200
Branches: spreadsheet-active-node
https://developer.blender.org/rBe0aab87f543885817379b001d1efa398e81bee52

initial node group support

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

M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/nodes/NOD_derived_node_tree.hh
M	source/blender/nodes/intern/derived_node_tree.cc

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

diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index ee0d70e70ec..d3a3a2f728d 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -43,11 +43,14 @@
 #include "DNA_pointcloud_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_windowmanager_types.h"
 
 #include "BKE_customdata.h"
 #include "BKE_global.h"
 #include "BKE_idprop.h"
 #include "BKE_lib_query.h"
+#include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
 #include "BKE_node_ui_storage.hh"
@@ -55,6 +58,7 @@
 #include "BKE_pointcloud.h"
 #include "BKE_screen.h"
 #include "BKE_simulation.h"
+#include "BKE_workspace.h"
 
 #include "BLO_read_write.h"
 
@@ -253,6 +257,47 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
   return false;
 }
 
+static DNode find_active_node_instance(const SpaceNode &snode, const DerivedNodeTree &dtree)
+{
+  const DTreeContext &root_context = dtree.root_context();
+  if ((ID *)snode.nodetree != DEG_get_original_id(&root_context.tree().btree()->id)) {
+    return {};
+  }
+
+  const DTreeContext *current_context = &root_context;
+  bool is_first = true;
+  LISTBASE_FOREACH (const bNodeTreePath *, path, &snode.treepath) {
+    if (is_first) {
+      is_first = false;
+      continue;
+    }
+    StringRef parent_node_name = path->node_name;
+    const NodeTreeRef &tree_ref = current_context->tree();
+    const NodeRef *parent_node_ref = nullptr;
+    for (const NodeRef *node_ref : tree_ref.nodes()) {
+      if (node_ref->name() == parent_node_name) {
+        parent_node_ref = node_ref;
+        break;
+      }
+    }
+    if (parent_node_ref == nullptr) {
+      return {};
+    }
+    current_context = current_context->child_context(*parent_node_ref);
+    if (current_context == nullptr) {
+      return {};
+    }
+  }
+
+  const NodeTreeRef &tree_ref = current_context->tree();
+  for (const NodeRef *node_ref : tree_ref.nodes()) {
+    if (node_ref->bnode()->flag & NODE_ACTIVE) {
+      return {current_context, node_ref};
+    }
+  }
+  return {};
+}
+
 class GeometryNodesEvaluator {
  private:
   blender::LinearAllocator<> allocator_;
@@ -403,12 +448,28 @@ class GeometryNodesEvaluator {
     this->execute_node(node, params);
 
     if (node->bnode()->flag & NODE_ACTIVE) {
-      for (const OutputSocketRef *output_socket : node->outputs()) {
-        if (output_socket->is_available() && output_socket->bsocket()->type == SOCK_GEOMETRY) {
-          GeometrySet value = node_outputs_map.lookup<GeometrySet>(output_socket->identifier());
-          value.ensure_own_non_instances();
-          BKE_object_preview_geometry_set(const_cast<Object *>(self_object_),
-                                          new GeometrySet(std::move(value)));
+      Main *bmain = DEG_get_bmain(depsgraph_);
+      wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
+      LISTBASE_FOREACH (wmWindow *, window, &wm->windows) {
+        bScreen *screen = BKE_workspace_active_screen_get(window->workspace_hook);
+        LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+          SpaceLink *sl = (SpaceLink *)area->spacedata.first;
+          if (sl->spacetype == SPACE_NODE) {
+            SpaceNode *snode = (SpaceNode *)sl;
+            DNode active_dnode = find_active_node_instance(*snode, node.context()->derived_tree());
+            if (active_dnode == node) {
+              for (const OutputSocketRef *output_socket : node->outputs()) {
+                if (output_socket->is_available() &&
+                    output_socket->bsocket()->type == SOCK_GEOMETRY) {
+                  GeometrySet value = node_outputs_map.lookup<GeometrySet>(
+                      output_socket->identifier());
+                  value.ensure_own_non_instances();
+                  BKE_object_preview_geometry_set(const_cast<Object *>(self_object_),
+                                                  new GeometrySet(std::move(value)));
+                }
+              }
+            }
+          }
         }
       }
     }
diff --git a/source/blender/nodes/NOD_derived_node_tree.hh b/source/blender/nodes/NOD_derived_node_tree.hh
index c29de611e18..738b94cde03 100644
--- a/source/blender/nodes/NOD_derived_node_tree.hh
+++ b/source/blender/nodes/NOD_derived_node_tree.hh
@@ -59,6 +59,7 @@ class DTreeContext {
   const NodeTreeRef *tree_;
   /* All the children contexts of this context. */
   Map<const NodeRef *, DTreeContext *> children_;
+  DerivedNodeTree *derived_tree_;
 
   friend DerivedNodeTree;
 
@@ -67,6 +68,7 @@ class DTreeContext {
   const DTreeContext *parent_context() const;
   const NodeRef *parent_node() const;
   const DTreeContext *child_context(const NodeRef &node) const;
+  const DerivedNodeTree &derived_tree() const;
   bool is_root() const;
 };
 
@@ -214,6 +216,11 @@ inline const DTreeContext *DTreeContext::child_context(const NodeRef &node) cons
   return children_.lookup_default(&node, nullptr);
 }
 
+inline const DerivedNodeTree &DTreeContext::derived_tree() const
+{
+  return *derived_tree_;
+}
+
 inline bool DTreeContext::is_root() const
 {
   return parent_context_ == nullptr;
diff --git a/source/blender/nodes/intern/derived_node_tree.cc b/source/blender/nodes/intern/derived_node_tree.cc
index e4f8a0c5fda..d83b9737693 100644
--- a/source/blender/nodes/intern/derived_node_tree.cc
+++ b/source/blender/nodes/intern/derived_node_tree.cc
@@ -40,6 +40,7 @@ DTreeContext &DerivedNodeTree::construct_context_recursively(DTreeContext *paren
   DTreeContext &context = *allocator_.construct<DTreeContext>().release();
   context.parent_context_ = parent_context;
   context.parent_node_ = parent_node;
+  context.derived_tree_ = this;
   context.tree_ = &get_tree_ref_from_map(node_tree_refs, btree);
   used_node_tree_refs_.add(context.tree_);



More information about the Bf-blender-cvs mailing list