This commit is contained in:
Nick Fisher
2024-03-01 22:48:39 +08:00
parent 9295059885
commit 6c6bcfe7a4
30 changed files with 1432 additions and 1052 deletions

View File

@@ -73,9 +73,14 @@ extern "C"
FLUTTER_PLUGIN_EXPORT EntityId add_light(const void *const viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
FLUTTER_PLUGIN_EXPORT void remove_light(const void *const viewer, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void clear_lights(const void *const viewer);
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void *sceneManager, const char *assetPath, bool unlit);
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void *sceneManager, const char *assetPath, int numInstances);
FLUTTER_PLUGIN_EXPORT EntityId load_glb_from_buffer(void *sceneManager, const void* const data, size_t length);
FLUTTER_PLUGIN_EXPORT EntityId load_gltf(void *sceneManager, const char *assetPath, const char *relativePath);
FLUTTER_PLUGIN_EXPORT EntityId create_instance(void *sceneManager, EntityId id);
FLUTTER_PLUGIN_EXPORT int get_instance_count(void *sceneManager, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void get_instances(void *sceneManager, EntityId entityId, EntityId *out);
FLUTTER_PLUGIN_EXPORT void set_main_camera(const void *const viewer);
FLUTTER_PLUGIN_EXPORT EntityId get_main_camera(const void *const viewer);
FLUTTER_PLUGIN_EXPORT bool set_camera(const void *const viewer, EntityId asset, const char *nodeName);
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void *const viewer, bool enabled);
FLUTTER_PLUGIN_EXPORT void render(
@@ -159,7 +164,7 @@ extern "C"
FLUTTER_PLUGIN_EXPORT void set_camera_exposure(const void *const viewer, float aperture, float shutterSpeed, float sensitivity);
FLUTTER_PLUGIN_EXPORT void set_camera_position(const void *const viewer, float x, float y, float z);
FLUTTER_PLUGIN_EXPORT void get_camera_position(const void *const viewer);
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(const void *const viewer, float rads, float x, float y, float z);
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(const void *const viewer, float w, float x, float y, float z);
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void *const viewer, const float *const matrix);
FLUTTER_PLUGIN_EXPORT const double *const get_camera_model_matrix(const void *const viewer);
FLUTTER_PLUGIN_EXPORT const double *const get_camera_view_matrix(const void *const viewer);

View File

@@ -38,34 +38,36 @@ FLUTTER_PLUGIN_EXPORT void remove_ibl_ffi(void* const viewer);
FLUTTER_PLUGIN_EXPORT EntityId add_light_ffi(void* const viewer, uint8_t type, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
FLUTTER_PLUGIN_EXPORT void remove_light_ffi(void* const viewer, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void clear_lights_ffi(void* const viewer);
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void* const assetManager, const char *assetPath, bool unlit);
FLUTTER_PLUGIN_EXPORT EntityId load_gltf_ffi(void* const assetManager, const char *assetPath, const char *relativePath);
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void* const sceneManager, const char *assetPath, int numInstances);
FLUTTER_PLUGIN_EXPORT EntityId load_glb_from_buffer_ffi(void* const sceneManager, const void* const data, size_t length, int numInstances);
FLUTTER_PLUGIN_EXPORT EntityId load_gltf_ffi(void* const sceneManager, const char *assetPath, const char *relativePath);
FLUTTER_PLUGIN_EXPORT EntityId create_instance_ffi(void* const sceneManager, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void remove_entity_ffi(void* const viewer, EntityId asset);
FLUTTER_PLUGIN_EXPORT void clear_entities_ffi(void* const viewer);
FLUTTER_PLUGIN_EXPORT bool set_camera_ffi(void* const viewer, EntityId asset, const char *nodeName);
FLUTTER_PLUGIN_EXPORT void apply_weights_ffi(
void* const assetManager,
void* const sceneManager,
EntityId asset,
const char *const entityName,
float *const weights,
int count
);
FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void* const assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void* const assetManager, EntityId asset, int animationIndex, int animationFrame);
FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void* const assetManager, EntityId asset, int index);
FLUTTER_PLUGIN_EXPORT int get_animation_count_ffi(void* const assetManager, EntityId asset);
FLUTTER_PLUGIN_EXPORT void get_animation_name_ffi(void* const assetManager, EntityId asset, char *const outPtr, int index);
FLUTTER_PLUGIN_EXPORT void get_morph_target_name_ffi(void* const assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count_ffi(void* const assetManager, EntityId asset, const char *meshName);
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights_ffi(void* const assetManager,
FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void* const sceneManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void* const sceneManager, EntityId asset, int animationIndex, int animationFrame);
FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void* const sceneManager, EntityId asset, int index);
FLUTTER_PLUGIN_EXPORT int get_animation_count_ffi(void* const sceneManager, EntityId asset);
FLUTTER_PLUGIN_EXPORT void get_animation_name_ffi(void* const sceneManager, EntityId asset, char *const outPtr, int index);
FLUTTER_PLUGIN_EXPORT void get_morph_target_name_ffi(void* const sceneManager, EntityId asset, const char *meshName, char *const outPtr, int index);
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count_ffi(void* const sceneManager, EntityId asset, const char *meshName);
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights_ffi(void* const sceneManager,
EntityId asset,
const char *const entityName,
const float *const morphData,
int numWeights
);
FLUTTER_PLUGIN_EXPORT bool set_morph_animation_ffi(
void *assetManager,
void *sceneManager,
EntityId asset,
const char *const entityName,
const float *const morphData,
@@ -74,13 +76,13 @@ FLUTTER_PLUGIN_EXPORT bool set_morph_animation_ffi(
int numFrames,
float frameLengthInMs);
FLUTTER_PLUGIN_EXPORT bool set_bone_transform_ffi(
void *assetManager,
void *sceneManager,
EntityId asset,
const char *entityName,
const float *const transform,
const char *boneName);
FLUTTER_PLUGIN_EXPORT void add_bone_animation_ffi(
void *assetManager,
void *sceneManager,
EntityId asset,
const float *const frameData,
int numFrames,
@@ -91,7 +93,7 @@ FLUTTER_PLUGIN_EXPORT void add_bone_animation_ffi(
bool isModelSpace);
FLUTTER_PLUGIN_EXPORT void set_post_processing_ffi(void* const viewer, bool enabled);
FLUTTER_PLUGIN_EXPORT void pick_ffi(void* const viewer, int x, int y, EntityId* entityId);
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose_ffi(void* const assetManager, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose_ffi(void* const sceneManager, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi();
FLUTTER_PLUGIN_EXPORT EntityId create_geometry_ffi(void* const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, const char* materialPath);

View File

@@ -1,93 +0,0 @@
#pragma once
#include "Log.hpp"
#include <filament/Engine.h>
#include <filament/RenderableManager.h>
#include <filament/Renderer.h>
#include <filament/Scene.h>
#include <filament/Texture.h>
#include <filament/TransformManager.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <math/mat3.h>
#include <math/norm.h>
#include <gltfio/Animator.h>
#include <gltfio/AssetLoader.h>
#include <gltfio/ResourceLoader.h>
#include <utils/NameComponentManager.h>
extern "C" {
#include "FlutterFilamentApi.h"
}
template class std::vector<float>;
namespace polyvox {
using namespace filament;
using namespace filament::gltfio;
using namespace utils;
using namespace std;
typedef std::chrono::time_point<std::chrono::high_resolution_clock> time_point_t;
enum AnimationType {
MORPH, BONE, GLTF
};
struct AnimationStatus {
time_point_t start = time_point_t::max();
bool loop = false;
bool reverse = false;
float durationInSecs = 0;
};
struct GltfAnimation : AnimationStatus {
int index = -1;
};
//
// Use this to construct a dynamic (i.e. non-glTF embedded) morph target animation.
//
struct MorphAnimation : AnimationStatus {
utils::Entity meshTarget;
int numFrames = -1;
float frameLengthInMs = 0;
vector<float> frameData;
vector<int> morphIndices;
int lengthInFrames;
};
//
// Use this to construct a dynamic (i.e. non-glTF embedded) bone/joint animation.
//
struct BoneAnimation : AnimationStatus {
size_t boneIndex;
vector<utils::Entity> meshTargets;
size_t skinIndex = 0;
int lengthInFrames;
float frameLengthInMs = 0;
vector<math::mat4f> frameData;
};
struct SceneAsset {
FilamentAsset* asset = nullptr;
vector<math::mat4f> initialJointTransforms;
vector<GltfAnimation> gltfAnimations;
vector<MorphAnimation> morphAnimations;
vector<BoneAnimation> boneAnimations;
// the index of the last active glTF animation,
// used to cross-fade
int fadeGltfAnimationIndex = -1;
float fadeDuration = 0.0f;
float fadeOutAnimationStart = 0.0f;
// a slot to preload textures
filament::Texture* texture = nullptr;
SceneAsset(
FilamentAsset* asset
) : asset(asset) {}
};
}

View File

@@ -1,41 +1,64 @@
#pragma once
#include <mutex>
#include <vector>
#include <memory>
#include <map>
#include <filament/Scene.h>
#include <gltfio/AssetLoader.h>
#include <gltfio/FilamentAsset.h>
#include <gltfio/FilamentInstance.h>
#include <gltfio/ResourceLoader.h>
#include "SceneAsset.hpp"
#include "utils/NameComponentManager.h"
#include "ResourceBuffer.hpp"
#include "components/StandardComponents.h"
#include "components/CollisionComponentManager.hpp"
#include "components/AnimationComponentManager.hpp"
typedef int32_t EntityId;
#include "tsl/robin_map.h"
namespace polyvox
namespace flutter_filament
{
typedef int32_t EntityId;
using namespace filament;
using namespace filament::gltfio;
using namespace utils;
using std::vector;
using std::unique_ptr;
using std::string;
class SceneManager
{
public:
SceneManager(const ResourceLoaderWrapper *const loader,
NameComponentManager *ncm,
Engine *engine,
Scene *scene,
const char *uberArchivePath);
~SceneManager();
EntityId loadGltf(const char *uri, const char *relativeResourcePath);
EntityId loadGlb(const char *uri, bool unlit);
FilamentAsset *getAssetByEntityId(EntityId entityId);
////
/// @brief
/// @param uri
/// @param numInstances
/// @return an Entity representing the FilamentAsset associated with the loaded FilamentAsset.
///
EntityId loadGlb(const char *uri, int numInstances);
EntityId loadGlbFromBuffer(const uint8_t* data, size_t length, int numInstances=1);
EntityId createInstance(EntityId entityId);
void remove(EntityId entity);
void destroyAll();
unique_ptr<vector<string>> getAnimationNames(EntityId entity);
float getAnimationDuration(EntityId entity, int animationIndex);
unique_ptr<vector<string>> getMorphTargetNames(EntityId entity, const char *meshName);
unique_ptr<vector<string>> getMorphTargetNames(EntityId entity, const char *name);
void transformToUnitCube(EntityId e);
inline void updateTransform(EntityId e);
void setScale(EntityId e, float scale);
@@ -45,8 +68,8 @@ namespace polyvox
void queueRotationUpdate(EntityId e, float rads, float x, float y, float z, float w, bool relative);
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;
const utils::Entity *getLightEntities(EntityId e) noexcept;
size_t getLightEntityCount(EntityId e) noexcept;
void updateAnimations();
void updateTransforms();
void testCollisions(EntityId entity);
@@ -107,29 +130,48 @@ namespace polyvox
void addCollisionComponent(EntityId entity, void (*onCollisionCallback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform);
void removeCollisionComponent(EntityId entityId);
void setParent(EntityId child, EntityId parent);
void addAnimatableComponent(EntityId entity);
/// @brief returns the number of instances of the FilamentAsset represented by the given entity.
/// @param entityId
/// @return
int getInstanceCount(EntityId entityId);
/// @brief returns an array containing all instances of the FilamentAsset represented by the given entity.
/// @param entityId
/// @return
void getInstances(EntityId entityId, EntityId* out);
friend class FilamentViewer;
private:
AssetLoader *_assetLoader = nullptr;
gltfio::AssetLoader *_assetLoader = nullptr;
const ResourceLoaderWrapper *const _resourceLoaderWrapper;
NameComponentManager *_ncm = nullptr;
Engine *_engine;
Scene *_scene;
MaterialProvider *_ubershaderProvider = nullptr;
gltfio::MaterialProvider *_ubershaderProvider = nullptr;
gltfio::ResourceLoader *_gltfResourceLoader = nullptr;
gltfio::TextureProvider *_stbDecoder = nullptr;
gltfio::TextureProvider *_ktxDecoder = nullptr;
std::mutex _mutex;
vector<SceneAsset> _assets;
tsl::robin_map<EntityId, int> _entityIdLookup;
tsl::robin_map<EntityId, std::tuple<math::float3,bool,math::quatf,bool,float>> _transformUpdates;
std::vector<EntityId> _nonTransformableCollidableEntities;
utils::NameComponentManager* _ncm;
tsl::robin_map<
EntityId,
gltfio::FilamentInstance*> _instances;
tsl::robin_map<EntityId, gltfio::FilamentAsset*> _assets;
tsl::robin_map<EntityId, std::tuple<math::float3,bool,math::quatf,bool,float>> _transformUpdates;
AnimationComponentManager* _animationComponentManager = nullptr;
CollisionComponentManager* _collisionComponentManager = nullptr;
gltfio::FilamentInstance* getInstanceByEntityId(EntityId entityId);
gltfio::FilamentAsset* getAssetByEntityId(EntityId entityId);
utils::Entity findEntityByName(
SceneAsset asset,
const gltfio::FilamentInstance* instance,
const char *entityName);
};

View File

@@ -5,9 +5,8 @@
#include <cassert>
#include <cstring>
namespace polyvox {
namespace flutter_filament {
using namespace std;
//
// A generic adapter to expose any contiguous section of memory as a std::streambuf.
@@ -20,15 +19,15 @@ namespace polyvox {
~StreamBufferAdapter() {
}
streamsize size();
std::streamsize size();
private:
int_type uflow() override;
int_type underflow() override;
int_type pbackfail(int_type ch) override;
streampos seekoff(streamoff off, ios_base::seekdir way, ios_base::openmode which) override;
streampos seekpos(streampos sp, ios_base::openmode which) override;
streamsize showmanyc() override;
std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which) override;
std::streampos seekpos(std::streampos sp, std::ios_base::openmode which) override;
std::streamsize showmanyc() override;
};

View File

@@ -91,11 +91,6 @@
#include "TimeIt.hpp"
#include "ThreadPool.hpp"
using namespace filament;
using namespace filament::math;
using namespace gltfio;
using namespace utils;
using namespace image;
namespace filament
{
@@ -103,9 +98,18 @@ namespace filament
class LightManager;
} // namespace filament
namespace polyvox
namespace flutter_filament
{
using namespace filament;
using namespace filament::math;
using namespace gltfio;
using namespace utils;
using namespace image;
using namespace std::chrono;
using std::string;
// const float kAperture = 1.0f;
// const float kShutterSpeed = 1.0f;
// const float kSensitivity = 50.0f;
@@ -135,6 +139,8 @@ namespace polyvox
_engine = Engine::create(Engine::Backend::OPENGL, (backend::Platform *)platform, (void *)sharedContext, nullptr);
#endif
_engine->setAutomaticInstancingEnabled(true);
_renderer = _engine->createRenderer();
_frameInterval = 1000.0f / 60.0f;
@@ -151,6 +157,7 @@ namespace polyvox
Log("Main camera created");
_view = _engine->createView();
Log("View created");
setToneMapping(ToneMapping::ACES);
@@ -200,15 +207,11 @@ namespace polyvox
_view->setDynamicResolutionOptions(options);
setAntiAliasing(false, true, false);
EntityManager &em = EntityManager::get();
_ncm = new NameComponentManager(em);
_sceneManager = new SceneManager(
_resourceLoaderWrapper,
_ncm,
_engine,
_scene,
uberArchivePath);
@@ -339,7 +342,7 @@ namespace polyvox
int32_t FilamentViewer::addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows)
{
auto light = EntityManager::get().create();
LightManager::Builder(t)
auto builder = LightManager::Builder(t)
.color(Color::cct(colour))
.intensity(intensity)
.position(math::float3(posX, posY, posZ))
@@ -377,7 +380,7 @@ namespace polyvox
_lights.clear();
}
static bool endsWith(string path, string ending)
static bool endsWith(std::string path, std::string ending)
{
return path.compare(path.length() - ending.length(), ending.length(), ending) == 0;
}
@@ -435,7 +438,7 @@ namespace polyvox
void FilamentViewer::loadPngTexture(string path, ResourceBuffer rb)
{
polyvox::StreamBufferAdapter sb((char *)rb.data, (char *)rb.data + rb.size);
flutter_filament::StreamBufferAdapter sb((char *)rb.data, (char *)rb.data + rb.size);
std::istream inputStream(&sb);
@@ -480,7 +483,7 @@ namespace polyvox
void FilamentViewer::loadTextureFromPath(string path)
{
string ktxExt(".ktx");
std::string ktxExt(".ktx");
string ktx2Ext(".ktx2");
string pngExt(".png");
@@ -802,10 +805,22 @@ namespace polyvox
cam.setFocusDistance(_cameraFocusDistance);
}
///
///
///
void FilamentViewer::setMainCamera() {
_view->setCamera(_mainCamera);
}
///
///
///
EntityId FilamentViewer::getMainCamera() {
return Entity::smuggle(_mainCamera->getEntity());
}
///
/// Sets the active camera to the GLTF camera node specified by [name] (or if null, the first camera found under that node).
/// N.B. Blender will generally export a three-node hierarchy -
@@ -832,18 +847,16 @@ namespace polyvox
utils::Entity target;
if (!cameraName)
{
auto inst = _ncm->getInstance(cameras[0]);
const char *name = _ncm->getName(inst);
{
target = cameras[0];
const char *name = asset->getName(target);
Log("No camera specified, using first camera node found (%s)", name);
}
else
{
for (int j = 0; j < count; j++)
{
auto inst = _ncm->getInstance(cameras[j]);
const char *name = _ncm->getName(inst);
const char *name = asset->getName(cameras[j]);
if (strcmp(name, cameraName) == 0)
{
target = cameras[j];
@@ -1138,7 +1151,7 @@ namespace polyvox
std::string filename = stringStream.str();
ofstream wf(filename, ios::out | ios::binary);
std::ofstream wf(filename, std::ios::out | std::ios::binary);
LinearImage image(toLinearWithAlpha<uint8_t>(vp.width, vp.height, vp.width * 4,
static_cast<uint8_t *>(buf)));
@@ -1228,7 +1241,7 @@ namespace polyvox
Camera &cam = _view->getCamera();
_cameraPosition = math::mat4f::translation(math::float3(x, y, z));
cam.setModelMatrix(_cameraPosition * _cameraRotation);
cam.setModelMatrix(_cameraRotation * _cameraPosition);
}
void FilamentViewer::moveCameraToAsset(EntityId entityId)
@@ -1249,11 +1262,11 @@ namespace polyvox
Log("Moved camera to %f %f %f, lookAt %f %f %f, near %f far %f", eye[0], eye[1], eye[2], lookAt[0], lookAt[1], lookAt[2], cam.getNear(), cam.getCullingFar());
}
void FilamentViewer::setCameraRotation(float rads, float x, float y, float z)
void FilamentViewer::setCameraRotation(float w, float x, float y, float z)
{
Camera &cam = _view->getCamera();
_cameraRotation = math::mat4f::rotation(rads, math::float3(x, y, z));
cam.setModelMatrix(_cameraPosition * _cameraRotation);
_cameraRotation = math::mat4f(math::quatf(w, x, y, z));
cam.setModelMatrix(_cameraRotation * _cameraPosition);
}
void FilamentViewer::setCameraModelMatrix(const float *const matrix)
@@ -1455,7 +1468,10 @@ namespace polyvox
void FilamentViewer::pick(uint32_t x, uint32_t y, EntityId *entityId)
{
_view->pick(x, y, [=](filament::View::PickingQueryResult const &result)
{ *entityId = Entity::smuggle(result.renderable); });
{
*entityId = Entity::smuggle(result.renderable);
});
}
EntityId FilamentViewer::createGeometry(float *vertices, uint32_t numVertices, uint16_t *indices, uint32_t numIndices, const char* materialPath)
@@ -1523,4 +1539,4 @@ namespace polyvox
return Entity::smuggle(renderable);
}
} // namespace polyvox
} // namespace flutter_filament

View File

@@ -8,7 +8,7 @@
#include <thread>
#include <functional>
using namespace polyvox;
using namespace flutter_filament;
extern "C"
{
@@ -114,9 +114,26 @@ extern "C"
((FilamentViewer *)viewer)->clearLights();
}
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void *sceneManager, const char *assetPath, bool unlit)
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void *sceneManager, const char *assetPath, int numInstances)
{
return ((SceneManager *)sceneManager)->loadGlb(assetPath, unlit);
return ((SceneManager *)sceneManager)->loadGlb(assetPath, numInstances);
}
FLUTTER_PLUGIN_EXPORT EntityId load_glb_from_buffer(void *sceneManager, const void* const data, size_t length)
{
return ((SceneManager *)sceneManager)->loadGlbFromBuffer((const uint8_t*)data, length);
}
FLUTTER_PLUGIN_EXPORT EntityId create_instance(void *sceneManager, EntityId entityId) {
return ((SceneManager *)sceneManager)->createInstance(entityId);
}
FLUTTER_PLUGIN_EXPORT int get_instance_count(void *sceneManager, EntityId entityId) {
return ((SceneManager*)sceneManager)->getInstanceCount(entityId);
}
FLUTTER_PLUGIN_EXPORT void get_instances(void *sceneManager, EntityId entityId, EntityId *out) {
return ((SceneManager*)sceneManager)->getInstances(entityId, out);
}
FLUTTER_PLUGIN_EXPORT EntityId load_gltf(void *sceneManager, const char *assetPath, const char *relativePath)
@@ -129,6 +146,12 @@ extern "C"
return ((FilamentViewer *)viewer)->setMainCamera();
}
FLUTTER_PLUGIN_EXPORT EntityId get_main_camera(const void *const viewer)
{
return ((FilamentViewer *)viewer)->getMainCamera();
}
FLUTTER_PLUGIN_EXPORT bool set_camera(const void *const viewer, EntityId asset, const char *nodeName)
{
return ((FilamentViewer *)viewer)->setCamera(asset, nodeName);
@@ -236,9 +259,9 @@ extern "C"
((FilamentViewer *)viewer)->setCameraPosition(x, y, z);
}
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(const void *const viewer, float rads, float x, float y, float z)
FLUTTER_PLUGIN_EXPORT void set_camera_rotation(const void *const viewer, float w, float x, float y, float z)
{
((FilamentViewer *)viewer)->setCameraRotation(rads, x, y, z);
((FilamentViewer *)viewer)->setCameraRotation(w, x, y, z);
}
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void *const viewer, const float *const matrix)
@@ -448,20 +471,20 @@ extern "C"
int index)
{
auto names = ((SceneManager *)sceneManager)->getAnimationNames(asset);
string name = names->at(index);
std::string name = names->at(index);
strcpy(outPtr, name.c_str());
}
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void *sceneManager, EntityId asset, const char *meshName)
{
unique_ptr<vector<string>> names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName);
std::unique_ptr<std::vector<std::string>> names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName);
return (int)names->size();
}
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void *sceneManager, EntityId asset, const char *meshName, char *const outPtr, int index)
{
unique_ptr<vector<string>> names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName);
string name = names->at(index);
std::unique_ptr<std::vector<std::string>> names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName);
std::string name = names->at(index);
strcpy(outPtr, name.c_str());
}
@@ -572,7 +595,7 @@ extern "C"
FLUTTER_PLUGIN_EXPORT EntityId find_child_entity_by_name(void *const sceneManager, const EntityId parent, const char* name) {
auto entity = ((SceneManager*)sceneManager)->findChildEntityByName(parent, name);
return Entity::smuggle(entity);
return utils::Entity::smuggle(entity);
}
FLUTTER_PLUGIN_EXPORT void set_parent(void *const sceneManager, EntityId child, EntityId parent) {

View File

@@ -31,7 +31,7 @@ extern "C"
#include <pthread.h>
#endif
using namespace polyvox;
using namespace flutter_filament;
using namespace std::chrono_literals;
class RenderLoop {
@@ -262,21 +262,30 @@ set_background_color_ffi(void *const viewer, const float r, const float g,
fut.wait();
}
FLUTTER_PLUGIN_EXPORT EntityId load_gltf_ffi(void *const assetManager,
FLUTTER_PLUGIN_EXPORT EntityId load_gltf_ffi(void *const sceneManager,
const char *path,
const char *relativeResourcePath) {
std::packaged_task<EntityId()> lambda([&]() mutable {
return load_gltf(assetManager, path, relativeResourcePath);
return load_gltf(sceneManager, path, relativeResourcePath);
});
auto fut = _rl->add_task(lambda);
fut.wait();
return fut.get();
}
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void *const assetManager,
const char *path, bool unlit) {
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void *const sceneManager,
const char *path, int numInstances) {
std::packaged_task<EntityId()> lambda(
[&]() mutable { return load_glb(assetManager, path, unlit); });
[&]() mutable { return load_glb(sceneManager, path, numInstances); });
auto fut = _rl->add_task(lambda);
fut.wait();
return fut.get();
}
FLUTTER_PLUGIN_EXPORT EntityId load_glb_from_buffer_ffi(void *const sceneManager,
const void *const data, size_t length, int numInstances) {
std::packaged_task<EntityId()> lambda(
[&]() mutable { return load_glb_from_buffer(sceneManager, data, length); });
auto fut = _rl->add_task(lambda);
fut.wait();
return fut.get();
@@ -388,20 +397,20 @@ FLUTTER_PLUGIN_EXPORT bool set_camera_ffi(void *const viewer, EntityId asset,
}
FLUTTER_PLUGIN_EXPORT void
get_morph_target_name_ffi(void *assetManager, EntityId asset,
get_morph_target_name_ffi(void *sceneManager, EntityId asset,
const char *meshName, char *const outPtr, int index) {
std::packaged_task<void()> lambda([&] {
get_morph_target_name(assetManager, asset, meshName, outPtr, index);
get_morph_target_name(sceneManager, asset, meshName, outPtr, index);
});
auto fut = _rl->add_task(lambda);
fut.wait();
}
FLUTTER_PLUGIN_EXPORT int
get_morph_target_name_count_ffi(void *assetManager, EntityId asset,
get_morph_target_name_count_ffi(void *sceneManager, EntityId asset,
const char *meshName) {
std::packaged_task<int()> lambda([&] {
return get_morph_target_name_count(assetManager, asset, meshName);
return get_morph_target_name_count(sceneManager, asset, meshName);
});
auto fut = _rl->add_task(lambda);
fut.wait();
@@ -410,52 +419,52 @@ get_morph_target_name_count_ffi(void *assetManager, EntityId asset,
FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void *const assetManager,
FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void *const sceneManager,
EntityId asset, int index,
bool loop, bool reverse,
bool replaceActive,
float crossfade) {
std::packaged_task<void()> lambda([&] {
play_animation(assetManager, asset, index, loop, reverse, replaceActive,
play_animation(sceneManager, asset, index, loop, reverse, replaceActive,
crossfade);
});
auto fut = _rl->add_task(lambda);
fut.wait();
}
FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void *const assetManager,
FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void *const sceneManager,
EntityId asset,
int animationIndex,
int animationFrame) {
std::packaged_task<void()> lambda([&] {
set_animation_frame(assetManager, asset, animationIndex, animationFrame);
set_animation_frame(sceneManager, asset, animationIndex, animationFrame);
});
auto fut = _rl->add_task(lambda);
fut.wait();
}
FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void *const assetManager,
FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void *const sceneManager,
EntityId asset, int index) {
std::packaged_task<void()> lambda(
[&] { stop_animation(assetManager, asset, index); });
[&] { stop_animation(sceneManager, asset, index); });
auto fut = _rl->add_task(lambda);
fut.wait();
}
FLUTTER_PLUGIN_EXPORT int get_animation_count_ffi(void *const assetManager,
FLUTTER_PLUGIN_EXPORT int get_animation_count_ffi(void *const sceneManager,
EntityId asset) {
std::packaged_task<int()> lambda(
[&] { return get_animation_count(assetManager, asset); });
[&] { return get_animation_count(sceneManager, asset); });
auto fut = _rl->add_task(lambda);
fut.wait();
return fut.get();
}
FLUTTER_PLUGIN_EXPORT void get_animation_name_ffi(void *const assetManager,
FLUTTER_PLUGIN_EXPORT void get_animation_name_ffi(void *const sceneManager,
EntityId asset,
char *const outPtr,
int index) {
std::packaged_task<void()> lambda(
[&] { get_animation_name(assetManager, asset, outPtr, index); });
[&] { get_animation_name(sceneManager, asset, outPtr, index); });
auto fut = _rl->add_task(lambda);
fut.wait();
}
@@ -476,27 +485,27 @@ FLUTTER_PLUGIN_EXPORT void pick_ffi(void *const viewer, int x, int y,
}
FLUTTER_PLUGIN_EXPORT const char *
get_name_for_entity_ffi(void *const assetManager, const EntityId entityId) {
get_name_for_entity_ffi(void *const sceneManager, const EntityId entityId) {
std::packaged_task<const char *()> lambda(
[&] { return get_name_for_entity(assetManager, entityId); });
[&] { return get_name_for_entity(sceneManager, entityId); });
auto fut = _rl->add_task(lambda);
fut.wait();
return fut.get();
}
void set_morph_target_weights_ffi(void *const assetManager,
void set_morph_target_weights_ffi(void *const sceneManager,
EntityId asset,
const char *const entityName,
const float *const morphData,
int numWeights) {
std::packaged_task<void()> lambda(
[&] { return set_morph_target_weights(assetManager, asset, entityName, morphData, numWeights); });
[&] { return set_morph_target_weights(sceneManager, asset, entityName, morphData, numWeights); });
auto fut = _rl->add_task(lambda);
fut.wait();
}
bool set_morph_animation_ffi(
void *assetManager,
void *sceneManager,
EntityId asset,
const char *const entityName,
const float *const morphData,
@@ -506,7 +515,7 @@ bool set_morph_animation_ffi(
float frameLengthInMs) {
std::packaged_task<bool()> lambda(
[&] {
return set_morph_animation(assetManager, asset, entityName, morphData, morphIndices, numMorphTargets, numFrames, frameLengthInMs);
return set_morph_animation(sceneManager, asset, entityName, morphData, morphIndices, numMorphTargets, numFrames, frameLengthInMs);
});
auto fut = _rl->add_task(lambda);
fut.wait();
@@ -515,27 +524,27 @@ bool set_morph_animation_ffi(
FLUTTER_PLUGIN_EXPORT bool set_bone_transform_ffi(
void *assetManager,
void *sceneManager,
EntityId asset,
const char *entityName,
const float *const transform,
const char *boneName) {
std::packaged_task<bool()> lambda(
[&] { return set_bone_transform(assetManager, asset, entityName, transform, boneName); });
[&] { return set_bone_transform(sceneManager, asset, entityName, transform, boneName); });
auto fut = _rl->add_task(lambda);
fut.wait();
return fut.get();
}
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose_ffi(void* const assetManager, EntityId entityId) {
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose_ffi(void* const sceneManager, EntityId entityId) {
std::packaged_task<void()> lambda(
[&] { return reset_to_rest_pose(assetManager, entityId); });
[&] { return reset_to_rest_pose(sceneManager, entityId); });
auto fut = _rl->add_task(lambda);
fut.wait();
}
FLUTTER_PLUGIN_EXPORT void add_bone_animation_ffi(
void *assetManager,
void *sceneManager,
EntityId asset,
const float *const frameData,
int numFrames,
@@ -547,7 +556,7 @@ FLUTTER_PLUGIN_EXPORT void add_bone_animation_ffi(
std::packaged_task<void()> lambda(
[=] {
add_bone_animation(assetManager, asset, frameData, numFrames, boneName, meshNames, numMeshTargets, frameLengthInMs, isModelSpace);
add_bone_animation(sceneManager, asset, frameData, numFrames, boneName, meshNames, numMeshTargets, frameLengthInMs, isModelSpace);
});
auto fut = _rl->add_task(lambda);
fut.wait();

File diff suppressed because it is too large Load Diff

View File

@@ -3,9 +3,7 @@
#include <cassert>
#include <cstring>
using namespace std;
namespace polyvox {
namespace flutter_filament {
class StreamBufferAdapter : public std::streambuf
{
@@ -14,14 +12,14 @@ class StreamBufferAdapter : public std::streambuf
~StreamBufferAdapter() {
}
streamsize size();
std::streamsize size();
private:
int_type uflow() override;
int_type underflow() override;
int_type pbackfail(int_type ch) override;
streampos seekoff(streamoff off, ios_base::seekdir way, ios_base::openmode which) override;
streampos seekpos(streampos sp, ios_base::openmode which) override;
std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which) override;
std::streampos seekpos(std::streampos sp, std::ios_base::openmode which) override;
std::streamsize showmanyc() override;
};
@@ -31,11 +29,11 @@ StreamBufferAdapter::StreamBufferAdapter(const char *begin, const char *end)
setg((char*)begin, (char*)begin, (char*)end);
}
streamsize StreamBufferAdapter::size() {
std::streamsize StreamBufferAdapter::size() {
return egptr() - eback();
}
streambuf::int_type StreamBufferAdapter::underflow()
std::streambuf::int_type StreamBufferAdapter::underflow()
{
if (gptr() == egptr()) {
return traits_type::eof();
@@ -43,7 +41,7 @@ streambuf::int_type StreamBufferAdapter::underflow()
return *(gptr());
}
streambuf::int_type StreamBufferAdapter::uflow()
std::streambuf::int_type StreamBufferAdapter::uflow()
{
if (gptr() == egptr()) {
return traits_type::eof();
@@ -53,7 +51,7 @@ streambuf::int_type StreamBufferAdapter::uflow()
return *(gptr());
}
streambuf::int_type StreamBufferAdapter::pbackfail(int_type ch)
std::streambuf::int_type StreamBufferAdapter::pbackfail(int_type ch)
{
if (gptr() == eback() || (ch != traits_type::eof() && ch != gptr()[-1]))
return traits_type::eof();
@@ -61,15 +59,15 @@ streambuf::int_type StreamBufferAdapter::pbackfail(int_type ch)
return *(gptr());
}
streamsize StreamBufferAdapter::showmanyc()
std::streamsize StreamBufferAdapter::showmanyc()
{
return egptr() - gptr();
}
streampos StreamBufferAdapter::seekoff(streamoff off, ios_base::seekdir way, ios_base::openmode which = ios_base::in) {
if(way == ios_base::beg) {
std::streampos StreamBufferAdapter::seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in) {
if(way == std::ios_base::beg) {
setg(eback(), eback()+off, egptr());
} else if(way == ios_base::cur) {
} else if(way == std::ios_base::cur) {
gbump(off);
} else {
setg(eback(), egptr()-off, egptr());
@@ -77,7 +75,7 @@ streampos StreamBufferAdapter::seekoff(streamoff off, ios_base::seekdir way, ios
return gptr() - eback();
}
streampos StreamBufferAdapter::seekpos(streampos sp, ios_base::openmode which = ios_base::in) {
std::streampos StreamBufferAdapter::seekpos(std::streampos sp, std::ios_base::openmode which = std::ios_base::in) {
return seekoff(sp - pos_type(off_type(0)), std::ios_base::beg, which);
}
}