add loop option to playAnimation
This commit is contained in:
@@ -594,7 +594,7 @@ namespace polyvox
|
|||||||
{
|
{
|
||||||
if (!_view || !_mainCamera || !_swapChain)
|
if (!_view || !_mainCamera || !_swapChain)
|
||||||
{
|
{
|
||||||
Log("Not ready for rendering");
|
// Log("Not ready for rendering");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -668,8 +668,12 @@ namespace polyvox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::playAnimation(int index) {
|
void FilamentViewer::playAnimation(int index, bool loop) {
|
||||||
embeddedAnimationBuffer = make_unique<EmbeddedAnimationBuffer>(index, _animator->getAnimationDuration(index));
|
if(index > _animator->getAnimationCount() - 1) {
|
||||||
|
Log("Asset does not contain an animation at index %d", index);
|
||||||
|
} else {
|
||||||
|
embeddedAnimationBuffer = make_unique<EmbeddedAnimationBuffer>(index, _animator->getAnimationDuration(index), loop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilamentViewer::updateEmbeddedAnimation() {
|
void FilamentViewer::updateEmbeddedAnimation() {
|
||||||
@@ -679,8 +683,12 @@ namespace polyvox
|
|||||||
embeddedAnimationBuffer->hasStarted = true;
|
embeddedAnimationBuffer->hasStarted = true;
|
||||||
embeddedAnimationBuffer->lastTime = std::chrono::high_resolution_clock::now();
|
embeddedAnimationBuffer->lastTime = std::chrono::high_resolution_clock::now();
|
||||||
} else if(dur.count() >= embeddedAnimationBuffer->duration) {
|
} else if(dur.count() >= embeddedAnimationBuffer->duration) {
|
||||||
embeddedAnimationBuffer = nullptr;
|
if(embeddedAnimationBuffer->loop) {
|
||||||
return;
|
embeddedAnimationBuffer->lastTime = std::chrono::high_resolution_clock::now();
|
||||||
|
} else {
|
||||||
|
embeddedAnimationBuffer = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
startTime = dur.count();
|
startTime = dur.count();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,12 @@ namespace polyvox {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct EmbeddedAnimationBuffer {
|
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;
|
bool hasStarted = false;
|
||||||
int animationIndex;
|
int animationIndex;
|
||||||
float duration = 0;
|
float duration = 0;
|
||||||
time_point_t lastTime;
|
time_point_t lastTime;
|
||||||
|
bool loop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -117,7 +118,7 @@ namespace polyvox {
|
|||||||
void applyWeights(float* weights, int count);
|
void applyWeights(float* weights, int count);
|
||||||
void animateWeights(float* data, int numWeights, int length, float frameRate);
|
void animateWeights(float* data, int numWeights, int length, float frameRate);
|
||||||
// void animateBones();
|
// void animateBones();
|
||||||
void playAnimation(int index);
|
void playAnimation(int index, bool loop);
|
||||||
bool setCamera(const char* nodeName);
|
bool setCamera(const char* nodeName);
|
||||||
void destroySwapChain();
|
void destroySwapChain();
|
||||||
void createSwapChain(void* surface);
|
void createSwapChain(void* surface);
|
||||||
|
|||||||
Reference in New Issue
Block a user