[Bf-blender-cvs] [cadfba7aad1] temp-attribute-processor: support changing sockets
Jacques Lucke
noreply at git.blender.org
Thu May 27 12:51:42 CEST 2021
Commit: cadfba7aad151990eff4f860df6236572d1743d6
Author: Jacques Lucke
Date: Tue May 25 11:13:20 2021 +0200
Branches: temp-attribute-processor
https://developer.blender.org/rBcadfba7aad151990eff4f860df6236572d1743d6
support changing sockets
===================================================================
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
===================================================================
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 98f1a3845d6..755372f911e 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -72,6 +72,8 @@ extern StructRNA RNA_ArrayModifier;
extern StructRNA RNA_Attribute;
extern StructRNA RNA_AttributeGroup;
extern StructRNA RNA_AttributeNodeTree;
+extern StructRNA RNA_AttributeProcessorInput;
+extern StructRNA RNA_AttributeProcessorOutput;
extern StructRNA RNA_AssetMetaData;
extern StructRNA RNA_AssetTag;
extern StructRNA RNA_BackgroundImage;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index bbcd1d80cc5..dc875427295 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -4462,13 +4462,30 @@ bool rna_NodeSocketMaterial_default_value_poll(PointerRNA *UNUSED(ptr), PointerR
return ma->gp_style == NULL;
}
-static bool rna_GeometrNodeAttributeProcessor_node_tree_poll(PointerRNA *UNUSED(ptr),
- const PointerRNA value)
+static bool rna_GeometryNodeAttributeProcessor_node_tree_poll(PointerRNA *UNUSED(ptr),
+ const PointerRNA value)
{
bNodeTree *ngroup = value.data;
return STREQ(ngroup->idname, "AttributeNodeTree");
}
+static void rna_GeometryNodeAttributeProcessor_mode_update(Main *bmain,
+ Scene *scene,
+ PointerRNA *ptr)
+{
+ /* Unfortunately, `ptr->data` points to data within the node storage. We can't get the node
+ * without iterating over all nodes.
+ * TODO: Investigate the viability of adding a back-pointer to the node. */
+ bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
+ LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
+ if (node->type == GEO_NODE_ATTRIBUTE_PROCESSOR) {
+ PointerRNA node_ptr;
+ RNA_pointer_create(ptr->owner_id, &RNA_Node, node, &node_ptr);
+ rna_Node_socket_update(bmain, scene, &node_ptr);
+ }
+ }
+}
+
#else
static const EnumPropertyItem prop_image_layer_items[] = {
@@ -9912,6 +9929,8 @@ static void def_geo_attribute_processor_group_input(BlenderRNA *brna)
prop = RNA_def_property(srna, "input_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_ui_text(prop, "Input Mode", "How the group input is provided");
RNA_def_property_enum_items(prop, input_mode_items);
+ RNA_def_property_update(
+ prop, NC_NODE | NA_EDITED, "rna_GeometryNodeAttributeProcessor_mode_update");
}
static void def_geo_attribute_processor_group_output(BlenderRNA *brna)
@@ -9943,18 +9962,19 @@ static void def_geo_attribute_processor_group_output(BlenderRNA *brna)
prop = RNA_def_property(srna, "output_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_ui_text(prop, "Output Mode", "How group output name is determined");
RNA_def_property_enum_items(prop, output_mode_items);
+ RNA_def_property_update(
+ prop, NC_NODE | NA_EDITED, "rna_GeometryNodeAttributeProcessor_mode_update");
}
static void def_geo_attribute_processor(StructRNA *srna)
{
PropertyRNA *prop;
- /* TODO: Only allow groups of correct type. */
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "NodeTree");
RNA_def_property_pointer_funcs(
- prop, NULL, NULL, NULL, "rna_GeometrNodeAttributeProcessor_node_tree_poll");
+ prop, NULL, NULL, NULL, "rna_GeometryNodeAttributeProcessor_node_tree_poll");
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "");
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
index 19f8a77dff2..f9366b9ae55 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_processor.cc
@@ -31,12 +31,41 @@
static void geo_node_attribute_processor_layout(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
bNode *node = (bNode *)ptr->data;
+ NodeGeometryAttributeProcessor *storage = (NodeGeometryAttributeProcessor *)node->storage;
+
uiLayout *row = uiLayoutRow(layout, true);
uiTemplateIDBrowse(
row, C, ptr, "node_tree", nullptr, nullptr, nullptr, UI_TEMPLATE_ID_FILTER_ALL, nullptr);
uiItemStringO(row, "", ICON_PLUS, "node.new_attribute_processor_group", "node_name", node->name);
uiItemR(layout, ptr, "domain", 0, "Domain", ICON_NONE);
+
+ bNodeTree *group = (bNodeTree *)node->id;
+ if (group == nullptr) {
+ return;
+ }
+ {
+ uiLayout *box = uiLayoutBox(layout);
+ bNodeSocket *interface_socket = (bNodeSocket *)group->inputs.first;
+ AttributeProcessorInput *input = (AttributeProcessorInput *)storage->group_inputs.first;
+ for (; interface_socket && input;
+ interface_socket = interface_socket->next, input = input->next) {
+ PointerRNA input_ptr;
+ RNA_pointer_create(ptr->owner_id, &RNA_AttributeProcessorInput, input, &input_ptr);
+ uiItemR(box, &input_ptr, "input_mode", 0, interface_socket->name, ICON_NONE);
+ }
+ }
+ {
+ uiLayout *box = uiLayoutBox(layout);
+ bNodeSocket *interface_socket = (bNodeSocket *)group->outputs.first;
+ AttributeProcessorOutput *output = (AttributeProcessorOutput *)storage->group_outputs.first;
+ for (; interface_socket && output;
+ interface_socket = interface_socket->next, output = output->next) {
+ PointerRNA output_ptr;
+ RNA_pointer_create(ptr->owner_id, &RNA_AttributeProcessorOutput, output, &output_ptr);
+ uiItemR(box, &output_ptr, "output_mode", 0, interface_socket->name, ICON_NONE);
+ }
+ }
}
static void geo_node_attribute_processor_init(bNodeTree *UNUSED(ntree), bNode *node)
@@ -49,56 +78,39 @@ static void geo_node_attribute_processor_init(bNodeTree *UNUSED(ntree), bNode *n
namespace blender::nodes {
-static void geo_node_attribute_processor_group_update(bNodeTree *ntree, bNode *node)
+static void free_group_input(AttributeProcessorInput *input)
{
- if (node->id == nullptr) {
- nodeRemoveAllSockets(ntree, node);
- nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketGeometry", "Geometry", "Geometry");
- nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketGeometry", "Geometry", "Geometry");
- return;
- }
- if ((ID_IS_LINKED(node->id) && (node->id->tag & LIB_TAG_MISSING))) {
- /* Missing datablock, leave sockets unchanged so that when it comes back
- * the links remain valid. */
- return;
- }
- nodeRemoveAllSockets(ntree, node);
- nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketGeometry", "Geometry", "Geometry");
- nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketGeometry", "Geometry", "Geometry");
+ MEM_freeN(input->identifier);
+ MEM_freeN(input);
+}
- bNodeTree *ngroup = (bNodeTree *)node->id;
- LISTBASE_FOREACH (bNodeSocket *, interface_sock, &ngroup->inputs) {
- nodeAddSocket(ntree,
- node,
- SOCK_IN,
- interface_sock->idname,
- interface_sock->identifier,
- interface_sock->name);
+static void free_group_output(AttributeProcessorOutput *output)
+{
+ MEM_freeN(output->identifier);
+ MEM_freeN(output);
+}
+
+static void free_group_inputs(ListBase *inputs)
+{
+ LISTBASE_FOREACH_MUTABLE (AttributeProcessorInput *, input, inputs) {
+ free_group_input(input);
}
- LISTBASE_FOREACH (bNodeSocket *, interface_sock, &ngroup->outputs) {
- nodeAddSocket(ntree,
- node,
- SOCK_OUT,
- interface_sock->idname,
- interface_sock->identifier,
- interface_sock->name);
+ BLI_listbase_clear(inputs);
+}
+
+static void free_group_outputs(ListBase *outputs)
+{
+ LISTBASE_FOREACH_MUTABLE (AttributeProcessorOutput *, output, outputs) {
+ free_group_output(output);
}
+ BLI_listbase_clear(outputs);
}
static void geo_node_attribute_processor_storage_free(bNode *node)
{
NodeGeometryAttributeProcessor *storage = (NodeGeometryAttributeProcessor *)node->storage;
-
- LISTBASE_FOREACH_MUTABLE (AttributeProcessorInput *, input, &storage->group_inputs) {
- MEM_freeN(input->identifier);
- MEM_freeN(input);
- }
- BLI_listbase_clear(&storage->group_inputs);
- LISTBASE_FOREACH_MUTABLE (AttributeProcessorOutput *, output, &storage->group_outputs) {
- MEM_freeN(output->identifier);
- MEM_freeN(output);
- }
- BLI_listbase_clear(&storage->group_outputs);
+ free_group_inputs(&storage->group_inputs);
+ free_group_outputs(&storage->group_outputs);
MEM_freeN(storage);
}
@@ -134,6 +146,81 @@ static void geo_node_attribute_processor_storage_copy(bNodeTree *UNUSED(dest_ntr
dst_node->storage = dst_storage;
}
+static void geo_node_attribute_processor_group_update(bNodeTree *ntree, bNode *node)
+{
+ NodeGeometryAttributeProcessor *storage = (NodeGeometryAttributeProcessor *)node->storage;
+ bNodeTree *ngroup = (bNodeTree *)node->id;
+
+ if (ngroup == nullptr) {
+ nodeRemoveAllSockets(ntree, node);
+ nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketGeometry", "Geometry", "Geometry");
+ nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketGeometry", "Geometry", "Geometry");
+ return;
+ }
+ if ((ID_IS_LINKED(ngroup) && (ngroup->id.tag & LIB_TAG_MISSING))) {
+ /* Missing datablock, leave sockets unchanged so that when it comes back
+ * the links remain valid. */
+ return;
+ }
+ nodeRemoveAllSockets(ntree, node);
+ nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketGeometry", "Geometry", "Geometry");
+ nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketGeometry", "Geometry", "Geometry");
+
+ free_group_inputs(&storage->group_inputs);
+ free_group_outputs(&storage->group_outputs);
+
+ LISTBASE_FOREACH (bNodeSocket *, interface_sock, &ngroup->inputs) {
+ AttributeProcessorInput *input = (AttributeProcessorInput *)MEM_callocN(
+ size
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list