finalize bone transform animation
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
|
||||
#include "SceneAssetLoader.hpp"
|
||||
#include "SceneAsset.hpp"
|
||||
#include "SceneResources.hpp"
|
||||
#include "ResourceManagement.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace filament;
|
||||
|
||||
@@ -5,91 +5,105 @@
|
||||
|
||||
typedef struct ResourceBuffer ResourceBuffer;
|
||||
|
||||
//ResourceBuffer create_resource_buffer(const void* data, const uint32_t size, const uint32_t id);
|
||||
void* filament_viewer_new(void* context, ResourceBuffer (*loadResource)(const char*), void (*freeResource)(uint32_t));
|
||||
void* filament_viewer_delete(void* viewer);
|
||||
void create_render_target(void* viewer, uint32_t textureId, uint32_t width, uint32_t height);
|
||||
void set_background_image(void* viewer, const char* path);
|
||||
void set_background_image_position(void* viewer, float x, float y, bool clamp);
|
||||
void load_skybox(void* viewer, const char* skyboxPath);
|
||||
void load_ibl(void* viewer, const char* iblPath);
|
||||
void remove_skybox(void* viewer);
|
||||
void remove_ibl(void* viewer);
|
||||
int32_t add_light(void* viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
void remove_light(void* viewer, int32_t entityId);
|
||||
void clear_lights(void* viewer);
|
||||
void* load_glb(void* viewer, const char* assetPath);
|
||||
void* load_gltf(void* viewer, const char* assetPath, const char* relativePath);
|
||||
bool set_camera(void* viewer, void* asset, const char* nodeName);
|
||||
void render(void* viewer, uint64_t frameTimeInNanos);
|
||||
void create_swap_chain(void* viewer, void* surface, uint32_t width, uint32_t height);
|
||||
void destroy_swap_chain(void* viewer);
|
||||
void set_frame_interval(void* viewer, float interval);
|
||||
void* get_renderer(void* viewer);
|
||||
void update_viewport_and_camera_projection(void* viewer, int width, int height, float scaleFactor);
|
||||
|
||||
void scroll_begin(void* viewer);
|
||||
void scroll_update(void* viewer, float x, float y , float z);
|
||||
void scroll_end(void* viewer);
|
||||
|
||||
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);
|
||||
///
|
||||
/// A wrapper for a single set of frame-data that may animate multiples bones/mesh nodes.
|
||||
/// [data]
|
||||
///
|
||||
struct BoneAnimation {
|
||||
const char** boneNames;
|
||||
const char** meshNames;
|
||||
float* data;
|
||||
size_t numBones;
|
||||
size_t numMeshTargets;
|
||||
};
|
||||
|
||||
void apply_weights(void* asset, float* const weights, int count);
|
||||
|
||||
void set_animation(
|
||||
void* asset,
|
||||
float* morphData,
|
||||
int numMorphWeights,
|
||||
float* boneData,
|
||||
const char** boneNames,
|
||||
const char** meshNames,
|
||||
int numBones,
|
||||
int numFrames,
|
||||
float frameLengthInMs
|
||||
);
|
||||
typedef struct BoneAnimation BoneAnimation;
|
||||
|
||||
void set_bone_transform(
|
||||
void* 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* asset, int index, bool loop, bool reverse);
|
||||
void stop_animation(void* asset, int index);
|
||||
|
||||
int get_animation_count(void* asset);
|
||||
extern "C" {
|
||||
void* filament_viewer_new(void* context, ResourceBuffer (*loadResource)(const char*), void (*freeResource)(uint32_t));
|
||||
void filament_viewer_delete(void* viewer);
|
||||
void create_render_target(void* viewer, uint32_t textureId, uint32_t width, uint32_t height);
|
||||
void set_background_image(void* viewer, const char* path);
|
||||
void set_background_image_position(void* viewer, float x, float y, bool clamp);
|
||||
void load_skybox(void* viewer, const char* skyboxPath);
|
||||
void load_ibl(void* viewer, const char* iblPath);
|
||||
void remove_skybox(void* viewer);
|
||||
void remove_ibl(void* viewer);
|
||||
int32_t add_light(void* viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
void remove_light(void* viewer, int32_t entityId);
|
||||
void clear_lights(void* viewer);
|
||||
void* load_glb(void* viewer, const char* assetPath);
|
||||
void* load_gltf(void* viewer, const char* assetPath, const char* relativePath);
|
||||
bool set_camera(void* viewer, void* asset, const char* nodeName);
|
||||
void render(void* viewer, uint64_t frameTimeInNanos);
|
||||
void create_swap_chain(void* viewer, void* surface, uint32_t width, uint32_t height);
|
||||
void destroy_swap_chain(void* viewer);
|
||||
void set_frame_interval(void* viewer, float interval);
|
||||
void* get_renderer(void* viewer);
|
||||
void update_viewport_and_camera_projection(void* viewer, int width, int height, float scaleFactor);
|
||||
|
||||
void get_animation_name(void* asset, char* const outPtr, int index);
|
||||
void scroll_begin(void* viewer);
|
||||
void scroll_update(void* viewer, float x, float y , float z);
|
||||
void scroll_end(void* viewer);
|
||||
|
||||
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 get_morph_target_name(void* asset, const char* meshName, char* const outPtr, int index );
|
||||
void apply_weights(void* asset, float* const weights, int count);
|
||||
|
||||
void set_animation(
|
||||
void* asset,
|
||||
float* morphData,
|
||||
int numMorphWeights,
|
||||
BoneAnimation* boneAnimations,
|
||||
int numBoneAnimations,
|
||||
int numFrames,
|
||||
float frameLengthInMs
|
||||
);
|
||||
|
||||
int get_morph_target_name_count(void* asset, const char* meshName);
|
||||
|
||||
void remove_asset(void* viewer, void* asset);
|
||||
|
||||
void clear_assets(void* viewer);
|
||||
|
||||
void load_texture(void* asset, const char* assetPath, int renderableIndex);
|
||||
void set_texture(void* asset);
|
||||
|
||||
void transform_to_unit_cube(void* asset);
|
||||
|
||||
void set_position(void* asset, float x, float y, float z);
|
||||
void set_rotation(void* asset, float rads, float x, float y, float z);
|
||||
void set_scale(void* asset, float scale);
|
||||
// void set_bone_transform(
|
||||
// void* 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* asset, int index, bool loop, bool reverse);
|
||||
void stop_animation(void* asset, int index);
|
||||
|
||||
void set_camera_position(void* viewer, float x, float y, float z);
|
||||
void set_camera_rotation(void* viewer, float rads, float x, float y, float z);
|
||||
void set_camera_focal_length(void* viewer, float focalLength);
|
||||
void set_camera_focus_distance(void* viewer, float focusDistance);
|
||||
int get_animation_count(void* asset);
|
||||
|
||||
void get_animation_name(void* asset, char* const outPtr, int index);
|
||||
|
||||
void get_morph_target_name(void* asset, const char* meshName, char* const outPtr, int index );
|
||||
|
||||
int get_morph_target_name_count(void* asset, const char* meshName);
|
||||
|
||||
void remove_asset(void* viewer, void* asset);
|
||||
|
||||
void clear_assets(void* viewer);
|
||||
|
||||
void load_texture(void* asset, const char* assetPath, int renderableIndex);
|
||||
void set_texture(void* asset);
|
||||
|
||||
void transform_to_unit_cube(void* asset);
|
||||
|
||||
void set_position(void* asset, float x, float y, float z);
|
||||
void set_rotation(void* asset, float rads, float x, float y, float z);
|
||||
void set_scale(void* asset, float scale);
|
||||
|
||||
void set_camera_position(void* viewer, float x, float y, float z);
|
||||
void set_camera_rotation(void* viewer, float rads, float x, float y, float z);
|
||||
void set_camera_focal_length(void* viewer, float focalLength);
|
||||
void set_camera_focus_distance(void* viewer, float focusDistance);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
27
ios/include/ResourceManagement.hpp
Normal file
27
ios/include/ResourceManagement.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
namespace polyvox {
|
||||
|
||||
using namespace std;
|
||||
|
||||
//
|
||||
// Typedef for a function that loads a resource into a ResourceBuffer from an asset URI.
|
||||
//
|
||||
using LoadResource = function<ResourceBuffer(const char* uri)>;
|
||||
|
||||
//
|
||||
// Typedef for a function that frees an ID associated with a ResourceBuffer.
|
||||
//
|
||||
using FreeResource = function<void (uint32_t)>;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,14 +17,16 @@
|
||||
|
||||
#include <utils/NameComponentManager.h>
|
||||
|
||||
#include "SceneResources.hpp"
|
||||
#include "ResourceManagement.hpp"
|
||||
#include "SceneAssetAnimation.hpp"
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
|
||||
namespace polyvox {
|
||||
using namespace filament;
|
||||
using namespace filament::gltfio;
|
||||
using namespace utils;
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SceneAsset {
|
||||
friend class SceneAssetLoader;
|
||||
public:
|
||||
@@ -71,25 +73,16 @@ namespace polyvox {
|
||||
void setAnimation(
|
||||
float* morphData,
|
||||
int numMorphWeights,
|
||||
float* boneData,
|
||||
const char** boneNames,
|
||||
const char** meshNames,
|
||||
int numBones,
|
||||
BoneAnimation* targets,
|
||||
int numBoneAnimations,
|
||||
int numFrames,
|
||||
float frameLengthInMs
|
||||
);
|
||||
|
||||
void setBoneTransform(
|
||||
const char* boneName,
|
||||
const char* meshName,
|
||||
float transX,
|
||||
float transY,
|
||||
float transZ,
|
||||
float quatX,
|
||||
float quatY,
|
||||
float quatZ,
|
||||
float quatW
|
||||
);
|
||||
void fillEntitiesByName(const char** name, int count, vector<Entity>& out);
|
||||
size_t getBoneIndex(const char* name);
|
||||
|
||||
Entity getNode(const char* name);
|
||||
|
||||
void transformToUnitCube();
|
||||
|
||||
@@ -97,9 +90,7 @@ namespace polyvox {
|
||||
|
||||
void setPosition(float x, float y, float z);
|
||||
|
||||
void setRotation(float rads, float x, float y, float z);
|
||||
|
||||
|
||||
void setRotation(float rads, float x, float y, float z);
|
||||
|
||||
const utils::Entity* getCameraEntities();
|
||||
|
||||
@@ -116,9 +107,17 @@ namespace polyvox {
|
||||
Engine* _engine = nullptr;
|
||||
NameComponentManager* _ncm;
|
||||
|
||||
void updateRuntimeAnimation();
|
||||
void updateEmbeddedAnimations();
|
||||
void setBoneTransform(
|
||||
uint8_t skinIndex,
|
||||
const vector<uint8_t>& boneIndices,
|
||||
const vector<Entity>& targets,
|
||||
const vector<float> data,
|
||||
int frameNumber
|
||||
);
|
||||
|
||||
void updateRuntimeAnimation();
|
||||
|
||||
void updateEmbeddedAnimations();
|
||||
|
||||
Animator* _animator;
|
||||
|
||||
@@ -143,4 +142,4 @@ namespace polyvox {
|
||||
void updateTransform();
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
#pragma once
|
||||
#ifndef SCENE_ASSET_ANIMATION_H_
|
||||
#define SCENE_ASSET_ANIMATION_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "utils/Entity.h"
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
namespace polyvox {
|
||||
namespace polyvox {
|
||||
|
||||
using namespace std;
|
||||
|
||||
//
|
||||
// Typedef for a function that loads a resource into a ResourceBuffer from an asset URI.
|
||||
//
|
||||
using LoadResource = function<ResourceBuffer(const char* uri)>;
|
||||
|
||||
//
|
||||
// Typedef for a function that frees an ID associated with a ResourceBuffer.
|
||||
//
|
||||
using FreeResource = function<void (uint32_t)>;
|
||||
|
||||
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
|
||||
|
||||
//
|
||||
@@ -66,48 +51,29 @@ namespace polyvox {
|
||||
|
||||
};
|
||||
|
||||
///
|
||||
/// Holds a single set of frame data that may be used to animate multiple bones/meshes.
|
||||
///
|
||||
struct BoneTransformTarget {
|
||||
|
||||
size_t skinIndex = 0;
|
||||
unique_ptr<vector<uint8_t>> mBoneIndices;
|
||||
unique_ptr<vector<utils::Entity>> mMeshTargets;
|
||||
unique_ptr<vector<float>> mBoneData;
|
||||
|
||||
BoneTransformTarget(
|
||||
unique_ptr<vector<uint8_t>>& boneIndices,
|
||||
unique_ptr<vector<utils::Entity>>& meshTargets,
|
||||
unique_ptr<vector<float>>& boneData) : mBoneIndices(move(boneIndices)), mMeshTargets(move(meshTargets)), mBoneData(move(boneData)) {}
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// An animation created by manually passing frame data for morph weights/bone transforms.
|
||||
//
|
||||
struct RuntimeAnimation {
|
||||
|
||||
RuntimeAnimation(float* morphData,
|
||||
int numMorphWeights,
|
||||
float* boneData,
|
||||
const char** boneNames,
|
||||
const char** meshNames,
|
||||
int numBones,
|
||||
int numFrames,
|
||||
float frameLengthInMs) :
|
||||
mNumFrames(numFrames),
|
||||
mFrameLengthInMs(frameLengthInMs),
|
||||
mNumMorphWeights(numMorphWeights),
|
||||
mNumBones(numBones) {
|
||||
|
||||
if(numMorphWeights > 0) {
|
||||
size_t morphSize = numMorphWeights * mNumFrames * sizeof(float);
|
||||
mMorphFrameData = (float*)malloc(morphSize);
|
||||
memcpy(mMorphFrameData, morphData, morphSize);
|
||||
}
|
||||
|
||||
if(numBones > 0) {
|
||||
size_t boneSize = numBones * numFrames * 7 * sizeof(float);
|
||||
mBoneFrameData = (float*)malloc(boneSize);
|
||||
memcpy(mBoneFrameData, boneData, boneSize);
|
||||
}
|
||||
|
||||
for(int i =0; i < numBones; i++) {
|
||||
mBoneNames.push_back(string(boneNames[i]));
|
||||
mMeshNames.push_back(string(meshNames[i]));
|
||||
}
|
||||
}
|
||||
|
||||
~RuntimeAnimation() {
|
||||
delete(mMorphFrameData);
|
||||
delete(mBoneFrameData);
|
||||
}
|
||||
|
||||
int frameIndex = -1;
|
||||
int frameNumber = -1;
|
||||
int mNumFrames = -1;
|
||||
float mFrameLengthInMs = 0;
|
||||
time_point_t startTime;
|
||||
@@ -115,13 +81,30 @@ namespace polyvox {
|
||||
float* mMorphFrameData = nullptr;
|
||||
int mNumMorphWeights = 0;
|
||||
|
||||
float* mBoneFrameData = nullptr;
|
||||
int mNumBones = 0;
|
||||
|
||||
vector<string> mBoneNames;
|
||||
vector<string> mMeshNames;
|
||||
unique_ptr<vector<BoneTransformTarget>> mTargets;
|
||||
|
||||
RuntimeAnimation(float* morphData,
|
||||
int numMorphWeights,
|
||||
unique_ptr<vector<BoneTransformTarget>>& targets,
|
||||
int numFrames,
|
||||
float frameLengthInMs) :
|
||||
mNumFrames(numFrames),
|
||||
mFrameLengthInMs(frameLengthInMs),
|
||||
mNumMorphWeights(numMorphWeights),
|
||||
mTargets(move(targets)) {
|
||||
|
||||
if(numMorphWeights > 0) {
|
||||
size_t morphSize = numMorphWeights * mNumFrames * sizeof(float);
|
||||
mMorphFrameData = (float*)malloc(morphSize);
|
||||
memcpy(mMorphFrameData, morphData, morphSize);
|
||||
}
|
||||
}
|
||||
|
||||
~RuntimeAnimation() {
|
||||
delete(mMorphFrameData);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <gltfio/FilamentAsset.h>
|
||||
#include <gltfio/ResourceLoader.h>
|
||||
|
||||
#include "SceneResources.hpp"
|
||||
#include "ResourceManagement.hpp"
|
||||
#include "SceneAsset.hpp"
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
@@ -39,4 +39,4 @@ namespace polyvox {
|
||||
Scene* _scene;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,8 @@ public:
|
||||
*/
|
||||
void detachSkin(size_t skinIndex, utils::Entity target) noexcept;
|
||||
|
||||
const math::mat4f* getInverseBindMatricesAt(size_t skinIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Resets the AABB on all renderables by manually computing the bounding box.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user