[Bf-blender-cvs] [47a72ac4fdf] master: Cleanup: Refactor use of implicit inputs in geometry nodes

Hans Goudey noreply at git.blender.org
Fri Oct 15 21:01:12 CEST 2021


Commit: 47a72ac4fdf777f2177037df3111a5cba2697bae
Author: Hans Goudey
Date:   Fri Oct 15 13:57:00 2021 -0500
Branches: master
https://developer.blender.org/rB47a72ac4fdf777f2177037df3111a5cba2697bae

Cleanup: Refactor use of implicit inputs in geometry nodes

Instead of checking whether the socket value was hidden, use the proper
node declaration to check whether the socket has an implicit input. The
remaining larger change to make is allowing nodes to specify what their
implicit input should actually be.

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

M	source/blender/modifiers/intern/MOD_nodes_evaluator.cc

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

diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index 3c51ef83311..20ee6127504 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -17,6 +17,7 @@
 #include "MOD_nodes_evaluator.hh"
 
 #include "NOD_geometry_exec.hh"
+#include "NOD_socket_declarations.hh"
 #include "NOD_type_conversions.hh"
 
 #include "DEG_depsgraph_query.h"
@@ -321,41 +322,45 @@ static const CPPType *get_socket_cpp_type(const DSocket socket)
   return get_socket_cpp_type(*socket.socket_ref());
 }
 
-static void get_socket_value(const SocketRef &socket, void *r_value)
+/**
+ * \note This is not supposed to be a long term solution. Eventually we want that nodes can
+ * specify more complex defaults (other than just single values) in their socket declarations.
+ */
+static bool get_implicit_socket_input(const SocketRef &socket, void *r_value)
 {
-  const bNodeSocket &bsocket = *socket.bsocket();
-  /* This is not supposed to be a long term solution. Eventually we want that nodes can specify
-   * more complex defaults (other than just single values) in their socket declarations. */
-  if (bsocket.flag & SOCK_HIDE_VALUE) {
-    const bNode &bnode = *socket.bnode();
-    if (bsocket.type == SOCK_VECTOR) {
-      if (ELEM(bnode.type,
-               GEO_NODE_SET_POSITION,
-               SH_NODE_TEX_GRADIENT,
-               SH_NODE_TEX_NOISE,
-               SH_NODE_TEX_VORONOI,
-               SH_NODE_TEX_WHITE_NOISE,
-               GEO_NODE_MESH_TO_POINTS,
-               GEO_NODE_PROXIMITY)) {
-        new (r_value) Field<float3>(bke::AttributeFieldInput::Create<float3>("position"));
-        return;
-      }
+  const NodeRef &node = socket.node();
+  const nodes::NodeDeclaration *node_declaration = node.declaration();
+  if (node_declaration == nullptr) {
+    return false;
+  }
+  const nodes::SocketDeclaration &socket_declaration = *node_declaration->inputs()[socket.index()];
+  if (socket_declaration.input_field_type() == nodes::InputSocketFieldType::Implicit) {
+    if (socket.typeinfo()->type == SOCK_VECTOR) {
+      const bNode &bnode = *socket.bnode();
       if (bnode.type == GEO_NODE_SET_CURVE_HANDLES) {
         StringRef side = ((NodeGeometrySetCurveHandlePositions *)bnode.storage)->mode ==
                                  GEO_NODE_CURVE_HANDLE_LEFT ?
                              "handle_left" :
                              "handle_right";
         new (r_value) Field<float3>(bke::AttributeFieldInput::Create<float3>(side));
-        return;
+        return true;
       }
+      new (r_value) Field<float3>(bke::AttributeFieldInput::Create<float3>("position"));
+      return true;
     }
-    else if (bsocket.type == SOCK_INT) {
-      if (ELEM(bnode.type, FN_NODE_RANDOM_VALUE, GEO_NODE_INSTANCE_ON_POINTS)) {
-        new (r_value) Field<int>(std::make_shared<fn::IndexFieldInput>());
-        return;
-      }
+    if (socket.typeinfo()->type == SOCK_INT) {
+      new (r_value) Field<int>(std::make_shared<fn::IndexFieldInput>());
+      return true;
     }
   }
+  return false;
+}
+
+static void get_socket_value(const SocketRef &socket, void *r_value)
+{
+  if (get_implicit_socket_input(socket, r_value)) {
+    return;
+  }
 
   const bNodeSocketType *typeinfo = socket.typeinfo();
   typeinfo->get_geometry_nodes_cpp_value(*socket.bsocket(), r_value);



More information about the Bf-blender-cvs mailing list