[Bf-blender-cvs] [6525f47afa7] temp-geometry-nodes-output-attributes: Geometry Nodes: Only show attribute toggle for field inputs (WIP)

Hans Goudey noreply at git.blender.org
Sat Sep 25 05:39:34 CEST 2021


Commit: 6525f47afa7a4ee6604ceb77da42331942325ef8
Author: Hans Goudey
Date:   Thu Sep 23 23:44:18 2021 -0500
Branches: temp-geometry-nodes-output-attributes
https://developer.blender.org/rB6525f47afa7a4ee6604ceb77da42331942325ef8

Geometry Nodes: Only show attribute toggle for field inputs (WIP)

With this patch, the toggle to change an input between an attribute and
a value is not added or displayed for inputs that are fields, as determined
by the socket field status inferrencing.

Differential Revision: https://developer.blender.org/D12623

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

M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/nodes/NOD_node_declaration.hh

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

diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 3f4e6281ca7..dd74ee47cf3 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -104,6 +104,7 @@ using blender::Span;
 using blender::Stack;
 using blender::Vector;
 using blender::VectorSet;
+using blender::nodes::FieldInferencingInterface;
 using blender::nodes::InputSocketFieldType;
 using blender::nodes::NodeDeclaration;
 using blender::nodes::OutputFieldDependency;
@@ -132,6 +133,9 @@ static FieldInferencingInterface *node_field_inferencing_interface_copy(
     const FieldInferencingInterface &field_inferencing_interface);
 static void node_field_inferencing_interface_free(
     const FieldInferencingInterface *field_inferencing_interface);
+// namespace blender::bke::node_tree_inferencing {
+// bool update_field_inferencing(bNodeTree &btree);
+// }
 
 static void ntree_init_data(ID *id)
 {
@@ -677,6 +681,10 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree)
   ntree->execdata = nullptr;
 
   ntree->field_inferencing_interface = nullptr;
+  if (ntree->type == NTREE_GEOMETRY) {
+    ntree->update |= (NTREE_UPDATE | NTREE_UPDATE_FIELD_INFERENCING);
+    // blender::bke::node_field_inferencing::update_field_inferencing(*ntree);
+  }
 
   BLO_read_data_address(reader, &ntree->adt);
   BKE_animdata_blend_read_data(reader, ntree->adt);
@@ -4456,24 +4464,6 @@ void ntreeUpdateAllNew(Main *main)
   FOREACH_NODETREE_END;
 }
 
-/**
- * Information about how a node interacts with fields.
- */
-struct FieldInferencingInterface {
-  Vector<InputSocketFieldType> inputs;
-  Vector<OutputFieldDependency> outputs;
-
-  friend bool operator==(const FieldInferencingInterface &a, const FieldInferencingInterface &b)
-  {
-    return a.inputs == b.inputs && a.outputs == b.outputs;
-  }
-
-  friend bool operator!=(const FieldInferencingInterface &a, const FieldInferencingInterface &b)
-  {
-    return !(a == b);
-  }
-};
-
 static FieldInferencingInterface *node_field_inferencing_interface_copy(
     const FieldInferencingInterface &field_inferencing_interface)
 {
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index a52816ecf57..9719a23791f 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -460,7 +460,15 @@ typedef struct bNodeLink {
 #define NTREE_CHUNKSIZE_512 512
 #define NTREE_CHUNKSIZE_1024 1024
 
+/** Workaround to forward-declare C++ type in C header. */
+#ifdef __cplusplus
+namespace blender::nodes {
 struct FieldInferencingInterface;
+}
+using FieldInferencingInterfaceHandle = blender::nodes::FieldInferencingInterface;
+#else
+typedef struct FieldInferencingInterfaceHandle FieldInferencingInterfaceHandle;
+#endif
 
 /* the basis for a Node tree, all links and nodes reside internal here */
 /* only re-usable node trees are in the library though,
@@ -485,7 +493,7 @@ typedef struct bNodeTree {
 
   ListBase nodes, links;
   /** Information about how inputs and outputs of the node group interact with fields. */
-  struct FieldInferencingInterface *field_inferencing_interface;
+  FieldInferencingInterfaceHandle *field_inferencing_interface;
 
   /** Set init on fileread. */
   int type, init;
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 8c02c83d479..bc530491fed 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -27,6 +27,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_array.hh"
 #include "BLI_float3.hh"
 #include "BLI_listbase.h"
 #include "BLI_multi_value_map.hh"
@@ -88,6 +89,7 @@
 #include "NOD_derived_node_tree.hh"
 #include "NOD_geometry.h"
 #include "NOD_geometry_nodes_eval_log.hh"
+#include "NOD_node_declaration.hh"
 
 #include "FN_field.hh"
 #include "FN_multi_function.hh"
@@ -105,7 +107,11 @@ using blender::StringRefNull;
 using blender::Vector;
 using blender::fn::GMutablePointer;
 using blender::fn::GPointer;
+using blender::nodes::FieldInferencingInterface;
 using blender::nodes::GeoNodeExecParams;
+using blender::nodes::InputSocketFieldType;
+using blender::nodes::OutputFieldDependency;
+using blender::nodes::OutputSocketFieldType;
 using blender::threading::EnumerableThreadSpecific;
 using namespace blender::fn::multi_function_types;
 using namespace blender::nodes::derived_node_tree_types;
@@ -301,9 +307,14 @@ static const std::string attribute_name_suffix = "_attribute_name";
 /**
  * \return Whether using an attribute to input values of this type is supported.
  */
-static bool socket_type_has_attribute_toggle(const bNodeSocket &socket)
+static bool input_has_attribute_toggle(const bNodeTree &node_tree, const int socket_index)
 {
-  return ELEM(socket.type, SOCK_FLOAT, SOCK_VECTOR, SOCK_BOOLEAN, SOCK_RGBA, SOCK_INT);
+  if (node_tree.field_inferencing_interface == nullptr) {
+    return false;
+  }
+  BLI_assert(node_tree.field_inferencing_interface != nullptr);
+  const FieldInferencingInterface &field_interface = *node_tree.field_inferencing_interface;
+  return field_interface.inputs[socket_index] != InputSocketFieldType::None;
 }
 
 static IDProperty *id_property_create_from_socket(const bNodeSocket &socket)
@@ -531,7 +542,8 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
     nmd->settings.properties = IDP_New(IDP_GROUP, &idprop, "Nodes Modifier Settings");
   }
 
-  LISTBASE_FOREACH (bNodeSocket *, socket, &nmd->node_group->inputs) {
+  int socket_index;
+  LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, &nmd->node_group->inputs, socket_index) {
     IDProperty *new_prop = id_property_create_from_socket(*socket);
     if (new_prop == nullptr) {
       /* Out of the set of supported input sockets, only
@@ -562,7 +574,7 @@ void MOD_nodes_update_interface(Object *object, NodesModifierData *nmd)
       }
     }
 
-    if (socket_type_has_attribute_toggle(*socket)) {
+    if (input_has_attribute_toggle(*nmd->node_group, socket_index)) {
       const std::string use_attribute_id = socket->identifier + use_attribute_suffix;
       const std::string attribute_name_id = socket->identifier + attribute_name_suffix;
 
@@ -624,37 +636,38 @@ void MOD_nodes_init(Main *bmain, NodesModifierData *nmd)
 }
 
 static void initialize_group_input(NodesModifierData &nmd,
-                                   const bNodeSocket &socket,
+                                   const OutputSocketRef &socket,
                                    void *r_value)
 {
+  const bNodeSocket &bsocket = *socket.bsocket();
   if (nmd.settings.properties == nullptr) {
-    socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
+    socket.typeinfo()->get_geometry_nodes_cpp_value(bsocket, r_value);
     return;
   }
   const IDProperty *property = IDP_GetPropertyFromGroup(nmd.settings.properties,
-                                                        socket.identifier);
+                                                        socket.identifier().c_str());
   if (property == nullptr) {
-    socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
+    socket.typeinfo()->get_geometry_nodes_cpp_value(bsocket, r_value);
     return;
   }
-  if (!id_property_type_matches_socket(socket, *property)) {
-    socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
+  if (!id_property_type_matches_socket(bsocket, *property)) {
+    socket.typeinfo()->get_geometry_nodes_cpp_value(bsocket, r_value);
     return;
   }
 
-  if (!socket_type_has_attribute_toggle(socket)) {
+  if (!input_has_attribute_toggle(*nmd.node_group, socket.index())) {
     init_socket_cpp_value_from_property(
-        *property, static_cast<eNodeSocketDatatype>(socket.type), r_value);
+        *property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value);
     return;
   }
 
   const IDProperty *property_use_attribute = IDP_GetPropertyFromGroup(
-      nmd.settings.properties, (socket.identifier + use_attribute_suffix).c_str());
+      nmd.settings.properties, (socket.identifier() + use_attribute_suffix).c_str());
   const IDProperty *property_attribute_name = IDP_GetPropertyFromGroup(
-      nmd.settings.properties, (socket.identifier + attribute_name_suffix).c_str());
+      nmd.settings.properties, (socket.identifier() + attribute_name_suffix).c_str());
   if (property_use_attribute == nullptr || property_attribute_name == nullptr) {
     init_socket_cpp_value_from_property(
-        *property, static_cast<eNodeSocketDatatype>(socket.type), r_value);
+        *property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value);
     return;
   }
 
@@ -662,12 +675,12 @@ static void initialize_group_input(NodesModifierData &nmd,
   if (use_attribute) {
     const StringRef attribute_name{IDP_String(property_attribute_name)};
     auto attribute_input = std::make_shared<blender::bke::AttributeFieldInput>(
-        attribute_name, *socket.typeinfo->get_base_cpp_type());
+        attribute_name, *socket.typeinfo()->get_base_cpp_type());
     new (r_value) blender::fn::GField(std::move(attribute_input), 0);
   }
   else {
     init_socket_cpp_value_from_property(
-        *property, static_cast<eNodeSocketDatatype>(socket.type), r_value);
+        *property, static_cast<eNodeSocketDatatype>(bsocket.type), r_value);
   }
 }
 
@@ -819,7 +832,7 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree,
     for (const OutputSocketRef *socket : remaining_input_sockets) {
       const CPPType &cpp_type = *socket->typeinfo()->get_geometry_nodes_cpp_type();
       void *value_in = allocator.allocate(cpp_type.size(), cpp_type.alignment());
-      initialize_group_input(*nmd, *socket->bsocket(), value_in);
+      initialize_group_input(*nmd, *socket, value_in);
       group_inputs.add_new({root_context, socket}, {cpp_type, value_in});
     }
   }
@@ -981,7 +994,8 @@ static void draw_property_for_socket(uiLayout *layout,
                                      NodesModifierData *nmd,
                                      PointerRNA *bmain_ptr,
                                      PointerRNA *md_ptr,
-                                     const bNodeSocket &socket)
+         

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list