WIP: Subtype for input function nodes #107010

Draft
Weikang-Qiu wants to merge 4 commits from Weikang-Qiu/blender:node-subtype into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
4 changed files with 33 additions and 46 deletions
Showing only changes of commit 384d734534 - Show all commits

View File

@ -358,6 +358,7 @@ char *RNA_property_string_get_alloc(
PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len);
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value);
void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len);
void RNA_property_subtype_set(struct ID* id, void* data, const char *propname, PropertySubType value);
eStringPropertySearchFlag RNA_property_string_search_flag(PropertyRNA *prop);
/**

View File

@ -5248,6 +5248,18 @@ void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
}
}
void RNA_property_subtype_set(struct ID *id,
void *data,
const char *propname,
PropertySubType value)
{
PointerRNA ptr;
RNA_pointer_create(id, &RNA_Node, data, &ptr);

This is not very practical, because in fact, it cannot be applied to the properties of an object, for example? Is it possible to make property references without statically specifying the structure type? It seems one of the node_layout arguments might be useful. That is, it seems that the update function should do this itself and pass in RNA_property_subtype_set prop as argument?

This is not very practical, because in fact, it cannot be applied to the properties of an object, for example? Is it possible to make property references without statically specifying the structure type? It seems one of the `node_layout` arguments might be useful. That is, it seems that the update function should do this itself and pass in `RNA_property_subtype_set` `prop` as argument?
PropertyRNA *prop = RNA_struct_find_property(&ptr, propname);
prop->subtype = value;
}
char *RNA_string_get_alloc(
PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
{

View File

@ -7,7 +7,6 @@
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "BLI_math.h"
#include "BLI_utildefines.h"
@ -5164,41 +5163,22 @@ static void def_fn_input_int(StructRNA *srna)
static void def_fn_input_vector(StructRNA *srna)
{
const EnumPropertyItem *rna_input_vector_subtype = rna_enum_property_subtype_number_array_items;
PropertyRNA *prop;
RNA_def_struct_sdna_from(srna, "NodeInputVector", "storage");
prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
prop = RNA_def_property(srna, "vector", PROP_FLOAT, PROP_XYZ);
RNA_def_property_array(prop, 3);
RNA_def_property_float_sdna(prop, NULL, "vector");
RNA_def_property_ui_text(prop, "Vector", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
const EnumPropertyItem *rna_input_vector_subtype = rna_enum_property_subtype_number_array_items;
prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_XYZ);
RNA_def_property_enum_sdna(prop, NULL, "subtype");
RNA_def_property_enum_items(prop, rna_input_vector_subtype);
RNA_def_property_ui_text(prop, "Subtype", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
static char prop_names[20][30];
int prop_ind = 0;
for (const EnumPropertyItem *item = rna_input_vector_subtype; item->identifier != NULL; item++) {
char *prop_name = prop_names[prop_ind++];
strcpy(prop_name, "vector_");
int i;
const char *identifier = item->identifier;
for (i = 0; i < strlen(identifier); i++) {
if (isalpha(identifier[i]))
prop_name[7 + i] = tolower(identifier[i]);
else
prop_name[7 + i] = '_';
}
prop_name[7 + i] = '\0';
prop = RNA_def_property(srna, prop_name, PROP_FLOAT, item->value);
RNA_def_property_array(prop, 3);
RNA_def_property_float_sdna(prop, NULL, "vector");
RNA_def_property_ui_text(prop, "Vector", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
}
static void def_fn_input_string(StructRNA *srna)

View File

@ -3,8 +3,8 @@
#include "node_function_util.hh"
#include "BLI_hash.h"
#include "RNA_types.h"
#include "RNA_enum_types.h"
#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
@ -18,23 +18,10 @@ static void node_declare(NodeDeclarationBuilder &b)
b.add_output<decl::Vector>(N_("Vector"));
}
static void node_layout_share(uiLayout* layout, bContext* /*C*/, PointerRNA* ptr)
static void node_layout_share(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
const NodeInputVector &data = node_storage(*static_cast<const bNode *>(ptr->data));
uiLayout *col = uiLayoutColumn(layout, true);
std::string prop_name;
for (const EnumPropertyItem *item = rna_enum_property_subtype_number_array_items;
item->identifier != NULL;
item++) {
if (item->value == data.subtype) {
std::string identifier(item->identifier);
transform(identifier.begin(), identifier.end(), identifier.begin(), std::tolower);
prop_name = "vector_" + identifier;
break;
}
}
uiItemR(col, ptr, prop_name.c_str(), UI_ITEM_R_EXPAND, "", ICON_NONE);
uiItemR(col, ptr, "vector", UI_ITEM_R_EXPAND, "", ICON_NONE);
}
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
@ -42,12 +29,18 @@ static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
node_layout_share(layout, nullptr, ptr);
}
static void node_layout_ex(uiLayout* layout, bContext* /*C*/, PointerRNA* ptr)
static void node_layout_ex(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
{
uiItemR(layout, ptr, "subtype", UI_ITEM_R_SPLIT_EMPTY_NAME, IFACE_("Subtype"), ICON_NONE);
node_layout_share(layout, nullptr, ptr);
}
static void node_update(bNodeTree *ntree, bNode *node) {
NodeInputVector *data = static_cast<NodeInputVector *>(node->storage);
RNA_property_subtype_set(&ntree->id, node, "vector", static_cast<PropertySubType>(data->subtype));
}
static void node_build_multi_function(NodeMultiFunctionBuilder &builder)
{
const bNode &bnode = builder.node();
@ -79,5 +72,6 @@ void register_node_type_fn_input_vector()
ntype.build_multi_function = file_ns::node_build_multi_function;
ntype.draw_buttons = file_ns::node_layout;
ntype.draw_buttons_ex = file_ns::node_layout_ex;
ntype.updatefunc = file_ns::node_update;
nodeRegisterType(&ntype);
}