fix dynamic bone animations

This commit is contained in:
Nick Fisher
2023-04-27 16:32:32 +08:00
parent d1e15b53c5
commit 62c4be0563
16 changed files with 538 additions and 520 deletions

View File

@@ -40,21 +40,22 @@ namespace polyvox {
size_t getLightEntityCount(EntityId e) const noexcept;
void updateAnimations();
bool setBoneAnimationBuffer(
EntityId entity,
int length,
const char** const boneNames,
const char** const meshNames,
const float* const frameData,
int numFrames,
float frameLengthInMs);
bool setMorphAnimationBuffer(
EntityId entity,
const char* entityName,
const float* const morphData,
EntityId entityId,
const char* entityName,
const float* const morphData,
int numMorphWeights,
int numFrames,
float frameLengthInMs);
bool setBoneAnimationBuffer(
EntityId entity,
const float* const frameData,
int numFrames,
int numBones,
const char** const boneNames,
const char* const meshName,
float frameLengthInMs);
void playAnimation(EntityId e, int index, bool loop, bool reverse);
void stopAnimation(EntityId e, int index);
void setMorphTargetWeights(const char* const entityName, float *weights, int count);
@@ -74,18 +75,15 @@ namespace polyvox {
vector<SceneAsset> _assets;
tsl::robin_map<EntityId, int> _entityIdLookup;
void setBoneTransform(
FilamentInstance* instance,
vector<BoneAnimationData> animations,
int frameNumber
);
utils::Entity findEntityByName(
SceneAsset asset,
const char* entityName
);
inline void updateTransform(SceneAsset asset);
inline void updateTransform(SceneAsset& asset);
inline void setBoneTransform(SceneAsset& asset, int frameNumber);
};

View File

@@ -57,29 +57,16 @@ bool set_morph_animation(
int numFrames,
float frameLengthInMs);
void set_bone_animation(
void set_bone_animation(
void* assetManager,
EntityId asset,
int length,
const char** const boneNames,
const char** const meshNames,
const float* const frameData,
int numFrames,
int numBones,
const char** const boneNames,
const char* const meshName,
float frameLengthInMs);
// void set_bone_transform(
// EntityId asset,
// const char* boneName,
// const char* entityName,
// float transX,
// float transY,
// float transZ,
// float quatX,
// float quatY,
// float quatZ,
// float quatW
// );
void play_animation(void* assetManager, EntityId asset, int index, bool loop, bool reverse);
void set_animation_frame(void* assetManager, EntityId asset, int animationIndex, int animationFrame);
void stop_animation(void* assetManager, EntityId asset, int index);

View File

@@ -7,6 +7,7 @@
#include <filament/Renderer.h>
#include <filament/Scene.h>
#include <filament/Texture.h>
#include <filament/TransformManager.h>
#include <math/vec3.h>
#include <math/vec4.h>
@@ -36,35 +37,6 @@ namespace polyvox {
bool mReverse = false;
float mDuration = 0;
bool mAnimating = false;
// AnimationStatus() {
// Log("default constr");
// }
// AnimationStatus(AnimationStatus& a) {
// mStart = a.mStart;
// mLoop = a.mLoop;
// mReverse = a.mReverse;
// mDuration = a.mDuration;
// mFrameNumber = a.mFrameNumber;
// }
// AnimationStatus& operator=(AnimationStatus a) {
// mStart = a.mStart;
// mLoop = a.mLoop;
// mReverse = a.mReverse;
// mDuration = a.mDuration;
// mFrameNumber = a.mFrameNumber;
// return *this;
// }
// AnimationStatus(AnimationStatus&& a) {
// mStart = a.mStart;
// mLoop = a.mLoop;
// mReverse = a.mReverse;
// mDuration = a.mDuration;
// mFrameNumber = a.mFrameNumber;
// }
};
//
@@ -78,24 +50,18 @@ namespace polyvox {
int mNumMorphWeights = 0;
};
///
/// Frame data for the bones/meshes specified by [mBoneIndices] and [mMeshTargets].
/// This is mainly used as a wrapper for animation data being transferred from the Dart to the native side.
///
struct BoneAnimationData {
size_t skinIndex = 0;
uint8_t mBoneIndex;
utils::Entity mMeshTarget;
vector<float> mFrameData;
};
//
// Use this to manually construct a buffer of frame data for bone animations.
// 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.
//
struct BoneAnimationBuffer {
utils::Entity mMeshTarget;
vector<uint8_t> mBones;
size_t skinIndex = 0;
int mNumFrames = -1;
float mFrameLengthInMs = 0;
vector<BoneAnimationData> mAnimations;
vector<float> mFrameData;
};
struct SceneAsset {
@@ -129,10 +95,12 @@ namespace polyvox {
mAnimations.resize(2 + mAnimator->getAnimationCount());
for(int i=2; i < mAnimations.size(); i++) {
mAnimations[i].mDuration = mAnimator->getAnimationDuration(i-2);
for(int i=0; i < mAnimations.size() - 2; i++) {
mAnimations[i].mDuration = mAnimator->getAnimationDuration(i);
}
}
};
}

View File

@@ -18,7 +18,7 @@ namespace polyvox {
public:
FileMaterialProvider(Engine* engine, void* const data, size_t size) {
FileMaterialProvider(Engine* engine, const void* const data, const size_t size) {
_m = Material::Builder()
.package(data, size)
.build(*engine);