Nodes: remove bNodeTree->interface_type

This is not used for anything in practice currently. The original intention
was probably to generate different socket subtypes, but that is solved
differently now (e.g. using `NodeSocketFloatDistance`). It's possible
that an addon tried to use this but it's rather unlikely.

Differential Revision: https://developer.blender.org/D13188
This commit is contained in:
Jacques Lucke 2022-11-23 13:48:53 +01:00
parent 247d75d2b1
commit 4f02817367
5 changed files with 4 additions and 229 deletions

View File

@ -171,9 +171,6 @@ typedef struct bNodeSocketType {
void (*interface_draw)(struct bContext *C, struct uiLayout *layout, struct PointerRNA *ptr);
void (*interface_draw_color)(struct bContext *C, struct PointerRNA *ptr, float *r_color);
void (*interface_register_properties)(struct bNodeTree *ntree,
struct bNodeSocket *interface_socket,
struct StructRNA *data_srna);
void (*interface_init_socket)(struct bNodeTree *ntree,
const struct bNodeSocket *interface_socket,
struct bNode *node,
@ -583,10 +580,6 @@ struct bNodeSocket *ntreeInsertSocketInterfaceFromSocket(struct bNodeTree *ntree
struct bNodeSocket *from_sock);
void ntreeRemoveSocketInterface(struct bNodeTree *ntree, struct bNodeSocket *sock);
struct StructRNA *ntreeInterfaceTypeGet(struct bNodeTree *ntree, bool create);
void ntreeInterfaceTypeFree(struct bNodeTree *ntree);
void ntreeInterfaceTypeUpdate(struct bNodeTree *ntree);
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -203,8 +203,6 @@ static void ntree_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, cons
new_node->parent = node_map.lookup(new_node->parent);
}
}
/* node tree will generate its own interface type */
ntree_dst->interface_type = nullptr;
if (ntree_src->runtime->field_inferencing_interface) {
ntree_dst->runtime->field_inferencing_interface = std::make_unique<FieldInferencingInterface>(
@ -242,9 +240,6 @@ static void ntree_free_data(ID *id)
/* XXX not nice, but needed to free localized node groups properly */
free_localized_node_groups(ntree);
/* Unregister associated RNA types. */
ntreeInterfaceTypeFree(ntree);
BLI_freelistN(&ntree->links);
LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree->nodes) {
@ -622,7 +617,6 @@ static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_addres
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
ntree->is_updating = false;
ntree->typeinfo = nullptr;
ntree->interface_type = nullptr;
ntree->progress = nullptr;
ntree->execdata = nullptr;
@ -676,7 +670,6 @@ void ntreeBlendReadData(BlendDataReader *reader, ID *owner_id, bNodeTree *ntree)
/* NOTE: writing and reading goes in sync, for speed. */
ntree->is_updating = false;
ntree->typeinfo = nullptr;
ntree->interface_type = nullptr;
ntree->progress = nullptr;
ntree->execdata = nullptr;
@ -3442,127 +3435,6 @@ void ntreeRemoveSocketInterface(bNodeTree *ntree, bNodeSocket *sock)
BKE_ntree_update_tag_interface(ntree);
}
/* generates a valid RNA identifier from the node tree name */
static void ntree_interface_identifier_base(bNodeTree *ntree, char *base)
{
/* generate a valid RNA identifier */
BLI_sprintf(base, "NodeTreeInterface_%s", ntree->id.name + 2);
RNA_identifier_sanitize(base, false);
}
/* check if the identifier is already in use */
static bool ntree_interface_unique_identifier_check(void * /*data*/, const char *identifier)
{
return (RNA_struct_find(identifier) != nullptr);
}
/* generates the actual unique identifier and ui name and description */
static void ntree_interface_identifier(bNodeTree *ntree,
const char *base,
char *identifier,
int maxlen,
char *name,
char *description)
{
/* There is a possibility that different node tree names get mapped to the same identifier
* after sanitation (e.g. "SomeGroup_A", "SomeGroup.A" both get sanitized to "SomeGroup_A").
* On top of the sanitized id string add a number suffix if necessary to avoid duplicates.
*/
identifier[0] = '\0';
BLI_uniquename_cb(
ntree_interface_unique_identifier_check, nullptr, base, '_', identifier, maxlen);
BLI_sprintf(name, "Node Tree %s Interface", ntree->id.name + 2);
BLI_sprintf(description, "Interface properties of node group %s", ntree->id.name + 2);
}
static void ntree_interface_type_create(bNodeTree *ntree)
{
/* strings are generated from base string + ID name, sizes are sufficient */
char base[MAX_ID_NAME + 64], identifier[MAX_ID_NAME + 64], name[MAX_ID_NAME + 64],
description[MAX_ID_NAME + 64];
/* generate a valid RNA identifier */
ntree_interface_identifier_base(ntree, base);
ntree_interface_identifier(ntree, base, identifier, sizeof(identifier), name, description);
/* register a subtype of PropertyGroup */
StructRNA *srna = RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup);
RNA_def_struct_ui_text(srna, name, description);
RNA_def_struct_duplicate_pointers(&BLENDER_RNA, srna);
/* associate the RNA type with the node tree */
ntree->interface_type = srna;
RNA_struct_blender_type_set(srna, ntree);
/* add socket properties */
LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->inputs) {
bNodeSocketType *stype = sock->typeinfo;
if (stype && stype->interface_register_properties) {
stype->interface_register_properties(ntree, sock, srna);
}
}
LISTBASE_FOREACH (bNodeSocket *, sock, &ntree->outputs) {
bNodeSocketType *stype = sock->typeinfo;
if (stype && stype->interface_register_properties) {
stype->interface_register_properties(ntree, sock, srna);
}
}
}
StructRNA *ntreeInterfaceTypeGet(bNodeTree *ntree, bool create)
{
if (ntree->interface_type) {
/* strings are generated from base string + ID name, sizes are sufficient */
char base[MAX_ID_NAME + 64], identifier[MAX_ID_NAME + 64], name[MAX_ID_NAME + 64],
description[MAX_ID_NAME + 64];
/* A bit of a hack: when changing the ID name, update the RNA type identifier too,
* so that the names match. This is not strictly necessary to keep it working,
* but better for identifying associated NodeTree blocks and RNA types.
*/
StructRNA *srna = ntree->interface_type;
ntree_interface_identifier_base(ntree, base);
/* RNA identifier may have a number suffix, but should start with the idbase string */
if (!STREQLEN(RNA_struct_identifier(srna), base, sizeof(base))) {
/* generate new unique RNA identifier from the ID name */
ntree_interface_identifier(ntree, base, identifier, sizeof(identifier), name, description);
/* rename the RNA type */
RNA_def_struct_free_pointers(&BLENDER_RNA, srna);
RNA_def_struct_identifier(&BLENDER_RNA, srna, identifier);
RNA_def_struct_ui_text(srna, name, description);
RNA_def_struct_duplicate_pointers(&BLENDER_RNA, srna);
}
}
else if (create) {
ntree_interface_type_create(ntree);
}
return ntree->interface_type;
}
void ntreeInterfaceTypeFree(bNodeTree *ntree)
{
if (ntree->interface_type) {
RNA_struct_free(&BLENDER_RNA, ntree->interface_type);
ntree->interface_type = nullptr;
}
}
void ntreeInterfaceTypeUpdate(bNodeTree *ntree)
{
/* XXX it would be sufficient to just recreate all properties
* instead of re-registering the whole struct type,
* but there is currently no good way to do this in the RNA functions.
* Overhead should be negligible.
*/
ntreeInterfaceTypeFree(ntree);
ntree_interface_type_create(ntree);
}
/* ************ find stuff *************** */
bNode *ntreeFindType(const bNodeTree *ntree, int type)

View File

@ -1009,10 +1009,6 @@ class NodeTreeMainUpdater {
result.interface_changed = true;
}
if (result.interface_changed) {
ntreeInterfaceTypeUpdate(&ntree);
}
return result;
}

View File

@ -495,9 +495,6 @@ typedef struct bNodeTree {
/** Runtime type identifier. */
char idname[64];
/** Runtime RNA type of the group interface. */
struct StructRNA *interface_type;
/** Grease pencil data. */
struct bGPdata *gpd;
/** Node tree stores own offset for consistent editor view. */

View File

@ -2935,31 +2935,6 @@ static void rna_NodeSocketInterface_draw_color(bContext *C, PointerRNA *ptr, flo
RNA_parameter_list_free(&list);
}
static void rna_NodeSocketInterface_register_properties(bNodeTree *ntree,
bNodeSocket *stemp,
StructRNA *data_srna)
{
extern FunctionRNA rna_NodeSocketInterface_register_properties_func;
PointerRNA ptr;
ParameterList list;
FunctionRNA *func;
if (!stemp->typeinfo) {
return;
}
RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, stemp, &ptr);
// RNA_struct_find_function(&ptr, "register_properties");
func = &rna_NodeSocketInterface_register_properties_func;
RNA_parameter_list_create(&list, &ptr, func);
RNA_parameter_set_lookup(&list, "data_rna_type", &data_srna);
stemp->typeinfo->ext_interface.call(NULL, &ptr, func, &list);
RNA_parameter_list_free(&list);
}
static void rna_NodeSocketInterface_init_socket(bNodeTree *ntree,
const bNodeSocket *interface_socket,
bNode *node,
@ -3046,7 +3021,7 @@ static StructRNA *rna_NodeSocketInterface_register(Main *UNUSED(bmain),
bNodeSocketType *st, dummyst;
bNodeSocket dummysock;
PointerRNA dummyptr;
int have_function[5];
int have_function[4];
/* setup dummy socket & socket type to store static properties in */
memset(&dummyst, 0, sizeof(bNodeSocketType));
@ -3089,11 +3064,8 @@ static StructRNA *rna_NodeSocketInterface_register(Main *UNUSED(bmain),
st->interface_draw = (have_function[0]) ? rna_NodeSocketInterface_draw : NULL;
st->interface_draw_color = (have_function[1]) ? rna_NodeSocketInterface_draw_color : NULL;
st->interface_register_properties = (have_function[2]) ?
rna_NodeSocketInterface_register_properties :
NULL;
st->interface_init_socket = (have_function[3]) ? rna_NodeSocketInterface_init_socket : NULL;
st->interface_from_socket = (have_function[4]) ? rna_NodeSocketInterface_from_socket : NULL;
st->interface_init_socket = (have_function[2]) ? rna_NodeSocketInterface_init_socket : NULL;
st->interface_from_socket = (have_function[3]) ? rna_NodeSocketInterface_from_socket : NULL;
/* update while blender is running */
WM_main_add_notifier(NC_NODE | NA_EDITED, NULL);
@ -3550,33 +3522,6 @@ static bool rna_NodeGroup_node_tree_poll(PointerRNA *ptr, const PointerRNA value
return nodeGroupPoll(ntree, ngroup, &disabled_hint);
}
static StructRNA *rna_NodeGroup_interface_typef(PointerRNA *ptr)
{
bNode *node = ptr->data;
bNodeTree *ngroup = (bNodeTree *)node->id;
if (ngroup) {
StructRNA *srna = ntreeInterfaceTypeGet(ngroup, true);
if (srna) {
return srna;
}
}
return &RNA_PropertyGroup;
}
static StructRNA *rna_NodeGroupInputOutput_interface_typef(PointerRNA *ptr)
{
bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
if (ntree) {
StructRNA *srna = ntreeInterfaceTypeGet(ntree, true);
if (srna) {
return srna;
}
}
return &RNA_PropertyGroup;
}
static void rna_distance_matte_t1_set(PointerRNA *ptr, float value)
{
bNode *node = (bNode *)ptr->data;
@ -4732,29 +4677,14 @@ static const EnumPropertyItem node_subsurface_method_items[] = {
/* -- Common nodes ---------------------------------------------------------- */
static void def_group_input(StructRNA *srna)
static void def_group_input(StructRNA *UNUSED(srna))
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "interface", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_funcs(
prop, NULL, NULL, "rna_NodeGroupInputOutput_interface_typef", NULL);
RNA_def_property_struct_type(prop, "PropertyGroup");
RNA_def_property_flag(prop, PROP_IDPROPERTY);
RNA_def_property_ui_text(prop, "Interface", "Interface socket data");
}
static void def_group_output(StructRNA *srna)
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "interface", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_funcs(
prop, NULL, NULL, "rna_NodeGroupInputOutput_interface_typef", NULL);
RNA_def_property_struct_type(prop, "PropertyGroup");
RNA_def_property_flag(prop, PROP_IDPROPERTY);
RNA_def_property_ui_text(prop, "Interface", "Interface socket data");
prop = RNA_def_property(srna, "is_active_output", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", NODE_DO_OUTPUT);
RNA_def_property_ui_text(
@ -4776,12 +4706,6 @@ static void def_group(StructRNA *srna)
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Node Tree", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeGroup_update");
prop = RNA_def_property(srna, "interface", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_funcs(prop, NULL, NULL, "rna_NodeGroup_interface_typef", NULL);
RNA_def_property_struct_type(prop, "PropertyGroup");
RNA_def_property_flag(prop, PROP_IDPROPERTY);
RNA_def_property_ui_text(prop, "Interface", "Interface socket data");
}
static void def_custom_group(BlenderRNA *brna,
@ -11300,13 +11224,6 @@ static void rna_def_node_socket_interface(BlenderRNA *brna)
func, "color", 4, default_draw_color, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);
RNA_def_function_output(func, parm);
func = RNA_def_function(srna, "register_properties", NULL);
RNA_def_function_ui_description(func, "Define RNA properties of a socket");
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
parm = RNA_def_pointer(
func, "data_rna_type", "Struct", "Data RNA Type", "RNA type for special socket properties");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
func = RNA_def_function(srna, "init_socket", NULL);
RNA_def_function_ui_description(func, "Initialize a node socket instance");
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);