[Bf-blender-cvs] [e352d7d3ca1] functions: new Float Range node
Jacques Lucke
noreply at git.blender.org
Mon Apr 8 17:29:16 CEST 2019
Commit: e352d7d3ca13f39a86dc87ae32b8ec37fb493171
Author: Jacques Lucke
Date: Mon Apr 8 17:29:04 2019 +0200
Branches: functions
https://developer.blender.org/rBe352d7d3ca13f39a86dc87ae32b8ec37fb493171
new Float Range node
===================================================================
A release/scripts/startup/function_nodes/nodes/float_range.py
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_functions.hpp
M source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
A source/blender/functions/functions/ranges.cpp
A source/blender/functions/functions/ranges.hpp
===================================================================
diff --git a/release/scripts/startup/function_nodes/nodes/float_range.py b/release/scripts/startup/function_nodes/nodes/float_range.py
new file mode 100644
index 00000000000..19fcea6f44b
--- /dev/null
+++ b/release/scripts/startup/function_nodes/nodes/float_range.py
@@ -0,0 +1,14 @@
+import bpy
+from .. base import FunctionNode
+from .. socket_builder import SocketBuilder
+
+class FloatRangeNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_FloatRangeNode"
+ bl_label = "Float Range"
+
+ def declaration(self, builder: SocketBuilder):
+ builder.fixed_input("amount", "Amount", "Integer")
+ builder.fixed_input("start", "Start", "Float")
+ builder.fixed_input("step", "Step", "Float")
+
+ builder.fixed_output("list", "List", "Float List")
\ No newline at end of file
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 098d571e6a0..5c9c550b00c 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -118,6 +118,8 @@ set(SRC
functions/switch.cpp
functions/auto_vectorization.hpp
functions/auto_vectorization.cpp
+ functions/ranges.hpp
+ functions/ranges.cpp
frontends/data_flow_nodes/builder.hpp
frontends/data_flow_nodes/builder.cpp
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index f20ec82b848..0f4a21ff8ab 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -8,3 +8,4 @@
#include "functions/simple_conversions.hpp"
#include "functions/switch.hpp"
#include "functions/auto_vectorization.hpp"
+#include "functions/ranges.hpp"
\ No newline at end of file
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 d809c26d596..1b6aa647204 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
@@ -232,6 +232,7 @@ namespace FN { namespace DataFlowNodes {
inserters.reg_node_function("fn_VectorDistanceNode", Functions::GET_FN_vector_distance);
inserters.reg_node_function("fn_RandomNumberNode", Functions::GET_FN_random_number);
inserters.reg_node_function("fn_MapRangeNode", Functions::GET_FN_map_range);
+ inserters.reg_node_function("fn_FloatRangeNode", Functions::GET_FN_float_range);
inserters.reg_node_inserter("fn_SeparateVectorNode", INSERT_separate_vector);
inserters.reg_node_inserter("fn_CombineVectorNode", INSERT_combine_vector);
diff --git a/source/blender/functions/functions/ranges.cpp b/source/blender/functions/functions/ranges.cpp
new file mode 100644
index 00000000000..44b50ff7132
--- /dev/null
+++ b/source/blender/functions/functions/ranges.cpp
@@ -0,0 +1,46 @@
+#include "FN_core.hpp"
+#include "FN_functions.hpp"
+#include "FN_types.hpp"
+
+#include "BLI_lazy_init.hpp"
+
+namespace FN { namespace Functions {
+
+ using namespace Types;
+
+ class FloatRange : public TupleCallBody {
+ void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
+ {
+ int amount = fn_in.get<int>(0);
+ float start = fn_in.get<float>(1);
+ float step = fn_in.get<float>(2);
+
+ if (amount < 0) {
+ amount = 0;
+ }
+
+ auto list = SharedFloatList::New();
+ float value = start;
+ for (uint i = 0; i < amount; i++) {
+ list->append(value);
+ value += step;
+ }
+
+ fn_out.move_in(0, list);
+ }
+ };
+
+ LAZY_INIT_REF__NO_ARG(SharedFunction, GET_FN_float_range)
+ {
+ auto fn = SharedFunction::New("Float Range", Signature({
+ InputParameter("Amount", GET_TYPE_int32()),
+ InputParameter("Start", GET_TYPE_float()),
+ InputParameter("Step", GET_TYPE_float()),
+ }, {
+ OutputParameter("List", GET_TYPE_float_list()),
+ }));
+ fn->add_body(new FloatRange());
+ return fn;
+ }
+
+} } /* namespace FN::Functions */
\ No newline at end of file
diff --git a/source/blender/functions/functions/ranges.hpp b/source/blender/functions/functions/ranges.hpp
new file mode 100644
index 00000000000..ee978ee2b09
--- /dev/null
+++ b/source/blender/functions/functions/ranges.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "FN_core.hpp"
+
+namespace FN { namespace Functions {
+
+ SharedFunction &GET_FN_float_range();
+
+} } /* namespace FN::Functions */
More information about the Bf-blender-cvs
mailing list