more FFI work
This commit is contained in:
@@ -55,7 +55,8 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
instance.resources[resId] = nsData
|
||||
let length = nsData.length
|
||||
print("Resolved asset to file of length \(length) at path \(path!)")
|
||||
return ResourceBuffer(data:nsData.bytes, size:UInt32(nsData.count), id:UInt32(resId))
|
||||
|
||||
return ResourceBuffer(data:nsData.bytes, size:Int64(nsData.length), id:UInt32(resId))
|
||||
} catch {
|
||||
print("ERROR LOADING RESOURCE")
|
||||
}
|
||||
@@ -160,8 +161,10 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
result([
|
||||
unsafeBitCast(renderCallback, to:Int64.self), unsafeBitCast(Unmanaged.passUnretained(self), to:UInt64.self)])
|
||||
case "createTexture":
|
||||
let args = call.arguments as! Array<Int32>
|
||||
createPixelBuffer(width:Int(args[0]), height:Int(args[1]))
|
||||
let args = call.arguments as! [Any]
|
||||
let width = UInt32(args[0] as! Int64)
|
||||
let height = UInt32(args[1] as! Int64)
|
||||
createPixelBuffer(width:Int(width), height:Int(height))
|
||||
|
||||
var cvret = CVMetalTextureCacheCreate(
|
||||
kCFAllocatorDefault,
|
||||
@@ -178,14 +181,19 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
cvMetalTextureCache!,
|
||||
pixelBuffer!, nil,
|
||||
MTLPixelFormat.bgra8Unorm,
|
||||
Int(args[0]), Int(args[1]),
|
||||
Int(width), Int(height),
|
||||
0,
|
||||
&cvMetalTexture);
|
||||
metalTexture = CVMetalTextureGetTexture(cvMetalTexture!);
|
||||
// createDisplayLink()
|
||||
let pixelBufferAddress = Int(bitPattern:CVPixelBufferGetBaseAddress(pixelBuffer!));
|
||||
let metalTextureAddress = Int(bitPattern:Unmanaged.passUnretained(metalTexture!).toOpaque())
|
||||
result([self.flutterTextureId as! Any, pixelBufferAddress, metalTextureAddress])
|
||||
let pixelBufferPtr = CVPixelBufferGetBaseAddress(pixelBuffer!);
|
||||
let pixelBufferAddress = Int(bitPattern:pixelBufferPtr);
|
||||
let metalTexturePtr = Unmanaged.passUnretained(metalTexture!).toOpaque()
|
||||
let metalTextureAddress = Int(bitPattern:metalTexturePtr)
|
||||
|
||||
let callback = make_resource_loader(loadResource, freeResource, Unmanaged.passUnretained(self).toOpaque())
|
||||
|
||||
result([self.flutterTextureId as Any, nil, metalTextureAddress])
|
||||
case "destroyTexture":
|
||||
if(viewer != nil) {
|
||||
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Destroy the viewer before destroying the texture", details: nil))
|
||||
@@ -217,7 +225,7 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
|
||||
resize(width:Int32(width), height:Int32(height))
|
||||
create_swap_chain(viewer, CVPixelBufferGetBaseAddress(pixelBuffer!), width, height)
|
||||
let metalTextureId = Int(bitPattern:Unmanaged.passUnretained(metalTexture!).toOpaque())
|
||||
create_render_target(viewer, UInt32(metalTextureId), width, height);
|
||||
create_render_target(viewer, metalTextureId, width, height);
|
||||
update_viewport_and_camera_projection(viewer, width, height, Float(args[2] as! Double))
|
||||
rendering = true
|
||||
print("Resized to \(args[0])x\(args[1])")
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef int32_t EntityId;
|
||||
|
||||
const void* create_filament_viewer(const void* const context, const ResourceLoaderWrapper* const loader);
|
||||
ResourceLoaderWrapper* make_resource_loader(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void* owner);
|
||||
void destroy_filament_viewer(const void* const viewer);
|
||||
void* get_asset_manager(const void* const viewer);
|
||||
void create_render_target(const void* const viewer, uint32_t textureId, uint32_t width, uint32_t height);
|
||||
void create_render_target(const void* const viewer, intptr_t texture, uint32_t width, uint32_t height);
|
||||
void clear_background_image(const void* const viewer);
|
||||
void set_background_image(const void* const viewer, const char *path, bool fillHeight);
|
||||
void set_background_image_position(const void* const viewer, float x, float y, bool clamp);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#ifndef _POLYVOX_FILAMENT_FFI_API_H
|
||||
#define _POLYVOX_FILAMENT_FFI_API_H
|
||||
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
|
||||
///
|
||||
/// This header replicates most of the methods in PolyvoxFilamentApi.h, and is only intended to be used to generate client FFI bindings.
|
||||
/// The intention is that calling one of these methods will call its respective method in PolyvoxFilamentApi.h, but wrapped in some kind of thread runner to ensure thread safety.
|
||||
///
|
||||
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
|
||||
typedef int32_t EntityId;
|
||||
|
||||
void* const create_filament_viewer_ffi(void* const context, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void* const renderCallbackOwner), void* const renderCallbackOwner);
|
||||
@@ -33,25 +33,25 @@ void remove_light_ffi(void* const viewer, EntityId entityId);
|
||||
void clear_lights_ffi(void* const viewer);
|
||||
EntityId load_glb_ffi(void* const assetManager, const char *assetPath, bool unlit);
|
||||
EntityId load_gltf_ffi(void* const assetManager, const char *assetPath, const char *relativePath);
|
||||
void remove_asset_ffi(void* const const viewer, EntityId asset);
|
||||
void clear_assets_ffi(void* const const viewer);
|
||||
void remove_asset_ffi(void* const viewer, EntityId asset);
|
||||
void clear_assets_ffi(void* const viewer);
|
||||
bool set_camera_ffi(void* const viewer, EntityId asset, const char *nodeName);
|
||||
void apply_weights_ffi(
|
||||
void* assetManager,
|
||||
void* const assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
float *const weights,
|
||||
int count
|
||||
);
|
||||
void set_morph_target_weights_ffi(
|
||||
void* assetManager,
|
||||
void* const assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const morphData,
|
||||
int numWeights
|
||||
);
|
||||
bool set_morph_animation_ffi(
|
||||
void* assetManager,
|
||||
void* const assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const morphData,
|
||||
@@ -61,7 +61,7 @@ bool set_morph_animation_ffi(
|
||||
float frameLengthInMs);
|
||||
|
||||
void set_bone_animation_ffi(
|
||||
void* assetManager,
|
||||
void* const assetManager,
|
||||
EntityId asset,
|
||||
const float* const frameData,
|
||||
int numFrames,
|
||||
@@ -71,13 +71,13 @@ void set_bone_animation_ffi(
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs);
|
||||
|
||||
void play_animation_ffi(void* assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
void set_animation_frame_ffi(void* assetManager, EntityId asset, int animationIndex, int animationFrame);
|
||||
void stop_animation_ffi(void* assetManager, EntityId asset, int index);
|
||||
int get_animation_count_ffi(void* assetManager, EntityId asset);
|
||||
void get_animation_name_ffi(void* assetManager, EntityId asset, char *const outPtr, int index);
|
||||
float get_animation_duration_ffi(void* assetManager, EntityId asset, int index);
|
||||
void get_morph_target_name_ffi(void* assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
|
||||
int get_morph_target_name_count_ffi(void* assetManager, EntityId asset, const char *meshName);
|
||||
void play_animation_ffi(void* const assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
void set_animation_frame_ffi(void* const assetManager, EntityId asset, int animationIndex, int animationFrame);
|
||||
void stop_animation_ffi(void* const assetManager, EntityId asset, int index);
|
||||
int get_animation_count_ffi(void* const assetManager, EntityId asset);
|
||||
void get_animation_name_ffi(void* const assetManager, EntityId asset, char *const outPtr, int index);
|
||||
float get_animation_duration_ffi(void* const assetManager, EntityId asset, int index);
|
||||
void get_morph_target_name_ffi(void* const assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
|
||||
int get_morph_target_name_count_ffi(void* const assetManager, EntityId asset, const char *meshName);
|
||||
|
||||
#endif // _POLYVOX_FILAMENT_FFI_API_H
|
||||
|
||||
@@ -33,7 +33,7 @@ extern "C" {
|
||||
|
||||
#endif
|
||||
const void * const data;
|
||||
const uint32_t size;
|
||||
const int64_t size;
|
||||
const uint32_t id;
|
||||
};
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper*
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
_engine = Engine::create(Engine::Backend::METAL);
|
||||
#elif TARGET_OS_OSX
|
||||
_engine = Engine::create(Engine::Backend::METAL);
|
||||
#else
|
||||
_engine = Engine::create(Engine::Backend::OPENGL); //L, nullptr, (void*)context, nullptr);
|
||||
#endif
|
||||
@@ -565,7 +567,7 @@ void FilamentViewer::createSwapChain(const void *window, uint32_t width, uint32_
|
||||
Log("Swapchain created.");
|
||||
}
|
||||
|
||||
void FilamentViewer::createRenderTarget(intptr_t textureId, uint32_t width, uint32_t height) {
|
||||
void FilamentViewer::createRenderTarget(intptr_t texture, uint32_t width, uint32_t height) {
|
||||
// Create filament textures and render targets (note the color buffer has the import call)
|
||||
_rtColor = filament::Texture::Builder()
|
||||
.width(width)
|
||||
@@ -573,7 +575,7 @@ void FilamentViewer::createRenderTarget(intptr_t textureId, uint32_t width, uint
|
||||
.levels(1)
|
||||
.usage(filament::Texture::Usage::COLOR_ATTACHMENT | filament::Texture::Usage::SAMPLEABLE)
|
||||
.format(filament::Texture::InternalFormat::RGBA8)
|
||||
.import(textureId)
|
||||
.import(texture)
|
||||
.build(*_engine);
|
||||
_rtDepth = filament::Texture::Builder()
|
||||
.width(width)
|
||||
@@ -590,7 +592,7 @@ void FilamentViewer::createRenderTarget(intptr_t textureId, uint32_t width, uint
|
||||
// Make a specific viewport just for our render target
|
||||
_view->setRenderTarget(_rt);
|
||||
|
||||
Log("Set render target for glTextureId %u %u x %u", textureId, width, height);
|
||||
Log("Set render target for glTextureId %u %u x %u", texture, width, height);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ using namespace polyvox;
|
||||
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);
|
||||
@@ -24,8 +25,8 @@ extern "C" {
|
||||
return new ResourceLoaderWrapper(loadFn, freeFn, owner);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_render_target(const void* const viewer, uint32_t textureId, uint32_t width, uint32_t height) {
|
||||
((FilamentViewer*)viewer)->createRenderTarget(textureId, width, height);
|
||||
FLUTTER_PLUGIN_EXPORT void create_render_target(const void* const viewer, intptr_t texture, uint32_t width, uint32_t height) {
|
||||
((FilamentViewer*)viewer)->createRenderTarget(texture, width, height);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer(const void* const viewer) {
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Log.hpp"
|
||||
#include "ThreadPool.hpp"
|
||||
|
||||
|
||||
#include <thread>
|
||||
#include <functional>
|
||||
|
||||
@@ -12,10 +13,13 @@ using namespace polyvox;
|
||||
|
||||
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
class RenderLoop {
|
||||
class RenderLoop
|
||||
{
|
||||
public:
|
||||
explicit RenderLoop() {
|
||||
_t = new std::thread([this]() {
|
||||
explicit RenderLoop()
|
||||
{
|
||||
_t = new std::thread([this]()
|
||||
{
|
||||
while(!_stop) {
|
||||
std::function<void()> task;
|
||||
{
|
||||
@@ -35,121 +39,294 @@ public:
|
||||
}
|
||||
|
||||
task();
|
||||
}
|
||||
});
|
||||
}
|
||||
~RenderLoop() {
|
||||
_stop = true;
|
||||
} });
|
||||
}
|
||||
~RenderLoop()
|
||||
{
|
||||
_stop = true;
|
||||
_t->join();
|
||||
}
|
||||
}
|
||||
|
||||
void* const createViewer(void* const context, const ResourceLoaderWrapper* const loader, void (*renderCallback)(void*), void* const owner) {
|
||||
void *const createViewer(void *const context, 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);
|
||||
});
|
||||
_renderCallbackOwner = owner;
|
||||
std::packaged_task<FilamentViewer *const()> lambda([&]() mutable
|
||||
{ return new FilamentViewer(context, loader); });
|
||||
auto fut = add_task(lambda);
|
||||
fut.wait();
|
||||
_viewer = fut.get();
|
||||
return (void* const)_viewer;
|
||||
return (void *const)_viewer;
|
||||
}
|
||||
|
||||
void setRendering(bool rendering) {
|
||||
void setRendering(bool rendering)
|
||||
{
|
||||
_rendering = rendering;
|
||||
}
|
||||
|
||||
void doRender() {
|
||||
void doRender()
|
||||
{
|
||||
render(_viewer, 0);
|
||||
_renderCallback(_renderCallbackOwner);
|
||||
}
|
||||
|
||||
template<class Rt>
|
||||
auto add_task(std::packaged_task<Rt()>& pt) -> std::future<Rt> {
|
||||
std::unique_lock<std::mutex> lock(_access);
|
||||
auto ret = pt.get_future();
|
||||
_tasks.push_back([pt=std::make_shared<std::packaged_task<Rt()>>(std::move(pt))]{ (*pt)();});
|
||||
_cond.notify_one();
|
||||
return ret;
|
||||
}
|
||||
private:
|
||||
template <class Rt>
|
||||
auto add_task(std::packaged_task<Rt()> &pt) -> std::future<Rt>
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_access);
|
||||
auto ret = pt.get_future();
|
||||
_tasks.push_back([pt = std::make_shared<std::packaged_task<Rt()>>(std::move(pt))]
|
||||
{ (*pt)(); });
|
||||
_cond.notify_one();
|
||||
return ret;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _stop = false;
|
||||
bool _rendering = false;
|
||||
int _frameIntervalInMilliseconds = 1000 / 60;
|
||||
std::mutex _access;
|
||||
FilamentViewer* _viewer = nullptr;
|
||||
void (*_renderCallback)(void* const) = nullptr;
|
||||
void* _renderCallbackOwner = nullptr;
|
||||
std::thread* _t = nullptr;
|
||||
std::condition_variable _cond;
|
||||
std::deque<std::function<void()>> _tasks;
|
||||
|
||||
std::mutex _access;
|
||||
FilamentViewer *_viewer = nullptr;
|
||||
void (*_renderCallback)(void *const) = nullptr;
|
||||
void *_renderCallbackOwner = nullptr;
|
||||
std::thread *_t = nullptr;
|
||||
std::condition_variable _cond;
|
||||
std::deque<std::function<void()>> _tasks;
|
||||
};
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "PolyvoxFilamentApi.h"
|
||||
|
||||
static RenderLoop *_rl;
|
||||
|
||||
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) {
|
||||
if(!_rl) {
|
||||
_rl = new RenderLoop();
|
||||
FLUTTER_PLUGIN_EXPORT void *const create_filament_viewer_ffi(void *const context, 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, loader, renderCallback, renderCallbackOwner);
|
||||
}
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void* const viewer, void* const surface, uint32_t width, uint32_t height) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
create_swap_chain(viewer, surface, width, height);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void create_swap_chain_ffi(void *const viewer, void *const surface, uint32_t width, uint32_t height)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ 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) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
create_render_target(viewer, nativeTextureId, 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)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ create_render_target(viewer, nativeTextureId, width, height); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
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)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ update_viewport_and_camera_projection(viewer, width, height, scaleFactor); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
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) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
update_viewport_and_camera_projection(viewer, width, height, scaleFactor);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_rendering_ffi(bool rendering)
|
||||
{
|
||||
if (!_rl)
|
||||
{
|
||||
Log("No render loop!"); // PANIC?
|
||||
} else {
|
||||
if(rendering) {
|
||||
Log("Set rendering to true");
|
||||
} else {
|
||||
Log("Set rendering to false");
|
||||
}
|
||||
_rl->setRendering(rendering);
|
||||
}
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT bool set_rendering_ffi(bool rendering) {
|
||||
if(!_rl) {
|
||||
return false;
|
||||
}
|
||||
_rl->setRendering(rendering);
|
||||
return true;
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void *const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ _rl->doRender(); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void render_ffi(void* const viewer) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
_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)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]() mutable
|
||||
{ set_background_color(viewer, r, g, b, a); });
|
||||
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) {
|
||||
std::packaged_task<void()> lambda([&]() mutable {
|
||||
set_background_color(viewer, r, g,b, a);
|
||||
});
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb_ffi(void *const assetManager, const char *path)
|
||||
{
|
||||
std::packaged_task<EntityId()> lambda([&]() mutable
|
||||
{ return load_glb(assetManager, path, false); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image_ffi(void *const viewer)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ 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)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::packaged_task<EntityId()> lambda([&]
|
||||
{ return add_light(viewer, type, colour, intensity, posX, posY, posZ, dirX, dirY, dirZ, shadows); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
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)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ clear_lights(viewer); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ clear_assets(viewer); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
|
||||
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); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_bone_animation_ffi(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
const float *const frameData,
|
||||
int numFrames,
|
||||
int numBones,
|
||||
const char **const boneNames,
|
||||
const char **const meshName,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ set_bone_animation(
|
||||
assetManager, asset, frameData, numFrames, numBones,
|
||||
boneNames, meshName, numMeshTargets, frameLengthInMs); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
}
|
||||
// implementations of rest of animation functions
|
||||
FLUTTER_PLUGIN_EXPORT void get_morph_target_name_ffi(void *assetManager, EntityId asset, const char *meshName, char *const outPtr, int index)
|
||||
{
|
||||
std::packaged_task<void()> lambda([&]
|
||||
{ get_morph_target_name(assetManager, 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, const char *meshName)
|
||||
{
|
||||
std::packaged_task<int()> lambda([&]
|
||||
{ return get_morph_target_name_count(assetManager, asset, meshName); });
|
||||
auto fut = _rl->add_task(lambda);
|
||||
fut.wait();
|
||||
return fut.get();
|
||||
}
|
||||
|
||||
void set_morph_target_weights_ffi(
|
||||
void* const assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const morphData,
|
||||
int numWeights
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user