[Bf-blender-cvs] [8dad29d0eac] temp-geometry-nodes-fields-prototype: new Attribute Extract node

Jacques Lucke noreply at git.blender.org
Mon Aug 9 11:11:18 CEST 2021


Commit: 8dad29d0eac64c7c73bb954885c77071e442b2d1
Author: Jacques Lucke
Date:   Mon Aug 9 11:10:57 2021 +0200
Branches: temp-geometry-nodes-fields-prototype
https://developer.blender.org/rB8dad29d0eac64c7c73bb954885c77071e442b2d1

new Attribute Extract node

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

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/geometry/nodes/node_geo_attribute_extract.cc

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

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 4933f28151c..a5316c14896 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -482,6 +482,7 @@ geometry_node_categories = [
         NodeItem("GeometryNodeAttributeRemove"),
         NodeItem("GeometryNodeAttributeMapRange"),
         NodeItem("GeometryNodeAttributeTransfer"),
+        NodeItem("GeometryNodeAttributeExtract"),
         NodeItem("GeometryNodeAttributeStore"),
     ]),
     GeometryNodeCategory("GEO_COLOR", "Color", items=[
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index ae78ec7bb55..3a8b228e04b 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1481,6 +1481,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_INDEX 1076
 #define GEO_NODE_EXTRUDE 1077
 #define GEO_NODE_ATTRIBUTE_STORE_ANONYMOUS 1078
+#define GEO_NODE_ATTRIBUTE_EXTRACT 1079
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index d53548a918f..c4d8aa50fa8 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -5124,6 +5124,7 @@ static void registerGeometryNodes()
   register_node_type_geo_attribute_compare();
   register_node_type_geo_attribute_convert();
   register_node_type_geo_attribute_curve_map();
+  register_node_type_geo_attribute_extract();
   register_node_type_geo_attribute_fill();
   register_node_type_geo_attribute_map_range();
   register_node_type_geo_attribute_math();
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index fa4bd8bfed1..3c2c0d5d33d 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1435,6 +1435,13 @@ typedef struct NodeGeometryAttribute {
   int8_t output_type;
 } NodeGeometryAttribute;
 
+typedef struct NodeGeometryAttributeExtract {
+  /* CustomDataType. */
+  int8_t data_type;
+  /* Boolean that indicates whether the persistent attribute should be removed. */
+  uint8_t delete_persistent;
+} NodeGeometryAttributeExtract;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL 0
 #define NODE_SCRIPT_EXTERNAL 1
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index f2481d50d1c..3daa2adedcd 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -9156,6 +9156,26 @@ static void def_geo_attribute_fill(StructRNA *srna)
   RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_geo_attribute_extract(StructRNA *srna)
+{
+  PropertyRNA *prop;
+
+  RNA_def_struct_sdna_from(srna, "NodeGeometryAttributeExtract", "storage");
+
+  prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "data_type");
+  RNA_def_property_enum_items(prop, rna_enum_attribute_type_items);
+  RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_GeometryNodeAttributeFill_type_itemf");
+  RNA_def_property_enum_default(prop, CD_PROP_FLOAT);
+  RNA_def_property_ui_text(prop, "Data Type", "Type of data stored in attribute");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_GeometryNode_socket_update");
+
+  prop = RNA_def_property(srna, "delete_persistent", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_ui_text(
+      prop, "Delete Persistent", "Delete the persistent attribute with the given name");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
 static void def_geo_attribute_store_anonymous(StructRNA *srna)
 {
   PropertyRNA *prop;
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 1417d3cc8e1..28058285f31 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -151,6 +151,7 @@ set(SRC
   geometry/nodes/node_geo_attribute_compare.cc
   geometry/nodes/node_geo_attribute_convert.cc
   geometry/nodes/node_geo_attribute_curve_map.cc
+  geometry/nodes/node_geo_attribute_extract.cc
   geometry/nodes/node_geo_attribute_fill.cc
   geometry/nodes/node_geo_attribute_map_range.cc
   geometry/nodes/node_geo_attribute_math.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 8dfae005f56..997868b6de5 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -43,6 +43,7 @@ void register_node_type_geo_attribute_fill(void);
 void register_node_type_geo_attribute_map_range(void);
 void register_node_type_geo_attribute_math(void);
 void register_node_type_geo_attribute_mix(void);
+void register_node_type_geo_attribute_extract(void);
 void register_node_type_geo_attribute_proximity(void);
 void register_node_type_geo_attribute_randomize(void);
 void register_node_type_geo_attribute_remove(void);
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 3aac71fd2f9..cfb54c254a9 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -278,6 +278,7 @@ DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_COMBINE_XYZ, def_geo_attribute_combine_
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_COMPARE, def_geo_attribute_attribute_compare, "ATTRIBUTE_COMPARE", AttributeCompare, "Attribute Compare", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_CONVERT, def_geo_attribute_convert, "ATTRIBUTE_CONVERT", AttributeConvert, "Attribute Convert", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_CURVE_MAP, def_geo_attribute_curve_map, "ATTRIBUTE_CURVE_MAP", AttributeCurveMap, "Attribute Curve Map", "")
+DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_EXTRACT, def_geo_attribute_extract, "ATTRIBUTE_EXTRACT", AttributeExtract, "Attribute Extract", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_FILL, def_geo_attribute_fill, "ATTRIBUTE_FILL", AttributeFill, "Store Persistent Attribute", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MAP_RANGE, def_geo_attribute_map_range, "ATTRIBUTE_MAP_RANGE", AttributeMapRange, "Attribute Map Range", "")
 DefNode(GeometryNode, GEO_NODE_ATTRIBUTE_MATH, def_geo_attribute_math, "ATTRIBUTE_MATH", AttributeMath, "Attribute Math", "")
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_extract.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_extract.cc
new file mode 100644
index 00000000000..3bd0114b035
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_extract.cc
@@ -0,0 +1,182 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "node_geometry_util.hh"
+
+static bNodeSocketTemplate geo_node_attribute_extract_in[] = {
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {SOCK_STRING, N_("Attribute")},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_attribute_extract_out[] = {
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {SOCK_VECTOR, N_("Value")},
+    {SOCK_FLOAT, N_("Value")},
+    {SOCK_RGBA, N_("Value")},
+    {SOCK_BOOLEAN, N_("Value")},
+    {SOCK_INT, N_("Value")},
+    {-1, ""},
+};
+
+static void geo_node_attribute_extract_layout(uiLayout *layout,
+                                              bContext *UNUSED(C),
+                                              PointerRNA *ptr)
+{
+  uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
+  uiItemR(layout, ptr, "delete_persistent", 0, nullptr, ICON_NONE);
+}
+
+static void geo_node_attribute_extract_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+  NodeGeometryAttributeExtract *storage = (NodeGeometryAttributeExtract *)MEM_callocN(
+      sizeof(NodeGeometryAttributeExtract), __func__);
+  storage->data_type = CD_PROP_FLOAT;
+  storage->delete_persistent = false;
+  node->storage = storage;
+}
+
+static void geo_node_attribute_extract_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+
+  const NodeGeometryAttributeExtract &storage = *(const NodeGeometryAttributeExtract *)
+                                                     node->storage;
+
+  bNodeSocket *socket_value_vector = (bNodeSocket *)BLI_findlink(&node->outputs, 1);
+  bNodeSocket *socket_value_float = socket_value_vector->next;
+  bNodeSocket *socket_value_color4f = socket_value_float->next;
+  bNodeSocket *socket_value_boolean = socket_value_color4f->next;
+  bNodeSocket *socket_value_int32 = socket_value_boolean->next;
+
+  const CustomDataType data_type = (CustomDataType)storage.data_type;
+
+  nodeSetSocketAvailability(socket_value_vector, data_type == CD_PROP_FLOAT3);
+  nodeSetSocketAvailability(socket_value_float, data_type == CD_PROP_FLOAT);
+  nodeSetSocketAvailability(socket_value_color4f, data_type == CD_PROP_COLOR);
+  nodeSetSocketAvailability(socket_value_boolean, data_type == CD_PROP_BOOL);
+  nodeSetSocketAvailability(socket_value_int32, data_type == CD_PROP_INT32);
+}
+
+namespace blender::nodes {
+
+static void convert_attribute(GeometryComponent &component,
+                              const StringRef attribute_name,
+                              const AnonymousCustomDataLayerID &layer_id,
+                              bool delete_persistent)
+{
+  ReadAttributeLookup attribute_lookup = component.attribute_try_get_for_read(attribute_name);
+  if (!attribute_lookup) {
+    return;
+  }
+  const GVArray &varray = *attribute_lookup.varray;
+  const CPPType &cpp_type = varray.type();
+  const CustomDataType data_type =

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list