This commit is contained in:
Nick Fisher
2023-04-19 18:06:48 +08:00
parent 7f4ca7e69b
commit a162ff2400
30 changed files with 3604 additions and 2293 deletions

View File

@@ -0,0 +1,95 @@
#pragma once
#include <filament/Scene.h>
#include <gltfio/AssetLoader.h>
#include <gltfio/FilamentAsset.h>
#include <gltfio/ResourceLoader.h>
#include "ResourceManagement.hpp"
#include "SceneAsset.hpp"
#include "ResourceBuffer.hpp"
typedef int32_t EntityId;
namespace polyvox {
using namespace filament;
using namespace filament::gltfio;
class AssetManager {
public:
AssetManager(LoadResource loadResource,
FreeResource freeResource,
NameComponentManager *ncm,
Engine *engine,
Scene *scene);
~AssetManager();
EntityId loadGltf(const char* uri, const char* relativeResourcePath);
EntityId loadGlb(const char* uri, bool unlit);
FilamentAsset* getAssetByEntityId(EntityId entityId);
void remove(EntityId entity);
void destroyAll();
unique_ptr<vector<string>> getAnimationNames(EntityId entity);
unique_ptr<vector<string>> getMorphTargetNames(EntityId entity, const char *meshName);
void transformToUnitCube(EntityId e);
inline void updateTransform(EntityId e);
void setScale(EntityId e, float scale);
void setPosition(EntityId e, float x, float y, float z);
void setRotation(EntityId e, float rads, float x, float y, float z);
const utils::Entity *getCameraEntities(EntityId e);
size_t getCameraEntityCount(EntityId e);
const utils::Entity* getLightEntities(EntityId e) const noexcept;
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,
int numMorphWeights,
int numFrames,
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);
void loadTexture(EntityId entity, const char* resourcePath, int renderableIndex);
void setAnimationFrame(EntityId entity, int animationIndex, int animationFrame);
private:
LoadResource _loadResource;
FreeResource _freeResource;
AssetLoader* _assetLoader = nullptr;
ResourceLoader* _resourceLoader = nullptr;
NameComponentManager* _ncm = nullptr;
Engine* _engine;
Scene* _scene;
MaterialProvider* _unlitProvider = nullptr;
MaterialProvider* _ubershaderProvider = nullptr;
gltfio::ResourceLoader* _gltfResourceLoader = nullptr;
gltfio::TextureProvider* _stbDecoder = nullptr;
tsl::robin_map<EntityId, SceneAsset> _assets;
void setBoneTransform(
FilamentInstance* instance,
vector<BoneAnimationData> animations,
int frameNumber
);
utils::Entity findEntityByName(
SceneAsset asset,
const char* entityName
);
inline void updateTransform(SceneAsset asset);
};
}

View File

@@ -31,17 +31,16 @@
#include <string>
#include <chrono>
#include "SceneAssetLoader.hpp"
#include "SceneAsset.hpp"
#include "AssetManager.hpp"
#include "ResourceManagement.hpp"
using namespace std;
using namespace filament;
using namespace filament::math;
using namespace gltfio;
using namespace utils;
using namespace camutils;
typedef int32_t EntityId;
namespace polyvox {
class FilamentViewer {
@@ -56,9 +55,7 @@ namespace polyvox {
void loadIbl(const char* const iblUri, float intensity);
void removeIbl();
SceneAsset* loadGlb(const char* const uri, bool unlit);
SceneAsset* loadGltf(const char* const uri, const char* relativeResourcePath);
void removeAsset(SceneAsset* asset);
void removeAsset(EntityId asset);
// removes all add assets from the current scene
void clearAssets();
@@ -66,8 +63,7 @@ namespace polyvox {
void render(uint64_t frameTimeInNanos);
void setFrameInterval(float interval);
bool setFirstCamera(SceneAsset* asset);
bool setCamera(SceneAsset* asset, const char* nodeName);
bool setCamera(EntityId asset, const char* nodeName);
void createSwapChain(void* surface, uint32_t width, uint32_t height);
void destroySwapChain();
@@ -95,9 +91,13 @@ namespace polyvox {
void scrollEnd();
int32_t addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
void removeLight(int32_t entityId);
void removeLight(EntityId entityId);
void clearLights();
AssetManager* const getAssetManager() {
return (AssetManager* const) _assetManager;
}
private:
void createImageRenderable();
void loadResources(std::string relativeResourcePath);
@@ -124,24 +124,18 @@ namespace polyvox {
SwapChain* _swapChain = nullptr;
vector<SceneAsset*> _assets;
SceneAssetLoader* _ubershaderAssetLoader;
SceneAssetLoader* _unlitAssetLoader;
NameComponentManager* _ncm;
AssetManager* _assetManager = nullptr;
NameComponentManager* _ncm = nullptr;
std::mutex mtx; // mutex to ensure thread safety when removing assets
vector<Entity> _lights;
vector<utils::Entity> _lights;
Texture* _skyboxTexture = nullptr;
Skybox* _skybox = nullptr;
Texture* _iblTexture = nullptr;
IndirectLight* _indirectLight = nullptr;
MaterialProvider* _ubershaderProvider = nullptr;
MaterialProvider* _unlitProvider = nullptr;
gltfio::ResourceLoader* _resourceLoader = nullptr;
gltfio::TextureProvider* _stbDecoder = nullptr;
bool _recomputeAabb = false;
bool _actualSize = false;
@@ -156,7 +150,7 @@ namespace polyvox {
uint32_t _imageWidth = 0;
mat4f _imageScale;
Texture* _imageTexture = nullptr;
Entity* _imageEntity = nullptr;
utils::Entity* _imageEntity = nullptr;
VertexBuffer* _imageVb = nullptr;
IndexBuffer* _imageIb = nullptr;
Material* _imageMaterial = nullptr;

View File

@@ -7,111 +7,104 @@
typedef struct ResourceBuffer ResourceBuffer;
///
/// Frame data for animating multiples bones for multiple meshes.
/// [data]
typedef int32_t EntityId;
///
/// struct to facilitate passing bone animation frame data between Dart/native.
///
struct BoneAnimation {
const char* const* const boneNames;
const char* const* const meshNames;
const float* const data;
size_t numBones;
size_t numMeshTargets;
};
void* create_filament_viewer(void *context, ResourceBuffer (*loadResource)(const char *), void (*freeResource)(uint32_t));
void delete_filament_viewer(void *viewer);
void* get_asset_manager(void* viewer);
void create_render_target(void *viewer, uint32_t textureId, uint32_t width, uint32_t height);
void clear_background_image(void *viewer);
void set_background_image(void *viewer, const char *path);
void set_background_image_position(void *viewer, float x, float y, bool clamp);
void set_background_color(void *viewer, const float r, const float g, const float b, const float a);
void load_skybox(void *viewer, const char *skyboxPath);
void load_ibl(void *viewer, const char *iblPath, float intensity);
void remove_skybox(void *viewer);
void remove_ibl(void *viewer);
EntityId 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, EntityId entityId);
void clear_lights(void *viewer);
EntityId load_glb(void *assetManager, const char *assetPath, bool unlit);
EntityId load_gltf(void *assetManager, const char *assetPath, const char *relativePath);
bool set_camera(void *viewer, EntityId 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);
typedef struct BoneAnimation BoneAnimation;
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* 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 clear_background_image(void* viewer);
void set_background_image(void* viewer, const char* path);
void set_background_image_position(void* viewer, float x, float y, bool clamp);
void set_background_color(void* viewer, const float r, const float g, const float b, const float a);
void load_skybox(void* viewer, const char* skyboxPath);
void load_ibl(void* viewer, const char* iblPath, float intensity);
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, bool unlit);
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);
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,
int numBoneAnimations,
int numFrames,
float frameLengthInMs
void apply_weights(
void* assetManager,
EntityId asset,
const char *const entityName,
float *const weights,
int count
);
void set_morph_animation(
void* assetManager,
EntityId asset,
const char *const entityName,
const float *const morphData,
int numMorphWeights,
int numFrames,
float frameLengthInMs);
void set_bone_animation(
void* assetManager,
EntityId asset,
int length,
const char** const boneNames,
const char** const meshNames,
const float* const frameData,
int numFrames,
float frameLengthInMs);
// void set_bone_transform(
// void* asset,
// const char* boneName,
// EntityId asset,
// const char* boneName,
// const char* entityName,
// float transX,
// float transY,
// float transZ,
// 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 set_animation_frame(void* asset, int animationIndex, int animationFrame);
void stop_animation(void* asset, int index);
int get_animation_count(void* asset);
void get_animation_name(void* asset, char* const outPtr, int index);
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);
int get_animation_count(void* assetManager, EntityId asset);
void get_animation_name(void* assetManager, EntityId asset, char *const outPtr, int index);
void get_morph_target_name(void* assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
int get_morph_target_name_count(void* assetManager, EntityId asset, const char *meshName);
void remove_asset(void *viewer, EntityId asset);
void clear_assets(void *viewer);
void load_texture(void* assetManager, EntityId asset, const char *assetPath, int renderableIndex);
void set_texture(void* assetManager, EntityId asset);
void transform_to_unit_cube(void* assetManager, EntityId asset);
void set_position(void* assetManager, EntityId asset, float x, float y, float z);
void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z);
void set_scale(void* assetManager, EntityId asset, float scale);
void set_camera_exposure(void *viewer, float aperture, float shutterSpeed, float sensitivity);
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_model_matrix(void *viewer, const float *const matrix);
void set_camera_focal_length(void *viewer, float focalLength);
void set_camera_focus_distance(void *viewer, float focusDistance);
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_exposure(void* viewer, float aperture, float shutterSpeed, float sensitivity);
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_model_matrix(void* viewer, const float* const matrix);
void set_camera_focal_length(void* viewer, float focalLength);
void set_camera_focus_distance(void* viewer, float focusDistance);
#endif

View File

@@ -1,2 +1,2 @@
void* filament_viewer_new_ios(void* texture, void* loadResource, void* freeResource, void* resources);
void* create_filament_viewer_ios(void* texture, void* loadResource, void* freeResource, void* resources);

View File

@@ -15,7 +15,7 @@ namespace polyvox {
//
// Typedef for a function that loads a resource into a ResourceBuffer from an asset URI.
//
using LoadResource = function<ResourceBuffer(const char* uri)>;
using LoadResource = function<ResourceBuffer(const char* uri)>;
//
// Typedef for a function that frees an ID associated with a ResourceBuffer.

View File

@@ -11,14 +11,12 @@
#include <math/mat3.h>
#include <math/norm.h>
#include <gltfio/Animator.h>
#include <gltfio/AssetLoader.h>
#include <gltfio/FilamentAsset.h>
#include <gltfio/ResourceLoader.h>
#include <utils/NameComponentManager.h>
#include "ResourceManagement.hpp"
#include "SceneAssetAnimation.hpp"
extern "C" {
#include "PolyvoxFilamentApi.h"
@@ -30,121 +28,88 @@ namespace polyvox {
using namespace utils;
using namespace std;
class SceneAsset {
friend class SceneAssetLoader;
public:
SceneAsset(FilamentAsset* asset, Engine* engine, NameComponentManager* ncm, LoadResource loadResource, FreeResource freeResource);
~SceneAsset();
unique_ptr<vector<string>> getMorphTargetNames(const char* meshName);
unique_ptr<vector<string>> getAnimationNames();
///
///
///
void loadTexture(const char* resourcePath, int renderableIndex);
void setTexture();
///
/// Update the bone/morph target animations to reflect the current frame (if applicable).
///
void updateAnimations();
///
/// Immediately stop the animation at the specified index. Noop if no animation is playing.
///
void stopAnimation(int index);
///
/// Play the embedded animation (i.e. animation node embedded in the GLTF asset) under the specified index. If [loop] is true, the animation will repeat indefinitely.
///
void playAnimation(int index, bool loop, bool reverse);
void setAnimationFrame(int animationIndex, int animationFrame);
///
/// 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(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].
/// The duration of each "frame" is specified by [frameLengthInMs] (i.e. this is not the framerate of the renderer).
/// [morphData] is a contiguous chunk of floats whose length will be (numMorphWeights * numFrames).
/// [boneData] is a contiguous chunk of floats whose length will be (numBones * 7 * numFrames) (where 7 is 3 floats for translation, 4 for quat rotation).
/// [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,
int numBoneAnimations,
int numFrames,
float frameLengthInMs
);
size_t getBoneIndex(const char* name);
Entity getNode(const char* name);
void transformToUnitCube();
void setScale(float scale);
void setPosition(float x, float y, float z);
void setRotation(float rads, float x, float y, float z);
const utils::Entity* getCameraEntities();
size_t getCameraEntityCount();
const Entity* getLightEntities() const noexcept;
size_t getLightEntityCount() const noexcept;
private:
FilamentAsset* _asset = nullptr;
Engine* _engine = nullptr;
NameComponentManager* _ncm;
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;
// animation flags;
unique_ptr<RuntimeAnimation> _runtimeAnimationBuffer;
vector<GLTFAnimation> _embeddedAnimationStatus;
LoadResource _loadResource;
FreeResource _freeResource;
// a slot to preload textures
filament::Texture* _texture = nullptr;
// initialized to identity
math::mat4f _position;
// initialized to identity
math::mat4f _rotation;
float _scale = 1;
void updateTransform();
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
struct AnimationStatus {
time_point_t mStart = time_point_t::max();
bool mLoop = false;
bool mReverse = false;
float mDuration = 0;
int mFrameNumber = -1;
};
//
// Use this to manually construct a buffer of frame data for morph animations.
//
struct MorphAnimationBuffer {
utils::EntityInstance<RenderableManager>* mInstance = nullptr;
int mNumFrames = -1;
float mFrameLengthInMs = 0;
vector<float> mFrameData;
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.
//
struct BoneAnimationBuffer {
int mNumFrames = -1;
float mFrameLengthInMs = 0;
vector<BoneAnimationData> mAnimations;
};
struct SceneAsset {
FilamentAsset* mAsset = nullptr;
Animator* mAnimator = nullptr;
// animation flags;
bool mAnimating = false;
// fixed-sized vector containing the status of the morph, bone and GLTF animations.
// entries 0 and 1 are the morph/bone animations.
// subsequent entries are the GLTF animations.
vector<AnimationStatus> mAnimations;
MorphAnimationBuffer mMorphAnimationBuffer;
BoneAnimationBuffer mBoneAnimationBuffer;
// a slot to preload textures
filament::Texture* mTexture = nullptr;
// initialized to identity
math::mat4f mPosition;
// initialized to identity
math::mat4f mRotation;
float mScale = 1;
SceneAsset(
FilamentAsset* asset
) : mAsset(asset) {
mAnimator = mAsset->getInstance()->getAnimator();
mAnimations.resize(2 + mAnimator->getAnimationCount());
for(int i=2; i < mAnimations.size(); i++) {
mAnimations[i].mDuration = mAnimator->getAnimationDuration(i-2);
}
}
};
}

View File

@@ -1,118 +0,0 @@
#ifndef SCENE_ASSET_ANIMATION_H_
#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;
//
// Holds the current state of a GLTF animation.
// Whenever a SceneAsset is created, an instance of GLTFAnimation will be created for every embedded animation.
// On each frame loop, we check if [play] is true, and if so, advance the animation to the correct frame based on [startedAt].
// The [GLTFAnimation] will persist for the lifetime of the SceneAsset.
//
struct GLTFAnimation {
GLTFAnimation(bool loop, bool reverse) : loop(loop), reverse(reverse) {}
//
// A flag that is checked each frame to determine whether or not the animation should play.
//
bool play = false;
//
// If [play] is true, this flag will be checked when the animation is complete. If true, the animation will restart.
//
bool loop = false;
//
// If true, the animation will be played in reverse.
//
bool reverse = false;
//
// If [play] is true, this flag will be set to true when the animation is started.
//
bool started = false;
//
// The index of the animation in the GLTF asset.
//
int animationIndex = -1;
//
// The time point at which this animation was last started.
// This is used to calculate the "animation time offset" that is passed to the Animator.
//
time_point_t startedAt;
};
///
/// 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 {
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(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),
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

View File

@@ -1,47 +0,0 @@
#pragma once
#include <filament/Scene.h>
#include <gltfio/AssetLoader.h>
#include <gltfio/FilamentAsset.h>
#include <gltfio/ResourceLoader.h>
#include "ResourceManagement.hpp"
#include "SceneAsset.hpp"
#include "ResourceBuffer.hpp"
namespace polyvox {
using namespace filament;
using namespace filament::gltfio;
using namespace utils;
class SceneAssetLoader {
public:
SceneAssetLoader(
LoadResource loadResource,
FreeResource freeResource,
MaterialProvider* materialProvider,
EntityManager* entityManager,
ResourceLoader* resourceLoader,
NameComponentManager* ncm,
Engine* engine,
Scene* scene);
~SceneAssetLoader();
SceneAsset* fromGltf(const char* uri, const char* relativeResourcePath);
SceneAsset* fromGlb(const char* uri);
void remove(SceneAsset* asset);
void destroyAll();
private:
LoadResource _loadResource;
FreeResource _freeResource;
AssetLoader* _assetLoader;
ResourceLoader* _resourceLoader;
NameComponentManager* _ncm;
Engine* _engine;
Scene* _scene;
vector<SceneAsset*> _assets;
};
}

32
ios/include/TimeIt.hpp Normal file
View File

@@ -0,0 +1,32 @@
#ifndef TIMEIT_H_
#define TIMEIT_H_
#pragma once
#if __cplusplus <= 199711L
#include <ctime>
#else
#include <chrono>
#endif
class Timer
{
public:
Timer() { reset(); }
void reset();
double elapsed();
private:
#if __cplusplus <= 199711L
timespec beg_, end_;
#else
typedef std::chrono::high_resolution_clock clock_;
typedef std::chrono::duration<double, std::ratio<1> > second_;
std::chrono::time_point<clock_> beg_;
#endif
};
#endif // TIMEIT_H_

View File

@@ -4,6 +4,10 @@
#include <filament/Texture.h>
#include <filament/TextureSampler.h>
#include <math/mat4.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <math/mat3.h>
#include <math/norm.h>
namespace polyvox {
class FileMaterialProvider : public MaterialProvider {
@@ -36,9 +40,8 @@ namespace polyvox {
return hasTexture ? int(uvmap->at(srcIndex)) - 1 : -1;
};
Log("CREATING MATERIAL INSTANCE");
auto instance = _m->createInstance();
mat3f identity;
math::mat3f identity;
instance->setParameter("baseColorUvMatrix", identity);
instance->setParameter("normalUvMatrix", identity);

View File

@@ -1,5 +1,8 @@
#ifndef UNLIT_MATERIAL_PROVIDER
#define UNLIT_MATERIAL_PROVIDER
#include "material/unlit_opaque.h"
namespace polyvox {
class UnlitMaterialProvider : public MaterialProvider {