Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Prowl.Runtime/AssetImporting/ModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,27 @@ private static void LoadAnimations(Assimp.Scene? scene, double scale, List<Anima
// Create Animation
AnimationClip animation = new AnimationClip();
animation.Name = anim.Name;
animation.Duration = anim.DurationInTicks / (anim.TicksPerSecond != 0 ? anim.TicksPerSecond : 25.0);
animation.TicksPerSecond = anim.TicksPerSecond;

double ticksPerSecond = anim.TicksPerSecond != 0 ? anim.TicksPerSecond : 25.0;

// FIX: glTF 2.0 files have a known Assimp bug where TicksPerSecond is wrong
// glTF times are in seconds, Assimp converts to milliseconds (*1000)
// but TicksPerSecond should be 1000, not the reported value
// Detect this by checking if TicksPerSecond is suspiciously low (< 100)
// and duration seems too long (> 30 seconds for typical animations)
double rawDuration = anim.DurationInTicks / ticksPerSecond;
if (ticksPerSecond < 100 && rawDuration > 30.0)
{
// This is likely a glTF file with the bug - force TicksPerSecond to 1000
Debug.LogWarning($"Animation '{anim.Name}' appears to be glTF with incorrect TicksPerSecond. " +
$"Original TPS: {ticksPerSecond}, Duration: {rawDuration:F2}s. " +
$"Correcting to TPS=1000 for glTF...");
ticksPerSecond = 1000.0;
}

animation.TicksPerSecond = ticksPerSecond;
animation.DurationInTicks = anim.DurationInTicks;
animation.Duration = anim.DurationInTicks / ticksPerSecond;

foreach (var channel in anim.NodeAnimationChannels)
{
Expand Down
4 changes: 2 additions & 2 deletions Prowl.Runtime/Components/ModelRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ModelRenderer : MonoBehaviour
public AnimationClip CurrentAnimation;
public bool PlayAutomatically = true;
public bool Loop = true;
public double AnimationSpeed = 10.0;
public double AnimationSpeed = 1.0;

private double _animationTime = 0.0;
private bool _isPlaying = false;
Expand Down Expand Up @@ -56,7 +56,7 @@ public override void Update()
// Update animation
if (_isPlaying && CurrentAnimation != null)
{
_animationTime += Time.deltaTimeF * AnimationSpeed;
_animationTime += Time.deltaTime * AnimationSpeed;

if (_animationTime >= CurrentAnimation.Duration)
{
Expand Down
Loading