[Bf-blender-cvs] [dad7371b41d] temp-enum-socket: progress
Jacques Lucke
noreply at git.blender.org
Mon Nov 8 16:07:02 CET 2021
Commit: dad7371b41d71d33745762aba7528fb15252744f
Author: Jacques Lucke
Date: Sat Nov 6 19:11:52 2021 +0100
Branches: temp-enum-socket
https://developer.blender.org/rBdad7371b41d71d33745762aba7528fb15252744f
progress
===================================================================
M release/scripts/startup/bl_operators/node.py
M source/blender/blenkernel/BKE_node.h
M source/blender/blenkernel/intern/node.cc
M source/blender/editors/space_node/node_templates.cc
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/nodes/NOD_node_declaration.hh
M source/blender/nodes/function/nodes/node_fn_enum.cc
===================================================================
diff --git a/release/scripts/startup/bl_operators/node.py b/release/scripts/startup/bl_operators/node.py
index 2eb1079a8db..c9feeaf9aa2 100644
--- a/release/scripts/startup/bl_operators/node.py
+++ b/release/scripts/startup/bl_operators/node.py
@@ -320,11 +320,14 @@ class NODE_OT_enum_item_add(Operator):
return space is not None and space.type == 'NODE_EDITOR' and space.edit_tree is not None
def execute(self, context):
+ import random
+
space = context.space_data
node = space.edit_tree.nodes.get(self.node_name)
if node is None:
return {'CANCELLED'}
- node.enum_items.new()
+ item = node.enum_items.new()
+ item.value = random.randint(0, 2 ** 31)
return {'FINISHED'}
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 53549dc61c3..222a53a86fe 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -736,6 +736,7 @@ void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available);
int nodeSocketLinkLimit(const struct bNodeSocket *sock);
void nodeDeclarationEnsure(struct bNodeTree *ntree, struct bNode *node);
+void nodeUpdateFromDeclaration(struct bNodeTree *ntree, struct bNode *node);
/* Node Clipboard */
void BKE_node_clipboard_init(const struct bNodeTree *ntree);
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 7a60a9a37ea..aca49a01384 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -1153,8 +1153,6 @@ static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
BLI_strncpy(node->name, DATA_(ntype->ui_name), NODE_MAXSTR);
nodeUniqueName(ntree, node);
- node_add_sockets_from_type(ntree, node, ntype);
-
if (ntype->initfunc != nullptr) {
ntype->initfunc(ntree, node);
}
@@ -1163,6 +1161,8 @@ static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node)
ntree->typeinfo->node_add_init(ntree, node);
}
+ node_add_sockets_from_type(ntree, node, ntype);
+
if (node->id) {
id_us_plus(node->id);
}
@@ -1440,7 +1440,7 @@ void nodeRegisterType(bNodeType *nt)
if (nt->declare && !nt->declaration_is_dynamic) {
if (nt->fixed_declaration == nullptr) {
nt->fixed_declaration = new blender::nodes::NodeDeclaration();
- blender::nodes::NodeDeclarationBuilder builder{*nt->fixed_declaration};
+ blender::nodes::NodeDeclarationBuilder builder{*nt->fixed_declaration, nullptr};
nt->declare(builder);
}
}
@@ -4066,7 +4066,7 @@ void nodeDeclarationEnsure(bNodeTree *UNUSED(ntree), bNode *node)
}
if (node->typeinfo->declaration_is_dynamic) {
node->declaration = new blender::nodes::NodeDeclaration();
- blender::nodes::NodeDeclarationBuilder builder{*node->declaration};
+ blender::nodes::NodeDeclarationBuilder builder{*node->declaration, node};
node->typeinfo->declare(builder);
}
else {
@@ -4076,6 +4076,16 @@ void nodeDeclarationEnsure(bNodeTree *UNUSED(ntree), bNode *node)
}
}
+void nodeUpdateFromDeclaration(bNodeTree *ntree, bNode *node)
+{
+ if (!node->typeinfo->declaration_is_dynamic) {
+ return;
+ }
+ delete node->declaration;
+ node->declaration = nullptr;
+ node_verify_sockets(ntree, node, true);
+}
+
/* ************** Node Clipboard *********** */
#define USE_NODE_CB_VALIDATE
@@ -5132,6 +5142,7 @@ void ntreeUpdateTree(Main *bmain, bNodeTree *ntree)
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
/* node tree update tags override individual node update flags */
if ((node->update & NODE_UPDATE) || (ntree->update & NTREE_UPDATE)) {
+ nodeUpdateFromDeclaration(ntree, node);
if (node->typeinfo->updatefunc) {
node->typeinfo->updatefunc(ntree, node);
}
@@ -5193,6 +5204,7 @@ void nodeUpdate(bNodeTree *ntree, bNode *node)
}
ntree->is_updating = true;
+ nodeUpdateFromDeclaration(ntree, node);
if (node->typeinfo->updatefunc) {
node->typeinfo->updatefunc(ntree, node);
}
@@ -5223,6 +5235,7 @@ bool nodeUpdateID(bNodeTree *ntree, ID *id)
if (node->id == id) {
changed = true;
node->update |= NODE_UPDATE_ID;
+ nodeUpdateFromDeclaration(ntree, node);
if (node->typeinfo->updatefunc) {
node->typeinfo->updatefunc(ntree, node);
}
diff --git a/source/blender/editors/space_node/node_templates.cc b/source/blender/editors/space_node/node_templates.cc
index f68d8589624..6d3b3b4415e 100644
--- a/source/blender/editors/space_node/node_templates.cc
+++ b/source/blender/editors/space_node/node_templates.cc
@@ -377,7 +377,7 @@ static Vector<NodeLinkItem> ui_node_link_items(NodeLinkArg *arg,
using namespace blender::nodes;
r_node_decl.emplace(NodeDeclaration());
- NodeDeclarationBuilder node_decl_builder{*r_node_decl};
+ NodeDeclarationBuilder node_decl_builder{*r_node_decl, nullptr};
arg->node_type->declare(node_decl_builder);
Span<SocketDeclarationPtr> socket_decls = (in_out == SOCK_IN) ? r_node_decl->inputs() :
r_node_decl->outputs();
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 8a2df8638aa..bdd965ddf9c 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3440,6 +3440,7 @@ static bool rna_NodeInternal_poll_instance(bNode *node, bNodeTree *ntree)
static void rna_NodeInternal_update(ID *id, bNode *node)
{
bNodeTree *ntree = (bNodeTree *)id;
+ nodeUpdateFromDeclaration(ntree, node);
if (node->typeinfo->updatefunc) {
node->typeinfo->updatefunc(ntree, node);
}
@@ -4571,12 +4572,19 @@ bool rna_NodeSocketMaterial_default_value_poll(PointerRNA *UNUSED(ptr), PointerR
return ma->gp_style == NULL;
}
-static NodeFunctionEnumItem *rna_NodeFunctionEnumItems_items_new(bNode *node)
+static NodeFunctionEnumItem *rna_NodeFunctionEnumItems_items_new(ID *id, bNode *node, bContext *C)
{
NodeFunctionEnum *storage = node->storage;
NodeFunctionEnumItem *item = MEM_callocN(sizeof(NodeFunctionEnumItem), __func__);
item->owner_node = node;
BLI_addtail(&storage->items, item);
+
+ PointerRNA node_ptr;
+ RNA_pointer_create(id, &RNA_Node, node, &node_ptr);
+
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ rna_Node_socket_update(bmain, scene, &node_ptr);
return item;
}
@@ -5105,6 +5113,7 @@ static void rna_def_fn_enum_items_api(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_struct_ui_text(srna, "Enum Items", "");
func = RNA_def_function(srna, "new", "rna_NodeFunctionEnumItems_items_new");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_SELF_ID);
RNA_def_function_ui_description(func, "Add a new enum item");
parm = RNA_def_pointer(func, "item", "NodeFunctionEnumItem", "", "New enum item");
RNA_def_function_return(func, parm);
diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index e9f2996bb30..01270aedc0b 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -244,11 +244,13 @@ class NodeDeclaration {
class NodeDeclarationBuilder {
private:
+ /** The node may be null. */
NodeDeclaration &declaration_;
+ const bNode *node_;
Vector<std::unique_ptr<BaseSocketDeclarationBuilder>> builders_;
public:
- NodeDeclarationBuilder(NodeDeclaration &declaration);
+ NodeDeclarationBuilder(NodeDeclaration &declaration, const bNode *node);
/**
* All inputs support fields, and all outputs are fields if any of the inputs is a field.
@@ -259,6 +261,12 @@ class NodeDeclarationBuilder {
declaration_.is_function_node_ = value;
}
+ /** Return the node this declaration is build for. It may be null. */
+ const bNode *node() const
+ {
+ return node_;
+ }
+
template<typename DeclType>
typename DeclType::Builder &add_input(StringRef name, StringRef identifier = "");
template<typename DeclType>
@@ -392,8 +400,9 @@ inline const OutputFieldDependency &SocketDeclaration::output_field_dependency()
/** \name #NodeDeclarationBuilder Inline Methods
* \{ */
-inline NodeDeclarationBuilder::NodeDeclarationBuilder(NodeDeclaration &declaration)
- : declaration_(declaration)
+inline NodeDeclarationBuilder::NodeDeclarationBuilder(NodeDeclaration &declaration,
+ const bNode *node)
+ : declaration_(declaration), node_(node)
{
}
diff --git a/source/blender/nodes/function/nodes/node_fn_enum.cc b/source/blender/nodes/function/nodes/node_fn_enum.cc
index fe21cc53baf..bf83fb043ed 100644
--- a/source/blender/nodes/function/nodes/node_fn_enum.cc
+++ b/source/blender/nodes/function/nodes/node_fn_enum.cc
@@ -27,9 +27,14 @@ namespace blender::nodes {
static void fn_node_enum_declare(NodeDeclarationBuilder &b)
{
- b.is_function_node();
- b.add_input<decl::Float>(N_("Float"));
- b.add_output<decl::Int>(N_("Integer"));
+ const bNode *node = b.node();
+ if (node == nullptr) {
+ return;
+ }
+ const NodeFunctionEnum *storage = (const NodeFunctionEnum *)node->storage;
+ LISTBASE_FOREACH (const NodeFunctionEnumItem *, item, &storage->items) {
+ b.add_output<decl::Bool>(N_("Bool"), "item_" + std::to_string(item->value));
+ }
};
static void fn_node_enum_init(bNodeTree *UNUSED(tree), bNode *node)
@@ -96,6 +101,7 @@ void register_node_type_fn_enum()
blender::nodes::fn_node_enum_copy_storage);
node_type_init(&ntype, blender::nodes::fn_node_enum_init);
ntype.declare = blender::nodes::fn_node_enum_declare;
+ ntype.declaration_is_dynamic = true;
ntype.build_multi_function = blender::nodes::fn_node_enum_build_multi_function;
ntype.draw_buttons = blender::nodes::fn_node_enum_layout;
nodeRegisterType(&ntype);
More information about the Bf-blender-cvs
mailing list