From b00fe3af1e6697040f4750c559e285f3d3e76ef3 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 29 Mar 2022 15:49:03 +0800 Subject: [PATCH] add loop option to playAnimation --- ios/src/FilamentViewer.cpp | 18 +++++++++++++----- ios/src/FilamentViewer.hpp | 5 +++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ios/src/FilamentViewer.cpp b/ios/src/FilamentViewer.cpp index c56892bc..59206927 100644 --- a/ios/src/FilamentViewer.cpp +++ b/ios/src/FilamentViewer.cpp @@ -594,7 +594,7 @@ namespace polyvox { if (!_view || !_mainCamera || !_swapChain) { - Log("Not ready for rendering"); + // Log("Not ready for rendering"); return; } @@ -668,8 +668,12 @@ namespace polyvox } } - void FilamentViewer::playAnimation(int index) { - embeddedAnimationBuffer = make_unique(index, _animator->getAnimationDuration(index)); + void FilamentViewer::playAnimation(int index, bool loop) { + if(index > _animator->getAnimationCount() - 1) { + Log("Asset does not contain an animation at index %d", index); + } else { + embeddedAnimationBuffer = make_unique(index, _animator->getAnimationDuration(index), loop); + } } void FilamentViewer::updateEmbeddedAnimation() { @@ -679,8 +683,12 @@ namespace polyvox embeddedAnimationBuffer->hasStarted = true; embeddedAnimationBuffer->lastTime = std::chrono::high_resolution_clock::now(); } else if(dur.count() >= embeddedAnimationBuffer->duration) { - embeddedAnimationBuffer = nullptr; - return; + if(embeddedAnimationBuffer->loop) { + embeddedAnimationBuffer->lastTime = std::chrono::high_resolution_clock::now(); + } else { + embeddedAnimationBuffer = nullptr; + return; + } } else { startTime = dur.count(); } diff --git a/ios/src/FilamentViewer.hpp b/ios/src/FilamentViewer.hpp index 5ba3a189..e338c3c2 100644 --- a/ios/src/FilamentViewer.hpp +++ b/ios/src/FilamentViewer.hpp @@ -55,11 +55,12 @@ namespace polyvox { }; struct EmbeddedAnimationBuffer { - EmbeddedAnimationBuffer(int animationIndex, float duration) : animationIndex(animationIndex), duration(duration) {} + EmbeddedAnimationBuffer(int animationIndex, float duration, bool loop) : animationIndex(animationIndex), duration(duration), loop(loop) {} bool hasStarted = false; int animationIndex; float duration = 0; time_point_t lastTime; + bool loop; }; @@ -117,7 +118,7 @@ namespace polyvox { void applyWeights(float* weights, int count); void animateWeights(float* data, int numWeights, int length, float frameRate); // void animateBones(); - void playAnimation(int index); + void playAnimation(int index, bool loop); bool setCamera(const char* nodeName); void destroySwapChain(); void createSwapChain(void* surface);