[Bf-blender-cvs] [d7d365f6eb5] functions: new Get List Elements node
Jacques Lucke
noreply at git.blender.org
Thu Dec 12 18:28:25 CET 2019
Commit: d7d365f6eb5a7e87bd8ab45dc5c60365e93eba52
Author: Jacques Lucke
Date: Thu Dec 12 15:34:53 2019 +0100
Branches: functions
https://developer.blender.org/rBd7d365f6eb5a7e87bd8ab45dc5c60365e93eba52
new Get List Elements node
===================================================================
M release/scripts/startup/nodes/function_nodes/list.py
M source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
M source/blender/functions/intern/multi_functions/lists.cc
M source/blender/functions/intern/multi_functions/lists.h
===================================================================
diff --git a/release/scripts/startup/nodes/function_nodes/list.py b/release/scripts/startup/nodes/function_nodes/list.py
index f7d5315d093..c2a688e41ed 100644
--- a/release/scripts/startup/nodes/function_nodes/list.py
+++ b/release/scripts/startup/nodes/function_nodes/list.py
@@ -18,6 +18,19 @@ class GetListElementNode(bpy.types.Node, FunctionNode):
builder.dynamic_base_output("value", "Value", "active_type")
+class GetListElementsNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_GetListElementsNode"
+ bl_label = "Get List Elements"
+
+ active_type: NodeBuilder.DynamicListProperty()
+
+ def declaration(self, builder: NodeBuilder):
+ builder.dynamic_list_input("list", "List", "active_type")
+ builder.fixed_input("indices", "Indices", "Integer List")
+ builder.dynamic_base_input("fallback", "Fallback", "active_type")
+ builder.dynamic_list_output("values", "Values", "active_type")
+
+
class ListLengthNode(bpy.types.Node, FunctionNode):
bl_idname = "fn_ListLengthNode"
bl_label = "List Length"
diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
index ce775083f35..9b4d609ec02 100644
--- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
+++ b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
@@ -45,6 +45,12 @@ static void INSERT_get_list_element(VNodeMFNetworkBuilder &builder)
builder.set_constructed_matching_fn<MF_GetListElement>(type);
}
+static void INSERT_get_list_elements(VNodeMFNetworkBuilder &builder)
+{
+ const CPPType &type = builder.cpp_type_from_property("active_type");
+ builder.set_constructed_matching_fn<MF_GetListElements>(type);
+}
+
static void INSERT_pack_list(VNodeMFNetworkBuilder &builder)
{
const CPPType &type = builder.cpp_type_from_property("active_type");
@@ -497,6 +503,7 @@ void add_inlined_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
mappings.xnode_inserters.add_new("fn_ListLengthNode", INSERT_list_length);
mappings.xnode_inserters.add_new("fn_PackListNode", INSERT_pack_list);
mappings.xnode_inserters.add_new("fn_GetListElementNode", INSERT_get_list_element);
+ mappings.xnode_inserters.add_new("fn_GetListElementsNode", INSERT_get_list_elements);
mappings.xnode_inserters.add_new("fn_ObjectTransformsNode", INSERT_object_location);
mappings.xnode_inserters.add_new("fn_ObjectMeshNode", INSERT_object_mesh_info);
mappings.xnode_inserters.add_new("fn_GetPositionOnSurfaceNode", INSERT_get_position_on_surface);
diff --git a/source/blender/functions/intern/multi_functions/lists.cc b/source/blender/functions/intern/multi_functions/lists.cc
index 75e37291bbc..7d5072c6c05 100644
--- a/source/blender/functions/intern/multi_functions/lists.cc
+++ b/source/blender/functions/intern/multi_functions/lists.cc
@@ -92,18 +92,52 @@ void MF_GetListElement::call(MFMask mask, MFParams params, MFContext UNUSED(cont
VirtualListRef<int> indices = params.readonly_single_input<int>(1, "Index");
GenericVirtualListRef fallbacks = params.readonly_single_input(2, "Fallback");
- GenericMutableArrayRef output_values = params.uninitialized_single_output(3, "Value");
+ GenericMutableArrayRef r_output_values = params.uninitialized_single_output(3, "Value");
for (uint i : mask.indices()) {
int index = indices[i];
if (index >= 0) {
GenericVirtualListRef list = lists[i];
if (index < list.size()) {
- m_base_type.copy_to_uninitialized(list[index], output_values[i]);
+ m_base_type.copy_to_uninitialized(list[index], r_output_values[i]);
continue;
}
}
- m_base_type.copy_to_uninitialized(fallbacks[i], output_values[i]);
+ m_base_type.copy_to_uninitialized(fallbacks[i], r_output_values[i]);
+ }
+}
+
+MF_GetListElements::MF_GetListElements(const CPPType &base_type) : m_base_type(base_type)
+{
+ MFSignatureBuilder signature("Get List Elements");
+ signature.vector_input("List", m_base_type);
+ signature.vector_input<int>("Indices");
+ signature.single_input("Fallback", m_base_type);
+ signature.vector_output("Values", m_base_type);
+ this->set_signature(signature);
+}
+
+void MF_GetListElements::call(MFMask mask, MFParams params, MFContext UNUSED(context)) const
+{
+ GenericVirtualListListRef lists = params.readonly_vector_input(0, "List");
+ VirtualListListRef<int> indices = params.readonly_vector_input<int>(1, "Indices");
+ GenericVirtualListRef fallbacks = params.readonly_single_input(2, "Fallback");
+
+ GenericVectorArray &r_output_values = params.vector_output(3, "Values");
+
+ for (uint i : mask.indices()) {
+ GenericVirtualListRef list = lists[i];
+ VirtualListRef<int> sub_indices = indices[i];
+ GenericMutableArrayRef values = r_output_values.allocate_single(i, sub_indices.size());
+ for (uint j = 0; j < sub_indices.size(); j++) {
+ uint index = sub_indices[j];
+ if (index >= 0 && index < list.size()) {
+ values.copy_in__uninitialized(j, list[index]);
+ }
+ else {
+ values.copy_in__uninitialized(j, fallbacks[i]);
+ }
+ }
}
}
diff --git a/source/blender/functions/intern/multi_functions/lists.h b/source/blender/functions/intern/multi_functions/lists.h
index 29821d13bbe..72df98e8635 100644
--- a/source/blender/functions/intern/multi_functions/lists.h
+++ b/source/blender/functions/intern/multi_functions/lists.h
@@ -13,6 +13,15 @@ class MF_GetListElement final : public MultiFunction {
void call(MFMask mask, MFParams params, MFContext context) const override;
};
+class MF_GetListElements final : public MultiFunction {
+ private:
+ const CPPType &m_base_type;
+
+ public:
+ MF_GetListElements(const CPPType &base_type);
+ void call(MFMask mask, MFParams params, MFContext context) const override;
+};
+
class MF_ListLength final : public MultiFunction {
private:
const CPPType &m_base_type;
More information about the Bf-blender-cvs
mailing list