[Bf-blender-cvs] [545e1b60f16] functions: implement start-stop mode in Float Range node
Jacques Lucke
noreply at git.blender.org
Wed Dec 18 13:54:09 CET 2019
Commit: 545e1b60f1609a072f1d8a2f87154328ac5816b9
Author: Jacques Lucke
Date: Wed Dec 18 13:53:16 2019 +0100
Branches: functions
https://developer.blender.org/rB545e1b60f1609a072f1d8a2f87154328ac5816b9
implement start-stop mode in Float Range node
===================================================================
M release/scripts/startup/nodes/function_nodes/float_range.py
M source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
M source/blender/functions/intern/multi_functions/mixed.cc
M source/blender/functions/intern/multi_functions/mixed.h
===================================================================
diff --git a/release/scripts/startup/nodes/function_nodes/float_range.py b/release/scripts/startup/nodes/function_nodes/float_range.py
index e5fb64db2eb..cfd9b9cd311 100644
--- a/release/scripts/startup/nodes/function_nodes/float_range.py
+++ b/release/scripts/startup/nodes/function_nodes/float_range.py
@@ -1,4 +1,5 @@
import bpy
+from bpy.props import *
from .. base import FunctionNode
from .. node_builder import NodeBuilder
@@ -6,9 +7,25 @@ class FloatRangeNode(bpy.types.Node, FunctionNode):
bl_idname = "fn_FloatRangeNode"
bl_label = "Float Range"
+ mode: EnumProperty(
+ name="Mode",
+ items=[
+ ("AMOUNT_START_STEP", "Amount / Start / Step", "", "NONE", 0),
+ ("AMOUNT_START_STOP", "Amount / Start / Stop", "", "NONE", 1),
+ ],
+ default="AMOUNT_START_STOP",
+ update=FunctionNode.sync_tree,
+ )
+
def declaration(self, builder: NodeBuilder):
- builder.fixed_input("amount", "Amount", "Integer")
+ builder.fixed_input("amount", "Amount", "Integer", default=10)
builder.fixed_input("start", "Start", "Float")
- builder.fixed_input("step", "Step", "Float")
+ if self.mode == "AMOUNT_START_STEP":
+ builder.fixed_input("step", "Step", "Float")
+ elif self.mode == "AMOUNT_START_STOP":
+ builder.fixed_input("stop", "Stop", "Float", default=1)
builder.fixed_output("list", "List", "Float List")
+
+ def draw(self, layout):
+ layout.prop(self, "mode", text="")
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 e738cab2698..1891352efeb 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
@@ -145,7 +145,19 @@ static void INSERT_vertex_info(VNodeMFNetworkBuilder &builder)
static void INSERT_float_range(VNodeMFNetworkBuilder &builder)
{
- builder.set_constructed_matching_fn<MF_FloatRange>();
+ int mode = RNA_enum_get(builder.rna(), "mode");
+ switch (mode) {
+ case 0: {
+ builder.set_constructed_matching_fn<MF_FloatRange_Amount_Start_Step>();
+ break;
+ }
+ case 1: {
+ builder.set_constructed_matching_fn<MF_FloatRange_Amount_Start_Stop>();
+ break;
+ }
+ default:
+ BLI_assert(false);
+ }
}
static void INSERT_time_info(VNodeMFNetworkBuilder &builder)
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index 2ee45d2bc83..e3565d7e505 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -172,7 +172,7 @@ void MF_FloatArraySum::call(MFMask mask, MFParams params, MFContext UNUSED(conte
}
}
-MF_FloatRange::MF_FloatRange()
+MF_FloatRange_Amount_Start_Step::MF_FloatRange_Amount_Start_Step()
{
MFSignatureBuilder signature = this->get_builder("Float Range");
signature.single_input<int>("Amount");
@@ -181,23 +181,66 @@ MF_FloatRange::MF_FloatRange()
signature.vector_output<float>("Range");
}
-void MF_FloatRange::call(MFMask mask, MFParams params, MFContext UNUSED(context)) const
+void MF_FloatRange_Amount_Start_Step::call(MFMask mask,
+ MFParams params,
+ MFContext UNUSED(context)) const
{
VirtualListRef<int> amounts = params.readonly_single_input<int>(0, "Amount");
VirtualListRef<float> starts = params.readonly_single_input<float>(1, "Start");
VirtualListRef<float> steps = params.readonly_single_input<float>(2, "Step");
auto r_ranges = params.vector_output<float>(3, "Range");
- for (uint i : mask.indices()) {
- int amount = amounts[i];
- float start = starts[i];
- float step = steps[i];
+ for (uint index : mask.indices()) {
+ uint amount = std::max<int>(0, amounts[index]);
+ float start = starts[index];
+ float step = steps[index];
+
+ MutableArrayRef<float> range = r_ranges.allocate(index, amount);
+
+ for (int i = 0; i < amount; i++) {
+ float value = start + i * step;
+ range[i] = value;
+ }
+ }
+}
+
+MF_FloatRange_Amount_Start_Stop::MF_FloatRange_Amount_Start_Stop()
+{
+ MFSignatureBuilder signature = this->get_builder("Float Range");
+ signature.single_input<int>("Amount");
+ signature.single_input<float>("Start");
+ signature.single_input<float>("Stop");
+ signature.vector_output<float>("Range");
+}
+
+void MF_FloatRange_Amount_Start_Stop::call(MFMask mask,
+ MFParams params,
+ MFContext UNUSED(context)) const
+{
+ VirtualListRef<int> amounts = params.readonly_single_input<int>(0, "Amount");
+ VirtualListRef<float> starts = params.readonly_single_input<float>(1, "Start");
+ VirtualListRef<float> stops = params.readonly_single_input<float>(2, "Stop");
+ auto r_ranges = params.vector_output<float>(3, "Range");
+
+ for (uint index : mask.indices()) {
+ uint amount = std::max<int>(0, amounts[index]);
+ float start = starts[index];
+ float stop = stops[index];
- MutableArrayRef<float> range = r_ranges.allocate(i, amount);
+ if (amount == 0) {
+ continue;
+ }
+ else if (amount == 1) {
+ r_ranges.append_single(index, (start + stop) / 2.0f);
+ }
+ else {
+ MutableArrayRef<float> range = r_ranges.allocate(index, amount);
- for (int j = 0; j < amount; j++) {
- float value = start + j * step;
- range[j] = value;
+ float step = (stop - start) / (amount - 1);
+ for (int i = 0; i < amount; i++) {
+ float value = start + i * step;
+ range[i] = value;
+ }
}
}
}
diff --git a/source/blender/functions/intern/multi_functions/mixed.h b/source/blender/functions/intern/multi_functions/mixed.h
index 29f290749f5..ab8e4fda8e3 100644
--- a/source/blender/functions/intern/multi_functions/mixed.h
+++ b/source/blender/functions/intern/multi_functions/mixed.h
@@ -42,9 +42,15 @@ class MF_FloatArraySum final : public MultiFunction {
void call(MFMask mask, MFParams params, MFContext context) const override;
};
-class MF_FloatRange final : public MultiFunction {
+class MF_FloatRange_Amount_Start_Step final : public MultiFunction {
public:
- MF_FloatRange();
+ MF_FloatRange_Amount_Start_Step();
+ void call(MFMask mask, MFParams params, MFContext context) const override;
+};
+
+class MF_FloatRange_Amount_Start_Stop final : public MultiFunction {
+ public:
+ MF_FloatRange_Amount_Start_Stop();
void call(MFMask mask, MFParams params, MFContext context) const override;
};
More information about the Bf-blender-cvs
mailing list