[Bf-blender-cvs] [369aa3a8a09] temp-attribute-processor: improve Set Attribute node
Jacques Lucke
noreply at git.blender.org
Wed Jun 9 12:51:21 CEST 2021
Commit: 369aa3a8a09074922e3a971830a2e7890ceb5690
Author: Jacques Lucke
Date: Wed Jun 9 11:41:25 2021 +0200
Branches: temp-attribute-processor
https://developer.blender.org/rB369aa3a8a09074922e3a971830a2e7890ceb5690
improve Set Attribute node
===================================================================
M source/blender/makesdna/DNA_node_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/NOD_static_types.h
M source/blender/nodes/geometry/nodes/node_attr_set_attribute.cc
===================================================================
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 1a481e12165..78898bd8bc0 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1391,6 +1391,12 @@ typedef struct NodeGeometryAttributeProcessor {
ListBase outputs_settings;
} NodeGeometryAttributeProcessor;
+typedef struct NodeAttributeSetAttribute {
+ char attribute_name[64];
+ uint8_t type;
+ char _pad[7];
+} NodeAttributeSetAttribute;
+
/* 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 e5fb40ee5b3..8b0bfe789d1 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -2011,6 +2011,20 @@ static const EnumPropertyItem *rna_GeometryNodeSwitch_type_itemf(bContext *UNUSE
return itemf_function_check(node_socket_data_type_items, switch_type_supported);
}
+static bool set_attribute_type_supported(const EnumPropertyItem *item)
+{
+ return ELEM(item->value, SOCK_FLOAT, SOCK_INT, SOCK_BOOLEAN, SOCK_VECTOR, SOCK_RGBA);
+}
+
+static const EnumPropertyItem *rna_AttributeNodeSetAttribute_type_itemf(bContext *UNUSED(C),
+ PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop),
+ bool *r_free)
+{
+ *r_free = true;
+ return itemf_function_check(node_socket_data_type_items, set_attribute_type_supported);
+}
+
static bool attribute_clamp_type_supported(const EnumPropertyItem *item)
{
return ELEM(item->value, CD_PROP_FLOAT, CD_PROP_FLOAT3, CD_PROP_INT32, CD_PROP_COLOR);
@@ -10048,6 +10062,23 @@ static void def_geo_attribute_processor(StructRNA *srna)
RNA_def_property_ui_text(prop, "Group Outputs", "");
}
+static void def_attr_set_attribute(StructRNA *srna)
+{
+ PropertyRNA *prop;
+
+ RNA_def_struct_sdna_from(srna, "NodeAttributeSetAttribute", "storage");
+
+ prop = RNA_def_property(srna, "attribute_name", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Attribute Name", "");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, node_socket_data_type_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_AttributeNodeSetAttribute_type_itemf");
+ RNA_def_property_ui_text(prop, "Type", "");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
+}
+
/* -------------------------------------------------------------------------- */
static void rna_def_shader_node(BlenderRNA *brna)
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 2fd4a586f48..73604f059d3 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -326,7 +326,7 @@ DefNode(GeometryNode, GEO_NODE_TRIANGULATE, def_geo_triangulate, "TRIANGULATE",
DefNode(GeometryNode, GEO_NODE_VOLUME_TO_MESH, def_geo_volume_to_mesh, "VOLUME_TO_MESH", VolumeToMesh, "Volume to Mesh", "")
DefNode(AttributeNode, ATTR_NODE_INDEX, 0, "INDEX", Index, "Index", "")
-DefNode(AttributeNode, ATTR_NODE_SET_ATTRIBUTE, 0, "SET_ATTRIBUTE", SetAttribute, "Set Attribute", "")
+DefNode(AttributeNode, ATTR_NODE_SET_ATTRIBUTE, def_attr_set_attribute, "SET_ATTRIBUTE", SetAttribute, "Set Attribute", "")
/* undefine macros */
#undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_attr_set_attribute.cc b/source/blender/nodes/geometry/nodes/node_attr_set_attribute.cc
index 8f35da3a712..a5f636ab1d1 100644
--- a/source/blender/nodes/geometry/nodes/node_attr_set_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_attr_set_attribute.cc
@@ -28,11 +28,38 @@ static bNodeSocketTemplate attr_node_set_attribute_in[] = {
{-1, ""},
};
+static void attr_node_set_attribute_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+ uiItemR(layout, ptr, "type", 0, "Type", ICON_NONE);
+ uiItemR(layout, ptr, "attribute_name", 0, "Name", ICON_NONE);
+}
+
+static void attr_node_set_attribute_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+ NodeAttributeSetAttribute *data = (NodeAttributeSetAttribute *)MEM_callocN(
+ sizeof(NodeAttributeSetAttribute), __func__);
+ data->type = SOCK_FLOAT;
+ node->storage = data;
+}
+
+static void attr_node_set_attribute_update(bNodeTree *UNUSED(ntree), bNode *node)
+{
+ NodeAttributeSetAttribute *node_storage = (NodeAttributeSetAttribute *)node->storage;
+ LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
+ nodeSetSocketAvailability(socket, socket->type == (eNodeSocketDatatype)node_storage->type);
+ }
+}
+
void register_node_type_attr_set_attribute()
{
static bNodeType ntype;
attr_node_type_base(&ntype, ATTR_NODE_SET_ATTRIBUTE, "Set Attribute", NODE_CLASS_OUTPUT, 0);
node_type_socket_templates(&ntype, attr_node_set_attribute_in, nullptr);
+ node_type_storage(
+ &ntype, "NodeAttributeSetAttribute", node_free_standard_storage, node_copy_standard_storage);
+ node_type_init(&ntype, attr_node_set_attribute_init);
+ node_type_update(&ntype, attr_node_set_attribute_update);
+ ntype.draw_buttons = attr_node_set_attribute_layout;
nodeRegisterType(&ntype);
}
More information about the Bf-blender-cvs
mailing list