[Bf-blender-cvs] [ce2081e5b31] functions: support for interpolated float values

Jacques Lucke noreply at git.blender.org
Tue Jul 16 18:20:40 CEST 2019


Commit: ce2081e5b31e8233cf33d62b6d2af0ace9ad1df6
Author: Jacques Lucke
Date:   Tue Jul 16 18:18:09 2019 +0200
Branches: functions
https://developer.blender.org/rBce2081e5b31e8233cf33d62b6d2af0ace9ad1df6

support for interpolated float values

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

M	source/blender/simulations/bparticles/world_state.hpp

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

diff --git a/source/blender/simulations/bparticles/world_state.hpp b/source/blender/simulations/bparticles/world_state.hpp
index 2a0625ae0e9..b3b5b04f19a 100644
--- a/source/blender/simulations/bparticles/world_state.hpp
+++ b/source/blender/simulations/bparticles/world_state.hpp
@@ -13,6 +13,15 @@ using BLI::SmallMap;
 using BLI::StringMap;
 using BLI::StringRef;
 
+struct InterpolatedFloat {
+  float start, end;
+
+  float interpolate(float t)
+  {
+    return start * (1.0f - t) + end * t;
+  }
+};
+
 struct InterpolatedFloat3 {
   float3 start, end;
 
@@ -38,10 +47,24 @@ class WorldState {
     T old_value, new_value;
   };
 
+  StringMap<OldAndNew<float>> m_float;
   StringMap<OldAndNew<float3>> m_float3;
   StringMap<OldAndNew<float4x4>> m_float4x4;
 
  public:
+  float get_last_and_store_current(StringRef id, float current)
+  {
+    auto *item = m_float.lookup_ptr(id);
+    if (item != nullptr) {
+      item->new_value = current;
+      return item->old_value;
+    }
+    else {
+      m_float.add_new(id, {current, current});
+      return current;
+    }
+  }
+
   float3 get_last_and_store_current(StringRef id, float3 current)
   {
     auto *item = m_float3.lookup_ptr(id);
@@ -68,6 +91,12 @@ class WorldState {
     }
   }
 
+  InterpolatedFloat get_interpolated_value(StringRef id, float current)
+  {
+    float last = this->get_last_and_store_current(id, current);
+    return {last, current};
+  }
+
   InterpolatedFloat3 get_interpolated_value(StringRef id, float3 current)
   {
     float3 last = this->get_last_and_store_current(id, current);
@@ -82,6 +111,9 @@ class WorldState {
 
   void current_step_is_over()
   {
+    for (auto &item : m_float.values()) {
+      item.old_value = item.new_value;
+    }
     for (auto &item : m_float3.values()) {
       item.old_value = item.new_value;
     }



More information about the Bf-blender-cvs mailing list