add maxDelta to blend between glTF and dynamic bone animations

This commit is contained in:
Nick Fisher
2024-06-10 22:32:44 +08:00
parent b5ed69483c
commit 5c5897f74d
12 changed files with 84 additions and 33 deletions

View File

@@ -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,

View File

@@ -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);

View File

@@ -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)