[Bf-blender-cvs] [9ff48285012] functions: cleanup mesh emitter

Jacques Lucke noreply at git.blender.org
Mon Sep 2 12:32:03 CEST 2019


Commit: 9ff482850121b1e01999cd42f27988c75eadca7b
Author: Jacques Lucke
Date:   Mon Sep 2 11:20:22 2019 +0200
Branches: functions
https://developer.blender.org/rB9ff482850121b1e01999cd42f27988c75eadca7b

cleanup mesh emitter

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

M	source/blender/simulations/bparticles/emitters.cpp
M	source/blender/simulations/bparticles/time_span.hpp
M	source/blender/simulations/bparticles/world_state.hpp

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

diff --git a/source/blender/simulations/bparticles/emitters.cpp b/source/blender/simulations/bparticles/emitters.cpp
index 9975cd69027..88274c7d0ed 100644
--- a/source/blender/simulations/bparticles/emitters.cpp
+++ b/source/blender/simulations/bparticles/emitters.cpp
@@ -247,16 +247,6 @@ static BLI_NOINLINE void sample_looptris(Mesh *mesh,
   }
 }
 
-static BLI_NOINLINE void sample_varying_transform(const VaryingFloat4x4 &transform,
-                                                  ArrayRef<float> times,
-                                                  float time_offset,
-                                                  MutableArrayRef<float4x4> r_transforms)
-{
-  for (uint i = 0; i < times.size(); i++) {
-    r_transforms[i] = transform.interpolate(times[i] + time_offset);
-  }
-}
-
 void SurfaceEmitter::emit(EmitterInterface &interface)
 {
   if (m_object == nullptr) {
@@ -302,16 +292,19 @@ void SurfaceEmitter::emit(EmitterInterface &interface)
   float epsilon = 0.01f;
   TemporaryArray<float4x4> transforms_at_birth(particles_to_emit);
   TemporaryArray<float4x4> transforms_before_birth(particles_to_emit);
-  sample_varying_transform(m_transform, birth_moments, 0.0f, transforms_at_birth);
-  sample_varying_transform(m_transform, birth_moments, -epsilon, transforms_before_birth);
+  m_transform.interpolate(birth_moments, 0.0f, transforms_at_birth);
+  m_transform.interpolate(birth_moments, -epsilon, transforms_before_birth);
+
+  TemporaryArray<float> sizes(particles_to_emit);
+  sizes.fill(m_size);
+
+  TemporaryArray<float> birth_times(particles_to_emit);
+  interface.time_span().interpolate(birth_moments, birth_times);
 
   Vector<float3> positions;
   Vector<float3> velocities;
-  Vector<float> sizes;
-  Vector<float> birth_times;
 
   for (uint i = 0; i < particles_to_emit; i++) {
-    float birth_moment = birth_moments[i];
     float3 pos = local_positions[i];
     float3 normal = local_normals[i];
 
@@ -326,8 +319,6 @@ void SurfaceEmitter::emit(EmitterInterface &interface)
 
     positions.append(point_at_birth);
     velocities.append(normal_velocity * m_normal_velocity + emitter_velocity * m_emitter_velocity);
-    birth_times.append(interface.time_span().interpolate(birth_moment));
-    sizes.append(m_size);
   }
 
   for (StringRef type_name : m_types_to_emit) {
diff --git a/source/blender/simulations/bparticles/time_span.hpp b/source/blender/simulations/bparticles/time_span.hpp
index ea012407d54..fcd0a157654 100644
--- a/source/blender/simulations/bparticles/time_span.hpp
+++ b/source/blender/simulations/bparticles/time_span.hpp
@@ -47,6 +47,14 @@ struct TimeSpan {
     return m_start + t * m_duration;
   }
 
+  void interpolate(ArrayRef<float> times, MutableArrayRef<float> r_results)
+  {
+    BLI_assert(times.size() == r_results.size());
+    for (uint i = 0; i < times.size(); i++) {
+      r_results[i] = this->interpolate(times[i]);
+    }
+  }
+
   /**
    * The reverse of interpolate.
    * Asserts when the duration is 0.
diff --git a/source/blender/simulations/bparticles/world_state.hpp b/source/blender/simulations/bparticles/world_state.hpp
index f0226070a32..d5e55f01e41 100644
--- a/source/blender/simulations/bparticles/world_state.hpp
+++ b/source/blender/simulations/bparticles/world_state.hpp
@@ -7,9 +7,11 @@
 
 namespace BParticles {
 
+using BLI::ArrayRef;
 using BLI::float3;
 using BLI::float4x4;
 using BLI::Map;
+using BLI::MutableArrayRef;
 using BLI::StringMap;
 using BLI::StringRef;
 
@@ -39,6 +41,16 @@ struct VaryingFloat4x4 {
   {
     return float4x4::interpolate(start, end, t);
   }
+
+  void interpolate(ArrayRef<float> times,
+                   float time_offset,
+                   MutableArrayRef<float4x4> r_results) const
+  {
+    BLI_assert(times.size() == r_results.size());
+    for (uint i = 0; i < times.size(); i++) {
+      r_results[i] = this->interpolate(times[i] + time_offset);
+    }
+  }
 };
 
 class WorldTransition;



More information about the Bf-blender-cvs mailing list