This commit is contained in:
Nick Fisher
2023-06-22 13:47:24 +08:00
25 changed files with 941 additions and 681 deletions

View File

@@ -40,23 +40,25 @@ 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);
void setMorphTargetWeights(EntityId entityId, const char* const entityName, const float* const weights, int count);
bool setBoneAnimationBuffer(
EntityId entity,
const float* const frameData,
int numFrames,
int numBones,
const char** const boneNames,
const char** const meshName,
int numMeshTargets,
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);
@@ -76,18 +78,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

@@ -65,29 +65,17 @@ 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,
int numMeshTargets,
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

@@ -27,17 +27,11 @@ extern "C" {
//
struct ResourceBuffer {
#if defined(__cplusplus)
ResourceBuffer(const void* data, const uint32_t size, const uint32_t id) : data(data), size(size), id(id) {};
ResourceBuffer& operator=(ResourceBuffer other) {
data = other.data;
size = other.size;
id = other.id;
return *this;
}
ResourceBuffer(const void* const data, const uint32_t size, const uint32_t id) : data(data), size(size), id(id) {};
#endif
const void* data;
uint32_t size;
uint32_t id;
const void * const data;
const uint32_t size;
const uint32_t id;
};
typedef struct ResourceBuffer ResourceBuffer;

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>
@@ -21,7 +22,7 @@
extern "C" {
#include "PolyvoxFilamentApi.h"
}
template class std::vector<float>;
namespace polyvox {
using namespace filament;
using namespace filament::gltfio;
@@ -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,22 @@ 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 {
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.
size_t skinIndex = 0;
int mNumFrames = -1;
float mFrameLengthInMs = 0;
vector<BoneAnimationData> mAnimations;
vector<float> mFrameData;
};
struct SceneAsset {
@@ -129,12 +99,9 @@ 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);