Browse Source

Fixed Curve Sampler when offset goes past the last key.

Vicente Penades 4 years ago
parent
commit
305c8ee437
1 changed files with 16 additions and 2 deletions
  1. 16 2
      src/SharpGLTF.Core/Animations/CurveSampler.cs

+ 16 - 2
src/SharpGLTF.Core/Animations/CurveSampler.cs

@@ -176,7 +176,14 @@ namespace SharpGLTF.Animations
                 prev = item;
             }
 
-            if (left == null && right == null) return (default(T), default(T), 0);
+            if (left == null && right == null)
+            {
+                // if both left and right are null is becase the sequence is empty,
+                // or the offset went past the last item.
+                if (prev.HasValue) return (prev.Value.Value, prev.Value.Value, 0);
+                return (default(T), default(T), 0);
+            }
+
             if (left == null) return (right.Value.Value, right.Value.Value, 0);
             if (right == null) return (left.Value.Value, left.Value.Value, 0);
 
@@ -230,7 +237,14 @@ namespace SharpGLTF.Animations
                 prev = item;
             }
 
-            if (left == null && right == null) return (0, 0, 0);
+            if (left == null && right == null)
+            {
+                // if both left and right are null is becase the sequence is empty,
+                // or the offset went past the last item.
+                if (prev.HasValue) return (prev.Value, prev.Value, 0);
+                return (0, 0, 0);
+            }
+
             if (left == null) return (right.Value, right.Value, 0);
             if (right == null) return (left.Value, left.Value, 0);