[Bf-blender-cvs] [0380b226065] functions: better handling of zero duration

Jacques Lucke noreply at git.blender.org
Fri Jul 5 17:38:42 CEST 2019


Commit: 0380b226065b3eaac8e6d01042c1c5f935d50b51
Author: Jacques Lucke
Date:   Fri Jul 5 13:42:52 2019 +0200
Branches: functions
https://developer.blender.org/rB0380b226065b3eaac8e6d01042c1c5f935d50b51

better handling of zero duration

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

M	source/blender/simulations/bparticles/core.hpp
M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/simulate.cpp
M	source/blender/simulations/bparticles/time_span.hpp

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

diff --git a/source/blender/simulations/bparticles/core.hpp b/source/blender/simulations/bparticles/core.hpp
index ed6f3f03b94..b2691b5dcac 100644
--- a/source/blender/simulations/bparticles/core.hpp
+++ b/source/blender/simulations/bparticles/core.hpp
@@ -846,6 +846,7 @@ inline float EventFilterInterface::end_time()
 
 inline void EventFilterInterface::trigger_particle(uint index, float time_factor)
 {
+  BLI_assert(0.0f <= time_factor && time_factor <= 1.0f);
   if (time_factor <= m_known_min_time_factors[index]) {
     m_filtered_indices.append(index);
     m_filtered_time_factors.append(time_factor);
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 0ed2c9a3dca..34b501cad3c 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -53,8 +53,16 @@ class AgeReachedEvent : public EventFilter {
 
       if (age_at_end >= trigger_age) {
         TimeSpan time_span = interface.time_span(i);
-        float time_factor = time_span.get_factor(birth_time + trigger_age);
-        interface.trigger_particle(i, time_factor);
+
+        float age_at_start = age_at_end - time_span.duration();
+        if (trigger_age < age_at_start) {
+          interface.trigger_particle(i, 0.0f);
+        }
+        else {
+          float time_factor = time_span.get_factor_safe(birth_time + trigger_age);
+          CLAMP(time_factor, 0.0f, 1.0f);
+          interface.trigger_particle(i, time_factor);
+        }
       }
     }
   }
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 38470dbf38d..dcbe8652800 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -182,10 +182,12 @@ BLI_NOINLINE static void find_unfinished_particles(
     uint pindex = particle_indices[i];
     if (kill_states[pindex] == 0) {
       float time_factor = time_factors_to_next_event[i];
-      float remaining_duration = durations[i] * (1.0f - time_factor);
 
-      r_unfinished_particle_indices.append(pindex);
-      r_remaining_durations.append(remaining_duration);
+      if (time_factor < 1.0f) {
+        float remaining_duration = durations[i] * (1.0f - time_factor);
+        r_unfinished_particle_indices.append(pindex);
+        r_remaining_durations.append(remaining_duration);
+      }
     }
   }
 }
diff --git a/source/blender/simulations/bparticles/time_span.hpp b/source/blender/simulations/bparticles/time_span.hpp
index 14d73ca6739..ea012407d54 100644
--- a/source/blender/simulations/bparticles/time_span.hpp
+++ b/source/blender/simulations/bparticles/time_span.hpp
@@ -56,6 +56,19 @@ struct TimeSpan {
     BLI_assert(m_duration > 0.0f);
     return (time - m_start) / m_duration;
   }
+
+  /**
+   * Same as get_factor, but returns zero when the duration is zero.
+   */
+  float get_factor_safe(float time) const
+  {
+    if (m_duration > 0) {
+      return this->get_factor(time);
+    }
+    else {
+      return 0.0f;
+    }
+  }
 };
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list