add model/view matrix getters & manipulator options
This commit is contained in:
@@ -1,34 +1,40 @@
|
||||
PODS:
|
||||
- Flutter (1.0.0)
|
||||
- flutter_filament (0.0.1):
|
||||
- Flutter
|
||||
- integration_test (0.0.1):
|
||||
- Flutter
|
||||
- path_provider_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- flutter_filament (0.0.1):
|
||||
- permission_handler_apple (9.1.1):
|
||||
- Flutter
|
||||
|
||||
DEPENDENCIES:
|
||||
- Flutter (from `Flutter`)
|
||||
- flutter_filament (from `.symlinks/plugins/flutter_filament/ios`)
|
||||
- integration_test (from `.symlinks/plugins/integration_test/ios`)
|
||||
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
|
||||
- flutter_filament (from `.symlinks/plugins/flutter_filament/ios`)
|
||||
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Flutter:
|
||||
:path: Flutter
|
||||
flutter_filament:
|
||||
:path: ".symlinks/plugins/flutter_filament/ios"
|
||||
integration_test:
|
||||
:path: ".symlinks/plugins/integration_test/ios"
|
||||
path_provider_foundation:
|
||||
:path: ".symlinks/plugins/path_provider_foundation/darwin"
|
||||
flutter_filament:
|
||||
:path: ".symlinks/plugins/flutter_filament/ios"
|
||||
permission_handler_apple:
|
||||
:path: ".symlinks/plugins/permission_handler_apple/ios"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
|
||||
flutter_filament: 9d744e795935e0fc5308e46a0c5947cb91714848
|
||||
integration_test: 13825b8a9334a850581300559b8839134b124670
|
||||
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
|
||||
flutter_filament: 35fece7761e74c973afd80fe3aa0ca225eaace32
|
||||
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
|
||||
|
||||
PODFILE CHECKSUM: 7adbc9d59f05e1b01f554ea99b6c79e97f2214a2
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:flutter_filament/animations/animation_data.dart';
|
||||
|
||||
@@ -11,7 +11,6 @@ import 'package:flutter_filament/filament_controller.dart';
|
||||
import 'package:flutter_filament/filament_controller_ffi.dart';
|
||||
import 'package:flutter_filament/animations/animation_builder.dart';
|
||||
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:flutter_filament/widgets/filament_gesture_detector.dart';
|
||||
import 'package:flutter_filament/widgets/filament_widget.dart';
|
||||
|
||||
@@ -45,6 +44,10 @@ class ExampleWidget extends StatefulWidget {
|
||||
class _ExampleWidgetState extends State<ExampleWidget> {
|
||||
FilamentController? _filamentController;
|
||||
|
||||
Timer? _cameraTimer;
|
||||
String? _cameraPosition;
|
||||
String? _cameraRotation;
|
||||
|
||||
FilamentEntity? _shapes;
|
||||
FilamentEntity? _flightHelmet;
|
||||
FilamentEntity? _buster;
|
||||
@@ -89,6 +92,7 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
||||
}
|
||||
|
||||
void _createController({String? uberArchivePath}) {
|
||||
_cameraTimer?.cancel();
|
||||
_filamentController =
|
||||
FilamentControllerFFI(uberArchivePath: uberArchivePath);
|
||||
_filamentController!.pickResult.listen((entityId) {
|
||||
@@ -98,6 +102,22 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
void _createViewer() {
|
||||
_filamentController!.createViewer();
|
||||
setState(() {
|
||||
_hasViewer = true;
|
||||
});
|
||||
|
||||
_cameraTimer =
|
||||
Timer.periodic(const Duration(milliseconds: 50), (timer) async {
|
||||
var cameraPosition = await _filamentController!.getCameraPosition();
|
||||
var cameraRotation = await _filamentController!.getCameraRotation();
|
||||
_cameraPosition = cameraPosition.toString();
|
||||
_cameraRotation = cameraRotation.toString();
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var children = <Widget>[];
|
||||
@@ -120,17 +140,11 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
||||
]);
|
||||
} else {
|
||||
if (!_hasViewer) {
|
||||
children.addAll([
|
||||
_item(() {
|
||||
_filamentController!.createViewer();
|
||||
setState(() {
|
||||
_hasViewer = true;
|
||||
});
|
||||
}, "create FilamentViewer")
|
||||
]);
|
||||
children.addAll([_item(_createViewer, "create FilamentViewer")]);
|
||||
} else {
|
||||
children.addAll([
|
||||
_item(() {
|
||||
_cameraTimer?.cancel();
|
||||
_filamentController!.destroy();
|
||||
_filamentController = null;
|
||||
setState(() {
|
||||
@@ -406,6 +420,21 @@ class _ExampleWidgetState extends State<ExampleWidget> {
|
||||
top: 50,
|
||||
child: Text(picked ?? "",
|
||||
style: const TextStyle(color: Colors.green, fontSize: 24))),
|
||||
_cameraTimer == null
|
||||
? Container()
|
||||
: Positioned(
|
||||
top: 10,
|
||||
left: 10,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
borderRadius: BorderRadius.circular(29)),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
child: Text(
|
||||
"Camera position : $_cameraPosition $_cameraRotation",
|
||||
style:
|
||||
const TextStyle(color: Colors.white, fontSize: 12)))),
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: OrientationBuilder(builder: (ctx, orientation) {
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
PODS:
|
||||
- flutter_filament (0.0.1):
|
||||
- FlutterMacOS
|
||||
- FlutterMacOS (1.0.0)
|
||||
- path_provider_foundation (0.0.1):
|
||||
- Flutter
|
||||
- FlutterMacOS
|
||||
- flutter_filament (0.0.1):
|
||||
- FlutterMacOS
|
||||
|
||||
DEPENDENCIES:
|
||||
- flutter_filament (from `Flutter/ephemeral/.symlinks/plugins/flutter_filament/macos`)
|
||||
- FlutterMacOS (from `Flutter/ephemeral`)
|
||||
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
|
||||
- flutter_filament (from `Flutter/ephemeral/.symlinks/plugins/flutter_filament/macos`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
flutter_filament:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flutter_filament/macos
|
||||
FlutterMacOS:
|
||||
:path: Flutter/ephemeral
|
||||
path_provider_foundation:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
|
||||
flutter_filament:
|
||||
:path: Flutter/ephemeral/.symlinks/plugins/flutter_filament/macos
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
flutter_filament: e47abb28417d10183c856a132777e3ca08d1551d
|
||||
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
|
||||
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
|
||||
flutter_filament: 410c2b06ba59f1182e2fa4338b583903631fb95f
|
||||
|
||||
PODFILE CHECKSUM: 9cc8fc8fc62b1d9a89fd6f974ad4157b35254030
|
||||
|
||||
|
||||
@@ -435,14 +435,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "11.10.0"
|
||||
wasm_ffi:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wasm_ffi
|
||||
sha256: "5da66560305dd659d62caef535c5314abd9302c122e6eef8681e6879fbbfe358"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.4"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -41,149 +41,148 @@ using namespace camutils;
|
||||
|
||||
typedef int32_t EntityId;
|
||||
|
||||
namespace polyvox {
|
||||
namespace polyvox
|
||||
{
|
||||
|
||||
enum ToneMapping {
|
||||
ACES, FILMIC, LINEAR
|
||||
};
|
||||
|
||||
class FilamentViewer {
|
||||
public:
|
||||
FilamentViewer(const void* context, const ResourceLoaderWrapper* const resourceLoaderWrapper, void* const platform=nullptr, const char* uberArchivePath=nullptr);
|
||||
~FilamentViewer();
|
||||
|
||||
void setToneMapping(ToneMapping toneMapping);
|
||||
void setBloom(float strength);
|
||||
void loadSkybox(const char* const skyboxUri);
|
||||
void removeSkybox();
|
||||
|
||||
void loadIbl(const char* const iblUri, float intensity);
|
||||
void removeIbl();
|
||||
|
||||
void removeAsset(EntityId asset);
|
||||
// removes all add assets from the current scene
|
||||
void clearAssets();
|
||||
|
||||
void updateViewportAndCameraProjection(int height, int width, float scaleFactor);
|
||||
void render(
|
||||
uint64_t frameTimeInNanos,
|
||||
void* pixelBuffer,
|
||||
void (*callback)(void *buf, size_t size, void *data),
|
||||
void* data
|
||||
);
|
||||
void setFrameInterval(float interval);
|
||||
|
||||
bool setCamera(EntityId asset, const char* nodeName);
|
||||
|
||||
|
||||
void createSwapChain(const void* surface, uint32_t width, uint32_t height);
|
||||
void destroySwapChain();
|
||||
|
||||
void createRenderTarget(intptr_t textureId, uint32_t width,uint32_t height);
|
||||
|
||||
Renderer* getRenderer();
|
||||
|
||||
void setBackgroundColor(const float r, const float g, const float b, const float a);
|
||||
void setBackgroundImage(const char* resourcePath, bool fillHeight);
|
||||
void clearBackgroundImage();
|
||||
void setBackgroundImagePosition(float x, float y, bool clamp);
|
||||
void moveCameraToAsset(EntityId entityId);
|
||||
void setViewFrustumCulling(bool enabled);
|
||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||
void setCameraPosition(float x, float y, float z);
|
||||
void setCameraRotation(float rads, float x, float y, float z);
|
||||
void setCameraModelMatrix(const float* const matrix);
|
||||
void setCameraFocalLength(float fl);
|
||||
void setCameraFocusDistance(float focusDistance);
|
||||
|
||||
void grabBegin(float x, float y, bool pan);
|
||||
void grabUpdate(float x, float y);
|
||||
void grabEnd();
|
||||
void scrollBegin();
|
||||
void scrollUpdate(float x, float y, float delta);
|
||||
void scrollEnd();
|
||||
|
||||
int32_t addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
void removeLight(EntityId entityId);
|
||||
void clearLights();
|
||||
void setPostProcessing(bool enabled);
|
||||
|
||||
void pick(uint32_t x, uint32_t y, EntityId* entityId);
|
||||
|
||||
AssetManager* const getAssetManager() {
|
||||
return (AssetManager* const) _assetManager;
|
||||
}
|
||||
|
||||
private:
|
||||
void createImageRenderable();
|
||||
void loadResources(std::string relativeResourcePath);
|
||||
void cleanup();
|
||||
|
||||
bool _panning = false;
|
||||
float _startX;
|
||||
float _startY;
|
||||
math::mat4f _cameraPosition;
|
||||
math::mat4f _cameraRotation;
|
||||
|
||||
const ResourceLoaderWrapper* const _resourceLoaderWrapper;
|
||||
|
||||
Scene* _scene = nullptr;
|
||||
View* _view = nullptr;
|
||||
Engine* _engine = nullptr;
|
||||
|
||||
// a default camera that we add to every scene
|
||||
Camera* _mainCamera = nullptr;
|
||||
|
||||
Renderer* _renderer = nullptr;
|
||||
RenderTarget* _rt = nullptr;
|
||||
Texture* _rtColor = nullptr;
|
||||
Texture* _rtDepth = nullptr;
|
||||
|
||||
SwapChain* _swapChain = nullptr;
|
||||
|
||||
AssetManager* _assetManager = nullptr;
|
||||
|
||||
NameComponentManager* _ncm = nullptr;
|
||||
|
||||
std::mutex mtx; // mutex to ensure thread safety when removing assets
|
||||
|
||||
vector<utils::Entity> _lights;
|
||||
Texture* _skyboxTexture = nullptr;
|
||||
Skybox* _skybox = nullptr;
|
||||
Texture* _iblTexture = nullptr;
|
||||
IndirectLight* _indirectLight = nullptr;
|
||||
|
||||
bool _recomputeAabb = false;
|
||||
|
||||
bool _actualSize = false;
|
||||
|
||||
float _cameraFocalLength = 28.0f;
|
||||
float _cameraFocusDistance = 0.0f;
|
||||
|
||||
ColorGrading *colorGrading = nullptr;
|
||||
|
||||
// background image properties
|
||||
uint32_t _imageHeight = 0;
|
||||
uint32_t _imageWidth = 0;
|
||||
mat4f _imageScale;
|
||||
Texture* _imageTexture = nullptr;
|
||||
utils::Entity* _imageEntity = nullptr;
|
||||
VertexBuffer* _imageVb = nullptr;
|
||||
IndexBuffer* _imageIb = nullptr;
|
||||
Material* _imageMaterial = nullptr;
|
||||
TextureSampler _imageSampler;
|
||||
void loadKtx2Texture(string path, ResourceBuffer data);
|
||||
void loadKtxTexture(string path, ResourceBuffer data);
|
||||
void loadPngTexture(string path, ResourceBuffer data);
|
||||
void loadTextureFromPath(string path);
|
||||
|
||||
Manipulator<double>* _manipulator = nullptr;
|
||||
void _createManipulator();
|
||||
uint32_t _lastFrameTimeInNanos;
|
||||
enum ToneMapping
|
||||
{
|
||||
ACES,
|
||||
FILMIC,
|
||||
LINEAR
|
||||
};
|
||||
|
||||
class FilamentViewer
|
||||
{
|
||||
public:
|
||||
FilamentViewer(const void *context, const ResourceLoaderWrapper *const resourceLoaderWrapper, void *const platform = nullptr, const char *uberArchivePath = nullptr);
|
||||
~FilamentViewer();
|
||||
|
||||
void setToneMapping(ToneMapping toneMapping);
|
||||
void setBloom(float strength);
|
||||
void loadSkybox(const char *const skyboxUri);
|
||||
void removeSkybox();
|
||||
|
||||
void loadIbl(const char *const iblUri, float intensity);
|
||||
void removeIbl();
|
||||
|
||||
void removeAsset(EntityId asset);
|
||||
void clearAssets();
|
||||
|
||||
void updateViewportAndCameraProjection(int height, int width, float scaleFactor);
|
||||
void render(
|
||||
uint64_t frameTimeInNanos,
|
||||
void *pixelBuffer,
|
||||
void (*callback)(void *buf, size_t size, void *data),
|
||||
void *data);
|
||||
void setFrameInterval(float interval);
|
||||
|
||||
bool setCamera(EntityId asset, const char *nodeName);
|
||||
|
||||
void createSwapChain(const void *surface, uint32_t width, uint32_t height);
|
||||
void destroySwapChain();
|
||||
|
||||
void createRenderTarget(intptr_t textureId, uint32_t width, uint32_t height);
|
||||
|
||||
Renderer *getRenderer();
|
||||
|
||||
void setBackgroundColor(const float r, const float g, const float b, const float a);
|
||||
void setBackgroundImage(const char *resourcePath, bool fillHeight);
|
||||
void clearBackgroundImage();
|
||||
void setBackgroundImagePosition(float x, float y, bool clamp);
|
||||
|
||||
|
||||
// Camera methods
|
||||
void moveCameraToAsset(EntityId entityId);
|
||||
void setViewFrustumCulling(bool enabled);
|
||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||
void setCameraPosition(float x, float y, float z);
|
||||
void setCameraRotation(float rads, float x, float y, float z);
|
||||
const math::mat4 getCameraModelMatrix();
|
||||
const math::mat4 getCameraViewMatrix();
|
||||
void setCameraModelMatrix(const float *const matrix);
|
||||
void setCameraFocalLength(float fl);
|
||||
void setCameraFocusDistance(float focusDistance);
|
||||
void setCameraManipulatorOptions(filament::camutils::Mode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed);
|
||||
void grabBegin(float x, float y, bool pan);
|
||||
void grabUpdate(float x, float y);
|
||||
void grabEnd();
|
||||
void scrollBegin();
|
||||
void scrollUpdate(float x, float y, float delta);
|
||||
void scrollEnd();
|
||||
void pick(uint32_t x, uint32_t y, EntityId *entityId);
|
||||
|
||||
EntityId addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
void removeLight(EntityId entityId);
|
||||
void clearLights();
|
||||
void setPostProcessing(bool enabled);
|
||||
|
||||
|
||||
AssetManager *const getAssetManager()
|
||||
{
|
||||
return (AssetManager *const)_assetManager;
|
||||
}
|
||||
|
||||
private:
|
||||
const ResourceLoaderWrapper *const _resourceLoaderWrapper;
|
||||
|
||||
Scene *_scene = nullptr;
|
||||
View *_view = nullptr;
|
||||
Engine *_engine = nullptr;
|
||||
|
||||
Renderer *_renderer = nullptr;
|
||||
RenderTarget *_rt = nullptr;
|
||||
Texture *_rtColor = nullptr;
|
||||
Texture *_rtDepth = nullptr;
|
||||
|
||||
SwapChain *_swapChain = nullptr;
|
||||
|
||||
AssetManager *_assetManager = nullptr;
|
||||
|
||||
NameComponentManager *_ncm = nullptr;
|
||||
|
||||
std::mutex mtx; // mutex to ensure thread safety when removing assets
|
||||
|
||||
vector<utils::Entity> _lights;
|
||||
Texture *_skyboxTexture = nullptr;
|
||||
Skybox *_skybox = nullptr;
|
||||
Texture *_iblTexture = nullptr;
|
||||
IndirectLight *_indirectLight = nullptr;
|
||||
|
||||
bool _recomputeAabb = false;
|
||||
|
||||
bool _actualSize = false;
|
||||
|
||||
// Camera properties
|
||||
Camera *_mainCamera = nullptr; // the default camera added to every scene. If you want the *active* camera, access via View.
|
||||
float _cameraFocalLength = 28.0f;
|
||||
float _cameraFocusDistance = 0.0f;
|
||||
Manipulator<double> *_manipulator = nullptr;
|
||||
filament::camutils::Mode _manipulatorMode;
|
||||
double _orbitSpeedX = 0.01;
|
||||
double _orbitSpeedY = 0.01;
|
||||
double _zoomSpeed = 0.01;
|
||||
math::mat4f _cameraPosition;
|
||||
math::mat4f _cameraRotation;
|
||||
|
||||
ColorGrading *colorGrading = nullptr;
|
||||
|
||||
// background image properties
|
||||
uint32_t _imageHeight = 0;
|
||||
uint32_t _imageWidth = 0;
|
||||
mat4f _imageScale;
|
||||
Texture *_imageTexture = nullptr;
|
||||
utils::Entity *_imageEntity = nullptr;
|
||||
VertexBuffer *_imageVb = nullptr;
|
||||
IndexBuffer *_imageIb = nullptr;
|
||||
Material *_imageMaterial = nullptr;
|
||||
TextureSampler _imageSampler;
|
||||
void loadKtx2Texture(string path, ResourceBuffer data);
|
||||
void loadKtxTexture(string path, ResourceBuffer data);
|
||||
void loadPngTexture(string path, ResourceBuffer data);
|
||||
void loadTextureFromPath(string path);
|
||||
|
||||
|
||||
uint32_t _lastFrameTimeInNanos;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -47,11 +47,11 @@
|
||||
#include "ResourceBuffer.hpp"
|
||||
|
||||
typedef int32_t EntityId;
|
||||
typedef int32_t ManipulatorMode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef int32_t EntityId;
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT const void* create_filament_viewer(const void* const context, const ResourceLoaderWrapper* const loader, void* const platform, const char* uberArchivePath);
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer(const void* const viewer);
|
||||
@@ -140,14 +140,23 @@ FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId a
|
||||
FLUTTER_PLUGIN_EXPORT void set_position(void* assetManager, EntityId asset, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z);
|
||||
FLUTTER_PLUGIN_EXPORT void set_scale(void* assetManager, EntityId asset, float scale);
|
||||
|
||||
// Camera methods
|
||||
FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void* const viewer, EntityId asset);
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void* const viewer, bool enabled);
|
||||
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_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);
|
||||
FLUTTER_PLUGIN_EXPORT const double* const get_camera_projection_matrix(const void* const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void* const viewer, float focalLength);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float focusDistance);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_manipulator_options(const void* const viewer, ManipulatorMode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed);
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName);
|
||||
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void* assetManager, EntityId asset, const char* meshName);
|
||||
FLUTTER_PLUGIN_EXPORT void set_post_processing(void* const viewer, bool enabled);
|
||||
|
||||
@@ -1108,6 +1108,18 @@ namespace polyvox
|
||||
cam.setModelMatrix(modelMatrix);
|
||||
}
|
||||
|
||||
const math::mat4 FilamentViewer::getCameraModelMatrix()
|
||||
{
|
||||
const auto& cam = _view->getCamera();
|
||||
return cam.getModelMatrix();
|
||||
}
|
||||
|
||||
const math::mat4 FilamentViewer::getCameraViewMatrix()
|
||||
{
|
||||
const auto& cam = _view->getCamera();
|
||||
return cam.getViewMatrix();
|
||||
}
|
||||
|
||||
void FilamentViewer::_createManipulator()
|
||||
{
|
||||
Camera &cam = _view->getCamera();
|
||||
@@ -1123,10 +1135,18 @@ namespace polyvox
|
||||
.viewport(vp.width, vp.height)
|
||||
.orbitHomePosition(home[0], home[1], home[2])
|
||||
.upVector(up.x, up.y, up.z)
|
||||
.zoomSpeed(zoomSpeed)
|
||||
// .orbitSpeed(0.0001, 0.0001)
|
||||
.zoomSpeed(_zoomSpeed)
|
||||
.orbitSpeed(_orbitSpeedX, _orbitSpeedY)
|
||||
.targetPosition(target[0], target[1], target[2])
|
||||
.build(Mode::ORBIT);
|
||||
.build(_manipulatorMode);
|
||||
}
|
||||
|
||||
void FilamentViewer::setCameraManipulatorOptions(filament::camutils::Mode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed)
|
||||
{
|
||||
_manipulatorMode = mode;
|
||||
_orbitSpeedX = orbitSpeedX;
|
||||
_orbitSpeedY = orbitSpeedY;
|
||||
_zoomSpeed = zoomSpeedY;
|
||||
}
|
||||
|
||||
void FilamentViewer::grabBegin(float x, float y, bool pan)
|
||||
|
||||
@@ -10,387 +10,439 @@
|
||||
|
||||
using namespace polyvox;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
extern "C" {
|
||||
#include "FlutterFilamentApi.h"
|
||||
|
||||
#include "FlutterFilamentApi.h"
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT const void* create_filament_viewer(const void* context, const ResourceLoaderWrapper* const loader, void* const platform, const char* uberArchivePath) {
|
||||
return (const void*) new FilamentViewer(context, loader, platform, uberArchivePath);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT const void *create_filament_viewer(const void *context, const ResourceLoaderWrapper *const loader, void *const platform, const char *uberArchivePath)
|
||||
{
|
||||
return (const void *)new FilamentViewer(context, loader, platform, uberArchivePath);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT ResourceLoaderWrapper* make_resource_loader(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void* const owner) {
|
||||
return new ResourceLoaderWrapper(loadFn, freeFn, owner);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT ResourceLoaderWrapper *make_resource_loader(LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, void *const owner)
|
||||
{
|
||||
return new ResourceLoaderWrapper(loadFn, freeFn, owner);
|
||||
}
|
||||
|
||||
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) {
|
||||
delete((FilamentViewer*)viewer);
|
||||
}
|
||||
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 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);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_filament_viewer(const void *const viewer)
|
||||
{
|
||||
delete ((FilamentViewer *)viewer);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->clearBackgroundImage();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_background_image(const void* const viewer, const char* path, bool fillHeight) {
|
||||
((FilamentViewer*)viewer)->setBackgroundImage(path, fillHeight);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void clear_background_image(const void *const viewer)
|
||||
{
|
||||
((FilamentViewer *)viewer)->clearBackgroundImage();
|
||||
}
|
||||
|
||||
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_background_image(const void *const viewer, const char *path, bool fillHeight)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setBackgroundImage(path, fillHeight);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_tone_mapping(const void* const viewer, int toneMapping) {
|
||||
((FilamentViewer*)viewer)->setToneMapping((ToneMapping)toneMapping);
|
||||
}
|
||||
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_bloom(const void* const viewer, float strength) {
|
||||
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)
|
||||
{
|
||||
Log("Setting bloom to %f", strength);
|
||||
((FilamentViewer*)viewer)->setBloom(strength);
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->loadIbl(iblPath, intensity);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->removeSkybox();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->removeIbl();
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->removeLight(entityId);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->clearLights();
|
||||
}
|
||||
|
||||
EntityId load_glb(void* assetManager, const char* assetPath, bool unlit) {
|
||||
return ((AssetManager*)assetManager)->loadGlb(assetPath, unlit);
|
||||
}
|
||||
|
||||
EntityId load_gltf(void* assetManager, const char* assetPath, const char* relativePath) {
|
||||
return ((AssetManager*)assetManager)->loadGltf(assetPath, relativePath);
|
||||
}
|
||||
|
||||
bool set_camera(const void* const viewer, EntityId asset, const char* nodeName) {
|
||||
return ((FilamentViewer*)viewer)->setCamera(asset, nodeName);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void* const viewer, bool enabled) {
|
||||
((FilamentViewer*)viewer)->setViewFrustumCulling(enabled);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void* const viewer, EntityId asset) {
|
||||
((FilamentViewer*)viewer)->moveCameraToAsset(asset);
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->setCameraExposure(aperture, shutterSpeed, sensitivity);
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void render(
|
||||
const void* const viewer,
|
||||
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(
|
||||
const void* const viewer,
|
||||
float frameInterval
|
||||
) {
|
||||
((FilamentViewer*)viewer)->setFrameInterval(frameInterval);
|
||||
}
|
||||
|
||||
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) {
|
||||
((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) {
|
||||
return ((FilamentViewer*)viewer)->updateViewportAndCameraProjection(width, height, scaleFactor);
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->scrollBegin();
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->grabBegin(x, y, pan);
|
||||
}
|
||||
|
||||
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) {
|
||||
((FilamentViewer*)viewer)->grabEnd();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void * get_asset_manager(const void* const viewer) {
|
||||
return (void*)((FilamentViewer*)viewer)->getAssetManager();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void apply_weights(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char* const entityName,
|
||||
float* const weights,
|
||||
int count) {
|
||||
// ((AssetManager*)assetManager)->setMorphTargetWeights(asset, entityName, weights, count);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char* const entityName,
|
||||
const float* const weights,
|
||||
const int numWeights
|
||||
) {
|
||||
|
||||
return ((AssetManager*)assetManager)->setMorphTargetWeights(
|
||||
asset,
|
||||
entityName,
|
||||
weights,
|
||||
numWeights
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool set_morph_animation(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const char* const entityName,
|
||||
const float* const morphData,
|
||||
const int* const morphIndices,
|
||||
int numMorphTargets,
|
||||
int numFrames,
|
||||
float frameLengthInMs) {
|
||||
|
||||
return ((AssetManager*)assetManager)->setMorphAnimationBuffer(
|
||||
asset,
|
||||
entityName,
|
||||
morphData,
|
||||
morphIndices,
|
||||
numMorphTargets,
|
||||
numFrames,
|
||||
frameLengthInMs
|
||||
);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_bone_animation(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
const float* const frameData,
|
||||
int numFrames,
|
||||
int numBones,
|
||||
const char** const boneNames,
|
||||
const char** const meshNames,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs) {
|
||||
((AssetManager*)assetManager)->setBoneAnimationBuffer(
|
||||
asset,
|
||||
frameData,
|
||||
numFrames,
|
||||
numBones,
|
||||
boneNames,
|
||||
meshNames,
|
||||
numMeshTargets,
|
||||
frameLengthInMs
|
||||
);
|
||||
((FilamentViewer *)viewer)->setBloom(strength);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_post_processing(void* const viewer, bool enabled) {
|
||||
((FilamentViewer*)viewer)->setPostProcessing(enabled);
|
||||
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)
|
||||
{
|
||||
((FilamentViewer *)viewer)->loadIbl(iblPath, intensity);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_skybox(const void *const viewer)
|
||||
{
|
||||
((FilamentViewer *)viewer)->removeSkybox();
|
||||
}
|
||||
|
||||
// void set_bone_transform(
|
||||
// EntityId asset,
|
||||
// const char* boneName,
|
||||
// const char* entityName,
|
||||
// float transX,
|
||||
// float transY,
|
||||
// float transZ,
|
||||
// float quatX,
|
||||
// float quatY,
|
||||
// float quatZ,
|
||||
// float quatW
|
||||
// ) {
|
||||
// ((AssetManager*)assetManager)->setBoneTransform(
|
||||
// boneName,
|
||||
// entityName,
|
||||
// transX,
|
||||
// transY,
|
||||
// transZ,
|
||||
// quatX,
|
||||
// quatY,
|
||||
// quatZ,
|
||||
// quatW,
|
||||
// false
|
||||
// );
|
||||
FLUTTER_PLUGIN_EXPORT void remove_ibl(const void *const viewer)
|
||||
{
|
||||
((FilamentViewer *)viewer)->removeIbl();
|
||||
}
|
||||
|
||||
// }
|
||||
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)
|
||||
{
|
||||
((FilamentViewer *)viewer)->removeLight(entityId);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
int index,
|
||||
bool loop,
|
||||
bool reverse,
|
||||
bool replaceActive,
|
||||
float crossfade) {
|
||||
((AssetManager*)assetManager)->playAnimation(asset, index, loop, reverse, replaceActive, crossfade);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void clear_lights(const void *const viewer)
|
||||
{
|
||||
((FilamentViewer *)viewer)->clearLights();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
int animationIndex,
|
||||
int animationFrame) {
|
||||
// ((AssetManager*)assetManager)->setAnimationFrame(asset, animationIndex, animationFrame);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT 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)
|
||||
{
|
||||
return ((AssetManager *)assetManager)->loadGltf(assetPath, relativePath);
|
||||
}
|
||||
|
||||
float get_animation_duration(void* assetManager, EntityId asset, int animationIndex) {
|
||||
return ((AssetManager*)assetManager)->getAnimationDuration(asset, animationIndex);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT bool set_camera(const void *const viewer, EntityId asset, const char *nodeName)
|
||||
{
|
||||
return ((FilamentViewer *)viewer)->setCamera(asset, nodeName);
|
||||
}
|
||||
|
||||
int get_animation_count(
|
||||
void* assetManager,
|
||||
EntityId asset) {
|
||||
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
||||
return (int)names->size();
|
||||
}
|
||||
const double *const get_camera_model_matrix(const void *const viewer)
|
||||
{
|
||||
const auto &modelMatrix = ((FilamentViewer *)viewer)->getCameraModelMatrix();
|
||||
double *array = (double *)calloc(16, sizeof(double));
|
||||
memcpy(array, modelMatrix.asArray(), 16 * sizeof(double));
|
||||
return array;
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void get_animation_name(
|
||||
void* assetManager,
|
||||
EntityId asset,
|
||||
char* const outPtr,
|
||||
int index
|
||||
) {
|
||||
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
|
||||
string name = names->at(index);
|
||||
strcpy(outPtr, name.c_str());
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void* assetManager, EntityId asset, const char* meshName) {
|
||||
unique_ptr<vector<string>> names = ((AssetManager*)assetManager)->getMorphTargetNames(asset, meshName);
|
||||
return (int)names->size();
|
||||
}
|
||||
const double *const get_camera_view_matrix(const void *const viewer)
|
||||
{
|
||||
const auto &modelMatrix = ((FilamentViewer *)viewer)->getCameraViewMatrix();
|
||||
return modelMatrix.asArray();
|
||||
}
|
||||
|
||||
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 set_camera_manipulator_options(const void *const viewer, ManipulatorMode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setCameraManipulatorOptions((filament::camutils::Mode)mode, orbitSpeedX, orbitSpeedY, zoomSpeed);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void remove_asset(const void* const viewer, EntityId asset) {
|
||||
((FilamentViewer*)viewer)->removeAsset(asset);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void *const viewer, bool enabled)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setViewFrustumCulling(enabled);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets(const void* const viewer) {
|
||||
((FilamentViewer*)viewer)->clearAssets();
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void *const viewer, EntityId asset)
|
||||
{
|
||||
((FilamentViewer *)viewer)->moveCameraToAsset(asset);
|
||||
}
|
||||
|
||||
bool set_material_color(void* assetManager, EntityId asset, const char* meshName, int materialIndex, const float r, const float g, const float b, const float a) {
|
||||
return ((AssetManager*)assetManager)->setMaterialColor(asset, meshName, materialIndex, r, g, b, a);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void *const viewer, float distance)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setCameraFocusDistance(distance);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId asset) {
|
||||
((AssetManager*)assetManager)->transformToUnitCube(asset);
|
||||
}
|
||||
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_position(void* assetManager, EntityId asset, float x, float y, float z) {
|
||||
((AssetManager*)assetManager)->setPosition(asset, x, y, 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_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_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_scale(void* assetManager, EntityId asset, float scale) {
|
||||
((AssetManager*)assetManager)->setScale(asset, scale);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void *const viewer, const float *const matrix)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setCameraModelMatrix(matrix);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void stop_animation(void* assetManager, EntityId asset, int index) {
|
||||
((AssetManager*)assetManager)->stopAnimation(asset, index);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void *const viewer, float focalLength)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setCameraFocalLength(focalLength);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||
return ((AssetManager*)assetManager)->hide(asset, meshName);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void render(
|
||||
const void *const viewer,
|
||||
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 int reveal_mesh(void* assetManager, EntityId asset, const char* meshName) {
|
||||
return ((AssetManager*)assetManager)->reveal(asset, meshName);
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void set_frame_interval(
|
||||
const void *const viewer,
|
||||
float frameInterval)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setFrameInterval(frameInterval);
|
||||
}
|
||||
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void pick(void* const viewer, int x, int y, EntityId* entityId) {
|
||||
((FilamentViewer*)viewer)->pick(static_cast<uint32_t>(x), static_cast<uint32_t>(y), static_cast<int32_t*>(entityId));
|
||||
}
|
||||
FLUTTER_PLUGIN_EXPORT void destroy_swap_chain(const void *const viewer)
|
||||
{
|
||||
((FilamentViewer *)viewer)->destroySwapChain();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT const char* get_name_for_entity(void* const assetManager, const EntityId entityId) {
|
||||
return ((AssetManager*)assetManager)->getNameForEntity(entityId);
|
||||
}
|
||||
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 ios_dummy() {
|
||||
Log("Dummy called");
|
||||
}
|
||||
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)
|
||||
{
|
||||
((FilamentViewer *)viewer)->scrollUpdate(x, y, delta);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void scroll_begin(const void *const viewer)
|
||||
{
|
||||
((FilamentViewer *)viewer)->scrollBegin();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
((FilamentViewer *)viewer)->grabBegin(x, y, pan);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
((FilamentViewer *)viewer)->grabEnd();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void *get_asset_manager(const void *const viewer)
|
||||
{
|
||||
return (void *)((FilamentViewer *)viewer)->getAssetManager();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void apply_weights(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
float *const weights,
|
||||
int count)
|
||||
{
|
||||
// ((AssetManager*)assetManager)->setMorphTargetWeights(asset, entityName, weights, count);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const weights,
|
||||
const int numWeights)
|
||||
{
|
||||
|
||||
return ((AssetManager *)assetManager)->setMorphTargetWeights(asset, entityName, weights, numWeights);
|
||||
}
|
||||
|
||||
bool set_morph_animation(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
const char *const entityName,
|
||||
const float *const morphData,
|
||||
const int *const morphIndices,
|
||||
int numMorphTargets,
|
||||
int numFrames,
|
||||
float frameLengthInMs)
|
||||
{
|
||||
|
||||
return ((AssetManager *)assetManager)->setMorphAnimationBuffer(asset, entityName, morphData, morphIndices, numMorphTargets, numFrames, frameLengthInMs);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_bone_animation(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
const float *const frameData,
|
||||
int numFrames,
|
||||
int numBones,
|
||||
const char **const boneNames,
|
||||
const char **const meshNames,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs)
|
||||
{
|
||||
((AssetManager *)assetManager)->setBoneAnimationBuffer(asset, frameData, numFrames, numBones, boneNames, meshNames, numMeshTargets, frameLengthInMs);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_post_processing(void *const viewer, bool enabled)
|
||||
{
|
||||
((FilamentViewer *)viewer)->setPostProcessing(enabled);
|
||||
}
|
||||
|
||||
// void set_bone_transform(
|
||||
// EntityId asset,
|
||||
// const char* boneName,
|
||||
// const char* entityName,
|
||||
// float transX,
|
||||
// float transY,
|
||||
// float transZ,
|
||||
// float quatX,
|
||||
// float quatY,
|
||||
// float quatZ,
|
||||
// float quatW
|
||||
// ) {
|
||||
// ((AssetManager*)assetManager)->setBoneTransform(
|
||||
// boneName,
|
||||
// entityName,
|
||||
// transX,
|
||||
// transY,
|
||||
// transZ,
|
||||
// quatX,
|
||||
// quatY,
|
||||
// quatZ,
|
||||
// quatW,
|
||||
// false
|
||||
// );
|
||||
|
||||
// }
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
int index,
|
||||
bool loop,
|
||||
bool reverse,
|
||||
bool replaceActive,
|
||||
float crossfade)
|
||||
{
|
||||
((AssetManager *)assetManager)->playAnimation(asset, index, loop, reverse, replaceActive, crossfade);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
int animationIndex,
|
||||
int animationFrame)
|
||||
{
|
||||
// ((AssetManager*)assetManager)->setAnimationFrame(asset, animationIndex, animationFrame);
|
||||
}
|
||||
|
||||
float get_animation_duration(void *assetManager, EntityId asset, int animationIndex)
|
||||
{
|
||||
return ((AssetManager *)assetManager)->getAnimationDuration(asset, animationIndex);
|
||||
}
|
||||
|
||||
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(
|
||||
void *assetManager,
|
||||
EntityId asset,
|
||||
char *const outPtr,
|
||||
int index)
|
||||
{
|
||||
auto names = ((AssetManager *)assetManager)->getAnimationNames(asset);
|
||||
string name = names->at(index);
|
||||
strcpy(outPtr, name.c_str());
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void *assetManager, EntityId asset, const char *meshName)
|
||||
{
|
||||
unique_ptr<vector<string>> names = ((AssetManager *)assetManager)->getMorphTargetNames(asset, meshName);
|
||||
return (int)names->size();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
((FilamentViewer *)viewer)->removeAsset(asset);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void clear_assets(const void *const viewer)
|
||||
{
|
||||
((FilamentViewer *)viewer)->clearAssets();
|
||||
}
|
||||
|
||||
bool set_material_color(void *assetManager, EntityId asset, const char *meshName, int materialIndex, const float r, const float g, const float b, const float a)
|
||||
{
|
||||
return ((AssetManager *)assetManager)->setMaterialColor(asset, meshName, materialIndex, r, g, b, a);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
((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)
|
||||
{
|
||||
((AssetManager *)assetManager)->setRotation(asset, rads, x, y, z);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
((AssetManager *)assetManager)->stopAnimation(asset, index);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT 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)
|
||||
{
|
||||
return ((AssetManager *)assetManager)->reveal(asset, meshName);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void pick(void *const viewer, int x, int y, EntityId *entityId)
|
||||
{
|
||||
((FilamentViewer *)viewer)->pick(static_cast<uint32_t>(x), static_cast<uint32_t>(y), static_cast<int32_t *>(entityId));
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT const char *get_name_for_entity(void *const assetManager, const EntityId entityId)
|
||||
{
|
||||
return ((AssetManager *)assetManager)->getNameForEntity(entityId);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void ios_dummy()
|
||||
{
|
||||
Log("Dummy called");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +178,16 @@ abstract class FilamentController {
|
||||
///
|
||||
Future clearLights();
|
||||
|
||||
///
|
||||
/// Load the .glb asset at the given path and insert into the scene.
|
||||
///
|
||||
Future<FilamentEntity> loadGlb(String path, {bool unlit = false});
|
||||
|
||||
///
|
||||
/// Load the .gltf asset at the given path and insert into the scene.
|
||||
/// [relativeResourcePath] is the folder path where the glTF resources are stored;
|
||||
/// this is usually the parent directory of the .gltf file itself.
|
||||
///
|
||||
Future<FilamentEntity> loadGltf(String path, String relativeResourcePath);
|
||||
|
||||
///
|
||||
@@ -314,13 +322,28 @@ abstract class FilamentController {
|
||||
///
|
||||
/// Get the camera position in world space.
|
||||
///
|
||||
Future<Vector3> getCameraPosition(double x, double y, double z);
|
||||
Future<Vector3> getCameraPosition();
|
||||
|
||||
///
|
||||
/// Get the camera's model matrix.
|
||||
///
|
||||
Future<Matrix4> getCameraModelMatrix();
|
||||
|
||||
///
|
||||
/// Get the camera's view matrix.
|
||||
///
|
||||
Future<Matrix4> getCameraViewMatrix();
|
||||
|
||||
///
|
||||
/// Set the camera position in world space.
|
||||
///
|
||||
Future setCameraPosition(double x, double y, double z);
|
||||
|
||||
///
|
||||
/// Get the camera rotation matrix.
|
||||
///
|
||||
Future<Matrix3> getCameraRotation();
|
||||
|
||||
///
|
||||
/// Repositions the camera to the last vertex of the bounding box of [asset], looking at the penultimate vertex.
|
||||
///
|
||||
@@ -347,11 +370,14 @@ abstract class FilamentController {
|
||||
///
|
||||
Future setCameraModelMatrix(List<double> matrix);
|
||||
|
||||
///
|
||||
/// Sets the `baseColorFactor` property for the material at index [materialIndex] in [entity] under node [meshName] to [color].
|
||||
///
|
||||
Future setMaterialColor(
|
||||
FilamentEntity entity, String meshName, int materialIndex, Color color);
|
||||
|
||||
///
|
||||
/// Scales [asset] up/down so it fits within a unit cube.
|
||||
/// Scale [asset] to fit within the unit cube.
|
||||
///
|
||||
Future transformToUnitCube(FilamentEntity entity);
|
||||
|
||||
@@ -369,6 +395,10 @@ abstract class FilamentController {
|
||||
/// Sets the scale for the given entity.
|
||||
///
|
||||
Future setScale(FilamentEntity entity, double scale);
|
||||
|
||||
///
|
||||
/// Sets the rotation for [entity] to [rads] around the axis {x,y,z}.
|
||||
///
|
||||
Future setRotation(
|
||||
FilamentEntity entity, double rads, double x, double y, double z);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
@@ -11,6 +12,7 @@ import 'package:flutter_filament/filament_controller.dart';
|
||||
import 'package:flutter_filament/animations/animation_data.dart';
|
||||
import 'package:flutter_filament/generated_bindings.dart';
|
||||
import 'package:flutter_filament/rendering_surface.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
|
||||
// ignore: constant_identifier_names
|
||||
const FilamentEntity _FILAMENT_ASSET_ERROR = 0;
|
||||
@@ -967,7 +969,7 @@ class FilamentControllerFFI extends FilamentController {
|
||||
_lib.pick_ffi(_viewer!, x, textureDetails.value!.height - y, outPtr);
|
||||
int wait = 0;
|
||||
while (outPtr.value == 0) {
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
await Future.delayed(const Duration(milliseconds: 32));
|
||||
wait++;
|
||||
if (wait > 10) {
|
||||
calloc.free(outPtr);
|
||||
@@ -978,4 +980,48 @@ class FilamentControllerFFI extends FilamentController {
|
||||
_pickResultController.add(entityId);
|
||||
calloc.free(outPtr);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Matrix4> getCameraViewMatrix() async {
|
||||
if (_viewer == null) {
|
||||
throw Exception("No viewer available");
|
||||
}
|
||||
var arrayPtr = _lib.get_camera_view_matrix(_viewer!);
|
||||
return Matrix4.fromList(arrayPtr.asTypedList(16));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Matrix4> getCameraModelMatrix() async {
|
||||
if (_viewer == null) {
|
||||
throw Exception("No viewer available");
|
||||
}
|
||||
var arrayPtr = _lib.get_camera_model_matrix(_viewer!);
|
||||
return Matrix4.fromList(arrayPtr.asTypedList(16));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Vector3> getCameraPosition() async {
|
||||
if (_viewer == null) {
|
||||
throw Exception("No viewer available");
|
||||
}
|
||||
var arrayPtr = _lib.get_camera_model_matrix(_viewer!);
|
||||
var doubleList = arrayPtr.asTypedList(16);
|
||||
var modelMatrix = Matrix4.fromFloat64List(doubleList);
|
||||
calloc.free(arrayPtr);
|
||||
return modelMatrix.getColumn(3).xyz;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Matrix3> getCameraRotation() async {
|
||||
if (_viewer == null) {
|
||||
throw Exception("No viewer available");
|
||||
}
|
||||
var arrayPtr = _lib.get_camera_model_matrix(_viewer!);
|
||||
var doubleList = arrayPtr.asTypedList(16);
|
||||
var modelMatrix = Matrix4.fromFloat64List(doubleList);
|
||||
var rotationMatrix = Matrix3.identity();
|
||||
modelMatrix.copyRotation(rotationMatrix);
|
||||
calloc.free(arrayPtr);
|
||||
return rotationMatrix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,9 +224,8 @@ class NativeLibrary {
|
||||
}
|
||||
|
||||
late final _set_bloomPtr = _lookup<
|
||||
ffi
|
||||
.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Float)>>(
|
||||
'set_bloom');
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Float)>>('set_bloom');
|
||||
late final _set_bloom =
|
||||
_set_bloomPtr.asFunction<void Function(ffi.Pointer<ffi.Void>, double)>();
|
||||
|
||||
@@ -351,9 +350,8 @@ class NativeLibrary {
|
||||
}
|
||||
|
||||
late final _remove_lightPtr = _lookup<
|
||||
ffi
|
||||
.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>>(
|
||||
'remove_light');
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>>('remove_light');
|
||||
late final _remove_light =
|
||||
_remove_lightPtr.asFunction<void Function(ffi.Pointer<ffi.Void>, int)>();
|
||||
|
||||
@@ -991,9 +989,8 @@ class NativeLibrary {
|
||||
}
|
||||
|
||||
late final _remove_assetPtr = _lookup<
|
||||
ffi
|
||||
.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>>(
|
||||
'remove_asset');
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>>('remove_asset');
|
||||
late final _remove_asset =
|
||||
_remove_assetPtr.asFunction<void Function(ffi.Pointer<ffi.Void>, int)>();
|
||||
|
||||
@@ -1192,6 +1189,20 @@ class NativeLibrary {
|
||||
late final _set_camera_position = _set_camera_positionPtr.asFunction<
|
||||
void Function(ffi.Pointer<ffi.Void>, double, double, double)>();
|
||||
|
||||
void get_camera_position(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
) {
|
||||
return _get_camera_position(
|
||||
viewer,
|
||||
);
|
||||
}
|
||||
|
||||
late final _get_camera_positionPtr =
|
||||
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>(
|
||||
'get_camera_position');
|
||||
late final _get_camera_position = _get_camera_positionPtr
|
||||
.asFunction<void Function(ffi.Pointer<ffi.Void>)>();
|
||||
|
||||
void set_camera_rotation(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
double rads,
|
||||
@@ -1232,6 +1243,51 @@ class NativeLibrary {
|
||||
late final _set_camera_model_matrix = _set_camera_model_matrixPtr.asFunction<
|
||||
void Function(ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Float>)>();
|
||||
|
||||
ffi.Pointer<ffi.Double> get_camera_model_matrix(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
) {
|
||||
return _get_camera_model_matrix(
|
||||
viewer,
|
||||
);
|
||||
}
|
||||
|
||||
late final _get_camera_model_matrixPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Pointer<ffi.Double> Function(
|
||||
ffi.Pointer<ffi.Void>)>>('get_camera_model_matrix');
|
||||
late final _get_camera_model_matrix = _get_camera_model_matrixPtr
|
||||
.asFunction<ffi.Pointer<ffi.Double> Function(ffi.Pointer<ffi.Void>)>();
|
||||
|
||||
ffi.Pointer<ffi.Double> get_camera_view_matrix(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
) {
|
||||
return _get_camera_view_matrix(
|
||||
viewer,
|
||||
);
|
||||
}
|
||||
|
||||
late final _get_camera_view_matrixPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Pointer<ffi.Double> Function(
|
||||
ffi.Pointer<ffi.Void>)>>('get_camera_view_matrix');
|
||||
late final _get_camera_view_matrix = _get_camera_view_matrixPtr
|
||||
.asFunction<ffi.Pointer<ffi.Double> Function(ffi.Pointer<ffi.Void>)>();
|
||||
|
||||
ffi.Pointer<ffi.Double> get_camera_projection_matrix(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
) {
|
||||
return _get_camera_projection_matrix(
|
||||
viewer,
|
||||
);
|
||||
}
|
||||
|
||||
late final _get_camera_projection_matrixPtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Pointer<ffi.Double> Function(
|
||||
ffi.Pointer<ffi.Void>)>>('get_camera_projection_matrix');
|
||||
late final _get_camera_projection_matrix = _get_camera_projection_matrixPtr
|
||||
.asFunction<ffi.Pointer<ffi.Double> Function(ffi.Pointer<ffi.Void>)>();
|
||||
|
||||
void set_camera_focal_length(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
double focalLength,
|
||||
@@ -1266,6 +1322,23 @@ class NativeLibrary {
|
||||
late final _set_camera_focus_distance = _set_camera_focus_distancePtr
|
||||
.asFunction<void Function(ffi.Pointer<ffi.Void>, double)>();
|
||||
|
||||
void set_camera_manipulator_mode(
|
||||
ffi.Pointer<ffi.Void> viewer,
|
||||
int mode,
|
||||
) {
|
||||
return _set_camera_manipulator_mode(
|
||||
viewer,
|
||||
mode,
|
||||
);
|
||||
}
|
||||
|
||||
late final _set_camera_manipulator_modePtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Void Function(ffi.Pointer<ffi.Void>,
|
||||
ManipulatorMode)>>('set_camera_manipulator_mode');
|
||||
late final _set_camera_manipulator_mode = _set_camera_manipulator_modePtr
|
||||
.asFunction<void Function(ffi.Pointer<ffi.Void>, int)>();
|
||||
|
||||
int hide_mesh(
|
||||
ffi.Pointer<ffi.Void> assetManager,
|
||||
int asset,
|
||||
@@ -2383,6 +2456,7 @@ typedef FreeFilamentResourceFromOwner = ffi.Pointer<
|
||||
/// This header replicates most of the methods in FlutterFilamentApi.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 FlutterFilamentApi.h, but wrapped in some kind of thread runner to ensure thread safety.
|
||||
typedef EntityId = ffi.Int32;
|
||||
typedef ManipulatorMode = ffi.Int32;
|
||||
typedef FilamentRenderCallback = ffi.Pointer<
|
||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void> owner)>>;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <filament/Scene.h>
|
||||
|
||||
#include <gltfio/AssetLoader.h>
|
||||
@@ -82,6 +84,7 @@ namespace polyvox {
|
||||
gltfio::ResourceLoader* _gltfResourceLoader = nullptr;
|
||||
gltfio::TextureProvider* _stbDecoder = nullptr;
|
||||
gltfio::TextureProvider* _ktxDecoder = nullptr;
|
||||
std::mutex _animationMutex;
|
||||
|
||||
vector<SceneAsset> _assets;
|
||||
tsl::robin_map<EntityId, int> _entityIdLookup;
|
||||
|
||||
@@ -92,6 +92,8 @@ namespace polyvox {
|
||||
void setCameraExposure(float aperture, float shutterSpeed, float sensitivity);
|
||||
void setCameraPosition(float x, float y, float z);
|
||||
void setCameraRotation(float rads, float x, float y, float z);
|
||||
const math::mat4 getCameraModelMatrix();
|
||||
const math::mat4 getCameraViewMatrix();
|
||||
void setCameraModelMatrix(const float* const matrix);
|
||||
void setCameraFocalLength(float fl);
|
||||
void setCameraFocusDistance(float focusDistance);
|
||||
@@ -103,7 +105,7 @@ namespace polyvox {
|
||||
void scrollUpdate(float x, float y, float delta);
|
||||
void scrollEnd();
|
||||
|
||||
int32_t addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
EntityId addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
|
||||
void removeLight(EntityId entityId);
|
||||
void clearLights();
|
||||
void setPostProcessing(bool enabled);
|
||||
|
||||
@@ -144,8 +144,12 @@ FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void* const viewer, Entity
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void* const viewer, bool enabled);
|
||||
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_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);
|
||||
FLUTTER_PLUGIN_EXPORT const double* const get_camera_projection_matrix(const void* const viewer);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focal_length(const void* const viewer, float focalLength);
|
||||
FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float focusDistance);
|
||||
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName);
|
||||
|
||||
@@ -257,7 +257,7 @@ FilamentAsset* AssetManager::getAssetByEntityId(EntityId entityId) {
|
||||
|
||||
void AssetManager::updateAnimations() {
|
||||
|
||||
|
||||
std::lock_guard lock(_animationMutex);
|
||||
RenderableManager &rm = _engine->getRenderableManager();
|
||||
|
||||
for (auto& asset : _assets) {
|
||||
@@ -467,7 +467,8 @@ bool AssetManager::setMorphAnimationBuffer(
|
||||
int numMorphTargets,
|
||||
int numFrames,
|
||||
float frameLengthInMs) {
|
||||
|
||||
std::lock_guard lock(_animationMutex);
|
||||
|
||||
const auto& pos = _entityIdLookup.find(entityId);
|
||||
if(pos == _entityIdLookup.end()) {
|
||||
Log("ERROR: asset not found for entity.");
|
||||
@@ -543,7 +544,8 @@ bool AssetManager::setBoneAnimationBuffer(
|
||||
const char** const meshNames,
|
||||
int numMeshTargets,
|
||||
float frameLengthInMs) {
|
||||
|
||||
std::lock_guard lock(_animationMutex);
|
||||
|
||||
const auto& pos = _entityIdLookup.find(entityId);
|
||||
if(pos == _entityIdLookup.end()) {
|
||||
Log("ERROR: asset not found for entity.");
|
||||
@@ -632,6 +634,8 @@ bool AssetManager::setBoneAnimationBuffer(
|
||||
|
||||
|
||||
void AssetManager::playAnimation(EntityId e, int index, bool loop, bool reverse, bool replaceActive, float crossfade) {
|
||||
std::lock_guard lock(_animationMutex);
|
||||
|
||||
if(index < 0) {
|
||||
Log("ERROR: glTF animation index must be greater than zero.");
|
||||
return;
|
||||
@@ -686,6 +690,8 @@ void AssetManager::playAnimation(EntityId e, int index, bool loop, bool reverse,
|
||||
}
|
||||
|
||||
void AssetManager::stopAnimation(EntityId entityId, int index) {
|
||||
std::lock_guard lock(_animationMutex);
|
||||
|
||||
const auto& pos = _entityIdLookup.find(entityId);
|
||||
if(pos == _entityIdLookup.end()) {
|
||||
Log("ERROR: asset not found for entity.");
|
||||
|
||||
@@ -1108,6 +1108,18 @@ namespace polyvox
|
||||
cam.setModelMatrix(modelMatrix);
|
||||
}
|
||||
|
||||
const math::mat4 FilamentViewer::getCameraModelMatrix()
|
||||
{
|
||||
const auto& cam = _view->getCamera();
|
||||
return cam.getModelMatrix();
|
||||
}
|
||||
|
||||
const math::mat4 FilamentViewer::getCameraViewMatrix()
|
||||
{
|
||||
const auto& cam = _view->getCamera();
|
||||
return cam.getViewMatrix();
|
||||
}
|
||||
|
||||
void FilamentViewer::_createManipulator()
|
||||
{
|
||||
Camera &cam = _view->getCamera();
|
||||
|
||||
@@ -84,18 +84,30 @@ extern "C" {
|
||||
((FilamentViewer*)viewer)->clearLights();
|
||||
}
|
||||
|
||||
EntityId load_glb(void* assetManager, const char* assetPath, bool unlit) {
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_glb(void* assetManager, const char* assetPath, bool unlit) {
|
||||
return ((AssetManager*)assetManager)->loadGlb(assetPath, unlit);
|
||||
}
|
||||
|
||||
EntityId load_gltf(void* assetManager, const char* assetPath, const char* relativePath) {
|
||||
FLUTTER_PLUGIN_EXPORT EntityId load_gltf(void* assetManager, const char* assetPath, const char* relativePath) {
|
||||
return ((AssetManager*)assetManager)->loadGltf(assetPath, relativePath);
|
||||
}
|
||||
|
||||
bool set_camera(const void* const viewer, EntityId asset, const char* nodeName) {
|
||||
FLUTTER_PLUGIN_EXPORT bool set_camera(const void* const viewer, EntityId asset, const char* nodeName) {
|
||||
return ((FilamentViewer*)viewer)->setCamera(asset, nodeName);
|
||||
}
|
||||
|
||||
const double* const get_camera_model_matrix(const void* const viewer) {
|
||||
const auto& modelMatrix = ((FilamentViewer*)viewer)->getCameraModelMatrix();
|
||||
double* array = (double*)calloc(16, sizeof(double));
|
||||
memcpy(array, modelMatrix.asArray(), 16 * sizeof(double));
|
||||
return array;
|
||||
}
|
||||
|
||||
const double* const get_camera_view_matrix(const void* const viewer) {
|
||||
const auto& modelMatrix = ((FilamentViewer*)viewer)->getCameraViewMatrix();
|
||||
return modelMatrix.asArray();
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void set_view_frustum_culling(const void* const viewer, bool enabled) {
|
||||
((FilamentViewer*)viewer)->setViewFrustumCulling(enabled);
|
||||
}
|
||||
|
||||
16
pubspec.lock
16
pubspec.lock
@@ -120,14 +120,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.7"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -269,14 +261,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
wasm_ffi:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: wasm_ffi
|
||||
sha256: "5da66560305dd659d62caef535c5314abd9302c122e6eef8681e6879fbbfe358"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.4"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
Reference in New Issue
Block a user