[Bf-blender-cvs] [fe2cde8390d] temp-enum-socket: improve

Jacques Lucke noreply at git.blender.org
Tue Nov 9 19:35:28 CET 2021


Commit: fe2cde8390d8130f3f2cfa1c25614a1d728a2fff
Author: Jacques Lucke
Date:   Tue Nov 9 19:28:55 2021 +0100
Branches: temp-enum-socket
https://developer.blender.org/rBfe2cde8390d8130f3f2cfa1c25614a1d728a2fff

improve

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

M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
M	source/blender/nodes/intern/node_geometry_exec.cc

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

diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 25a54866577..493646744d6 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -66,6 +66,27 @@ using fn::GVMutableArray_Typed;
 using fn::GVMutableArrayPtr;
 using geometry_nodes_eval_log::NodeWarningType;
 
+/** Wrapper for an integer so that one can not perform various operations like addition on it. */
+struct EnumValue {
+  int value;
+
+  friend std::ostream &operator<<(std::ostream &stream, const EnumValue &value)
+  {
+    stream << value.value;
+    return stream;
+  }
+
+  friend bool operator==(const EnumValue &a, const EnumValue &b)
+  {
+    return a.value == b.value;
+  }
+
+  uint64_t hash() const
+  {
+    return this->value;
+  }
+};
+
 /**
  * This class exists to separate the memory management details of the geometry nodes evaluator
  * from the node execution functions and related utilities.
@@ -139,7 +160,8 @@ class GeoNodeExecParams {
                                                       std::is_same_v<T, bool> ||
                                                       std::is_same_v<T, ColorGeometry4f> ||
                                                       std::is_same_v<T, float3> ||
-                                                      std::is_same_v<T, std::string>;
+                                                      std::is_same_v<T, std::string> ||
+                                                      std::is_same_v<T, EnumValue>;
 
   /**
    * Get the input value for the input socket with the given identifier.
@@ -211,6 +233,10 @@ class GeoNodeExecParams {
       const Field<T> &field = this->get_input<Field<T>>(identifier);
       return fn::evaluate_constant_field(field);
     }
+    else if constexpr (std::is_enum_v<T>) {
+      const int value = this->get_input<EnumValue>(identifier).value;
+      return (T)this->validate_enum_value(identifier, value);
+    }
     else {
 #ifdef DEBUG
       this->check_input_access(identifier, &CPPType::get<T>());
@@ -354,27 +380,8 @@ class GeoNodeExecParams {
 
   /* Find the active socket with the input name (not the identifier). */
   const bNodeSocket *find_available_socket(const StringRef name) const;
-};
-
-/** Wrapper for an integer so that one can not perform various operations like addition on it. */
-struct EnumValue {
-  int value;
 
-  friend std::ostream &operator<<(std::ostream &stream, const EnumValue &value)
-  {
-    stream << value.value;
-    return stream;
-  }
-
-  friend bool operator==(const EnumValue &a, const EnumValue &b)
-  {
-    return a.value == b.value;
-  }
-
-  uint64_t hash() const
-  {
-    return this->value;
-  }
+  const int validate_enum_value(StringRef identifier, const int value) const;
 };
 
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
index 219effadec4..c2f10e08b55 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
@@ -35,15 +35,17 @@ namespace blender::nodes {
 
 static void geo_node_curve_fill_declare(NodeDeclarationBuilder &b)
 {
+  static const EnumPropertyItem mode_items[] = {
+      {GEO_NODE_CURVE_FILL_MODE_TRIANGULATED, "TRIANGLES", 0, "Triangles", ""},
+      {GEO_NODE_CURVE_FILL_MODE_NGONS, "NGONS", 0, "N-gons", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   b.add_input<decl::Geometry>(N_("Curve")).supported_type(GEO_COMPONENT_TYPE_CURVE);
+  b.add_input<decl::Enum>(N_("Mode")).static_items(mode_items);
   b.add_output<decl::Geometry>(N_("Mesh"));
 }
 
-static void geo_node_curve_fill_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
-  uiItemR(layout, ptr, "mode", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
-}
-
 static void geo_node_curve_fill_init(bNodeTree *UNUSED(ntree), bNode *node)
 {
   NodeGeometryCurveFill *data = (NodeGeometryCurveFill *)MEM_callocN(sizeof(NodeGeometryCurveFill),
@@ -151,8 +153,7 @@ static void geo_node_curve_fill_exec(GeoNodeExecParams params)
 {
   GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
 
-  const NodeGeometryCurveFill &storage = *(const NodeGeometryCurveFill *)params.node().storage;
-  const GeometryNodeCurveFillMode mode = (GeometryNodeCurveFillMode)storage.mode;
+  const GeometryNodeCurveFillMode mode = params.get_input<GeometryNodeCurveFillMode>("Mode");
 
   geometry_set.modify_geometry_sets(
       [&](GeometrySet &geometry_set) { curve_fill_calculate(geometry_set, mode); });
@@ -173,6 +174,5 @@ void register_node_type_geo_curve_fill()
       &ntype, "NodeGeometryCurveFill", node_free_standard_storage, node_copy_standard_storage);
   ntype.declare = blender::nodes::geo_node_curve_fill_declare;
   ntype.geometry_node_execute = blender::nodes::geo_node_curve_fill_exec;
-  ntype.draw_buttons = blender::nodes::geo_node_curve_fill_layout;
   nodeRegisterType(&ntype);
 }
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index 27bc206187d..838e07c14a2 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -254,6 +254,29 @@ std::string GeoNodeExecParams::attribute_producer_name() const
   return provider_->dnode->label_or_name() + TIP_(" node");
 }
 
+const int GeoNodeExecParams::validate_enum_value(StringRef identifier, const int value) const
+{
+  const bNodeSocket &socket = *provider_->dnode->input_by_identifier(identifier).bsocket();
+  BLI_assert(socket.type == SOCK_ENUM);
+  const bNodeSocketValueEnum *socket_value = (const bNodeSocketValueEnum *)socket.default_value;
+  BLI_assert(socket_value->items != nullptr);
+  for (const EnumPropertyItem *item = socket_value->items; item->identifier != nullptr; item++) {
+    if (item->identifier[0]) {
+      if (item->value == value) {
+        return value;
+      }
+    }
+  }
+  /* Use the first value as default if the passed in value is invalid. */
+  for (const EnumPropertyItem *item = socket_value->items; item->identifier != nullptr; item++) {
+    if (item->identifier[0]) {
+      return item->value;
+    }
+  }
+  BLI_assert_unreachable();
+  return 0;
+}
+
 void GeoNodeExecParams::check_input_access(StringRef identifier,
                                            const CPPType *requested_type) const
 {



More information about the Bf-blender-cvs mailing list