add support for multiple bone animations using quaternions
This commit is contained in:
@@ -36,50 +36,46 @@ namespace polyvox {
|
||||
};
|
||||
|
||||
struct AnimationStatus {
|
||||
time_point_t mStart = time_point_t::max();
|
||||
bool mLoop = false;
|
||||
bool mReverse = false;
|
||||
float mDuration = 0;
|
||||
AnimationType type;
|
||||
int gltfIndex = -1;
|
||||
time_point_t start = time_point_t::max();
|
||||
bool loop = false;
|
||||
bool reverse = false;
|
||||
float durationInSecs = 0;
|
||||
};
|
||||
|
||||
struct GltfAnimation : AnimationStatus {
|
||||
int index = -1;
|
||||
};
|
||||
|
||||
//
|
||||
// Use this to manually construct a buffer of frame data for morph animations.
|
||||
// Use this to construct a dynamic (i.e. non-glTF embedded) morph target animation.
|
||||
//
|
||||
struct MorphAnimationBuffer {
|
||||
utils::Entity mMeshTarget;
|
||||
int mNumFrames = -1;
|
||||
float mFrameLengthInMs = 0;
|
||||
vector<float> mFrameData;
|
||||
vector<int> mMorphIndices;
|
||||
struct MorphAnimation : AnimationStatus {
|
||||
utils::Entity meshTarget;
|
||||
int numFrames = -1;
|
||||
float frameLengthInMs = 0;
|
||||
vector<float> frameData;
|
||||
vector<int> morphIndices;
|
||||
int lengthInFrames;
|
||||
};
|
||||
|
||||
//
|
||||
// Use this to construct a dynamic (i.e. non-glTF embedded) bone animation.
|
||||
// Only a single animation is supported at any time (i.e you can't blend animations).
|
||||
// Multiple bones are supported but these must be skinned to a single mesh target.
|
||||
// Use this to construct a dynamic (i.e. non-glTF embedded) bone/joint animation.
|
||||
//
|
||||
struct BoneAnimationBuffer {
|
||||
vector<utils::Entity> mMeshTargets;
|
||||
vector<uint8_t> mBones;
|
||||
vector<math::mat4f> mBaseTransforms;
|
||||
// vector<math::float3> mBaseTranslations; // these are the base transforms for the bones we will animate; the translations/rotations in mFrameData will be relative to this.
|
||||
// vector<math::quatf> mBaseRotations; // these are the base transforms for the bones we will animate; the translations/rotations in mFrameData will be relative to this.
|
||||
// vector<math::float3> mBaseScales; // these are the base transforms for the bones we will animate; the translations/rotations in mFrameData will be relative to this.
|
||||
struct BoneAnimation : AnimationStatus {
|
||||
uint8_t boneIndex;
|
||||
vector<utils::Entity> meshTargets;
|
||||
size_t skinIndex = 0;
|
||||
int mNumFrames = -1;
|
||||
float mFrameLengthInMs = 0;
|
||||
vector<float> mFrameData;
|
||||
int lengthInFrames;
|
||||
float frameLengthInMs = 0;
|
||||
vector<const math::quatf> frameData;
|
||||
};
|
||||
|
||||
struct SceneAsset {
|
||||
bool mAnimating = false;
|
||||
FilamentAsset* mAsset = nullptr;
|
||||
Animator* mAnimator = nullptr;
|
||||
|
||||
// vector containing AnimationStatus structs for the morph, bone and/or glTF animations.
|
||||
vector<AnimationStatus> mAnimations;
|
||||
FilamentAsset* asset = nullptr;
|
||||
|
||||
vector<GltfAnimation> gltfAnimations;
|
||||
vector<MorphAnimation> morphAnimations;
|
||||
vector<BoneAnimation> boneAnimations;
|
||||
|
||||
// the index of the last active glTF animation,
|
||||
// used to cross-fade
|
||||
@@ -87,24 +83,19 @@ namespace polyvox {
|
||||
float fadeDuration = 0.0f;
|
||||
float fadeOutAnimationStart = 0.0f;
|
||||
|
||||
MorphAnimationBuffer mMorphAnimationBuffer;
|
||||
BoneAnimationBuffer mBoneAnimationBuffer;
|
||||
|
||||
// a slot to preload textures
|
||||
filament::Texture* mTexture = nullptr;
|
||||
filament::Texture* texture = nullptr;
|
||||
|
||||
// initialized to identity
|
||||
math::mat4f mPosition;
|
||||
math::mat4f position;
|
||||
|
||||
// initialized to identity
|
||||
math::mat4f mRotation;
|
||||
math::mat4f rotation;
|
||||
|
||||
float mScale = 1;
|
||||
|
||||
SceneAsset(
|
||||
FilamentAsset* asset
|
||||
) : mAsset(asset) {
|
||||
mAnimator = mAsset->getInstance()->getAnimator();
|
||||
}
|
||||
) : asset(asset) {}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user