Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-08-05 16:53:48 +0300
committerJacques Lucke <jacques@blender.org>2021-08-05 16:53:48 +0300
commitfa37d09040214858cce516792afaec5b1555ad6a (patch)
tree2fe3de87ae7ecbc40ff57865f664749e1484672b /source
parent0ce5b5be3b3dc693aca2e092223ffa59522b69a5 (diff)
reuse GeometryExpanderOutput struct
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_node.h3
-rw-r--r--source/blender/blenkernel/intern/node.cc34
-rw-r--r--source/blender/editors/space_node/node_edit.cc83
-rw-r--r--source/blender/makesdna/DNA_node_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c9
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc11
6 files changed, 86 insertions, 58 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 0f50a7bc1f6..4c4231877bf 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -735,6 +735,9 @@ void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available);
int nodeSocketLinkLimit(const struct bNodeSocket *sock);
+void nodeGeometryExpanderUpdateOutputNameCache(struct GeometryExpanderOutput *expander_output,
+ const bNodeTree *ntree);
+
/* Node Clipboard */
void BKE_node_clipboard_init(const struct bNodeTree *ntree);
void BKE_node_clipboard_clear(void);
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 625973d8a92..03ade8b0cc1 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -71,7 +71,9 @@
#include "BKE_node.h"
#include "BLI_ghash.h"
+#include "BLI_string_ref.hh"
#include "BLI_threads.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -90,6 +92,8 @@
#include "MOD_nodes.h"
+using blender::StringRef;
+
#define NODE_DEFAULT_MAX_WIDTH 700
/* Fallback types for undefined tree, nodes, sockets */
@@ -3926,6 +3930,36 @@ int nodeSocketLinkLimit(const bNodeSocket *sock)
return sock->limit;
}
+static std::string expander_output_to_name(const GeometryExpanderOutput &expander_output,
+ const bNodeTree &ntree)
+{
+ switch (expander_output.type) {
+ case GEOMETRY_EXPANDER_OUTPUT_TYPE_LOCAL: {
+ return expander_output.local_node_name + StringRef(" ▶ ") +
+ expander_output.local_socket_identifier;
+ }
+ case GEOMETRY_EXPANDER_OUTPUT_TYPE_INPUT: {
+ LISTBASE_FOREACH (const bNodeSocket *, socket, &ntree.inputs) {
+ if (socket->identifier == StringRef(expander_output.input_identifier)) {
+ return StringRef("Input ▶ ") + socket->name;
+ }
+ }
+ return "Unkown input";
+ }
+ case GEOMETRY_EXPANDER_OUTPUT_TYPE_BUILTIN: {
+ return StringRef("Built-in ▶ ") + expander_output.builtin_identifier;
+ }
+ }
+ return "";
+}
+
+void nodeGeometryExpanderUpdateOutputNameCache(struct GeometryExpanderOutput *expander_output,
+ const bNodeTree *ntree)
+{
+ const std::string name = expander_output_to_name(*expander_output, *ntree);
+ STRNCPY(expander_output->display_name_cache, name.c_str());
+}
+
/* ************** Node Clipboard *********** */
#define USE_NODE_CB_VALIDATE
diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc
index 8039c79fcc2..8a22199986a 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -82,6 +82,7 @@
#include "node_intern.h" /* own include */
using blender::FunctionRef;
+using blender::MutableSpan;
using blender::Span;
using blender::StringRef;
using blender::StringRefNull;
@@ -2989,35 +2990,18 @@ void NODE_OT_cryptomatte_layer_remove(wmOperatorType *ot)
/* ****************** Geometry Expander Add Output ******************* */
-namespace {
-struct AvailableAttribute {
- 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
-
static void foreach_available_attribute(
bNodeTree *ntree,
bNode *UNUSED(current_node),
- FunctionRef<void(const AvailableAttribute &attribute)> callback)
+ FunctionRef<void(const GeometryExpanderOutput &attribute)> callback)
{
LISTBASE_FOREACH (bNodeSocket *, group_input, &ntree->inputs) {
if (ELEM(group_input->type, SOCK_INT, SOCK_FLOAT, SOCK_VECTOR, SOCK_RGBA, SOCK_BOOLEAN)) {
- AvailableAttribute attribute;
+ GeometryExpanderOutput attribute;
attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_INPUT;
- attribute.input_identifier = group_input->identifier;
- attribute.input_name = group_input->name;
+ attribute.domain = ATTR_DOMAIN_POINT;
attribute.socket_type = (eNodeSocketDatatype)group_input->type;
- attribute.socket_name = StringRef("Input ▶ ") + group_input->name;
+ STRNCPY(attribute.input_identifier, group_input->identifier);
callback(attribute);
}
}
@@ -3025,24 +3009,40 @@ 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;
+ GeometryExpanderOutput 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;
+ attribute.domain = ATTR_DOMAIN_POINT;
+ STRNCPY(attribute.local_node_name, node->name);
+ STRNCPY(attribute.local_socket_identifier, node_output->identifier);
callback(attribute);
}
}
}
+ {
+ GeometryExpanderOutput attribute;
+ attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_BUILTIN;
+ attribute.socket_type = SOCK_VECTOR;
+ attribute.domain = ATTR_DOMAIN_POINT;
+ STRNCPY(attribute.builtin_identifier, "position");
+ callback(attribute);
+ }
+ {
+ GeometryExpanderOutput attribute;
+ attribute.type = GEOMETRY_EXPANDER_OUTPUT_TYPE_BUILTIN;
+ attribute.socket_type = SOCK_INT;
+ attribute.domain = ATTR_DOMAIN_FACE;
+ STRNCPY(attribute.builtin_identifier, "material_index");
+ callback(attribute);
+ }
}
-static Span<AvailableAttribute> get_updated_cached_available_attributes(bNodeTree *ntree,
- bNode *node)
+static MutableSpan<GeometryExpanderOutput> get_updated_cached_available_attributes(
+ bNodeTree *ntree, bNode *node)
{
- static Vector<AvailableAttribute> cached_available_attributes;
+ static Vector<GeometryExpanderOutput> cached_available_attributes;
cached_available_attributes.clear();
- foreach_available_attribute(ntree, node, [&](const AvailableAttribute &attribute) {
+ foreach_available_attribute(ntree, node, [&](const GeometryExpanderOutput &attribute) {
cached_available_attributes.append(attribute);
});
return cached_available_attributes;
@@ -3062,13 +3062,15 @@ static const EnumPropertyItem *node_geometry_expander_output_add_items(bContext
bNode *node = nodeFindNodebyName(ntree, node_name);
MEM_freeN(node_name);
- Span<AvailableAttribute> attributes = get_updated_cached_available_attributes(ntree, node);
+ MutableSpan<GeometryExpanderOutput> attributes = get_updated_cached_available_attributes(ntree,
+ node);
for (const int i : attributes.index_range()) {
- const AvailableAttribute &attribute = attributes[i];
+ GeometryExpanderOutput &attribute = attributes[i];
+ nodeGeometryExpanderUpdateOutputNameCache(&attribute, ntree);
EnumPropertyItem item = {0};
item.value = i;
- item.name = attribute.socket_name.c_str();
+ item.name = attribute.display_name_cache;
item.identifier = "test";
RNA_enum_item_add(&items, &totitem, &item);
}
@@ -3091,8 +3093,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");
- Span<AvailableAttribute> attributes = get_updated_cached_available_attributes(ntree, node);
- const AvailableAttribute &attribute = attributes[item_value];
+ Span<GeometryExpanderOutput> attributes = get_updated_cached_available_attributes(ntree, node);
+ const GeometryExpanderOutput &attribute = attributes[item_value];
auto to_identifier = [](int id) { return "out_" + std::to_string(id); };
@@ -3104,17 +3106,8 @@ static int node_geometry_expander_output_add_exec(bContext *C, wmOperator *op)
GeometryExpanderOutput *expander_output = (GeometryExpanderOutput *)MEM_callocN(
sizeof(GeometryExpanderOutput), __func__);
-
- 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());
+ *expander_output = attribute;
+ STRNCPY(expander_output->socket_identifier, identifier.c_str());
BLI_addtail(&storage->outputs, expander_output);
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index af0c47ca211..671e6da4e56 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1440,7 +1440,9 @@ typedef struct GeometryExpanderOutput {
/* Identifier of the corresponding socket in the geometry expander. */
char socket_identifier[64];
- char socket_name[64];
+
+ /* Derived from the other data. */
+ char display_name_cache[64];
/* AttributeDomain. */
int8_t domain;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 82f6a77af77..81e11e93fcd 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -2443,6 +2443,9 @@ static void rna_Node_select_set(PointerRNA *ptr, bool value)
nodeSetSelected(node, value);
}
+void nodeGeometryExpanderUpdateOutputNameCache(GeometryExpanderOutput *expander_output,
+ const bNodeTree *ntree);
+
static void rna_Node_name_set(PointerRNA *ptr, const char *value)
{
bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
@@ -2467,11 +2470,7 @@ static void rna_Node_name_set(PointerRNA *ptr, const char *value)
}
if (STREQ(expander_output->local_node_name, oldname)) {
STRNCPY(expander_output->local_node_name, node->name);
- BLI_snprintf(expander_output->socket_name,
- sizeof(expander_output->socket_name),
- "%s ▶ %s",
- node->name,
- expander_output->local_socket_identifier);
+ nodeGeometryExpanderUpdateOutputNameCache(expander_output, ntree);
}
}
}
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 5857c1d5ec0..54fc1b46652 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_geometry_expander.cc
@@ -54,6 +54,7 @@ static bool geo_node_geometry_expander_socket_layout(const bContext *UNUSED(C),
GeometryExpanderOutput *expander_output = (GeometryExpanderOutput *)BLI_findlink(
&storage->outputs, socket_index);
+ nodeGeometryExpanderUpdateOutputNameCache(expander_output, ntree);
PointerRNA expander_output_ptr;
RNA_pointer_create(
@@ -61,7 +62,7 @@ static bool geo_node_geometry_expander_socket_layout(const bContext *UNUSED(C),
uiLayout *row = uiLayoutRow(layout, true);
uiLayout *split = uiLayoutSplit(row, 0.7, false);
- uiItemL(split, expander_output->socket_name, ICON_NONE);
+ uiItemL(split, expander_output->display_name_cache, ICON_NONE);
uiItemR(split, &expander_output_ptr, "domain", 0, "", ICON_NONE);
return true;
@@ -131,12 +132,8 @@ static void geo_node_geometry_expander_update(bNodeTree *ntree, bNode *node)
bNodeSocket *socket = old_outputs.lookup_default(expander_output->socket_identifier, nullptr);
if (socket == nullptr) {
const char *idname = nodeStaticSocketType(expander_output->socket_type, PROP_NONE);
- socket = nodeAddSocket(ntree,
- node,
- SOCK_OUT,
- idname,
- expander_output->socket_identifier,
- expander_output->socket_name);
+ socket = nodeAddSocket(
+ ntree, node, SOCK_OUT, idname, expander_output->socket_identifier, "name");
}
new_sockets.add_new(socket);
}