[Bf-blender-cvs] [3e413d9289f] temp-geometry-nodes-expandable-geometry-socket-prototype: improve expander attribute search
Jacques Lucke
noreply at git.blender.org
Wed Aug 4 17:10:49 CEST 2021
Commit: 3e413d9289fa9861e98a3c40842d8b3240afd045
Author: Jacques Lucke
Date: Wed Aug 4 16:41:09 2021 +0200
Branches: temp-geometry-nodes-expandable-geometry-socket-prototype
https://developer.blender.org/rB3e413d9289fa9861e98a3c40842d8b3240afd045
improve expander attribute search
===================================================================
M source/blender/blenkernel/intern/node.cc
M source/blender/editors/space_node/node_edit.cc
M source/blender/makesdna/DNA_node_types.h
M source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 3d1296f8fc4..625973d8a92 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -576,10 +576,6 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
NodeGeometryGeometryExpander *storage = (NodeGeometryGeometryExpander *)node->storage;
BLO_write_struct(writer, NodeGeometryGeometryExpander, storage);
BLO_write_struct_list(writer, GeometryExpanderOutput, &storage->outputs);
- LISTBASE_FOREACH (const GeometryExpanderOutput *, expander_output, &storage->outputs) {
- BLO_write_string(writer, expander_output->data_identifier);
- BLO_write_string(writer, expander_output->socket_identifier);
- }
}
else if (node->typeinfo != &NodeTypeUndefined) {
BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage);
@@ -763,10 +759,6 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree)
case GEO_NODE_GEOMETRY_EXPANDER: {
NodeGeometryGeometryExpander *storage = (NodeGeometryGeometryExpander *)node->storage;
BLO_read_list(reader, &storage->outputs);
- LISTBASE_FOREACH (GeometryExpanderOutput *, expander_output, &storage->outputs) {
- BLO_read_data_address(reader, &expander_output->socket_identifier);
- BLO_read_data_address(reader, &expander_output->data_identifier);
- }
break;
}
default:
diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index 91a756be97b..8039c79fcc2 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -35,6 +35,7 @@
#include "BLI_blenlib.h"
#include "BLI_function_ref.hh"
#include "BLI_math.h"
+#include "BLI_string_ref.hh"
#include "BKE_context.h"
#include "BKE_geometry_set.hh"
@@ -81,6 +82,10 @@
#include "node_intern.h" /* own include */
using blender::FunctionRef;
+using blender::Span;
+using blender::StringRef;
+using blender::StringRefNull;
+using blender::Vector;
#define USE_ESC_COMPO
@@ -2986,10 +2991,17 @@ void NODE_OT_cryptomatte_layer_remove(wmOperatorType *ot)
namespace {
struct AvailableAttribute {
- /* Can be empty of the attribute comes from a group input. */
- bNode *source_node;
- /* Can be a socket of a node or a node tree input. */
- bNodeSocket *source_socket;
+ eGeometryExpanderOutputType type;
+ eNodeSocketDatatype socket_type = SOCK_FLOAT;
+ std::string socket_name;
+
+ std::string local_node_name;
+ std::string local_socket_identifier;
+
+ std::string input_identifier;
+ std::string input_name;
+
+ std::string builtin_identifier;
};
} // namespace
@@ -3000,7 +3012,12 @@ static void foreach_available_attribute(
{
LISTBASE_FOREACH (bNodeSocket *, group_input, &ntree->inputs) {
if (ELEM(group_input->type, SOCK_INT, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_BOOLEAN)) {
- AvailableAttribute attribute{nullptr, group_input};
+ AvailableAttribute attribute;
+ attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_INPUT;
+ attribute.input_identifier = group_input->identifier;
+ attribute.input_name = group_input->name;
+ attribute.socket_type = (eNodeSocketDatatype)group_input->type;
+ attribute.socket_name = StringRef("Input ▶ ") + group_input->name;
callback(attribute);
}
}
@@ -3008,13 +3025,29 @@ static void foreach_available_attribute(
LISTBASE_FOREACH (bNodeSocket *, node_output, &node->outputs) {
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};
+ AvailableAttribute attribute;
+ attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_LOCAL;
+ attribute.local_node_name = node->name;
+ attribute.local_socket_identifier = node_output->identifier;
+ attribute.socket_type = (eNodeSocketDatatype)node_output->type;
+ attribute.socket_name = node->name + StringRef(" ▶ ") + node_output->name;
callback(attribute);
}
}
}
}
+static Span<AvailableAttribute> get_updated_cached_available_attributes(bNodeTree *ntree,
+ bNode *node)
+{
+ static Vector<AvailableAttribute> cached_available_attributes;
+ cached_available_attributes.clear();
+ foreach_available_attribute(ntree, node, [&](const AvailableAttribute &attribute) {
+ cached_available_attributes.append(attribute);
+ });
+ return cached_available_attributes;
+}
+
static const EnumPropertyItem *node_geometry_expander_output_add_items(bContext *C,
PointerRNA *ptr,
PropertyRNA *UNUSED(prop),
@@ -3029,14 +3062,16 @@ static const EnumPropertyItem *node_geometry_expander_output_add_items(bContext
bNode *node = nodeFindNodebyName(ntree, node_name);
MEM_freeN(node_name);
- int index = 0;
- foreach_available_attribute(ntree, node, [&](const AvailableAttribute &attribute) {
+ Span<AvailableAttribute> attributes = get_updated_cached_available_attributes(ntree, node);
+
+ for (const int i : attributes.index_range()) {
+ const AvailableAttribute &attribute = attributes[i];
EnumPropertyItem item = {0};
- item.value = index++;
- item.name = attribute.source_socket->name;
+ item.value = i;
+ item.name = attribute.socket_name.c_str();
item.identifier = "test";
RNA_enum_item_add(&items, &totitem, &item);
- });
+ }
RNA_enum_item_end(&items, &totitem);
*r_free = true;
@@ -3056,13 +3091,8 @@ static int node_geometry_expander_output_add_exec(bContext *C, wmOperator *op)
NodeGeometryGeometryExpander *storage = (NodeGeometryGeometryExpander *)node->storage;
const int item_value = RNA_enum_get(op->ptr, "item");
- AvailableAttribute used_attribute;
- int index = 0;
- foreach_available_attribute(ntree, node, [&](const AvailableAttribute &attribute) {
- if (index++ == item_value) {
- used_attribute = attribute;
- }
- });
+ Span<AvailableAttribute> attributes = get_updated_cached_available_attributes(ntree, node);
+ const AvailableAttribute &attribute = attributes[item_value];
auto to_identifier = [](int id) { return "out_" + std::to_string(id); };
@@ -3074,11 +3104,18 @@ static int node_geometry_expander_output_add_exec(bContext *C, wmOperator *op)
GeometryExpanderOutput *expander_output = (GeometryExpanderOutput *)MEM_callocN(
sizeof(GeometryExpanderOutput), __func__);
- expander_output->data_identifier = BLI_strdup(used_attribute.source_socket->identifier);
- expander_output->socket_identifier = BLI_strdup(identifier.c_str());
- expander_output->socket_type = used_attribute.source_socket->type;
- expander_output->component_type = (int)GEO_COMPONENT_TYPE_MESH;
+
+ expander_output->type = attribute.type;
expander_output->domain = ATTR_DOMAIN_POINT;
+ expander_output->component_type = (int)GEO_COMPONENT_TYPE_MESH;
+ expander_output->socket_type = (int)attribute.socket_type;
+
+ STRNCPY(expander_output->socket_name, attribute.socket_name.c_str());
+ STRNCPY(expander_output->local_node_name, attribute.local_node_name.c_str());
+ STRNCPY(expander_output->local_socket_identifier, attribute.local_socket_identifier.c_str());
+ STRNCPY(expander_output->input_identifier, attribute.input_identifier.c_str());
+ STRNCPY(expander_output->builtin_identifier, attribute.builtin_identifier.c_str());
+
BLI_addtail(&storage->outputs, expander_output);
nodeUpdate(ntree, node);
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 2bc81b2276e..af0c47ca211 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1425,17 +1425,40 @@ typedef struct NodeGeometryRaycast {
char _pad[1];
} NodeGeometryRaycast;
+typedef enum eGeometryExpanderOutputType {
+ GEOMETRY_EXPANDER_OUTPUT_TYPE_LOCAL,
+ GEOMETRY_EXPANDER_OUTPUT_TYPE_INPUT,
+ GEOMETRY_EXPANDER_OUTPUT_TYPE_BUILTIN,
+} eGeometryExpanderOutputType;
+
typedef struct GeometryExpanderOutput {
struct GeometryExpanderOutput *next, *prev;
+
+ /* eGeometryExpanderOutputType. */
+ int type;
+ char _pad[4];
+
+ /* Identifier of the corresponding socket in the geometry expander. */
+ char socket_identifier[64];
+ char socket_name[64];
+
/* AttributeDomain. */
int8_t domain;
/* GeometryComponentType. */
int8_t component_type;
/* eNodeSocketDatatype. */
int8_t socket_type;
- char _pad[5];
- char *data_identifier;
- char *socket_identifier;
+ char _pad2[5];
+
+ /* Local attribute data. */
+ char local_node_name[64];
+ char local_socket_identifier[64];
+
+ /* Input attribute data. */
+ char input_identifier[64];
+
+ /* Builtin attribute data. */
+ char builtin_identifier[64];
} GeometryExpanderOutput;
typedef struct NodeGeometryGeometryExpander {
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 3be793a2c77..ad774f00825 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
@@ -60,8 +60,9 @@ static bool geo_node_geometry_expander_socket_layout(const bContext *UNUSED(C),
&ntree->id, &RNA_GeometryExpanderOutput, expander_output, &expander_output_ptr);
uiLayout *row = uiLayoutRow(layout, true);
- uiItemL(row, socket->name, ICON_NONE);
- uiItemR(row, &expander_output_ptr, "domain", 0, "", ICON_NONE);
+ uiLayout *split = uiLayoutSplit(row, 0.7, false);
+ uiItemL(split, socket->name, ICON_NONE);
+ uiItemR(split, &expander_output_ptr, "domain", 0, "", ICON_NONE);
return true;
}
@@ -72,20 +73,41 @@ static void geo_node_geometry_expander_exec(GeoNodeExecParams params)
const NodeGeometryGeometryExpande
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list