add maxDelta to blend between glTF and dynamic bone animations
This commit is contained in:
@@ -149,7 +149,8 @@ extern "C"
|
||||
int numFrames,
|
||||
float frameLengthInMs,
|
||||
float fadeOutInSecs,
|
||||
float fadeInInSecs);
|
||||
float fadeInInSecs,
|
||||
float maxDelta);
|
||||
EMSCRIPTEN_KEEPALIVE void get_local_transform(void *sceneManager,
|
||||
EntityId entityId, float* const);
|
||||
EMSCRIPTEN_KEEPALIVE void get_rest_local_transforms(void *sceneManager,
|
||||
|
||||
@@ -118,8 +118,9 @@ namespace flutter_filament
|
||||
int numFrames,
|
||||
float frameLengthInMs,
|
||||
float fadeOutInSecs,
|
||||
float fadeInInSecs
|
||||
);
|
||||
float fadeInInSecs,
|
||||
float maxDelta
|
||||
);
|
||||
|
||||
std::unique_ptr<std::vector<math::mat4f>> getBoneRestTranforms(EntityId entityId, int skinIndex);
|
||||
void resetBones(EntityId entityId);
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace flutter_filament
|
||||
std::vector<math::mat4f> frameData;
|
||||
float fadeOutInSecs = 0;
|
||||
float fadeInInSecs = 0;
|
||||
float maxDelta = 1.0f;
|
||||
};
|
||||
|
||||
struct AnimationComponent
|
||||
@@ -290,11 +291,13 @@ namespace flutter_filament
|
||||
// if we're fading in, this will be 0.0 at the start of the fade and 1.0 at the end
|
||||
auto fadeDelta = elapsedInSecs / animationStatus.fadeInInSecs;
|
||||
|
||||
// if we're fading out, this will be 1.0 at the start of the fade and 0.0 at the end
|
||||
// // if we're fading out, this will be 1.0 at the start of the fade and 0.0 at the end
|
||||
if(fadeDelta > 1.0f) {
|
||||
fadeDelta = 1 - ((elapsedInSecs - animationStatus.durationInSecs - animationStatus.fadeInInSecs) / animationStatus.fadeOutInSecs);
|
||||
}
|
||||
|
||||
fadeDelta = std::clamp(fadeDelta, 0.0f, animationStatus.maxDelta);
|
||||
|
||||
auto jointTransform = _transformManager.getInstance(joint);
|
||||
|
||||
// linearly interpolate this animation between its current (interpolated) frame and the current transform (i.e. as set by the gltf frame)
|
||||
|
||||
@@ -429,9 +429,10 @@ extern "C"
|
||||
int numFrames,
|
||||
float frameLengthInMs,
|
||||
float fadeOutInSecs,
|
||||
float fadeInInSecs)
|
||||
float fadeInInSecs,
|
||||
float maxDelta)
|
||||
{
|
||||
((SceneManager *)sceneManager)->addBoneAnimation(asset, skinIndex, boneIndex, frameData, numFrames, frameLengthInMs, fadeOutInSecs, fadeInInSecs);
|
||||
((SceneManager *)sceneManager)->addBoneAnimation(asset, skinIndex, boneIndex, frameData, numFrames, frameLengthInMs, fadeOutInSecs, fadeInInSecs, maxDelta);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_post_processing(void *const viewer, bool enabled)
|
||||
|
||||
@@ -1024,7 +1024,9 @@ namespace flutter_filament
|
||||
const float *const frameData,
|
||||
int numFrames,
|
||||
float frameLengthInMs,
|
||||
float fadeOutInSecs, float fadeInInSecs)
|
||||
float fadeOutInSecs,
|
||||
float fadeInInSecs,
|
||||
float maxDelta)
|
||||
{
|
||||
std::lock_guard lock(_mutex);
|
||||
|
||||
@@ -1072,7 +1074,6 @@ namespace flutter_filament
|
||||
}
|
||||
|
||||
animation.frameLengthInMs = frameLengthInMs;
|
||||
|
||||
animation.start = std::chrono::high_resolution_clock::now();
|
||||
animation.reverse = false;
|
||||
animation.durationInSecs = (frameLengthInMs * numFrames) / 1000.0f;
|
||||
@@ -1080,6 +1081,7 @@ namespace flutter_filament
|
||||
animation.frameLengthInMs = frameLengthInMs;
|
||||
animation.fadeOutInSecs = fadeOutInSecs;
|
||||
animation.fadeInInSecs = fadeInInSecs;
|
||||
animation.maxDelta = maxDelta;
|
||||
animation.skinIndex = skinIndex;
|
||||
if(!_animationComponentManager->hasComponent(instance->getRoot())) {
|
||||
Log("ERROR: specified entity is not animatable (has no animation component attached).");
|
||||
|
||||
Reference in New Issue
Block a user