Commit: 4c5332cae7024eb3594b09c2b001cc30652a8527 Author: Jacques Lucke Date: Wed Dec 18 12:31:19 2019 +0100 Branches: functions https://developer.blender.org/rB4c5332cae7024eb3594b09c2b001cc30652a8527
new Random Vectors node =================================================================== M release/scripts/startup/nodes/function_nodes/noise.py M source/blender/blenlib/BLI_math_cxx.h 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/noise.py b/release/scripts/startup/nodes/function_nodes/noise.py index 4c7dbb78bc2..b438ea88efa 100644 --- a/release/scripts/startup/nodes/function_nodes/noise.py +++ b/release/scripts/startup/nodes/function_nodes/noise.py @@ -104,5 +104,39 @@ class RandomVectorNode(bpy.types.Node, FunctionNode): def duplicate(self, src_node): self.node_seed = new_node_seed() + +class RandomVectorsNode(bpy.types.Node, FunctionNode): + bl_idname = "fn_RandomVectorsNode" + bl_label = "Random Vectors" + + node_seed: IntProperty( + name="Node Seed", + ) + + mode: EnumProperty( + name="Mode", + items=random_vector_mode_items, + default="UNIFORM_IN_CUBE", + ) + + def init_props(self): + self.node_seed = new_node_seed() + + def declaration(self, builder: NodeBuilder): + builder.fixed_input("amount", "Amount", "Integer", default=10) + builder.fixed_input("factor", "Factor", "Vector", default=(1, 1, 1)) + builder.fixed_input("seed", "Seed", "Integer") + builder.fixed_output("vectors", "Vectors", "Vector List") + + def draw(self, layout): + layout.prop(self, "mode", text="") + + def draw_advanced(self, layout): + layout.prop(self, "node_seed") + + def duplicate(self, src_node): + self.node_seed = new_node_seed() + + def new_node_seed(): return random.randint(0, 10000) diff --git a/source/blender/blenlib/BLI_math_cxx.h b/source/blender/blenlib/BLI_math_cxx.h index 0c10a87665d..f5fdae2d0be 100644 --- a/source/blender/blenlib/BLI_math_cxx.h +++ b/source/blender/blenlib/BLI_math_cxx.h @@ -225,6 +225,13 @@ struct float3 { this->z *= scalar; } + void operator*=(float3 other) + { + this->x *= other.x; + this->y *= other.y; + this->z *= other.z; + } + friend float3 operator*(float3 a, float3 b) { return {a.x * b.x, a.y * b.y, a.z * b.z}; 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 034025d9243..03296564076 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 @@ -485,6 +485,13 @@ static void INSERT_random_vector(VNodeMFNetworkBuilder &builder) {"use_list__factor", "use_list__seed"}, node_seed, mode); } +static void INSERT_random_vectors(VNodeMFNetworkBuilder &builder) +{ + uint node_seed = (uint)RNA_int_get(builder.rna(), "node_seed"); + RandomVectorMode::Enum mode = (RandomVectorMode::Enum)RNA_enum_get(builder.rna(), "mode"); + builder.set_constructed_matching_fn<MF_RandomVectors>(node_seed, mode); +} + static void INSERT_value(VNodeMFNetworkBuilder &builder) { const XOutputSocket &xsocket = builder.xnode().output(0); @@ -551,6 +558,7 @@ void add_inlined_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings) mappings.xnode_inserters.add_new("fn_RandomFloatNode", INSERT_random_float); mappings.xnode_inserters.add_new("fn_RandomFloatsNode", INSERT_random_floats); mappings.xnode_inserters.add_new("fn_RandomVectorNode", INSERT_random_vector); + mappings.xnode_inserters.add_new("fn_RandomVectorsNode", INSERT_random_vectors); mappings.xnode_inserters.add_new("fn_ValueNode", INSERT_value); mappings.xnode_inserters.add_new("fn_EmitterTimeInfoNode", INSERT_emitter_time_info); mappings.xnode_inserters.add_new("fn_SampleObjectSurfaceNode", INSERT_sample_object_surface); diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc index 722fc123411..6ee1684001b 100644 --- a/source/blender/functions/intern/multi_functions/mixed.cc +++ b/source/blender/functions/intern/multi_functions/mixed.cc @@ -585,7 +585,8 @@ void MF_RandomFloats::call(MFMask mask, MFParams params, MFContext UNUSED(contex RNG *rng = BLI_rng_new(0); for (uint i : mask.indices()) { - MutableArrayRef<float> r_array = r_values.allocate(i, amounts[i]); + uint amount = std::max<int>(0, amounts[i]); + MutableArrayRef<float> r_array = r_values.allocate(i, amount); BLI_rng_srandom(rng, seeds[i] + m_seed); float range = max_values[i] - min_values[i]; @@ -645,6 +646,63 @@ void MF_RandomVector::call(MFMask mask, MFParams params, MFContext UNUSED(contex BLI_rng_free(rng); } +MF_RandomVectors::MF_RandomVectors(uint seed, RandomVectorMode::Enum mode) + : m_seed(seed * 45621347), m_mode(mode) +{ + MFSignatureBuilder signature = this->get_builder("Random Vectors"); + signature.single_input<int>("Amount"); + signature.single_input<float3>("Factor"); + signature.single_input<int>("Seed"); + signature.vector_output<float3>("Vectors"); +} + +void MF_RandomVectors::call(MFMask mask, MFParams params, MFContext UNUSED(context)) const +{ + VirtualListRef<int> amounts = params.readonly_single_input<int>(0, "Amount"); + VirtualListRef<float3> factors = params.readonly_single_input<float3>(1, "Factor"); + VirtualListRef<int> seeds = params.readonly_single_input<int>(2, "Seed"); + GenericVectorArray::MutableTypedRef<float3> r_vectors_array = params.vector_output<float3>( + 3, "Vectors"); + + RNG *rng = BLI_rng_new(0); + + for (uint index : mask.indices()) { + uint amount = std::max<int>(0, amounts[index]); + float3 factor = factors[index]; + uint seed = seeds[index] ^ m_seed; + + MutableArrayRef<float3> r_vectors = r_vectors_array.allocate(index, amount); + + BLI_rng_srandom(rng, seed); + + switch (m_mode) { + case RandomVectorMode::SampleInCube: { + for (uint i : IndexRange(amount)) { + float x = BLI_rng_get_float(rng) - 0.5f; + float y = BLI_rng_get_float(rng) - 0.5f; + float z = BLI_rng_get_float(rng) - 0.5f; + r_vectors[i] = {x, y, z}; + } + break; + } + case RandomVectorMode::SampleOnSphere: { + for (uint i : IndexRange(amount)) { + float3 vector; + BLI_rng_get_float_unit_v3(rng, vector); + r_vectors[i] = vector; + } + break; + } + } + + for (float3 &vector : r_vectors) { + vector *= factor; + } + } + + BLI_rng_free(rng); +} + MF_FindNonClosePoints::MF_FindNonClosePoints() { MFSignatureBuilder signature = this->get_builder("Remove Close Points"); diff --git a/source/blender/functions/intern/multi_functions/mixed.h b/source/blender/functions/intern/multi_functions/mixed.h index 2c36de698b7..89b73faf634 100644 --- a/source/blender/functions/intern/multi_functions/mixed.h +++ b/source/blender/functions/intern/multi_functions/mixed.h @@ -66,7 +66,7 @@ class MF_RandomFloat final : public MultiFunction { public: MF_RandomFloat(uint seed); - void call(MFMask mask, MFParams parms, MFContext context) const override; + void call(MFMask mask, MFParams params, MFContext context) const override; }; class MF_RandomFloats final : public MultiFunction { @@ -75,7 +75,7 @@ class MF_RandomFloats final : public MultiFunction { public: MF_RandomFloats(uint seed); - void call(MFMask mask, MFParams parms, MFContext context) const override; + void call(MFMask mask, MFParams params, MFContext context) const override; }; namespace RandomVectorMode { @@ -92,7 +92,17 @@ class MF_RandomVector final : public MultiFunction { public: MF_RandomVector(uint seed, RandomVectorMode::Enum mode); - void call(MFMask mask, MFParams parms, MFContext context) const override; + void call(MFMask mask, MFParams params, MFContext context) const override; +}; + +class MF_RandomVectors final : public MultiFunction { + private: + uint m_seed; + RandomVectorMode::Enum m_mode; + + public: + MF_RandomVectors(uint seed, RandomVectorMode::Enum mode); + void call(MFMask mask, MFParams params, MFContext context) const override; }; class MF_ContextVertexPosition final : public MultiFunction { _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs