copy morph animation weights
This commit is contained in:
@@ -66,6 +66,7 @@ namespace polyvox {
|
|||||||
/// Accordingly:
|
/// Accordingly:
|
||||||
/// length(data) = numWeights * numFrames
|
/// length(data) = numWeights * numFrames
|
||||||
/// total_animation_duration_in_ms = number_of_frames * frameLengthInMs
|
/// total_animation_duration_in_ms = number_of_frames * frameLengthInMs
|
||||||
|
/// [data] will be copied; you should ensure this is freed after invoking this function.
|
||||||
///
|
///
|
||||||
void animateWeights(float* data, int numWeights, int numFrames, float frameLengthInMs);
|
void animateWeights(float* data, int numWeights, int numFrames, float frameLengthInMs);
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "ResourceBuffer.hpp"
|
#include "ResourceBuffer.hpp"
|
||||||
|
|
||||||
@@ -66,19 +67,26 @@ namespace polyvox {
|
|||||||
//
|
//
|
||||||
struct MorphAnimationStatus {
|
struct MorphAnimationStatus {
|
||||||
|
|
||||||
MorphAnimationStatus(float* frameData,
|
MorphAnimationStatus(float* data,
|
||||||
int numWeights,
|
int numWeights,
|
||||||
int numFrames,
|
int numFrames,
|
||||||
float frameLength) : numFrames(numFrames), frameLengthInMs(frameLength), frameData(frameData), numWeights(numWeights) {
|
float frameLengthInMs) : numFrames(numFrames), frameLengthInMs(frameLengthInMs), numWeights(numWeights) {
|
||||||
|
size_t size = numWeights * numFrames * sizeof(float);
|
||||||
|
frameData = (float*)malloc(size);
|
||||||
|
memcpy(frameData, data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
~MorphAnimationStatus() {
|
||||||
|
delete(frameData);
|
||||||
}
|
}
|
||||||
|
|
||||||
int frameIndex = -1;
|
int frameIndex = -1;
|
||||||
int numFrames;
|
int numFrames = -1;
|
||||||
float frameLengthInMs;
|
float frameLengthInMs = 0;
|
||||||
time_point_t startTime;
|
time_point_t startTime;
|
||||||
|
|
||||||
float* frameData;
|
float* frameData = nullptr;
|
||||||
int numWeights;
|
int numWeights = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ void SceneAsset::updateMorphAnimation() {
|
|||||||
_morphAnimationBuffer->frameIndex);
|
_morphAnimationBuffer->frameIndex);
|
||||||
_morphAnimationBuffer = nullptr;
|
_morphAnimationBuffer = nullptr;
|
||||||
} else if (frameIndex != _morphAnimationBuffer->frameIndex) {
|
} else if (frameIndex != _morphAnimationBuffer->frameIndex) {
|
||||||
Log("Rendering frame %d (of a total %d)", frameIndex,
|
// Log("Rendering frame %d (of a total %d)", frameIndex,
|
||||||
_morphAnimationBuffer->numFrames);
|
// _morphAnimationBuffer->numFrames);
|
||||||
_morphAnimationBuffer->frameIndex = frameIndex;
|
_morphAnimationBuffer->frameIndex = frameIndex;
|
||||||
auto framePtrOffset = frameIndex * _morphAnimationBuffer->numWeights;
|
auto framePtrOffset = frameIndex * _morphAnimationBuffer->numWeights;
|
||||||
applyWeights(_morphAnimationBuffer->frameData + framePtrOffset,
|
applyWeights(_morphAnimationBuffer->frameData + framePtrOffset,
|
||||||
@@ -123,6 +123,7 @@ void SceneAsset::playAnimation(int index, bool loop, bool reverse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SceneAsset::stopAnimation(int index) {
|
void SceneAsset::stopAnimation(int index) {
|
||||||
|
Log("Stopping animation %d", index);
|
||||||
// TODO - does this need to be threadsafe?
|
// TODO - does this need to be threadsafe?
|
||||||
_embeddedAnimationStatus[index].play = false;
|
_embeddedAnimationStatus[index].play = false;
|
||||||
_embeddedAnimationStatus[index].started = false;
|
_embeddedAnimationStatus[index].started = false;
|
||||||
@@ -199,7 +200,7 @@ void SceneAsset::updateEmbeddedAnimations() {
|
|||||||
auto now = high_resolution_clock::now();
|
auto now = high_resolution_clock::now();
|
||||||
int animationIndex = 0;
|
int animationIndex = 0;
|
||||||
for (auto &status : _embeddedAnimationStatus) {
|
for (auto &status : _embeddedAnimationStatus) {
|
||||||
if (!status.play) {
|
if (status.play == false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user