[Bf-blender-cvs] [6343cd913da] temp-geometry-nodes-expandable-geometry-socket-prototype: support execution geometry expander

Jacques Lucke noreply at git.blender.org
Thu Aug 5 17:27:07 CEST 2021


Commit: 6343cd913da35925cb6673813f1ad69043f6deb8
Author: Jacques Lucke
Date:   Thu Aug 5 17:27:00 2021 +0200
Branches: temp-geometry-nodes-expandable-geometry-socket-prototype
https://developer.blender.org/rB6343cd913da35925cb6673813f1ad69043f6deb8

support execution geometry expander

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

M	source/blender/editors/space_node/node_edit.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/NOD_geometry_exec.hh
M	source/blender/nodes/geometry/node_geometry_util.hh
M	source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
M	source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc

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

diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index dd053367eff..f35318f2ad1 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -2999,7 +2999,7 @@ static void foreach_available_attribute(
     if (ELEM(group_input->type, SOCK_INT, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_BOOLEAN)) {
       GeometryExpanderOutput attribute;
       attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_INPUT;
-      attribute.domain = ATTR_DOMAIN_POINT;
+      attribute.array_source = GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES;
       attribute.socket_type = (eNodeSocketDatatype)group_input->type;
       STRNCPY(attribute.input_identifier, group_input->identifier);
       callback(attribute);
@@ -3012,7 +3012,7 @@ static void foreach_available_attribute(
         GeometryExpanderOutput attribute;
         attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_LOCAL;
         attribute.socket_type = (eNodeSocketDatatype)node_output->type;
-        attribute.domain = ATTR_DOMAIN_POINT;
+        attribute.array_source = GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES;
         STRNCPY(attribute.local_node_name, node->name);
         STRNCPY(attribute.local_socket_identifier, node_output->identifier);
         callback(attribute);
@@ -3023,7 +3023,7 @@ static void foreach_available_attribute(
     GeometryExpanderOutput attribute;
     attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_BUILTIN;
     attribute.socket_type = SOCK_VECTOR;
-    attribute.domain = ATTR_DOMAIN_POINT;
+    attribute.array_source = GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES;
     STRNCPY(attribute.builtin_identifier, "position");
     callback(attribute);
   }
@@ -3031,7 +3031,7 @@ static void foreach_available_attribute(
     GeometryExpanderOutput attribute;
     attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_BUILTIN;
     attribute.socket_type = SOCK_INT;
-    attribute.domain = ATTR_DOMAIN_FACE;
+    attribute.array_source = GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES;
     STRNCPY(attribute.builtin_identifier, "material_index");
     callback(attribute);
   }
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 62a09719904..d79721cdeca 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1431,6 +1431,16 @@ typedef enum eGeometryExpanderOutputType {
   GEOMETRY_EXPANDER_OUTPUT_TYPE_BUILTIN,
 } eGeometryExpanderOutputType;
 
+typedef enum eGeometryExpanderArraySource {
+  GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES = 0,
+  GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_EDGES = 1,
+  GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACES = 2,
+  GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACE_CORNERS = 3,
+  GEOMETRY_EXPANDER_ARRAY_SOURCE_POINT_CLOUD_POINTS = 4,
+  GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_POINTS = 5,
+  GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_SPLINES = 6,
+} AttributeArraySource;
+
 typedef struct GeometryExpanderOutput {
   struct GeometryExpanderOutput *next, *prev;
 
@@ -1445,13 +1455,11 @@ typedef struct GeometryExpanderOutput {
   /* Derived from the other data. */
   char display_name_cache[64];
 
-  /* AttributeDomain. */
-  int8_t domain;
-  /* GeometryComponentType. */
-  int8_t component_type;
+  /* eGeometryExpanderAttributeSource. */
+  int8_t array_source;
   /* eNodeSocketDatatype. */
   int8_t socket_type;
-  char _pad2[5];
+  char _pad2[6];
 
   /* Local attribute data. */
   char local_node_name[64];
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 310f04e54cc..95495022c13 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -39,6 +39,7 @@
 #include "BKE_animsys.h"
 #include "BKE_attribute.h"
 #include "BKE_cryptomatte.h"
+#include "BKE_geometry_set.h"
 #include "BKE_image.h"
 #include "BKE_node.h"
 #include "BKE_texture.h"
@@ -10260,13 +10261,35 @@ static void def_geo_geometry_expander_output(BlenderRNA *brna)
   StructRNA *srna;
   PropertyRNA *prop;
 
+  static const EnumPropertyItem array_source_items[] = {
+      {GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES, "MESH_VERTICES", ICON_NONE, "Vertices", ""},
+      {GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_EDGES, "MESH_EDGES", ICON_NONE, "Edges", ""},
+      {GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACES, "MESH_FACES", ICON_NONE, "Faces", ""},
+      {GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACE_CORNERS,
+       "MESH_FACE_CORNERS",
+       ICON_NONE,
+       "Face Corners",
+       ""},
+      {GEOMETRY_EXPANDER_ARRAY_SOURCE_POINT_CLOUD_POINTS,
+       "POINT_CLOUD_POINTS",
+       ICON_NONE,
+       "Points",
+       ""},
+      {GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_POINTS,
+       "CURVE_POINTS",
+       ICON_NONE,
+       "Control Points",
+       ""},
+      {GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_SPLINES, "CURVE_SPLINES", ICON_NONE, "Splines", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   srna = RNA_def_struct(brna, "GeometryExpanderOutput", NULL);
 
-  prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items);
-  RNA_def_property_ui_text(prop, "Domain", "");
-  /* TODO: Update callback. */
-  RNA_def_property_update(prop, NC_NODE | NA_EDITED, NULL);
+  prop = RNA_def_property(srna, "array_source", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, array_source_items);
+  RNA_def_property_ui_text(prop, "Array Source", "");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeTree_update");
 }
 
 static void def_geo_geometry_expander(StructRNA *srna)
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 26827372445..6748d538e6a 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -225,6 +225,17 @@ class GeoNodeExecParams {
     }
   }
 
+  void set_output_by_move(StringRef identifier, GMutablePointer value)
+  {
+    const CPPType &type = *value.type();
+#ifdef DEBUG
+    this->check_output_access(identifier, type);
+#endif
+    GMutablePointer stored_value = provider_->alloc_output_value(type);
+    type.move_construct(value.get(), stored_value.get());
+    provider_->set_output(identifier, stored_value);
+  }
+
   /**
    * Tell the evaluator that a specific input won't be used anymore.
    */
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index 12d8deb9921..4ae9b1c4d62 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -102,11 +102,17 @@ inline bool should_add_output_attribute(const bNode &node, StringRef output_name
   return false;
 }
 
-inline std::string get_output_attribute_name(const bNodeTree &ntree,
-                                             const bNode &node,
-                                             StringRef output_name)
+inline std::string get_local_attribute_name(const StringRef tree_name,
+                                            const StringRef node_name,
+                                            const StringRef socket_identifier)
 {
-  return StringRef("local_") + ntree.id.name + "_" + node.name + "_" + output_name;
+  return "local_" + tree_name + "_" + node_name + "_" + socket_identifier;
+}
+
+inline std::string get_input_attribute_name(const StringRef tree_name,
+                                            const StringRef input_identifier)
+{
+  return "input_" + tree_name + "_" + input_identifier;
 }
 
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc b/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
index 647dcf6520a..b2d175ea0ae 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
@@ -67,53 +67,133 @@ static bool geo_node_geometry_expander_socket_layout(const bContext *UNUSED(C),
     uiItemL(split, "", ICON_ERROR);
   }
   else {
-    uiItemR(split, &expander_output_ptr, "domain", 0, "", ICON_NONE);
+    uiItemR(split, &expander_output_ptr, "array_source", 0, "", ICON_NONE);
   }
 
   return true;
 }
 
+static GeometryComponentType array_source_to_component_type(
+    const eGeometryExpanderArraySource array_source)
+{
+  switch (array_source) {
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES:
+      return GEO_COMPONENT_TYPE_MESH;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_EDGES:
+      return GEO_COMPONENT_TYPE_MESH;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACES:
+      return GEO_COMPONENT_TYPE_MESH;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACE_CORNERS:
+      return GEO_COMPONENT_TYPE_MESH;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_POINT_CLOUD_POINTS:
+      return GEO_COMPONENT_TYPE_POINT_CLOUD;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_POINTS:
+      return GEO_COMPONENT_TYPE_CURVE;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_SPLINES:
+      return GEO_COMPONENT_TYPE_CURVE;
+  }
+  BLI_assert_unreachable();
+  return GEO_COMPONENT_TYPE_MESH;
+}
+
+static AttributeDomain array_source_to_domain(const eGeometryExpanderArraySource array_source)
+{
+  switch (array_source) {
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_VERTICES:
+      return ATTR_DOMAIN_POINT;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_EDGES:
+      return ATTR_DOMAIN_EDGE;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACES:
+      return ATTR_DOMAIN_FACE;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_MESH_FACE_CORNERS:
+      return ATTR_DOMAIN_CORNER;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_POINT_CLOUD_POINTS:
+      return ATTR_DOMAIN_POINT;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_POINTS:
+      return ATTR_DOMAIN_POINT;
+    case GEOMETRY_EXPANDER_ARRAY_SOURCE_CURVE_SPLINES:
+      return ATTR_DOMAIN_CURVE;
+  }
+  BLI_assert_unreachable();
+  return ATTR_DOMAIN_POINT;
+}
+
 static void geo_node_geometry_expander_exec(GeoNodeExecParams params)
 {
   const bNode &bnode = params.node();
+  const bNodeTree &ntree = params.ntree();
   const NodeGeometryGeometryEx

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list