[Bf-blender-cvs] [57ceacf8b4e] functions: move falloff implementations out of header

Jacques Lucke noreply at git.blender.org
Fri Sep 6 16:56:05 CEST 2019


Commit: 57ceacf8b4e8de33a2071a08438587df58382c1c
Author: Jacques Lucke
Date:   Fri Sep 6 15:42:54 2019 +0200
Branches: functions
https://developer.blender.org/rB57ceacf8b4e8de33a2071a08438587df58382c1c

move falloff implementations out of header

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

M	source/blender/blenkernel/BKE_falloff.hpp
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/falloff.cpp

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

diff --git a/source/blender/blenkernel/BKE_falloff.hpp b/source/blender/blenkernel/BKE_falloff.hpp
index f3ba0d1d572..82c4025ef0d 100644
--- a/source/blender/blenkernel/BKE_falloff.hpp
+++ b/source/blender/blenkernel/BKE_falloff.hpp
@@ -10,9 +10,11 @@ class Falloff {
   MEM_CXX_CLASS_ALLOC_FUNCS("BKE:Falloff")
 #endif
 
-  virtual ~Falloff()
-  {
-  }
+  virtual ~Falloff();
+
+  /**
+   * Create an identical copy of this falloff.
+   */
   virtual Falloff *clone() const = 0;
 
   /**
@@ -20,7 +22,7 @@ class Falloff {
    */
   virtual void compute(AttributesRef attributes,
                        ArrayRef<uint> indices,
-                       MutableArrayRef<float> r_weights) = 0;
+                       MutableArrayRef<float> r_weights) const = 0;
 };
 
 class ConstantFalloff : public Falloff {
@@ -39,12 +41,7 @@ class ConstantFalloff : public Falloff {
 
   void compute(AttributesRef UNUSED(attributes),
                ArrayRef<uint> indices,
-               MutableArrayRef<float> r_weights)
-  {
-    for (uint index : indices) {
-      r_weights[index] = m_weight;
-    }
-  }
+               MutableArrayRef<float> r_weights) const override;
 };
 
 class PointDistanceFalloff : public Falloff {
@@ -59,28 +56,14 @@ class PointDistanceFalloff : public Falloff {
   {
   }
 
-  Falloff *clone() const
+  Falloff *clone() const override
   {
     return new PointDistanceFalloff(m_point, m_min_distance, m_max_distance);
   }
 
-  void compute(AttributesRef attributes, ArrayRef<uint> indices, MutableArrayRef<float> r_weights)
-  {
-    auto positions = attributes.get<float3>("Position");
-    float distance_diff = m_max_distance - m_min_distance;
-
-    for (uint index : indices) {
-      float3 position = positions[index];
-      float distance = float3::distance(position, m_point);
-
-      float weight = 0;
-      if (distance_diff > 0) {
-        weight = 1.0f - (distance - m_min_distance) / distance_diff;
-        CLAMP(weight, 0.0f, 1.0f);
-      }
-      r_weights[index] = weight;
-    }
-  }
+  void compute(AttributesRef attributes,
+               ArrayRef<uint> indices,
+               MutableArrayRef<float> r_weights) const override;
 };
 
 }  // namespace BKE
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index d268f06cf63..d40cf457608 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -110,6 +110,7 @@ set(SRC
   intern/editmesh_cache.c
   intern/editmesh_tangent.c
   intern/effect.c
+  intern/falloff.cpp
   intern/fcurve.c
   intern/fluidsim.c
   intern/fmodifier.c
diff --git a/source/blender/blenkernel/intern/falloff.cpp b/source/blender/blenkernel/intern/falloff.cpp
new file mode 100644
index 00000000000..a5eba4a473c
--- /dev/null
+++ b/source/blender/blenkernel/intern/falloff.cpp
@@ -0,0 +1,38 @@
+#include "BKE_falloff.hpp"
+
+namespace BKE {
+
+Falloff::~Falloff()
+{
+}
+
+void ConstantFalloff::compute(AttributesRef UNUSED(attributes),
+                              ArrayRef<uint> indices,
+                              MutableArrayRef<float> r_weights) const
+{
+  for (uint index : indices) {
+    r_weights[index] = m_weight;
+  }
+}
+
+void PointDistanceFalloff::compute(AttributesRef attributes,
+                                   ArrayRef<uint> indices,
+                                   MutableArrayRef<float> r_weights) const
+{
+  auto positions = attributes.get<float3>("Position");
+  float distance_diff = m_max_distance - m_min_distance;
+
+  for (uint index : indices) {
+    float3 position = positions[index];
+    float distance = float3::distance(position, m_point);
+
+    float weight = 0;
+    if (distance_diff > 0) {
+      weight = 1.0f - (distance - m_min_distance) / distance_diff;
+      CLAMP(weight, 0.0f, 1.0f);
+    }
+    r_weights[index] = weight;
+  }
+}
+
+}  // namespace BKE



More information about the Bf-blender-cvs mailing list