[Bf-blender-cvs] [83e75345a2e] functions: simple rate input for Trail node

Jacques Lucke noreply at git.blender.org
Thu Jul 18 18:19:43 CEST 2019


Commit: 83e75345a2ee131c915ac8b721390b12fe6992c4
Author: Jacques Lucke
Date:   Thu Jul 18 16:19:31 2019 +0200
Branches: functions
https://developer.blender.org/rB83e75345a2ee131c915ac8b721390b12fe6992c4

simple rate input for Trail node

===================================================================

M	release/scripts/startup/nodes/bparticle_nodes/trails.py
M	source/blender/simulations/bparticles/forces.cpp
M	source/blender/simulations/bparticles/forces.hpp
M	source/blender/simulations/bparticles/inserters.cpp

===================================================================

diff --git a/release/scripts/startup/nodes/bparticle_nodes/trails.py b/release/scripts/startup/nodes/bparticle_nodes/trails.py
index 125d9a046c0..c932fc498af 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/trails.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/trails.py
@@ -10,6 +10,7 @@ class ParticleTrailsNode(bpy.types.Node, BParticlesNode):
     particle_type_name: StringProperty()
 
     def declaration(self, builder : SocketBuilder):
+        builder.fixed_input("rate", "Rate", "Float", default=10)
         builder.particle_modifier_output("effect", "Effect")
 
     def draw(self, layout):
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index 8c6bfe1b963..e9e83744be4 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -46,14 +46,27 @@ void TurbulenceForce::add_force(ParticlesBlock &block, ArrayRef<float3> r_force)
 
 void CreateTrailHandler::execute(OffsetHandlerInterface &interface)
 {
+  if (m_rate <= 0.0f) {
+    return;
+  }
+
   ParticleSet particles = interface.particles();
   auto positions = particles.attributes().get_float3("Position");
+  auto position_offsets = interface.offsets().get_float3("Position");
+
+  float frequency = 1.0f / m_rate;
 
   SmallVector<float3> new_positions;
   SmallVector<float> new_birth_times;
   for (uint pindex : particles.pindices()) {
-    new_positions.append(positions[pindex]);
-    new_birth_times.append(interface.time_span(pindex).start());
+    TimeSpan time_span = interface.time_span(pindex);
+    float current_time = frequency * (std::floor(time_span.start() / frequency) + 1.0f);
+    while (current_time < time_span.end()) {
+      float factor = time_span.get_factor_safe(current_time);
+      new_positions.append(positions[pindex] + position_offsets[pindex] * factor);
+      new_birth_times.append(current_time);
+      current_time += frequency;
+    }
   }
 
   auto new_particles = interface.particle_allocator().request(m_particle_type_name,
diff --git a/source/blender/simulations/bparticles/forces.hpp b/source/blender/simulations/bparticles/forces.hpp
index 365c27ff07a..119a7fb7fcb 100644
--- a/source/blender/simulations/bparticles/forces.hpp
+++ b/source/blender/simulations/bparticles/forces.hpp
@@ -43,10 +43,11 @@ class TurbulenceForce : public Force {
 class CreateTrailHandler : public OffsetHandler {
  private:
   std::string m_particle_type_name;
+  float m_rate;
 
  public:
-  CreateTrailHandler(StringRef particle_type_name)
-      : m_particle_type_name(particle_type_name.to_std_string())
+  CreateTrailHandler(StringRef particle_type_name, float rate)
+      : m_particle_type_name(particle_type_name.to_std_string()), m_rate(rate)
   {
   }
 
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 5e88422794e..2c6f8645d03 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -403,8 +403,15 @@ static std::unique_ptr<OffsetHandler> BUILD_OFFSET_HANDLER_trails(BuildContext &
   char name[65];
   RNA_string_get(&rna, "particle_type_name", name);
 
+  SharedFunction fn = create_function_for_data_inputs(bnode, ctx.indexed_tree, ctx.data_graph);
+  TupleCallBody *body = fn->body<TupleCallBody>();
+  FN_TUPLE_CALL_ALLOC_TUPLES(body, fn_in, fn_out);
+  body->call__setup_execution_context(fn_in, fn_out);
+  float rate = body->get_output<float>(fn_out, 0, "Rate");
+  rate = std::max(rate, 0.0f);
+
   if (ctx.step_builder.has_type(name)) {
-    return std::unique_ptr<OffsetHandler>(new CreateTrailHandler(name));
+    return std::unique_ptr<OffsetHandler>(new CreateTrailHandler(name, rate));
   }
   else {
     return {};



More information about the Bf-blender-cvs mailing list