allow multiple simultaneous gltf animatiosn

This commit is contained in:
Nick Fisher
2023-08-09 13:59:10 +08:00
parent fa8c6b1ca0
commit e62bf64c04
7 changed files with 130 additions and 141 deletions

View File

@@ -59,7 +59,7 @@ namespace polyvox {
const char** const meshName,
int numMeshTargets,
float frameLengthInMs);
void playAnimation(EntityId e, int index, bool loop, bool reverse, float crossfade = 0.3f);
void playAnimation(EntityId e, int index, bool loop, bool reverse, bool replaceActive, float crossfade = 0.3f);
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);

View File

@@ -68,7 +68,7 @@ void set_bone_animation(
int numMeshTargets,
float frameLengthInMs);
void play_animation(void* assetManager, EntityId asset, int index, bool loop, bool reverse, float crossfade);
void play_animation(void* assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
void set_animation_frame(void* assetManager, EntityId asset, int animationIndex, int animationFrame);
void stop_animation(void* assetManager, EntityId asset, int index);
int get_animation_count(void* assetManager, EntityId asset);

View File

@@ -31,12 +31,17 @@ namespace polyvox {
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
enum AnimationType {
MORPH, BONE, GLTF
};
struct AnimationStatus {
time_point_t mStart = time_point_t::max();
bool mLoop = false;
bool mReverse = false;
float mDuration = 0;
bool mActive = false;
AnimationType type;
int gltfIndex = -1;
};
//
@@ -73,11 +78,9 @@ namespace polyvox {
FilamentAsset* mAsset = nullptr;
Animator* mAnimator = nullptr;
// fixed-sized array containing pointers to the active morph, bone and GLTF animations.
AnimationStatus mAnimations[3];
// the index of the active glTF animation in the Filament Asset animations array
// if no glTF animation is active, this is -1
int gltfAnimationIndex = -1;
// vector containing AnimationStatus structs for the morph, bone and/or glTF animations.
vector<AnimationStatus> mAnimations;
// the index of the last active glTF animation,
// used to cross-fade
int fadeGltfAnimationIndex = -1;