[Bf-blender-cvs] [2423f1c531b] functions: add Random Float node
Jacques Lucke
noreply at git.blender.org
Thu Nov 14 16:31:29 CET 2019
Commit: 2423f1c531b9316a4d1ae388e941fb2ae76b8716
Author: Jacques Lucke
Date: Thu Nov 14 15:20:07 2019 +0100
Branches: functions
https://developer.blender.org/rB2423f1c531b9316a4d1ae388e941fb2ae76b8716
add Random Float node
===================================================================
M release/scripts/startup/nodes/function_nodes/noise.py
M source/blender/functions/intern/multi_functions/mixed.cc
M source/blender/functions/intern/multi_functions/mixed.h
M source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
===================================================================
diff --git a/release/scripts/startup/nodes/function_nodes/noise.py b/release/scripts/startup/nodes/function_nodes/noise.py
index 92914c8e1dc..10b70e0ae3c 100644
--- a/release/scripts/startup/nodes/function_nodes/noise.py
+++ b/release/scripts/startup/nodes/function_nodes/noise.py
@@ -13,3 +13,14 @@ class PerlinNoiseNode(bpy.types.Node, FunctionNode):
builder.fixed_input("scale", "Scale", "Float", default=1)
builder.fixed_output("noise_1d", "Noise", "Float")
builder.fixed_output("noise_3d", "Noise", "Vector")
+
+
+class RandomFloatNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_RandomFloatNode"
+ bl_label = "Random Float"
+
+ def declaration(self, builder: NodeBuilder):
+ builder.fixed_input("seed", "Seed", "Integer")
+ builder.fixed_input("min", "Min", "Float", default=0)
+ builder.fixed_input("max", "Max", "Float", default=1)
+ builder.fixed_output("value", "Value", "Float")
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index c24f9e00a66..b05d84d076e 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -705,4 +705,27 @@ void MF_Clamp::call(MFMask mask, MFParams params, MFContext UNUSED(context)) con
}
}
+MF_RandomFloat::MF_RandomFloat()
+{
+ MFSignatureBuilder signature("Random Float");
+ signature.readonly_single_input<int>("Seed");
+ signature.readonly_single_input<float>("Min");
+ signature.readonly_single_input<float>("Max");
+ signature.single_output<float>("Value");
+ this->set_signature(signature);
+}
+
+void MF_RandomFloat::call(MFMask mask, MFParams params, MFContext UNUSED(context)) const
+{
+ VirtualListRef<int> seeds = params.readonly_single_input<int>(0, "Seed");
+ VirtualListRef<float> min_values = params.readonly_single_input<float>(1, "Min");
+ VirtualListRef<float> max_values = params.readonly_single_input<float>(2, "Max");
+ MutableArrayRef<float> r_values = params.uninitialized_single_output<float>(3, "Value");
+
+ for (uint i : mask.indices()) {
+ float value = BLI_hash_int_01(seeds[i]);
+ r_values[i] = value * (max_values[i] - min_values[i]) + min_values[i];
+ }
+}
+
} // namespace FN
diff --git a/source/blender/functions/intern/multi_functions/mixed.h b/source/blender/functions/intern/multi_functions/mixed.h
index 1e794db94b6..3fe6cb8630f 100644
--- a/source/blender/functions/intern/multi_functions/mixed.h
+++ b/source/blender/functions/intern/multi_functions/mixed.h
@@ -81,6 +81,12 @@ class MF_TextLength final : public MultiFunction {
void call(MFMask mask, MFParams params, MFContext context) const override;
};
+class MF_RandomFloat final : public MultiFunction {
+ public:
+ MF_RandomFloat();
+ void call(MFMask mask, MFParams parms, MFContext context) const override;
+};
+
template<typename T> class MF_ConstantValue : public MultiFunction {
private:
T m_value;
diff --git a/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc b/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
index a2398da0de5..a969f18a5a7 100644
--- a/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
+++ b/source/blender/functions/intern/vtree_multi_function_network/mappings_nodes.cc
@@ -543,6 +543,12 @@ static void INSERT_group_node(VTreeMFNetworkBuilder &builder, const VNode &vnode
builder.resources().add(std::move(fn), "Function for Group");
}
+static void INSERT_random_float(VTreeMFNetworkBuilder &builder, const VNode &vnode)
+{
+ const MultiFunction &fn = builder.construct_fn<MF_RandomFloat>();
+ builder.add_function(fn, {0, 1, 2}, {3}, vnode);
+}
+
void add_vtree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
{
mappings.vnode_inserters.add_new("fn_CombineColorNode", INSERT_combine_color);
@@ -566,6 +572,7 @@ void add_vtree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
mappings.vnode_inserters.add_new("fn_MapRangeNode", INSERT_map_range);
mappings.vnode_inserters.add_new("fn_FloatClampNode", INSERT_clamp_float);
mappings.vnode_inserters.add_new("fn_GroupNode", INSERT_group_node);
+ mappings.vnode_inserters.add_new("fn_RandomFloatNode", INSERT_random_float);
mappings.vnode_inserters.add_new("fn_AddFloatsNode", INSERT_add_floats);
mappings.vnode_inserters.add_new("fn_MultiplyFloatsNode", INSERT_multiply_floats);
More information about the Bf-blender-cvs
mailing list