[Bf-blender-cvs] [5afddf257df] temp-geometry-nodes-expandable-geometry-socket-prototype: add plus icon to rotation output in point distribute node

Jacques Lucke noreply at git.blender.org
Wed Aug 4 17:10:49 CEST 2021


Commit: 5afddf257dfd371e97b64520394dc1ec24888cc3
Author: Jacques Lucke
Date:   Wed Aug 4 15:16:41 2021 +0200
Branches: temp-geometry-nodes-expandable-geometry-socket-prototype
https://developer.blender.org/rB5afddf257dfd371e97b64520394dc1ec24888cc3

add plus icon to rotation output in point distribute node

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

M	source/blender/editors/space_node/node_draw.cc
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_point_distribute.cc

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

diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index ec257f428ca..613e5684bfd 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -372,6 +372,10 @@ static void draw_socket_layout(
   RNA_pointer_create(&ntree->id, &RNA_NodeSocket, socket, &sockptr);
   const char *socket_label = nodeSocketLabel(socket);
   socket->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label));
+
+  if (socket->flag & SOCK_IS_ATTRIBUTE_OUTPUT) {
+    uiItemR(row, &sockptr, "add_to_geometry", 0, "", ICON_ADD);
+  }
 }
 
 /**
diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index ee0312a52ae..91a756be97b 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -3005,10 +3005,8 @@ static void foreach_available_attribute(
     }
   }
   LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
-    bool has_seen_geometry = false;
     LISTBASE_FOREACH (bNodeSocket *, node_output, &node->outputs) {
-      has_seen_geometry |= node_output->type == SOCK_GEOMETRY;
-      if (has_seen_geometry && node->type != NODE_GROUP_INPUT &&
+      if ((node_output->flag & SOCK_ADD_ATTRIBUTE_TO_GEOMETRY) &&
           ELEM(node_output->type, SOCK_INT, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_BOOLEAN)) {
         AvailableAttribute attribute{node, node_output};
         callback(attribute);
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 3e317f777d9..2bc81b2276e 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -214,6 +214,8 @@ typedef enum eNodeSocketFlag {
    * type is obvious and the name takes up too much space.
    */
   SOCK_HIDE_LABEL = (1 << 12),
+  SOCK_ADD_ATTRIBUTE_TO_GEOMETRY = (1 << 13),
+  SOCK_IS_ATTRIBUTE_OUTPUT = (1 << 14),
 } eNodeSocketFlag;
 
 /* TODO: Limit data in bNode to what we want to see saved. */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 58764d2105d..ca972989413 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -10383,6 +10383,14 @@ static void rna_def_node_socket(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Hide Value", "Hide the socket input value");
   RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, NULL);
 
+  prop = RNA_def_property(srna, "add_to_geometry", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "flag", SOCK_ADD_ATTRIBUTE_TO_GEOMETRY);
+  RNA_def_property_ui_text(
+      prop,
+      "Add to Geometry",
+      "Add attribute output to the geometry so that it can be accessed later");
+  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocket_update");
+
   prop = RNA_def_property(srna, "node", PROP_POINTER, PROP_NONE);
   RNA_def_property_pointer_funcs(prop, "rna_NodeSocket_node_get", NULL, NULL, NULL);
   RNA_def_property_struct_type(prop, "Node");
diff --git a/source/blender/nodes/NOD_geometry_exec.hh b/source/blender/nodes/NOD_geometry_exec.hh
index 0514d36a77d..26827372445 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -272,6 +272,11 @@ class GeoNodeExecParams {
     return *provider_->dnode->bnode();
   }
 
+  const bNodeTree &ntree() const
+  {
+    return *provider_->dnode->tree().btree();
+  }
+
   const Object *self_object() const
   {
     return provider_->self_object;
diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh
index 956b7b8a005..12d8deb9921 100644
--- a/source/blender/nodes/geometry/node_geometry_util.hh
+++ b/source/blender/nodes/geometry/node_geometry_util.hh
@@ -92,4 +92,21 @@ void curve_create_default_rotation_attribute(Span<float3> tangents,
                                              Span<float3> normals,
                                              MutableSpan<float3> rotations);
 
+inline bool should_add_output_attribute(const bNode &node, StringRef output_name)
+{
+  LISTBASE_FOREACH (bNodeSocket *, sock, &node.outputs) {
+    if (sock->name == output_name) {
+      return (sock->flag & SOCK_ADD_ATTRIBUTE_TO_GEOMETRY);
+    }
+  }
+  return false;
+}
+
+inline std::string get_output_attribute_name(const bNodeTree &ntree,
+                                             const bNode &node,
+                                             StringRef output_name)
+{
+  return StringRef("local_") + ntree.id.name + "_" + node.name + "_" + output_name;
+}
+
 }  // namespace blender::nodes
diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
index b413f0e4614..09357844c85 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
@@ -50,7 +50,7 @@ static bNodeSocketTemplate geo_node_point_distribute_in[] = {
 
 static bNodeSocketTemplate geo_node_point_distribute_out[] = {
     {SOCK_GEOMETRY, N_("Geometry")},
-    {SOCK_VECTOR, N_("Rotation")},
+    {SOCK_VECTOR, N_("Rotation"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_IS_ATTRIBUTE_OUTPUT},
     {-1, ""},
 };
 
@@ -646,6 +646,16 @@ static void geo_node_point_distribute_exec(GeoNodeExecParams params)
                                  looptri_indices_all,
                                  rotations);
 
+  if (should_add_output_attribute(params.node(), "Rotation")) {
+    const std::string rotation_attribute_name = get_output_attribute_name(
+        params.ntree(), params.node(), "Rotation");
+    fn::GVArray_For_Span rotations_varray{rotations.as_span()};
+    point_component.attribute_try_create(rotation_attribute_name,
+                                         ATTR_DOMAIN_POINT,
+                                         CD_PROP_FLOAT3,
+                                         AttributeInitVArray{&rotations_varray});
+  }
+
   params.set_output("Geometry", std::move(geometry_set_out));
   params.set_output("Rotation", Array<float3>(rotations.as_span()));
 }



More information about the Bf-blender-cvs mailing list