Android, iOS, macOS supported
This commit is contained in:
@@ -21,13 +21,11 @@
|
||||
#include "Log.hpp"
|
||||
#include "AssetManager.hpp"
|
||||
|
||||
#include "material/UnlitMaterialProvider.hpp"
|
||||
#include "material/FileMaterialProvider.hpp"
|
||||
#include "gltfio/materials/uberarchive.h"
|
||||
|
||||
extern "C" {
|
||||
#include "material/image.h"
|
||||
#include "material/unlit_opaque.h"
|
||||
}
|
||||
|
||||
namespace polyvox {
|
||||
@@ -54,20 +52,19 @@ _scene(scene) {
|
||||
_gltfResourceLoader = new ResourceLoader({.engine = _engine,
|
||||
.normalizeSkinningWeights = true });
|
||||
|
||||
// auto uberdata = resourceLoaderWrapper->load("packages/polyvox_filament/assets/materials_ios_arm64.uberz");
|
||||
|
||||
// _ubershaderProvider = gltfio::createUbershaderProvider(
|
||||
// _engine, uberdata.data, uberdata.size);
|
||||
// TODO - allow passing uberz archive
|
||||
// e.g. auto uberArchivePath = "packages/polyvox_filament/assets/default.uberz"
|
||||
// auto uberdata = resourceLoaderWrapper->load(uberArchivePath);
|
||||
// if (!uberdata.data) {
|
||||
// Log("Failed to load ubershader material. This is fatal.");
|
||||
// }
|
||||
// _ubershaderProvider = gltfio::createUbershaderProvider(_engine, uberdata.data, uberdata.size);
|
||||
_ubershaderProvider = gltfio::createUbershaderProvider(
|
||||
_engine, UBERARCHIVE_DEFAULT_DATA, UBERARCHIVE_DEFAULT_SIZE);
|
||||
// _ubershaderProvider = gltfio::createJitShaderProvider(_engine, true);
|
||||
_engine, UBERARCHIVE_DEFAULT_DATA, UBERARCHIVE_DEFAULT_SIZE);
|
||||
Log("Created ubershader provider.");
|
||||
|
||||
EntityManager &em = EntityManager::get();
|
||||
|
||||
//_unlitProvider = new UnlitMaterialProvider(_engine);
|
||||
|
||||
// auto rb = _resourceLoaderWrapper->load("file:///mnt/hdd_2tb/home/hydroxide/projects/polyvox/flutter/polyvox_filament/materials/toon.filamat");
|
||||
// auto toonProvider = new FileMaterialProvider(_engine, rb.data, (size_t) rb.size);
|
||||
|
||||
|
||||
_assetLoader = AssetLoader::create({_engine, _ubershaderProvider, _ncm, &em });
|
||||
_gltfResourceLoader->addTextureProvider("image/ktx2", _ktxDecoder);
|
||||
_gltfResourceLoader->addTextureProvider("image/png", _stbDecoder);
|
||||
@@ -77,7 +74,6 @@ _scene(scene) {
|
||||
AssetManager::~AssetManager() {
|
||||
_gltfResourceLoader->asyncCancelLoad();
|
||||
_ubershaderProvider->destroyMaterials();
|
||||
//_unlitProvider->destroyMaterials();
|
||||
destroyAll();
|
||||
AssetLoader::destroy(&_assetLoader);
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
#include "TargetConditionals.h"
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
@@ -20,6 +23,7 @@
|
||||
*/
|
||||
#include <filament/Camera.h>
|
||||
#include <backend/DriverEnums.h>
|
||||
#include <backend/platforms/OpenGLPlatform.h>
|
||||
#include <filament/ColorGrading.h>
|
||||
#include <filament/Engine.h>
|
||||
#include <filament/IndexBuffer.h>
|
||||
@@ -107,15 +111,17 @@ static constexpr float4 sFullScreenTriangleVertices[3] = {
|
||||
|
||||
static const uint16_t sFullScreenTriangleIndices[3] = {0, 1, 2};
|
||||
|
||||
FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper* const resourceLoaderWrapper)
|
||||
FilamentViewer::FilamentViewer(const void* sharedContext, const ResourceLoaderWrapper* const resourceLoaderWrapper, void* const platform)
|
||||
: _resourceLoaderWrapper(resourceLoaderWrapper) {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
ASSERT_POSTCONDITION(platform == nullptr, "Custom Platform not supported on iOS");
|
||||
_engine = Engine::create(Engine::Backend::METAL);
|
||||
#elif TARGET_OS_OSX
|
||||
ASSERT_POSTCONDITION(platform == nullptr, "Custom Platform not supported on macOS");
|
||||
_engine = Engine::create(Engine::Backend::METAL);
|
||||
#else
|
||||
_engine = Engine::create(Engine::Backend::OPENGL); //L, nullptr, (void*)context, nullptr);
|
||||
_engine = Engine::create(Engine::Backend::OPENGL, (backend::Platform*)platform, (void*)sharedContext, nullptr);
|
||||
#endif
|
||||
|
||||
_renderer = _engine->createRenderer();
|
||||
@@ -137,10 +143,15 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper*
|
||||
|
||||
Log("Main camera created");
|
||||
_view = _engine->createView();
|
||||
_view->setPostProcessingEnabled(false);
|
||||
Log("View created");
|
||||
|
||||
setToneMapping(ToneMapping::ACES);
|
||||
|
||||
Log("Set tone mapping");
|
||||
|
||||
setBloom(0.6f);
|
||||
Log("Set bloom");
|
||||
|
||||
_view->setScene(_scene);
|
||||
_view->setCamera(_mainCamera);
|
||||
@@ -149,7 +160,7 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper*
|
||||
_mainCamera->setLensProjection(_cameraFocalLength, 1.0f, kNearPlane,
|
||||
kFarPlane);
|
||||
// _mainCamera->setExposure(kAperture, kShutterSpeed, kSensitivity);
|
||||
|
||||
Log("View created");
|
||||
const float aperture = _mainCamera->getAperture();
|
||||
const float shutterSpeed = _mainCamera->getShutterSpeed();
|
||||
const float sens = _mainCamera->getSensitivity();
|
||||
@@ -189,14 +200,18 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper*
|
||||
.format(Texture::InternalFormat::RGB16F)
|
||||
.sampler(Texture::Sampler::SAMPLER_2D)
|
||||
.build(*_engine);
|
||||
|
||||
_imageMaterial =
|
||||
Material::Builder()
|
||||
.package(IMAGE_PACKAGE, IMAGE_IMAGE_SIZE)
|
||||
.build(*_engine);
|
||||
_imageMaterial->setDefaultParameter("showImage",0);
|
||||
_imageMaterial->setDefaultParameter("backgroundColor", RgbaType::sRGB, float4(0.5f, 0.5f, 0.5f, 1.0f));
|
||||
_imageMaterial->setDefaultParameter("image", _imageTexture, _imageSampler);
|
||||
try {
|
||||
_imageMaterial =
|
||||
Material::Builder()
|
||||
.package(IMAGE_IMAGE_DATA, IMAGE_IMAGE_SIZE)
|
||||
.build(*_engine);
|
||||
_imageMaterial->setDefaultParameter("showImage",0);
|
||||
_imageMaterial->setDefaultParameter("backgroundColor", RgbaType::sRGB, float4(0.5f, 0.5f, 0.5f, 1.0f));
|
||||
_imageMaterial->setDefaultParameter("image", _imageTexture, _imageSampler);
|
||||
} catch(...) {
|
||||
Log("Failed to load background image material provider");
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
_imageScale = mat4f { 1.0f , 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
_imageMaterial->setDefaultParameter("transform", _imageScale);
|
||||
@@ -402,16 +417,14 @@ void FilamentViewer::loadTextureFromPath(string path) {
|
||||
} else if(endsWith(path, pngExt)) {
|
||||
loadPngTexture(path, rb);
|
||||
}
|
||||
|
||||
_resourceLoaderWrapper->free(rb);
|
||||
|
||||
}
|
||||
|
||||
void FilamentViewer::setBackgroundColor(const float r, const float g, const float b, const float a) {
|
||||
_imageMaterial->setDefaultParameter("showImage", 0);
|
||||
_imageMaterial->setDefaultParameter("backgroundColor", RgbaType::sRGB, float4(r, g, b, a));
|
||||
const Viewport& vp = _view->getViewport();
|
||||
_imageMaterial->setDefaultParameter("transform", _imageScale);
|
||||
_imageMaterial->setDefaultParameter("transform", _imageScale);
|
||||
}
|
||||
|
||||
void FilamentViewer::clearBackgroundImage() {
|
||||
@@ -560,11 +573,12 @@ void FilamentViewer::createSwapChain(const void *window, uint32_t width, uint32_
|
||||
#else
|
||||
if(window) {
|
||||
_swapChain = _engine->createSwapChain((void*)window, filament::backend::SWAP_CHAIN_CONFIG_TRANSPARENT | filament::backend::SWAP_CHAIN_CONFIG_READABLE);
|
||||
Log("Created window swapchain.");
|
||||
} else {
|
||||
Log("Created headless swapchain.");
|
||||
_swapChain = _engine->createSwapChain(width, height, filament::backend::SWAP_CHAIN_CONFIG_TRANSPARENT | filament::backend::SWAP_CHAIN_CONFIG_READABLE);
|
||||
}
|
||||
#endif
|
||||
Log("Swapchain created.");
|
||||
#endif
|
||||
}
|
||||
|
||||
void FilamentViewer::createRenderTarget(intptr_t texture, uint32_t width, uint32_t height) {
|
||||
@@ -582,7 +596,7 @@ void FilamentViewer::createRenderTarget(intptr_t texture, uint32_t width, uint32
|
||||
.height(height)
|
||||
.levels(1)
|
||||
.usage(filament::Texture::Usage::DEPTH_ATTACHMENT)
|
||||
.format(filament::Texture::InternalFormat::DEPTH24)
|
||||
.format(filament::Texture::InternalFormat::DEPTH32F)
|
||||
.build(*_engine);
|
||||
_rt = filament::RenderTarget::Builder()
|
||||
.texture(RenderTarget::AttachmentPoint::COLOR, _rtColor)
|
||||
@@ -812,7 +826,11 @@ void FilamentViewer::loadIbl(const char *const iblPath, float intensity) {
|
||||
double _elapsed = 0;
|
||||
int _frameCount = 0;
|
||||
|
||||
void FilamentViewer::render(uint64_t frameTimeInNanos) {
|
||||
void FilamentViewer::render(
|
||||
uint64_t frameTimeInNanos,
|
||||
void* pixelBuffer,
|
||||
void (*callback)(void *buf, size_t size, void *data),
|
||||
void* data) {
|
||||
|
||||
if (!_view || !_mainCamera || !_swapChain) {
|
||||
Log("Not ready for rendering");
|
||||
@@ -832,12 +850,24 @@ void FilamentViewer::render(uint64_t frameTimeInNanos) {
|
||||
_elapsed += tmr.elapsed();
|
||||
_frameCount++;
|
||||
|
||||
// Render the scene, unless the renderer wants to skip the frame.
|
||||
if (_renderer->beginFrame(_swapChain, frameTimeInNanos)) {
|
||||
if(pixelBuffer) {
|
||||
auto pbd = Texture::PixelBufferDescriptor(
|
||||
pixelBuffer, size_t(1024 * 768 * 4),
|
||||
Texture::Format::RGBA,
|
||||
Texture::Type::BYTE, nullptr, callback, data);
|
||||
|
||||
_renderer->beginFrame(_swapChain, 0);
|
||||
_renderer->render(_view);
|
||||
_renderer->readPixels(0,0,1024,768, std::move(pbd));
|
||||
_renderer->endFrame();
|
||||
} else {
|
||||
// skipped frame
|
||||
// Render the scene, unless the renderer wants to skip the frame.
|
||||
if (_renderer->beginFrame(_swapChain, frameTimeInNanos)) {
|
||||
_renderer->render(_view);
|
||||
_renderer->endFrame();
|
||||
} else {
|
||||
// skipped frame
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -865,6 +895,10 @@ void FilamentViewer::updateViewportAndCameraProjection(
|
||||
contentScaleFactor);
|
||||
}
|
||||
|
||||
void FilamentViewer::setViewFrustumCulling(bool enabled) {
|
||||
_view->setFrustumCullingEnabled(enabled);
|
||||
}
|
||||
|
||||
void FilamentViewer::setCameraPosition(float x, float y, float z) {
|
||||
Camera& cam =_view->getCamera();
|
||||
|
||||
@@ -872,10 +906,6 @@ void FilamentViewer::setCameraPosition(float x, float y, float z) {
|
||||
cam.setModelMatrix(_cameraPosition * _cameraRotation);
|
||||
}
|
||||
|
||||
void FilamentViewer::setViewFrustumCulling(bool enabled) {
|
||||
_view->setFrustumCullingEnabled(enabled);
|
||||
}
|
||||
|
||||
void FilamentViewer::moveCameraToAsset(EntityId entityId) {
|
||||
auto asset = _assetManager->getAssetByEntityId(entityId);
|
||||
if(!asset) {
|
||||
@@ -938,18 +968,15 @@ void FilamentViewer::grabUpdate(float x, float y) {
|
||||
return;
|
||||
}
|
||||
Camera& cam =_view->getCamera();
|
||||
auto eye = cam.getPosition();// math::float3 {0.0f, 0.5f, 50.0f } ;// ; //
|
||||
auto eye = cam.getPosition();
|
||||
auto target = eye + cam.getForwardVector();
|
||||
auto upward = cam.getUpVector();
|
||||
Viewport const& vp = _view->getViewport();
|
||||
if(_panning) {
|
||||
auto trans = cam.getModelMatrix() * mat4::translation(math::float3 { 10 * (x - _startX) / vp.width, 10 * (y - _startY) / vp.height, 0.0f });
|
||||
auto trans = cam.getModelMatrix() * mat4::translation(math::float3 { 50 * (x - _startX) / vp.width, 50 * (y - _startY) / vp.height, 0.0f });
|
||||
cam.setModelMatrix(trans);
|
||||
} else {
|
||||
auto trans = cam.getModelMatrix() * mat4::rotation(
|
||||
|
||||
0.01,
|
||||
// math::float3 { 0.0f, 1.0f, 0.0f });
|
||||
auto trans = cam.getModelMatrix() * mat4::rotation(0.05,
|
||||
math::float3 { (y - _startY) / vp.height, (x - _startX) / vp.width, 0.0f });
|
||||
cam.setModelMatrix(trans);
|
||||
}
|
||||
|
||||
@@ -10,17 +10,15 @@
|
||||
|
||||
using namespace polyvox;
|
||||
|
||||
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT const void* create_filament_viewer(const void* context, const ResourceLoaderWrapper* const loader) {
|
||||
return (const void*) new FilamentViewer(context, loader);
|
||||
FLUTTER_PLUGIN_EXPORT const void* create_filament_viewer(const void* context, const ResourceLoaderWrapper* const loader, void* const platform) {
|
||||
return (const void*) new FilamentViewer(context, loader, platform);
|
||||
}
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT ResourceLoaderWrapper* make_resource_loader(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void* const owner) {
|
||||
return new ResourceLoaderWrapper(loadFn, freeFn, owner);
|
||||
}
|
||||
@@ -34,7 +32,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_color(const void* const viewer, const float r, const float g, const float b, const float a) {
|
||||
((FilamentViewer*)viewer)->setBackgroundColor(r, g, b, a);
|
||||
((FilamentViewer*)viewer)->setBackgroundColor(r, g, b, a);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image(const void* const viewer) {
|
||||
@@ -45,56 +43,56 @@ extern "C" {
|
||||
((FilamentViewer*)viewer)->setBackgroundImage(path, fillHeight);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position(const void* const viewer, float x, float y, bool clamp) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position(const void* const viewer, float x, float y, bool clamp) {
|
||||
((FilamentViewer*)viewer)->setBackgroundImagePosition(x, y, clamp);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping(const void* const viewer, int toneMapping) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping(const void* const viewer, int toneMapping) {
|
||||
((FilamentViewer*)viewer)->setToneMapping((ToneMapping)toneMapping);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_bloom(const void* const viewer, float strength) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_bloom(const void* const viewer, float strength) {
|
||||
Log("Setting bloom to %f", strength);
|
||||
((FilamentViewer*)viewer)->setBloom(strength);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void load_skybox(const void* const viewer, const char* skyboxPath) {
|
||||
FLUTTER_PLUGIN_EXPORT void load_skybox(const void* const viewer, const char* skyboxPath) {
|
||||
((FilamentViewer*)viewer)->loadSkybox(skyboxPath);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void load_ibl(const void* const viewer, const char* iblPath, float intensity) {
|
||||
FLUTTER_PLUGIN_EXPORT void load_ibl(const void* const viewer, const char* iblPath, float intensity) {
|
||||
((FilamentViewer*)viewer)->loadIbl(iblPath, intensity);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->removeSkybox();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->removeIbl();
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
return ((FilamentViewer*)viewer)->addLight((LightManager::Type)type, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_light(const void* const viewer, int32_t entityId) {
|
||||
FLUTTER_PLUGIN_EXPORT void remove_light(const void* const viewer, int32_t entityId) {
|
||||
((FilamentViewer*)viewer)->removeLight(entityId);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->clearLights();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void* assetManager, const char* assetPath, bool unlit) {
|
||||
EntityId load_glb(void* assetManager, const char* assetPath, bool unlit) {
|
||||
return ((AssetManager*)assetManager)->loadGlb(assetPath, unlit);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_gltf(void* assetManager, const char* assetPath, const char* relativePath) {
|
||||
EntityId load_gltf(void* assetManager, const char* assetPath, const char* relativePath) {
|
||||
return ((AssetManager*)assetManager)->loadGltf(assetPath, relativePath);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT bool set_camera(const void* const viewer, EntityId asset, const char* nodeName) {
|
||||
bool set_camera(const void* const viewer, EntityId asset, const char* nodeName) {
|
||||
return ((FilamentViewer*)viewer)->setCamera(asset, nodeName);
|
||||
}
|
||||
|
||||
@@ -106,85 +104,87 @@ extern "C" {
|
||||
((FilamentViewer*)viewer)->moveCameraToAsset(asset);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float distance) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float distance) {
|
||||
((FilamentViewer*)viewer)->setCameraFocusDistance(distance);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_exposure(const void* const viewer, float aperture, float shutterSpeed, float sensitivity) {
|
||||
((FilamentViewer*)viewer)->setCameraExposure(aperture, shutterSpeed, sensitivity);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_position(const void* const viewer, float x, float y, float z) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_position(const void* const viewer, float x, float y, float z) {
|
||||
((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 rads, float x, float y, float z) {
|
||||
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void* const viewer, const float* const matrix) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void* const viewer, const float* const matrix) {
|
||||
((FilamentViewer*)viewer)->setCameraModelMatrix(matrix);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void* const viewer, float focalLength) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void* const viewer, float focalLength) {
|
||||
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void render(
|
||||
const void* const viewer,
|
||||
uint64_t frameTimeInNanos
|
||||
) {
|
||||
((FilamentViewer*)viewer)->render(frameTimeInNanos);
|
||||
uint64_t frameTimeInNanos,
|
||||
void* pixelBuffer,
|
||||
void (*callback)(void *buf, size_t size, void *data),
|
||||
void* data) {
|
||||
((FilamentViewer*)viewer)->render(frameTimeInNanos, pixelBuffer, callback, data);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval(
|
||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval(
|
||||
const void* const viewer,
|
||||
float frameInterval
|
||||
) {
|
||||
((FilamentViewer*)viewer)->setFrameInterval(frameInterval);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->destroySwapChain();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain(const void* const viewer, const void* const window, uint32_t width, uint32_t height) {
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain(const void* const viewer, const void* const window, uint32_t width, uint32_t height) {
|
||||
((FilamentViewer*)viewer)->createSwapChain(window, width, height);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection(const void* const viewer, uint32_t width, uint32_t height, float scaleFactor) {
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection(const void* const viewer, uint32_t width, uint32_t height, float scaleFactor) {
|
||||
return ((FilamentViewer*)viewer)->updateViewportAndCameraProjection(width, height, scaleFactor);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_update(const void* const viewer, float x, float y, float delta) {
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_update(const void* const viewer, float x, float y, float delta) {
|
||||
((FilamentViewer*)viewer)->scrollUpdate(x, y, delta);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_begin(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_begin(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->scrollBegin();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_end(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_end(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->scrollEnd();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void grab_begin(const void* const viewer, float x, float y, bool pan) {
|
||||
FLUTTER_PLUGIN_EXPORT void grab_begin(const void* const viewer, float x, float y, bool pan) {
|
||||
((FilamentViewer*)viewer)->grabBegin(x, y, pan);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void grab_update(const void* const viewer, float x, float y) {
|
||||
FLUTTER_PLUGIN_EXPORT void grab_update(const void* const viewer, float x, float y) {
|
||||
((FilamentViewer*)viewer)->grabUpdate(x, y);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void grab_end(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void grab_end(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->grabEnd();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void* get_asset_manager(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void * get_asset_manager(const void* const viewer) {
|
||||
return (void*)((FilamentViewer*)viewer)->getAssetManager();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void apply_weights(
|
||||
FLUTTER_PLUGIN_EXPORT void apply_weights(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char* const entityName,
|
||||
@@ -193,7 +193,7 @@ extern "C" {
|
||||
// ((AssetManager*)assetManager)->setMorphTargetWeights(asset, entityName, weights, count);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights(
|
||||
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char* const entityName,
|
||||
@@ -211,7 +211,7 @@ extern "C" {
|
||||
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT bool set_morph_animation(
|
||||
bool set_morph_animation(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char* const entityName,
|
||||
@@ -232,7 +232,7 @@ extern "C" {
|
||||
);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_bone_animation(
|
||||
FLUTTER_PLUGIN_EXPORT void set_bone_animation(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const float* const frameData,
|
||||
@@ -284,7 +284,7 @@ extern "C" {
|
||||
// }
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation(
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
int index,
|
||||
@@ -295,7 +295,7 @@ extern "C" {
|
||||
((AssetManager*)assetManager)->playAnimation(asset, index, loop, reverse, replaceActive, crossfade);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame(
|
||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
int animationIndex,
|
||||
@@ -304,18 +304,18 @@ extern "C" {
|
||||
}
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT float get_animation_duration(void* assetManager, EntityId asset, int animationIndex) {
|
||||
float get_animation_duration(void* assetManager, EntityId asset, int animationIndex) {
|
||||
return ((AssetManager*)assetManager)->getAnimationDuration(asset, animationIndex);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int get_animation_count(
|
||||
int get_animation_count(
|
||||
void* assetManager,
|
||||
EntityId asset) {
|
||||
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
||||
return (int)names->size();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void get_animation_name(
|
||||
FLUTTER_PLUGIN_EXPORT void get_animation_name(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
char* const outPtr,
|
||||
@@ -331,17 +331,17 @@ extern "C" {
|
||||
return (int)names->size();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void* assetManager, EntityId asset, const char* meshName, char* const outPtr, int index ) {
|
||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void* assetManager, EntityId asset, const char* meshName, char* const outPtr, int index ) {
|
||||
unique_ptr<vector<string>> names = ((AssetManager*)assetManager)->getMorphTargetNames(asset, meshName);
|
||||
string name = names->at(index);
|
||||
strcpy(outPtr, name.c_str());
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_asset(const void* const viewer, EntityId asset) {
|
||||
FLUTTER_PLUGIN_EXPORT void remove_asset(const void* const viewer, EntityId asset) {
|
||||
((FilamentViewer*)viewer)->removeAsset(asset);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets(const void* const viewer) {
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->clearAssets();
|
||||
}
|
||||
|
||||
@@ -349,35 +349,35 @@ extern "C" {
|
||||
return ((AssetManager*)assetManager)->setMaterialColor(asset, meshName, materialIndex, r, g, b, a);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId asset) {
|
||||
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId asset) {
|
||||
((AssetManager*)assetManager)->transformToUnitCube(asset);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void* assetManager, EntityId asset, float x, float y, float z) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void* assetManager, EntityId asset, float x, float y, float z) {
|
||||
((AssetManager*)assetManager)->setPosition(asset, x, y, z);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z) {
|
||||
((AssetManager*)assetManager)->setRotation(asset, rads, x, y, z);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_scale(void* assetManager, EntityId asset, float scale) {
|
||||
FLUTTER_PLUGIN_EXPORT void set_scale(void* assetManager, EntityId asset, float scale) {
|
||||
((AssetManager*)assetManager)->setScale(asset, scale);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void stop_animation(void* assetManager, EntityId asset, int index) {
|
||||
FLUTTER_PLUGIN_EXPORT void stop_animation(void* assetManager, EntityId asset, int index) {
|
||||
((AssetManager*)assetManager)->stopAnimation(asset, index);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||
int hide_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||
return ((AssetManager*)assetManager)->hide(asset, meshName);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||
int reveal_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||
return ((AssetManager*)assetManager)->reveal(asset, meshName);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy() {
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy() {
|
||||
Log("Dummy called");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include "PolyvoxFilamentFFIApi.h"
|
||||
}
|
||||
|
||||
#include "FilamentViewer.hpp"
|
||||
#include "filament/LightManager.h"
|
||||
@@ -10,8 +13,6 @@
|
||||
|
||||
using namespace polyvox;
|
||||
|
||||
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
class RenderLoop
|
||||
{
|
||||
public:
|
||||
@@ -27,15 +28,12 @@ public:
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_access);
|
||||
if(_tasks.empty()) {
|
||||
_cond.wait_for(lock, std::chrono::duration<int, std::milli>(_frameIntervalInMilliseconds));
|
||||
_cond.wait_for(lock, std::chrono::duration<float, std::milli>(_frameIntervalInMilliseconds));
|
||||
continue;
|
||||
}
|
||||
task = std::move(_tasks.front());
|
||||
_tasks.pop_front();
|
||||
// std::this_thread::sleep_for(
|
||||
// std::chrono::milliseconds(_frameIntervalInMilliseconds));
|
||||
_tasks.pop_front();
|
||||
}
|
||||
|
||||
task();
|
||||
} });
|
||||
}
|
||||
@@ -45,16 +43,22 @@ public:
|
||||
_t->join();
|
||||
}
|
||||
|
||||
void *const createViewer(void *const context, const ResourceLoaderWrapper *const loader, void (*renderCallback)(void *), void *const owner)
|
||||
{
|
||||
void* const createViewer(
|
||||
void* const context,
|
||||
void* const platform,
|
||||
const ResourceLoaderWrapper* const loader,
|
||||
void (*renderCallback)(void*), void* const owner
|
||||
) {
|
||||
_renderCallback = renderCallback;
|
||||
_renderCallbackOwner = owner;
|
||||
std::packaged_task<FilamentViewer *const()> lambda([&]() mutable
|
||||
{ return new FilamentViewer(context, loader); });
|
||||
std::packaged_task<FilamentViewer*()> lambda([&]() mutable
|
||||
{
|
||||
return new FilamentViewer(context, loader, platform);
|
||||
});
|
||||
auto fut = add_task(lambda);
|
||||
fut.wait();
|
||||
_viewer = fut.get();
|
||||
return (void *const)_viewer;
|
||||
return (void* const)_viewer;
|
||||
}
|
||||
|
||||
void setRendering(bool rendering)
|
||||
@@ -64,10 +68,14 @@ public:
|
||||
|
||||
void doRender()
|
||||
{
|
||||
render(_viewer, 0);
|
||||
render(_viewer, 0, nullptr, nullptr, nullptr);
|
||||
_renderCallback(_renderCallbackOwner);
|
||||
}
|
||||
|
||||
void setFrameIntervalInMilliseconds(float frameIntervalInMilliseconds) {
|
||||
_frameIntervalInMilliseconds = frameIntervalInMilliseconds;
|
||||
}
|
||||
|
||||
template <class Rt>
|
||||
auto add_task(std::packaged_task<Rt()> &pt) -> std::future<Rt>
|
||||
{
|
||||
@@ -82,10 +90,10 @@ public:
|
||||
private:
|
||||
bool _stop = false;
|
||||
bool _rendering = false;
|
||||
int _frameIntervalInMilliseconds = 1000 / 60;
|
||||
float _frameIntervalInMilliseconds = 1000.0 / 60.0;
|
||||
std::mutex _access;
|
||||
FilamentViewer *_viewer = nullptr;
|
||||
void (*_renderCallback)(void *const) = nullptr;
|
||||
void (*_renderCallback)(void* const) = nullptr;
|
||||
void *_renderCallbackOwner = nullptr;
|
||||
std::thread *_t = nullptr;
|
||||
std::condition_variable _cond;
|
||||
@@ -94,28 +102,34 @@ private:
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
|
||||
static RenderLoop *_rl;
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void *const create_filament_viewer_ffi(void *const context, const ResourceLoaderWrapper *const loader, void (*renderCallback)(void *const renderCallbackOwner), void *const renderCallbackOwner)
|
||||
{
|
||||
FLUTTER_PLUGIN_EXPORT void* const create_filament_viewer_ffi(
|
||||
void* const context,
|
||||
void* const platform,
|
||||
const ResourceLoaderWrapper* const loader,
|
||||
void (*renderCallback)(void* const renderCallbackOwner),
|
||||
void* const renderCallbackOwner) {
|
||||
if (!_rl)
|
||||
{
|
||||
_rl = new RenderLoop();
|
||||
}
|
||||
return _rl->createViewer(context, loader, renderCallback, renderCallbackOwner);
|
||||
return _rl->createViewer(context, platform, loader, renderCallback, renderCallbackOwner);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void *const viewer, void *const surface, uint32_t width, uint32_t height)
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height)
|
||||
{
|
||||
Log("Creating swapchain %dx%d", width, height);
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ create_swap_chain(viewer, surface, width, height); });
|
||||
{
|
||||
create_swap_chain(viewer, surface, width, height);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void *const viewer, uint32_t nativeTextureId, uint32_t width, uint32_t height)
|
||||
FLUTTER_PLUGIN_EXPORT void create_render_target_ffi(void* const viewer, uint32_t nativeTextureId, uint32_t width, uint32_t height)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ create_render_target(viewer, nativeTextureId, width, height); });
|
||||
@@ -123,15 +137,18 @@ extern "C"
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection_ffi(void *const viewer, const uint32_t width, const uint32_t height, const float scaleFactor)
|
||||
FLUTTER_PLUGIN_EXPORT void update_viewport_and_camera_projection_ffi(void* const viewer, const uint32_t width, const uint32_t height, const float scaleFactor)
|
||||
{
|
||||
Log("Update viewport %dx%d", width, height);
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ update_viewport_and_camera_projection(viewer, width, height, scaleFactor); });
|
||||
{
|
||||
update_viewport_and_camera_projection(viewer, width, height, scaleFactor);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_rendering_ffi(void *const viewer, bool rendering)
|
||||
FLUTTER_PLUGIN_EXPORT void set_rendering_ffi(void* const viewer, bool rendering)
|
||||
{
|
||||
if (!_rl)
|
||||
{
|
||||
@@ -151,15 +168,21 @@ extern "C"
|
||||
}
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void *const viewer)
|
||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval_ffi(float frameIntervalInMilliseconds) {
|
||||
_rl->setFrameIntervalInMilliseconds(frameIntervalInMilliseconds);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ _rl->doRender(); });
|
||||
{
|
||||
_rl->doRender();
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_color_ffi(void *const viewer, const float r, const float g, const float b, const float a)
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_color_ffi(void* const viewer, const float r, const float g, const float b, const float a)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ set_background_color(viewer, r, g, b, a); });
|
||||
@@ -167,80 +190,84 @@ extern "C"
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void *const assetManager, const char *path)
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void* const assetManager, const char *path, bool unlit)
|
||||
{
|
||||
std::packaged_task<EntityId()> lambda([&]() mutable
|
||||
{ return load_glb(assetManager, path, false); });
|
||||
{ return load_glb(assetManager, path, unlit); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image_ffi(void *const viewer)
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image_ffi(void* const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ clear_background_image(viewer); });
|
||||
{
|
||||
clear_background_image(viewer);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_ffi(void *const viewer, const char *path, bool fillHeight)
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_ffi(void* const viewer, const char *path, bool fillHeight)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ set_background_image(viewer, path, fillHeight); });
|
||||
{
|
||||
set_background_image(viewer, path, fillHeight);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position_ffi(void *const viewer, float x, float y, bool clamp)
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image_position_ffi(void* const viewer, float x, float y, bool clamp)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ set_background_image_position(viewer, x, y, clamp); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping_ffi(void *const viewer, int toneMapping)
|
||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping_ffi(void* const viewer, int toneMapping)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ set_tone_mapping(viewer, toneMapping); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_bloom_ffi(void *const viewer, float strength)
|
||||
FLUTTER_PLUGIN_EXPORT void set_bloom_ffi(void* const viewer, float strength)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ set_bloom(viewer, strength); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void load_skybox_ffi(void *const viewer, const char *skyboxPath)
|
||||
FLUTTER_PLUGIN_EXPORT void load_skybox_ffi(void* const viewer, const char *skyboxPath)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ load_skybox(viewer, skyboxPath); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void load_ibl_ffi(void *const viewer, const char *iblPath, float intensity)
|
||||
FLUTTER_PLUGIN_EXPORT void load_ibl_ffi(void* const viewer, const char *iblPath, float intensity)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ load_ibl(viewer, iblPath, intensity); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox_ffi(void *const viewer)
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox_ffi(void* const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ remove_skybox(viewer); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl_ffi(void *const viewer)
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl_ffi(void* const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ remove_ibl(viewer); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
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)
|
||||
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)
|
||||
{
|
||||
std::packaged_task<EntityId()> lambda([&]
|
||||
{ return add_light(viewer, type, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows); });
|
||||
@@ -248,14 +275,16 @@ extern "C"
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void remove_light_ffi(void *const viewer, EntityId entityId)
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_light_ffi(void* const viewer, EntityId entityId)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ remove_light(viewer, entityId); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights_ffi(void *const viewer)
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights_ffi(void* const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ clear_lights(viewer); });
|
||||
@@ -263,14 +292,14 @@ extern "C"
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_asset_ffi(void *const viewer, EntityId asset)
|
||||
FLUTTER_PLUGIN_EXPORT void remove_asset_ffi(void* const viewer, EntityId asset)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ remove_asset(viewer, asset); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets_ffi(void *const viewer)
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets_ffi(void* const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ clear_assets(viewer); });
|
||||
@@ -278,7 +307,7 @@ extern "C"
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT bool set_camera_ffi(void *const viewer, EntityId asset, const char *nodeName)
|
||||
FLUTTER_PLUGIN_EXPORT bool set_camera_ffi(void* const viewer, EntityId asset, const char *nodeName)
|
||||
{
|
||||
std::packaged_task<bool()> lambda([&]
|
||||
{ return set_camera(viewer, asset, nodeName); });
|
||||
@@ -324,7 +353,7 @@ extern "C"
|
||||
}
|
||||
|
||||
void set_morph_target_weights_ffi(
|
||||
void *const assetManager,
|
||||
void* const assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const morphData,
|
||||
@@ -333,28 +362,28 @@ extern "C"
|
||||
// TODO
|
||||
}
|
||||
|
||||
void play_animation_ffi(void *const assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade)
|
||||
void play_animation_ffi(void* const assetManager, 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, crossfade); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
void set_animation_frame_ffi(void *const assetManager, EntityId asset, int animationIndex, int animationFrame)
|
||||
void set_animation_frame_ffi(void* const assetManager, EntityId asset, int animationIndex, int animationFrame)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ set_animation_frame(assetManager, asset, animationIndex, animationFrame); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
void stop_animation_ffi(void *const assetManager, EntityId asset, int index)
|
||||
void stop_animation_ffi(void* const assetManager, EntityId asset, int index)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ stop_animation(assetManager, asset, index); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
int get_animation_count_ffi(void *const assetManager, EntityId asset)
|
||||
int get_animation_count_ffi(void* const assetManager, EntityId asset)
|
||||
{
|
||||
std::packaged_task<int()> lambda([&]
|
||||
{ return get_animation_count(assetManager, asset); });
|
||||
@@ -362,7 +391,7 @@ extern "C"
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
void get_animation_name_ffi(void *const assetManager, EntityId asset, char *const outPtr, int index)
|
||||
void get_animation_name_ffi(void* const assetManager, EntityId asset, char *const outPtr, int index)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&] {
|
||||
get_animation_name(assetManager, asset, outPtr, index);
|
||||
@@ -370,4 +399,8 @@ extern "C"
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi() {
|
||||
Log("Dummy called");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "TimeIt.hpp"
|
||||
|
||||
#if __cplusplus <= 199711L
|
||||
#if __cplusplus <= 199711L && !_WIN32
|
||||
|
||||
void Timer::reset()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user