[Bf-blender-cvs] [a90642816ca] temp-nodes-group-declarations: Some progress

Hans Goudey noreply at git.blender.org
Fri Dec 16 23:42:25 CET 2022


Commit: a90642816ca478fe6acb4c922943b827136d1e7e
Author: Hans Goudey
Date:   Fri Dec 16 16:42:19 2022 -0600
Branches: temp-nodes-group-declarations
https://developer.blender.org/rBa90642816ca478fe6acb4c922943b827136d1e7e

Some progress

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

M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node_tree_update.cc
M	source/blender/nodes/NOD_common.h
M	source/blender/nodes/NOD_node_declaration.hh
M	source/blender/nodes/NOD_socket.h
M	source/blender/nodes/geometry/nodes/node_geo_common.cc
M	source/blender/nodes/intern/node_common.cc
M	source/blender/nodes/intern/node_declaration.cc
M	source/blender/nodes/intern/node_socket.cc

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

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 845b5a5566d..8a747844f97 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -122,7 +122,7 @@ using CPPTypeHandle = blender::CPPType;
 using NodeMultiFunctionBuildFunction = void (*)(blender::nodes::NodeMultiFunctionBuilder &builder);
 using NodeGeometryExecFunction = void (*)(blender::nodes::GeoNodeExecParams params);
 using NodeDeclareFunction = void (*)(blender::nodes::NodeDeclarationBuilder &builder);
-using NodeDeclareDynamicFunction = bool (*)(const bNodeTree &tree,
+using NodeDeclareDynamicFunction = void (*)(const bNodeTree &tree,
                                             const bNode &node,
                                             blender::nodes::NodeDeclaration &r_declaration);
 using SocketGetCPPValueFunction = void (*)(const struct bNodeSocket &socket, void *r_value);
diff --git a/source/blender/blenkernel/intern/node_tree_update.cc b/source/blender/blenkernel/intern/node_tree_update.cc
index b1cae45ba45..f43d3f0d1d2 100644
--- a/source/blender/blenkernel/intern/node_tree_update.cc
+++ b/source/blender/blenkernel/intern/node_tree_update.cc
@@ -22,6 +22,7 @@
 #include "MOD_nodes.h"
 
 #include "NOD_node_declaration.hh"
+#include "NOD_socket.h"
 #include "NOD_texture.h"
 
 #include "DEG_depsgraph_query.h"
@@ -535,7 +536,6 @@ class NodeTreeMainUpdater {
 
   void update_individual_nodes(bNodeTree &ntree)
   {
-    Vector<bNode *> group_inout_nodes;
     for (bNode *node : ntree.all_nodes()) {
       nodeDeclarationEnsure(&ntree, node);
       if (this->should_update_individual_node(ntree, *node)) {
@@ -546,28 +546,14 @@ class NodeTreeMainUpdater {
         if (ntype.updatefunc) {
           ntype.updatefunc(&ntree, node);
         }
-        // if (ntype.declare_dynamic) {
-        //   if (!node->runtime->declaration) {
-        //     node->runtime->declaration = new blender::nodes::NodeDeclaration();
-        //   }
-        //   build_node_declaration_dynamic(ntree, *node, *node->runtime->declaration);
-        // }
-      }
-      if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) {
-        group_inout_nodes.append(node);
-      }
-    }
-    /* The update function of group input/output nodes may add new interface sockets. When that
-     * happens, all the input/output nodes have to be updated again. In the future it would be
-     * better to move this functionality out of the node update function into the operator that's
-     * supposed to create the new interface socket. */
-    if (ntree.runtime->changed_flag & NTREE_CHANGED_INTERFACE) {
-      for (bNode *node : group_inout_nodes) {
-        if (node->typeinfo->declare_dynamic) {
+        if (ntype.declare_dynamic) {
           if (!node->runtime->declaration) {
             node->runtime->declaration = new blender::nodes::NodeDeclaration();
           }
           build_node_declaration_dynamic(ntree, *node, *node->runtime->declaration);
+          /* TODO: Move this to blenkernel or something. */
+          nodes::refresh_node_sockets_from_declaration(
+              ntree, *node, *node->runtime->declaration, true);
         }
       }
     }
diff --git a/source/blender/nodes/NOD_common.h b/source/blender/nodes/NOD_common.h
index d860e60864c..7b6244042f8 100644
--- a/source/blender/nodes/NOD_common.h
+++ b/source/blender/nodes/NOD_common.h
@@ -31,9 +31,9 @@ void node_internal_links_create(struct bNodeTree *ntree, struct bNode *node);
 
 namespace blender::nodes {
 
-bool node_group_declare_dynamic(const bNodeTree &node_tree,
-                                   const bNode &node,
-                                   NodeDeclaration &r_declaration);
+void node_group_declare_dynamic(const bNodeTree &node_tree,
+                                const bNode &node,
+                                NodeDeclaration &r_declaration);
 
 }  // namespace blender::nodes
 
diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index f67806a4cd4..f2523823e5e 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -311,6 +311,8 @@ class NodeDeclaration {
   Vector<SocketDeclarationPtr> inputs_;
   Vector<SocketDeclarationPtr> outputs_;
 
+  bool skip_updating_sockets = false;
+
   friend NodeDeclarationBuilder;
 
  public:
diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h
index e4f675135bd..1eeda4a7edf 100644
--- a/source/blender/nodes/NOD_socket.h
+++ b/source/blender/nodes/NOD_socket.h
@@ -28,7 +28,6 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree,
                                                   eNodeSocketInOut in_out);
 
 void node_verify_sockets(struct bNodeTree *ntree, struct bNode *node, bool do_id_user);
-
 void node_socket_init_default_value(struct bNodeSocket *sock);
 void node_socket_copy_default_value(struct bNodeSocket *to, const struct bNodeSocket *from);
 void node_socket_skip_reroutes(struct ListBase *links,
@@ -41,3 +40,16 @@ void register_standard_node_socket_types(void);
 #ifdef __cplusplus
 }
 #endif
+
+#ifdef __cplusplus
+
+namespace blender::nodes {
+
+void refresh_node_sockets_from_declaration(bNodeTree &ntree,
+                                           bNode &node,
+                                           const NodeDeclaration &node_decl,
+                                           bool do_id_user);
+
+}
+
+#endif
diff --git a/source/blender/nodes/geometry/nodes/node_geo_common.cc b/source/blender/nodes/geometry/nodes/node_geo_common.cc
index 46d6d18fa74..077c260e71a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_common.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_common.cc
@@ -11,13 +11,15 @@
 
 namespace blender::nodes {
 
-static bool node_declare(const bNodeTree &node_tree,
+static void node_declare(const bNodeTree &node_tree,
                          const bNode &node,
                          NodeDeclaration &r_declaration)
 {
-  if (!node_group_declare_dynamic(node_tree, node, r_declaration)) {
-    return false;
+  node_group_declare_dynamic(node_tree, node, r_declaration);
+  if (!node.id) {
+    return;
   }
+  /* TODO: Other return early checks. */
 
   const bNodeTree &group = reinterpret_cast<const bNodeTree &>(*node.id);
   FieldInferencingInterface field_interface;
@@ -28,8 +30,6 @@ static bool node_declare(const bNodeTree &node_tree,
   for (const int i : r_declaration.outputs_.index_range()) {
     r_declaration.outputs_[i]->output_field_dependency_ = field_interface.outputs[i];
   }
-
-  return true;
 }
 
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/intern/node_common.cc b/source/blender/nodes/intern/node_common.cc
index e1164515634..7900db475f7 100644
--- a/source/blender/nodes/intern/node_common.cc
+++ b/source/blender/nodes/intern/node_common.cc
@@ -208,17 +208,17 @@ static SocketDeclarationPtr declataion_for_interface_socket(const bNodeSocket &i
   return dst;
 }
 
-bool node_group_declare_dynamic(const bNodeTree & /*node_tree*/,
+void node_group_declare_dynamic(const bNodeTree & /*node_tree*/,
                                 const bNode &node,
                                 NodeDeclaration &r_declaration)
 {
   const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node.id);
   if (!group) {
-    return false;
+    return;
   }
   if (ID_IS_LINKED(&group->id) && (group->id.tag & LIB_TAG_MISSING)) {
-    /* TODO: Restore the behavior that keeps the sockets until the ID is found. */
-    return false;
+    r_declaration.skip_updating_sockets = true;
+    return;
   }
 
   /* TODO: Specialize for geometry nodes and fields. */
@@ -229,8 +229,6 @@ bool node_group_declare_dynamic(const bNodeTree & /*node_tree*/,
   LISTBASE_FOREACH (const bNodeSocket *, output, &group->outputs) {
     r_declaration.outputs_.append(declataion_for_interface_socket(*output));
   }
-
-  return true;
 }
 
 }  // namespace blender::nodes
@@ -437,7 +435,7 @@ static SocketDeclarationPtr extend_declaration(const eNodeSocketInOut in_out)
   return decl;
 }
 
-static bool group_input_declare_dynamic(const bNodeTree &node_tree,
+static void group_input_declare_dynamic(const bNodeTree &node_tree,
                                         const bNode & /*node*/,
                                         NodeDeclaration &r_declaration)
 {
@@ -448,21 +446,37 @@ static bool group_input_declare_dynamic(const bNodeTree &node_tree,
   if (!ID_IS_LINKED(&node_tree.id)) {
     r_declaration.outputs_.append(extend_declaration(SOCK_OUT));
   }
-  return true;
 }
 
-static bool group_output_declare_dynamic(const bNodeTree &node_tree,
+static void group_output_declare_dynamic(const bNodeTree &node_tree,
                                          const bNode & /*node*/,
                                          NodeDeclaration &r_declaration)
 {
   LISTBASE_FOREACH (const bNodeSocket *, input, &node_tree.inputs) {
     r_declaration.inputs_.append(declataion_for_interface_socket(*input));
-    r_declaration.inputs_.last()->in_out_ = SOCK_OUT;
+    r_declaration.inputs_.last()->in_out_ = SOCK_IN;
   }
   if (!ID_IS_LINKED(&node_tree.id)) {
-    r_declaration.inputs_.append(extend_declaration(SOCK_OUT));
+    r_declaration.inputs_.append(extend_declaration(SOCK_IN));
+  }
+}
+
+static void group_input_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
+{
+  BLI_assert(link->tonode != node);
+  BLI_assert(link->tosock->in_out == SOCK_IN);
+  if (link->fromsock->identifier == StringRef("__extend__")) {
+    ntreeAddSocketInterfaceFromSocket(ntree, link->tonode, link->tosock);
+  }
+}
+
+static void group_output_insert_link(bNodeTree *ntree, bNode *node, bNodeLink *link)
+{
+  BLI_assert(link->fromnode != node);
+  BLI_assert(link->fromsock->in_out == SOCK_OUT);
+  if (link->tosock->identifier == StringRef("__extend__")) {
+    ntreeAddSocketInterfaceFromSocket(ntree, link->fromnode, link->fromsock);
   }
-  return true;
 }
 
 }  // namespace blender::nodes
@@ -475,8 +489,8 @@ void register_node_type_group_input()
 
   node_type_base(ntype, NODE_GROUP_INPUT, "Group Input", NODE_CLASS_INTERFACE);
   node_type_size(ntyp

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list