Merge branch 'master' of github.com:nmfisher/polyvox_filament

This commit is contained in:
Nick Fisher
2023-02-26 12:22:14 +08:00
12 changed files with 172 additions and 106 deletions

View File

@@ -8,9 +8,10 @@
typedef struct ResourceBuffer ResourceBuffer;
///
/// A wrapper for a single set of frame-data that may animate multiples bones/mesh nodes.
/// Frame data for animating multiples bones for multiple meshes.
/// [data]
///
struct BoneAnimation {
const char* const* const boneNames;
const char* const* const meshNames;
@@ -52,10 +53,11 @@ void grab_begin(void* viewer, float x, float y, bool pan);
void grab_update(void* viewer, float x, float y);
void grab_end(void* viewer);
void apply_weights(void* asset, float* const weights, int count);
void apply_weights(void* asset, const char* const entityName, float* const weights, int count);
void set_animation(
void* asset,
const char* const entityName,
const float* const morphData,
int numMorphWeights,
const BoneAnimation* const boneAnimations,

View File

@@ -63,10 +63,10 @@ namespace polyvox {
void setAnimationFrame(int animationIndex, int animationFrame);
///
/// Manually set the weights for all morph targets in the assets to the provided values.
/// Set the weights for all [count] morph targets in this asset's entity named [inst] to [weights].
/// See [setAnimation] if you want to do the same across a number of frames (and extended to bone transforms).
///
void setMorphTargetWeights(float* weights, int count);
void setMorphTargetWeights(const char* const entityName, float* weights, int count);
///
/// Animates the asset's morph targets/bone transforms according to the frame weights/transforms specified in [morphData]/[boneData].
@@ -76,6 +76,7 @@ namespace polyvox {
/// [morphData] and [boneData] will both be copied, so remember to free these after calling this function.
///
void setAnimation(
const char* entityName,
const float* const morphData,
int numMorphWeights,
const BoneAnimation* const targets,
@@ -84,7 +85,6 @@ namespace polyvox {
float frameLengthInMs
);
void fillEntitiesByName(const char** name, int count, vector<Entity>& out);
size_t getBoneIndex(const char* name);
Entity getNode(const char* name);

View File

@@ -2,10 +2,13 @@
#define SCENE_ASSET_ANIMATION_H_
#include "utils/Entity.h"
#include <filament/RenderableManager.h>
namespace polyvox {
using namespace std;
using Instance = utils::EntityInstance<filament::RenderableManager>;
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
@@ -73,21 +76,26 @@ namespace polyvox {
//
struct RuntimeAnimation {
Instance mInstance;
int frameNumber = -1;
int mNumFrames = -1;
float mFrameLengthInMs = 0;
time_point_t startTime;
float* mMorphFrameData = nullptr;
int mNumMorphWeights = 0;
unique_ptr<vector<BoneTransformTarget>> mTargets;
RuntimeAnimation(const float* const morphData,
RuntimeAnimation(Instance instance,
const float* const morphData,
int numMorphWeights,
unique_ptr<vector<BoneTransformTarget>>& targets,
int numFrames,
float frameLengthInMs) :
mInstance(instance),
mNumFrames(numFrames),
mFrameLengthInMs(frameLengthInMs),
mNumMorphWeights(numMorphWeights),