[Bf-blender-cvs] [391ee167463] functions: new Combine Lists node
Jacques Lucke
noreply at git.blender.org
Sun Mar 10 18:32:47 CET 2019
Commit: 391ee167463d09b4299f9689ca8f9ed8166e15ea
Author: Jacques Lucke
Date: Sun Mar 10 18:29:00 2019 +0100
Branches: functions
https://developer.blender.org/rB391ee167463d09b4299f9689ca8f9ed8166e15ea
new Combine Lists node
===================================================================
A release/scripts/startup/function_nodes/nodes/combine_lists.py
M source/blender/blenlib/BLI_small_vector.hpp
M source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
M source/blender/functions/functions/lists.cpp
M source/blender/functions/functions/lists.hpp
M source/blender/functions/types/lists.hpp
===================================================================
diff --git a/release/scripts/startup/function_nodes/nodes/combine_lists.py b/release/scripts/startup/function_nodes/nodes/combine_lists.py
new file mode 100644
index 00000000000..6d651c3cd39
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/combine_lists.py
@@ -0,0 +1,14 @@
+import bpy
+from .. base import FunctionNode
+
+class CombineListsNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_CombineListsNode"
+ bl_label = "Combine Lists"
+
+ def get_sockets(self):
+ return [
+ ("fn_FloatListSocket", "List 1"),
+ ("fn_FloatListSocket", "List 2"),
+ ], [
+ ("fn_FloatListSocket", "List"),
+ ]
\ No newline at end of file
diff --git a/source/blender/blenlib/BLI_small_vector.hpp b/source/blender/blenlib/BLI_small_vector.hpp
index 92e4948da56..9044908eaa3 100644
--- a/source/blender/blenlib/BLI_small_vector.hpp
+++ b/source/blender/blenlib/BLI_small_vector.hpp
@@ -102,6 +102,13 @@ namespace BLI {
m_size++;
}
+ void extend(const SmallVector &other)
+ {
+ for (const T &value : other) {
+ this->append(value);
+ }
+ }
+
void fill(const T &value)
{
for (uint i = 0; i < m_size; i++) {
diff --git a/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
index a2e113553ed..8de9a2aa0e5 100644
--- a/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/test_nodes.cpp
@@ -91,6 +91,16 @@ namespace FN { namespace DataFlowNodes {
builder.map_sockets(node, bnode);
}
+ static void insert_combine_lists_node(
+ Builder &builder,
+ const BuilderContext UNUSED(ctx),
+ bNode *bnode)
+ {
+ SharedFunction &combine_float_lists = Functions::combine_float_lists();
+ Node *node = builder.insert_function(combine_float_lists);
+ builder.map_sockets(node, bnode);
+ }
+
void register_node_inserters(GraphInserters &inserters)
{
inserters.reg_node_function("fn_CombineVectorNode", Functions::combine_vector);
@@ -104,6 +114,7 @@ namespace FN { namespace DataFlowNodes {
inserters.reg_node_inserter("fn_ClampNode", insert_clamp_node);
inserters.reg_node_inserter("fn_AppendToListNode", insert_append_list_node);
inserters.reg_node_inserter("fn_GetListElementNode", insert_get_list_element_node);
+ inserters.reg_node_inserter("fn_CombineListsNode", insert_combine_lists_node);
}
} }
\ No newline at end of file
diff --git a/source/blender/functions/functions/lists.cpp b/source/blender/functions/functions/lists.cpp
index d8f50a03659..75624d9a84b 100644
--- a/source/blender/functions/functions/lists.cpp
+++ b/source/blender/functions/functions/lists.cpp
@@ -22,6 +22,19 @@ namespace FN { namespace Functions {
}
};
+ LAZY_INIT_REF__NO_ARG(SharedFunction, append_float)
+ {
+ auto fn = SharedFunction::New("Append Float", Signature({
+ InputParameter("List", get_float_list_type()),
+ InputParameter("Value", get_float_type()),
+ }, {
+ OutputParameter("List", get_float_list_type()),
+ }));
+ fn->add_body(new AppendToList<float>());
+ return fn;
+ }
+
+
template<typename T>
class GetListElement : public TupleCallBody {
void call(Tuple &fn_in, Tuple &fn_out) const override
@@ -41,18 +54,6 @@ namespace FN { namespace Functions {
}
};
- LAZY_INIT_REF__NO_ARG(SharedFunction, append_float)
- {
- auto fn = SharedFunction::New("Append Float", Signature({
- InputParameter("List", get_float_list_type()),
- InputParameter("Value", get_float_type()),
- }, {
- OutputParameter("List", get_float_list_type()),
- }));
- fn->add_body(new AppendToList<float>());
- return fn;
- }
-
LAZY_INIT_REF__NO_ARG(SharedFunction, get_float_list_element)
{
auto fn = SharedFunction::New("Get Float List Element", Signature({
@@ -66,4 +67,33 @@ namespace FN { namespace Functions {
return fn;
}
+
+ template<typename T>
+ class CombineList : public TupleCallBody {
+ void call(Tuple &fn_in, Tuple &fn_out) const override
+ {
+ auto list1 = fn_in.relocate_out<SharedList<T>>(0);
+ auto list2 = fn_in.relocate_out<SharedList<T>>(1);
+
+ list1 = list1->get_mutable();
+ list1->extend(list2.ptr());
+
+ fn_out.move_in(0, list1);
+ }
+ };
+
+ LAZY_INIT_REF__NO_ARG(SharedFunction, combine_float_lists)
+ {
+ SharedType &float_list_ty = get_float_list_type();
+
+ auto fn = SharedFunction::New("Combine Float List", Signature({
+ InputParameter("List 1", float_list_ty),
+ InputParameter("List 2", float_list_ty),
+ }, {
+ OutputParameter("List", float_list_ty),
+ }));
+ fn->add_body(new CombineList<float>());
+ return fn;
+ }
+
} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/lists.hpp b/source/blender/functions/functions/lists.hpp
index 347ff5152b2..af7b80561d0 100644
--- a/source/blender/functions/functions/lists.hpp
+++ b/source/blender/functions/functions/lists.hpp
@@ -6,5 +6,6 @@ namespace FN { namespace Functions {
SharedFunction &append_float();
SharedFunction &get_float_list_element();
+ SharedFunction &combine_float_lists();
} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/types/lists.hpp b/source/blender/functions/types/lists.hpp
index ab419a2f21b..1fcd0f327d9 100644
--- a/source/blender/functions/types/lists.hpp
+++ b/source/blender/functions/types/lists.hpp
@@ -39,6 +39,12 @@ namespace FN { namespace Types {
m_data.append(std::move(value));
}
+ void extend(List *other)
+ {
+ this->assert_mutable();
+ m_data.extend(other->m_data);
+ }
+
List *copy() const
{
List *new_list = new List();
More information about the Bf-blender-cvs
mailing list