[Bf-blender-cvs] [0df9c555783] functions: pass time step in from the modifier

Jacques Lucke noreply at git.blender.org
Wed Jul 17 18:03:11 CEST 2019


Commit: 0df9c555783e138eaaba326cca2540e2c2e3b799
Author: Jacques Lucke
Date:   Wed Jul 17 17:11:05 2019 +0200
Branches: functions
https://developer.blender.org/rB0df9c555783e138eaaba326cca2540e2c2e3b799

pass time step in from the modifier

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

M	source/blender/modifiers/intern/MOD_bparticles.c
M	source/blender/simulations/BParticles.h
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/modifiers/intern/MOD_bparticles.c b/source/blender/modifiers/intern/MOD_bparticles.c
index aa5f29ff37e..e2110ccaa20 100644
--- a/source/blender/modifiers/intern/MOD_bparticles.c
+++ b/source/blender/modifiers/intern/MOD_bparticles.c
@@ -127,7 +127,7 @@ static Mesh *applyModifier(ModifierData *md,
   }
   else if (current_frame == runtime->last_simulated_frame + 1.0f) {
     BParticles_simulate_modifier(
-        bpmd, ctx->depsgraph, runtime->particles_state, runtime->world_state);
+        bpmd, ctx->depsgraph, runtime->particles_state, runtime->world_state, 1.0f / FPS);
     runtime->last_simulated_frame = current_frame;
   }
   else {
@@ -137,6 +137,10 @@ static Mesh *applyModifier(ModifierData *md,
     runtime->world_state = BParticles_new_world_state();
     runtime->last_simulated_frame = current_frame;
     BParticles_modifier_free_cache(bpmd_orig);
+
+    BParticles_simulate_modifier(
+        bpmd, ctx->depsgraph, runtime->particles_state, runtime->world_state, 0.0f);
+    runtime->last_simulated_frame = current_frame;
   }
 
   BParticles_modifier_cache_state(bpmd_orig, runtime->particles_state, current_frame);
diff --git a/source/blender/simulations/BParticles.h b/source/blender/simulations/BParticles.h
index a8e23716f92..498b83fdf3f 100644
--- a/source/blender/simulations/BParticles.h
+++ b/source/blender/simulations/BParticles.h
@@ -25,7 +25,8 @@ void BParticles_world_state_free(BParticlesWorldState world_state);
 void BParticles_simulate_modifier(struct BParticlesModifierData *bpmd,
                                   Depsgraph *depsgraph,
                                   BParticlesState particles_state,
-                                  BParticlesWorldState world_state);
+                                  BParticlesWorldState world_state,
+                                  float time_step);
 
 uint BParticles_state_particle_count(BParticlesState particles_state);
 void BParticles_state_get_positions(BParticlesState particles_state, float (*dst)[3]);
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 2080afbb288..02c89bd8ace 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -67,7 +67,8 @@ void BParticles_world_state_free(BParticlesWorldState world_state_c)
 void BParticles_simulate_modifier(BParticlesModifierData *bpmd,
                                   Depsgraph *UNUSED(depsgraph),
                                   BParticlesState particles_state_c,
-                                  BParticlesWorldState world_state_c)
+                                  BParticlesWorldState world_state_c,
+                                  float time_step)
 {
   SCOPED_TIMER(__func__);
 
@@ -80,7 +81,7 @@ void BParticles_simulate_modifier(BParticlesModifierData *bpmd,
   bNodeTree *btree = (bNodeTree *)DEG_get_original_id((ID *)bpmd->bparticles_tree);
   IndexedNodeTree indexed_tree(btree);
 
-  auto step_description = step_description_from_node_tree(indexed_tree, world_state, 1.0f / 24.0f);
+  auto step_description = step_description_from_node_tree(indexed_tree, world_state, time_step);
 
   ParticlesState &particles_state = *unwrap(particles_state_c);
   simulate_step(particles_state, *step_description);
diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index 1acfd99ae91..70aefdc2ebb 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -183,6 +183,7 @@ class ParticlesState {
  private:
   StringMap<ParticlesContainer *> m_container_by_id;
   float m_current_time = 0.0f;
+  uint m_current_step = 0;
 
  public:
   ParticlesState() = default;
@@ -192,7 +193,17 @@ class ParticlesState {
   /**
    * Access the time since the simulation started.
    */
-  float &current_time();
+  float current_time() const;
+
+  /**
+   * Move current time forward.
+   */
+  void increase_time(float time_step);
+
+  /**
+   * Get the current simulation step.
+   */
+  uint current_step() const;
 
   /**
    * Access the mapping from particle type names to their corresponding containers.
@@ -601,11 +612,23 @@ inline StringRefNull ParticlesState::particle_container_id(ParticlesContainer &c
   return *(StringRefNull *)nullptr;
 }
 
-inline float &ParticlesState::current_time()
+inline float ParticlesState::current_time() const
 {
   return m_current_time;
 }
 
+inline void ParticlesState::increase_time(float time_step)
+{
+  BLI_assert(time_step >= 0.0f);
+  m_current_time += time_step;
+  m_current_step++;
+}
+
+inline uint ParticlesState::current_step() const
+{
+  return m_current_step;
+}
+
 /* ParticleAllocator inline functions
  ********************************************/
 
@@ -657,7 +680,7 @@ inline TimeSpan EmitterInterface::time_span()
 
 inline bool EmitterInterface::is_first_step()
 {
-  return m_time_span.start() < 0.00001f;
+  return m_particle_allocator.particles_state().current_step() == 1;
 }
 
 /* ParticleSet inline functions
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 2932bec2162..771f97d3d47 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -660,8 +660,9 @@ BLI_NOINLINE static void emit_and_simulate_particles(ParticlesState &state,
 
 void simulate_step(ParticlesState &state, StepDescription &step_description)
 {
-  TimeSpan time_span(state.current_time(), step_description.step_duration());
-  state.current_time() = time_span.end();
+  float start_time = state.current_time();
+  state.increase_time(step_description.step_duration());
+  TimeSpan time_span(start_time, step_description.step_duration());
 
   ensure_required_containers_exist(state, step_description);
   ensure_required_attributes_exist(state, step_description);



More information about the Bf-blender-cvs mailing list