Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-02-25 20:01:03 +0300
committerJacques Lucke <jacques@blender.org>2020-02-25 20:01:03 +0300
commit07fa59f11d8857cd9507aabc9855b679c8c542f0 (patch)
tree437b10060ff3a8ca723b7ce857831178068522be
parentb206f0ae0f3774f08e95663610165ebb5f5b0a24 (diff)
initial operator socket callback
-rw-r--r--source/blender/simulations/nodes/my_test_node.cc75
1 files changed, 73 insertions, 2 deletions
diff --git a/source/blender/simulations/nodes/my_test_node.cc b/source/blender/simulations/nodes/my_test_node.cc
index 21b960079a6..987fb666925 100644
--- a/source/blender/simulations/nodes/my_test_node.cc
+++ b/source/blender/simulations/nodes/my_test_node.cc
@@ -170,7 +170,7 @@ class SocketDecl {
}
};
-using OperatorSocketFn = bool (*)(bNodeTree *ntree,
+using OperatorSocketFn = void (*)(bNodeTree *ntree,
bNode *node,
bNodeSocket *socket,
bNodeSocket *directly_linked_socket,
@@ -230,6 +230,7 @@ class NodeDecl {
bNode *m_node;
LinearAllocatedVector<SocketDecl *> m_inputs;
LinearAllocatedVector<SocketDecl *> m_outputs;
+ bool m_has_operator_input = false;
NodeDecl(bNodeTree *ntree, bNode *node) : m_ntree(ntree), m_node(node)
{
@@ -323,6 +324,7 @@ class NodeBuilder {
OperatorSocketDecl *decl = m_allocator.construct<OperatorSocketDecl>(
m_allocator.copy_string(ui_name), m_allocator.copy_string(identifier), callback);
m_node_decl.m_inputs.append(decl, m_allocator);
+ m_node_decl.m_has_operator_input = true;
}
void float_input(StringRef identifier, StringRef ui_name)
@@ -856,7 +858,26 @@ void register_node_type_my_test_node()
LISTBASE_FOREACH (VariadicNodeSocketIdentifier *, value, &storage->inputs_info) {
node_builder.float_input(value->identifier, "Value");
}
- node_builder.operator_input("New Input", "New", nullptr);
+ node_builder.operator_input(
+ "New Input",
+ "New",
+ [](bNodeTree *UNUSED(ntree),
+ bNode *node,
+ bNodeSocket *UNUSED(socket),
+ bNodeSocket *UNUSED(directly_linked_socket),
+ bNodeSocket *UNUSED(linked_socket)) {
+ /* TODO: refresh node and make link */
+ FloatAddNodeStorage *storage = get_node_storage<FloatAddNodeStorage>(node);
+ VariadicNodeSocketIdentifier *value = (VariadicNodeSocketIdentifier *)MEM_callocN(
+ sizeof(VariadicNodeSocketIdentifier), __func__);
+ BLI_uniquename(&storage->inputs_info,
+ value,
+ "ID",
+ '.',
+ offsetof(VariadicNodeSocketIdentifier, identifier),
+ sizeof(value->identifier));
+ BLI_addtail(&storage->inputs_info, value);
+ });
node_builder.float_output("result", "Result");
});
ntype.add_draw_fn([](uiLayout *layout, struct bContext *UNUSED(C), struct PointerRNA *ptr) {
@@ -1128,6 +1149,52 @@ static void get_node_declarations(bNodeTree *ntree,
}
}
+static bool run_operator_sockets(const VirtualNodeTree &vtree,
+ ArrayRef<const NodeDecl *> node_decls)
+{
+ bNodeTree *ntree = vtree.btree();
+ bool tree_changed = false;
+
+ /* TODO: correctly handle multiple operator sockets per node */
+ for (uint node_index : node_decls.index_range()) {
+ const NodeDecl *node_decl = node_decls[node_index];
+ if (node_decl->m_has_operator_input) {
+ const VNode *vnode = vtree.nodes()[node_index];
+ for (uint input_index : vnode->inputs().index_range()) {
+ SocketDecl *socket_decl = node_decl->m_inputs[input_index];
+ if (socket_decl->category() == SocketDeclCategory::Operator) {
+ const VInputSocket &vinput = vnode->input(input_index);
+
+ if (vinput.directly_linked_sockets().size() == 1 &&
+ vinput.linked_sockets().size() == 1) {
+ bNodeLink *link = vinput.incident_links()[0];
+ nodeRemLink(ntree, link);
+ tree_changed = true;
+
+ bNodeSocket *directly_linked_socket = vinput.directly_linked_sockets()[0]->bsocket();
+ bNodeSocket *linked_socket = vinput.linked_sockets()[0]->bsocket();
+
+ OperatorSocketDecl *operator_decl = (OperatorSocketDecl *)socket_decl;
+ OperatorSocketFn callback = operator_decl->callback();
+ if (callback) {
+ callback(
+ ntree, vnode->bnode(), vinput.bsocket(), directly_linked_socket, linked_socket);
+ }
+ }
+ else {
+ for (bNodeLink *link : vinput.incident_links()) {
+ nodeRemLink(ntree, link);
+ tree_changed = true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return tree_changed;
+}
+
void update_sim_node_tree(bNodeTree *ntree)
{
VirtualNodeTree vtree(ntree);
@@ -1140,5 +1207,9 @@ void update_sim_node_tree(bNodeTree *ntree)
vtree.~VirtualNodeTree();
new (&vtree) VirtualNodeTree(ntree);
}
+ if (run_operator_sockets(vtree, node_decls)) {
+ vtree.~VirtualNodeTree();
+ new (&vtree) VirtualNodeTree(ntree);
+ }
remove_invalid_links(vtree);
}