re-add morph animation
This commit is contained in:
@@ -517,6 +517,10 @@ void FilamentViewer::render() {
|
||||
return;
|
||||
}
|
||||
|
||||
if(morphAnimationBuffer) {
|
||||
updateMorphAnimation();
|
||||
}
|
||||
|
||||
math::float3 eye, target, upward;
|
||||
manipulator->getLookAt(&eye, &target, &upward);
|
||||
_mainCamera->lookAt(eye, target, upward);
|
||||
@@ -544,52 +548,37 @@ void FilamentViewer::updateViewportAndCameraProjection(int width, int height, fl
|
||||
Log("Set viewport to %d %d", _width, _height);
|
||||
}
|
||||
|
||||
void FilamentViewer::animateWeights(float* data, int numWeights, int numFrames, float frameRate) {
|
||||
morphAnimationBuffer = std::make_unique<MorphAnimationBuffer>(data, numWeights, numFrames, 1000 / frameRate );
|
||||
}
|
||||
|
||||
void FilamentViewer::updateMorphAnimation() {
|
||||
|
||||
if(morphAnimationBuffer->frameIndex >= morphAnimationBuffer->numFrames) {
|
||||
morphAnimationBuffer = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if(morphAnimationBuffer->frameIndex == -1) {
|
||||
morphAnimationBuffer->frameIndex++;
|
||||
morphAnimationBuffer->startTime = std::chrono::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;
|
||||
if(frameIndex != morphAnimationBuffer->frameIndex) {
|
||||
morphAnimationBuffer->frameIndex = frameIndex;
|
||||
applyWeights(morphAnimationBuffer->frameData + (morphAnimationBuffer->frameIndex * morphAnimationBuffer->numWeights), morphAnimationBuffer->numWeights);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//void FilamentViewer::updateAnimation(AnimationBuffer animation, std::function<void(int)> moo) {
|
||||
// if(morphAnimationBuffer.frameIndex >= animation.numFrames) {
|
||||
// this.animation = null;
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if(animation.frameIndex == -1) {
|
||||
// animation->frameIndex++;
|
||||
// animation->lastTime = std::chrono::high_resolution_clock::now();
|
||||
// callback(); // applyWeights(morphAnimationBuffer->frameData, morphAnimationBuffer->numWeights);
|
||||
// } else {
|
||||
// duration dur = std::chrono::high_resolution_clock::now() - morphAnimationBuffer->lastTime;
|
||||
// float msElapsed = dur.count();
|
||||
// if(msElapsed > animation->frameLength) {
|
||||
// animation->frameIndex++;
|
||||
// animation->lastTime = std::chrono::high_resolution_clock::now();
|
||||
// callback(); // applyWeights(frameData + (frameIndex * numWeights), numWeights);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// void FilamentViewer::updateMorphAnimation() {
|
||||
|
||||
// if(morphAnimationBuffer->frameIndex >= morphAnimationBuffer->numFrames) {
|
||||
// morphAnimationBuffer = nullptr;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if(morphAnimationBuffer->frameIndex == -1) {
|
||||
// morphAnimationBuffer->frameIndex++;
|
||||
// morphAnimationBuffer->startTime = std::chrono::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;
|
||||
// if(frameIndex != morphAnimationBuffer->frameIndex) {
|
||||
// morphAnimationBuffer->frameIndex = frameIndex;
|
||||
// applyWeights(morphAnimationBuffer->frameData + (morphAnimationBuffer->frameIndex * morphAnimationBuffer->numWeights), morphAnimationBuffer->numWeights);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
// void FilamentViewer::updateEmbeddedAnimation() {
|
||||
// duration<double> dur = duration_cast<duration<double>>(std::chrono::high_resolution_clock::now() - embeddedAnimationBuffer->lastTime);
|
||||
@@ -632,26 +621,6 @@ void FilamentViewer::updateViewportAndCameraProjection(int width, int height, fl
|
||||
// embeddedAnimationBuffer = make_unique<EmbeddedAnimationBuffer>(index, _animator->getAnimationDuration(index));
|
||||
// }
|
||||
|
||||
// void FilamentViewer::animateWeights(float* data, int numWeights, int length, float frameRate) {
|
||||
// morphAnimationBuffer = std::make_unique<MorphAnimationBuffer>(data, numWeights, length / numWeights, 1000 / frameRate );
|
||||
// }
|
||||
|
||||
// if(shaderPath) {
|
||||
// opaqueShaderResources = _loadResource(opaqueShaderPath);
|
||||
// fadeShaderResources = _loadResource(fadeShaderPath);
|
||||
// _materialProvider = createGPUMorphShaderLoader(
|
||||
// opaqueShaderResources.data,
|
||||
// opaqueShaderResources.size,
|
||||
// fadeShaderResources.data,
|
||||
// fadeShaderResources.size,
|
||||
// _engine);
|
||||
// } else {
|
||||
// }
|
||||
// void printWeights(float* weights, int numWeights) {
|
||||
// for(int i =0; i < numWeights; i++) {
|
||||
// // std::cout << weights[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
// void FilamentViewer::createMorpher(const char* meshName, int* primitives, int numPrimitives) {
|
||||
// // morphHelper = new gltfio::GPUMorphHelper((FFilamentAsset*)_asset, meshName, primitives, numPrimitives);
|
||||
@@ -680,4 +649,25 @@ void FilamentViewer::updateViewportAndCameraProjection(int width, int height, fl
|
||||
// // xform = composeMatrix(translation + float3 { weights[0], weights[1], weights[2] }, rotation, scale );
|
||||
// transformManager.setTransform(node, xform);
|
||||
|
||||
// }
|
||||
|
||||
// void FilamentViewer::updateAnimation(AnimationBuffer animation, std::function<void(int)> callback) {
|
||||
// if(morphAnimationBuffer.frameIndex >= animation.numFrames) {
|
||||
// this.animation = null;
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if(animation.frameIndex == -1) {
|
||||
// animation->frameIndex++;
|
||||
// animation->lastTime = std::chrono::high_resolution_clock::now();
|
||||
// callback(); // applyWeights(morphAnimationBuffer->frameData, morphAnimationBuffer->numWeights);
|
||||
// } else {
|
||||
// duration dur = std::chrono::high_resolution_clock::now() - morphAnimationBuffer->lastTime;
|
||||
// float msElapsed = dur.count();
|
||||
// if(msElapsed > animation->frameLength) {
|
||||
// animation->frameIndex++;
|
||||
// animation->lastTime = std::chrono::high_resolution_clock::now();
|
||||
// callback(); // applyWeights(frameData + (frameIndex * numWeights), numWeights);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -72,6 +72,23 @@ namespace polyvox {
|
||||
using LoadResource = std::function<ResourceBuffer(const char* uri)>;
|
||||
using FreeResource = std::function<void (ResourceBuffer)>;
|
||||
|
||||
struct MorphAnimationBuffer {
|
||||
|
||||
MorphAnimationBuffer(float* frameData,
|
||||
int numWeights,
|
||||
int numFrames,
|
||||
float frameLength) : frameData(frameData), numWeights(numWeights), numFrames(numFrames), frameLength(frameLength) {
|
||||
}
|
||||
|
||||
int frameIndex = -1;
|
||||
int numFrames;
|
||||
float frameLength;
|
||||
time_point_t startTime;
|
||||
|
||||
float* frameData;
|
||||
int numWeights;
|
||||
};
|
||||
|
||||
class FilamentViewer {
|
||||
public:
|
||||
FilamentViewer(void* layer, const char* opaqueShaderPath, const char* fadeShaderPath, LoadResource loadResource, FreeResource freeResource);
|
||||
@@ -87,7 +104,7 @@ namespace polyvox {
|
||||
StringList getTargetNames(const char* meshName);
|
||||
Manipulator<float>* manipulator;
|
||||
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 playAnimation(int index);
|
||||
bool setCamera(const char* nodeName);
|
||||
@@ -140,18 +157,20 @@ namespace polyvox {
|
||||
|
||||
float _cameraFocalLength = 0.0f;
|
||||
|
||||
void updateMorphAnimation();
|
||||
// void updateEmbeddedAnimation();
|
||||
|
||||
// animation flags;
|
||||
bool isAnimating;
|
||||
unique_ptr<MorphAnimationBuffer> morphAnimationBuffer;
|
||||
// unique_ptr<EmbeddedAnimationBuffer> embeddedAnimationBuffer;
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// void updateMorphAnimation();
|
||||
// void updateEmbeddedAnimation();
|
||||
|
||||
// animation flags;
|
||||
// bool isAnimating;
|
||||
// unique_ptr<MorphAnimationBuffer> morphAnimationBuffer;
|
||||
// unique_ptr<EmbeddedAnimationBuffer> embeddedAnimationBuffer;
|
||||
|
||||
// struct EmbeddedAnimationBuffer {
|
||||
|
||||
@@ -162,19 +181,4 @@ namespace polyvox {
|
||||
// time_point_t lastTime;
|
||||
// };
|
||||
|
||||
// struct MorphAnimationBuffer {
|
||||
|
||||
// MorphAnimationBuffer(float* frameData,
|
||||
// int numWeights,
|
||||
// int numFrames,
|
||||
// float frameLength) : frameData(frameData), numWeights(numWeights), numFrames(numFrames), frameLength(frameLength) {
|
||||
// }
|
||||
|
||||
// int frameIndex = -1;
|
||||
// int numFrames;
|
||||
// float frameLength;
|
||||
// time_point_t startTime;
|
||||
|
||||
// float* frameData;
|
||||
// int numWeights;
|
||||
// };
|
||||
|
||||
Reference in New Issue
Block a user