fix up morph target animations and add stopAnimation function
This commit is contained in:
@@ -539,9 +539,11 @@ namespace polyvox
|
||||
Log("Set viewport to width: %d height: %d scaleFactor : %f", width, height, contentScaleFactor);
|
||||
}
|
||||
|
||||
void FilamentViewer::animateWeights(float *data, int numWeights, int numFrames, float frameRate)
|
||||
void FilamentViewer::animateWeights(float *data, int numWeights, int numFrames, float frameLengthInMs)
|
||||
{
|
||||
morphAnimationBuffer = std::make_unique<MorphAnimationBuffer>(data, numWeights, numFrames, 1000 / frameRate);
|
||||
// assert numWeights == asset.numWeights ?
|
||||
Log("Making morph animation buffer with %d weights across %d frames and frame length %f ms ", numWeights, numFrames, frameLengthInMs);
|
||||
morphAnimationBuffer = std::make_unique<MorphAnimationBuffer>(data, numWeights, numFrames, frameLengthInMs);
|
||||
}
|
||||
|
||||
void FilamentViewer::updateMorphAnimation()
|
||||
@@ -549,20 +551,19 @@ namespace polyvox
|
||||
|
||||
if (morphAnimationBuffer->frameIndex >= morphAnimationBuffer->numFrames)
|
||||
{
|
||||
duration<double, std::milli> dur = high_resolution_clock::now() - morphAnimationBuffer->startTime;
|
||||
Log("Morph animation completed in %f ms (%d frames at framerate %f), final frame was %d", dur.count(), morphAnimationBuffer->numFrames, 1000 / morphAnimationBuffer->frameLengthInMs, morphAnimationBuffer->frameIndex);
|
||||
morphAnimationBuffer = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (morphAnimationBuffer->frameIndex == -1)
|
||||
} else if (morphAnimationBuffer->frameIndex == -1)
|
||||
{
|
||||
morphAnimationBuffer->frameIndex++;
|
||||
morphAnimationBuffer->startTime = std::chrono::high_resolution_clock::now();
|
||||
morphAnimationBuffer->startTime = high_resolution_clock::now();
|
||||
applyWeights(morphAnimationBuffer->frameData, morphAnimationBuffer->numWeights);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::chrono::duration<double, std::milli> dur = std::chrono::high_resolution_clock::now() - morphAnimationBuffer->startTime;
|
||||
int frameIndex = dur.count() / morphAnimationBuffer->frameLength;
|
||||
duration<double, std::milli> dur = high_resolution_clock::now() - morphAnimationBuffer->startTime;
|
||||
int frameIndex = static_cast<int>(dur.count() / morphAnimationBuffer->frameLengthInMs);
|
||||
if (frameIndex != morphAnimationBuffer->frameIndex)
|
||||
{
|
||||
morphAnimationBuffer->frameIndex = frameIndex;
|
||||
@@ -579,15 +580,20 @@ namespace polyvox
|
||||
}
|
||||
}
|
||||
|
||||
void FilamentViewer::stopAnimation() {
|
||||
// TODO - does this need to be threadsafe?
|
||||
embeddedAnimationBuffer = nullptr;
|
||||
}
|
||||
|
||||
void FilamentViewer::updateEmbeddedAnimation() {
|
||||
duration<double> dur = duration_cast<duration<double>>(std::chrono::high_resolution_clock::now() - embeddedAnimationBuffer->lastTime);
|
||||
duration<double> dur = duration_cast<duration<double>>(high_resolution_clock::now() - embeddedAnimationBuffer->lastTime);
|
||||
float startTime = 0;
|
||||
if(!embeddedAnimationBuffer->hasStarted) {
|
||||
embeddedAnimationBuffer->hasStarted = true;
|
||||
embeddedAnimationBuffer->lastTime = std::chrono::high_resolution_clock::now();
|
||||
embeddedAnimationBuffer->lastTime = high_resolution_clock::now();
|
||||
} else if(dur.count() >= embeddedAnimationBuffer->duration) {
|
||||
if(embeddedAnimationBuffer->loop) {
|
||||
embeddedAnimationBuffer->lastTime = std::chrono::high_resolution_clock::now();
|
||||
embeddedAnimationBuffer->lastTime = high_resolution_clock::now();
|
||||
} else {
|
||||
embeddedAnimationBuffer = nullptr;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user