[Bf-blender-cvs] [84670db6ea1] functions: List Length node and fail early when socket types don't match
Jacques Lucke
noreply at git.blender.org
Sat Apr 6 12:00:49 CEST 2019
Commit: 84670db6ea12b3839cb57873027f7eb96b5f30f7
Author: Jacques Lucke
Date: Sat Apr 6 12:00:35 2019 +0200
Branches: functions
https://developer.blender.org/rB84670db6ea12b3839cb57873027f7eb96b5f30f7
List Length node and fail early when socket types don't match
===================================================================
A release/scripts/startup/function_nodes/nodes/list_length.py
M source/blender/functions/frontends/data_flow_nodes/builder.cpp
M source/blender/functions/frontends/data_flow_nodes/builder.hpp
M source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
M source/blender/functions/frontends/data_flow_nodes/inserters.cpp
M source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
M source/blender/functions/functions/lists.cpp
M source/blender/functions/functions/lists.hpp
===================================================================
diff --git a/release/scripts/startup/function_nodes/nodes/list_length.py b/release/scripts/startup/function_nodes/nodes/list_length.py
new file mode 100644
index 00000000000..8899d65cacf
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/list_length.py
@@ -0,0 +1,13 @@
+import bpy
+from .. base import FunctionNode
+from .. socket_builder import SocketBuilder
+
+class ListLengthNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_ListLengthNode"
+ bl_label = "List Length"
+
+ active_type: SocketBuilder.ListTypeProperty()
+
+ def declaration(self, builder: SocketBuilder):
+ builder.dynamic_list_input("list", "List", "active_type")
+ builder.fixed_output("length", "Length", "Integer")
\ No newline at end of file
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.cpp b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
index 86a2fc57c91..f12da413abc 100644
--- a/source/blender/functions/frontends/data_flow_nodes/builder.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.cpp
@@ -109,35 +109,36 @@ namespace FN { namespace DataFlowNodes {
m_graph->link(a, b);
}
- void Builder::map_socket(Socket socket, bNodeSocket *bsocket)
+ void Builder::map_socket(const BuilderContext &ctx, Socket socket, bNodeSocket *bsocket)
{
+ BLI_assert(ctx.is_data_socket(bsocket) ? socket.type() == ctx.type_of_socket(bsocket) : true);
m_socket_map.add(bsocket, socket);
}
- void Builder::map_sockets(Node *node, struct bNode *bnode)
+ void Builder::map_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode)
{
BLI_assert(BLI_listbase_count(&bnode->inputs) == node->input_amount());
BLI_assert(BLI_listbase_count(&bnode->outputs) == node->output_amount());
uint input_index = 0;
for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
- this->map_socket(node->input(input_index), bsocket);
+ this->map_socket(ctx, node->input(input_index), bsocket);
input_index++;
}
uint output_index = 0;
for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
- this->map_socket(node->output(output_index), bsocket);
+ this->map_socket(ctx, node->output(output_index), bsocket);
output_index++;
}
}
- void Builder::map_data_sockets(Node *node, struct bNode *bnode, const BuilderContext &ctx)
+ void Builder::map_data_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode)
{
uint input_index = 0;
for (bNodeSocket *bsocket : bSocketList(&bnode->inputs)) {
if (ctx.is_data_socket(bsocket)) {
- this->map_socket(node->input(input_index), bsocket);
+ this->map_socket(ctx, node->input(input_index), bsocket);
input_index++;
}
}
@@ -145,24 +146,24 @@ namespace FN { namespace DataFlowNodes {
uint output_index = 0;
for (bNodeSocket *bsocket : bSocketList(&bnode->outputs)) {
if (ctx.is_data_socket(bsocket)) {
- this->map_socket(node->output(output_index), bsocket);
+ this->map_socket(ctx, node->output(output_index), bsocket);
output_index++;
}
}
}
- void Builder::map_input(Socket socket, struct bNode *bnode, uint index)
+ void Builder::map_input(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index)
{
BLI_assert(socket.is_input());
auto bsocket = (bNodeSocket *)BLI_findlink(&bnode->inputs, index);
- this->map_socket(socket, bsocket);
+ this->map_socket(ctx, socket, bsocket);
}
- void Builder::map_output(Socket socket, struct bNode *bnode, uint index)
+ void Builder::map_output(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index)
{
BLI_assert(socket.is_output());
auto bsocket = (bNodeSocket *)BLI_findlink(&bnode->outputs, index);
- this->map_socket(socket, bsocket);
+ this->map_socket(ctx, socket, bsocket);
}
Socket Builder::lookup_socket(struct bNodeSocket *bsocket)
diff --git a/source/blender/functions/frontends/data_flow_nodes/builder.hpp b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
index 2ee90ae80d4..c82e7de8d46 100644
--- a/source/blender/functions/frontends/data_flow_nodes/builder.hpp
+++ b/source/blender/functions/frontends/data_flow_nodes/builder.hpp
@@ -32,11 +32,11 @@ namespace FN { namespace DataFlowNodes {
Node *insert_function(SharedFunction &fn, struct bNodeTree *btree, struct bNodeLink *blink);
void insert_link(Socket a, Socket b);
- void map_socket(Socket socket, struct bNodeSocket *bsocket);
- void map_sockets(Node *node, struct bNode *bnode);
- void map_data_sockets(Node *node, struct bNode *bnode, const BuilderContext &ctx);
- void map_input(Socket socket, struct bNode *bnode, uint index);
- void map_output(Socket socket, struct bNode *bnode, uint index);
+ void map_socket(const BuilderContext &ctx, Socket socket, struct bNodeSocket *bsocket);
+ void map_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode);
+ void map_data_sockets(const BuilderContext &ctx, Node *node, struct bNode *bnode);
+ void map_input(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index);
+ void map_output(const BuilderContext &ctx, Socket socket, struct bNode *bnode, uint index);
Socket lookup_socket(struct bNodeSocket *bsocket);
bool verify_data_sockets_mapped(struct bNode *bnode, const BuilderContext &ctx) const;
diff --git a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
index 3cae92cf08e..844f2d86bdf 100644
--- a/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/graph_generation.cpp
@@ -53,7 +53,7 @@ namespace FN { namespace DataFlowNodes {
auto fn = SharedFunction::New("Function Input", Signature({}, outputs));
Node *node = builder.insert_function(fn);
- builder.map_data_sockets(node, bnode, ctx);
+ builder.map_data_sockets(ctx, node, bnode);
}
static void insert_output_node(
@@ -69,7 +69,7 @@ namespace FN { namespace DataFlowNodes {
auto fn = SharedFunction::New("Function Output", Signature(inputs, {}));
Node *node = builder.insert_function(fn);
- builder.map_data_sockets(node, bnode, ctx);
+ builder.map_data_sockets(ctx, node, bnode);
}
struct BSocketLink {
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
index 655ed7e2fe1..514b3cb024a 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters.cpp
@@ -38,7 +38,7 @@ namespace FN { namespace DataFlowNodes {
{
SharedFunction fn = getter();
Node *node = builder.insert_function(fn, ctx.btree(), bnode);
- builder.map_sockets(node, bnode);
+ builder.map_sockets(ctx, node, bnode);
};
this->reg_node_inserter(idname, inserter);
}
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
index ac9973c8c2a..1ccdcbec38b 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
@@ -23,7 +23,7 @@ namespace FN { namespace DataFlowNodes {
auto fn = Functions::object_location(object);
Node *node = builder.insert_function(fn, ctx.btree(), bnode);
- builder.map_sockets(node, bnode);
+ builder.map_sockets(ctx, node, bnode);
}
static SharedFunction &get_float_math_function(int operation)
@@ -52,7 +52,7 @@ namespace FN { namespace DataFlowNodes {
SharedFunction &fn = get_float_math_function(operation);
Node *node = builder.insert_function(fn, ctx.btree(), bnode);
- builder.map_sockets(node, bnode);
+ builder.map_sockets(ctx, node, bnode);
}
static SharedFunction &get_vector_math_function(int operation)
@@ -77,7 +77,7 @@ namespace FN { namespace DataFlowNodes {
SharedFunction &fn = get_vector_math_function(operation);
Node *node = builder.insert_function(fn, ctx.btree(), bnode);
- builder.map_sockets(node, bnode);
+ builder.map_sockets(ctx, node, bnode);
}
static void insert_clamp_node(
@@ -92,10 +92,10 @@ namespace FN { namespace DataFlowNodes {
Node *min_node = builder.insert_function(min_fn, ctx.btree(), bnode);
builder.insert_link(max_node->output(0), min_node->input(0));
- builder.map_input(max_node->input(0), bnode, 0);
- builder.map_input(max_node->input(1), bnode, 1);
- builder.map_input(min_node->input(1), bnode, 2);
- builder.map_output(min_node->output(0), bnode, 0);
+ builder.map_input(ctx, max_node->input(0), bnode, 0);
+ builder.map_input(ctx, max_node->input(1), bnode, 1);
+ builder.map_input(ctx, min_node->input(1), bnode, 2);
+ builder.map_output(ctx, min_node->output(0), bnode, 0);
}
static void insert_get_list_element_node(
@@ -106,7 +106,18 @@ namespace FN { namespace DataFlowNodes {
SharedType &base_type = ctx.type_from_rna(bnode, "active_type");
SharedFunction &fn = Functions::get_list_element(base_type);
Node *node = builder.insert_function(fn, ctx.btree(), bnode);
- builder.map_sockets(node, bnode);
+ builder.map_sockets(ctx, node, bnode);
+ }
+
+ static void insert_list_length_node(
+ Builder &builder,
+ const BuilderContext &ctx,
+ bNode *bnode)
+ {
+ SharedType &base_type = ctx.type_from_rna(bnode, "active_type");
+ SharedFunction &fn = Functions::list_length(base_type);
+ Node *node = builder.insert_function(fn, ctx.btree(), bnode);
+ builder.map_sockets(ctx, node, bnode);
}
static Socket insert_pack_list_sockets(
@@ -133,14 +144,14 @@ namespace FN { namespace DataFlowNodes {
auto &append_fn = Functions::append_to_list(base_type);
new_node = builder.insert_function(append_fn, ctx.btree(), bnode);
builder.insert_link(node->output(0), new_node->input(0));
- builder.map_input(new_node->input(1), bnode, index);
+ builder.map_input(ctx, new_node->input(1), bnode, index);
}
else if (state == 1) {
/* list case */
auto &combine_fn = Functions::combine_lists(base_type);
new_node = builder.insert_function(combine_fn, ctx.btree(), bno
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list