feat: add startOffset parameter to gltf playAnimation
This commit is contained in:
@@ -129,7 +129,7 @@ namespace thermion_filament
|
||||
void resetBones(EntityId entityId);
|
||||
bool setTransform(EntityId entityId, math::mat4f transform);
|
||||
bool updateBoneMatrices(EntityId entityId);
|
||||
void playAnimation(EntityId e, int index, bool loop, bool reverse, bool replaceActive, float crossfade = 0.3f);
|
||||
void playAnimation(EntityId e, int index, bool loop, bool reverse, bool replaceActive, float crossfade = 0.3f, float startOffset = 0.0f);
|
||||
void stopAnimation(EntityId e, int index);
|
||||
void setMorphTargetWeights(const char *const entityName, float *weights, int count);
|
||||
void loadTexture(EntityId entity, const char *resourcePath, int renderableIndex);
|
||||
|
||||
@@ -168,7 +168,7 @@ extern "C"
|
||||
int skinIndex,
|
||||
int boneIndex,
|
||||
const float *const transform);
|
||||
EMSCRIPTEN_KEEPALIVE void play_animation(void *sceneManager, EntityId entity, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
EMSCRIPTEN_KEEPALIVE void play_animation(void *sceneManager, EntityId entity, int index, bool loop, bool reverse, bool replaceActive, float crossfade, float startOffset);
|
||||
EMSCRIPTEN_KEEPALIVE void set_animation_frame(void *sceneManager, EntityId entity, int animationIndex, int animationFrame);
|
||||
EMSCRIPTEN_KEEPALIVE void stop_animation(void *sceneManager, EntityId entity, int index);
|
||||
EMSCRIPTEN_KEEPALIVE int get_animation_count(void *sceneManager, EntityId asset);
|
||||
|
||||
@@ -78,8 +78,6 @@ extern "C"
|
||||
const char *const entityName,
|
||||
float *const weights,
|
||||
int count);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void play_animation_ffi(void *const sceneManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
EMSCRIPTEN_KEEPALIVE void set_animation_frame_ffi(void *const sceneManager, EntityId asset, int animationIndex, int animationFrame);
|
||||
EMSCRIPTEN_KEEPALIVE void stop_animation_ffi(void *const sceneManager, EntityId asset, int index);
|
||||
EMSCRIPTEN_KEEPALIVE void get_animation_count_ffi(void *const sceneManager, EntityId asset, void (*callback)(int));
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace thermion_filament
|
||||
struct AnimationStatus
|
||||
{
|
||||
time_point_t start = time_point_t::max();
|
||||
float startOffset;
|
||||
bool loop = false;
|
||||
bool reverse = false;
|
||||
float durationInSecs = 0;
|
||||
@@ -182,7 +183,7 @@ namespace thermion_filament
|
||||
|
||||
auto animationStatus = animationComponent.gltfAnimations[i];
|
||||
|
||||
auto elapsedInSecs = float(std::chrono::duration_cast<std::chrono::milliseconds>(now - animationStatus.start).count()) / 1000.0f;
|
||||
auto elapsedInSecs = animationStatus.startOffset + float(std::chrono::duration_cast<std::chrono::milliseconds>(now - animationStatus.start).count()) / 1000.0f;
|
||||
|
||||
if (!animationStatus.loop && elapsedInSecs >= animationStatus.durationInSecs)
|
||||
{
|
||||
|
||||
@@ -1135,8 +1135,8 @@ namespace thermion_filament
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SceneManager::playAnimation(EntityId entityId, int index, bool loop, bool reverse, bool replaceActive, float crossfade)
|
||||
|
||||
void SceneManager::playAnimation(EntityId entityId, int index, bool loop, bool reverse, bool replaceActive, float crossfade, float startOffset)
|
||||
{
|
||||
std::lock_guard lock(_mutex);
|
||||
|
||||
@@ -1200,6 +1200,7 @@ namespace thermion_filament
|
||||
}
|
||||
|
||||
GltfAnimation animation;
|
||||
animation.startOffset = startOffset;
|
||||
animation.index = index;
|
||||
animation.start = std::chrono::high_resolution_clock::now();
|
||||
animation.loop = loop;
|
||||
|
||||
@@ -586,9 +586,10 @@ extern "C"
|
||||
bool loop,
|
||||
bool reverse,
|
||||
bool replaceActive,
|
||||
float crossfade)
|
||||
float crossfade,
|
||||
float startOffset)
|
||||
{
|
||||
((SceneManager *)sceneManager)->playAnimation(asset, index, loop, reverse, replaceActive, crossfade);
|
||||
((SceneManager *)sceneManager)->playAnimation(asset, index, loop, reverse, replaceActive, crossfade, startOffset);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_animation_frame(
|
||||
|
||||
@@ -677,18 +677,6 @@ extern "C"
|
||||
auto fut = _rl->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void play_animation_ffi(void *const sceneManager,
|
||||
EntityId asset, int index,
|
||||
bool loop, bool reverse,
|
||||
bool replaceActive,
|
||||
float crossfade)
|
||||
{
|
||||
std::packaged_task<void()> lambda([=]
|
||||
{ play_animation(sceneManager, asset, index, loop, reverse, replaceActive,
|
||||
crossfade); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_animation_frame_ffi(void *const sceneManager,
|
||||
EntityId asset,
|
||||
int animationIndex,
|
||||
|
||||
Reference in New Issue
Block a user