From 395de95d375291d3aecced9c5a8dd66edf3562a9 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Thu, 9 Nov 2023 11:41:40 +0800 Subject: [PATCH] more methods for projection/culling projection matrices & frustum --- ios/include/FilamentViewer.hpp | 2 + ios/include/FlutterFilamentApi.h | 2 + ios/src/FilamentViewer.cpp | 34 +++- ios/src/FlutterFilamentApi.cpp | 13 ++ lib/filament_controller.dart | 7 +- lib/filament_controller_ffi.dart | 25 ++- lib/generated_bindings.dart | 272 +++++++++++++++-------------- macos/include/FilamentViewer.hpp | 2 + macos/include/FlutterFilamentApi.h | 2 + macos/src/AssetManager.cpp | 7 +- macos/src/FilamentViewer.cpp | 30 ++++ macos/src/FlutterFilamentApi.cpp | 13 ++ pubspec.yaml | 2 +- 13 files changed, 267 insertions(+), 144 deletions(-) diff --git a/ios/include/FilamentViewer.hpp b/ios/include/FilamentViewer.hpp index e8f723bd..74fa1d48 100644 --- a/ios/include/FilamentViewer.hpp +++ b/ios/include/FilamentViewer.hpp @@ -101,8 +101,10 @@ namespace polyvox const math::mat4 getCameraModelMatrix(); const math::mat4 getCameraViewMatrix(); const math::mat4 getCameraProjectionMatrix(); + const math::mat4 getCameraCullingProjectionMatrix(); const filament::Frustum getCameraFrustum(); void setCameraModelMatrix(const float *const matrix); + void setCameraProjectionMatrix(const double *const matrix, double near, double far); void setCameraFocalLength(float fl); void setCameraFocusDistance(float focusDistance); void setCameraManipulatorOptions(filament::camutils::Mode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed); diff --git a/ios/include/FlutterFilamentApi.h b/ios/include/FlutterFilamentApi.h index 882c595c..d53a0a71 100644 --- a/ios/include/FlutterFilamentApi.h +++ b/ios/include/FlutterFilamentApi.h @@ -152,6 +152,8 @@ FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void* const viewer, con 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_projection_matrix(const void* const viewer, const double *const matrix, double near, double far); +FLUTTER_PLUGIN_EXPORT const double* const get_camera_culling_projection_matrix(const void* const viewer); FLUTTER_PLUGIN_EXPORT const double* const get_camera_frustum(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); diff --git a/ios/src/FilamentViewer.cpp b/ios/src/FilamentViewer.cpp index 1a17370f..13bb7302 100644 --- a/ios/src/FilamentViewer.cpp +++ b/ios/src/FilamentViewer.cpp @@ -677,10 +677,8 @@ namespace polyvox .texture(RenderTarget::AttachmentPoint::DEPTH, _rtDepth) .build(*_engine); - // Make a specific viewport just for our render target _view->setRenderTarget(_rt); - - Log("Set render target for texture id %u to %u x %u", texture, width, height); + Log("Created render target for texture id %u (%u x %u)", texture, width, height); } void FilamentViewer::destroySwapChain() @@ -1109,6 +1107,30 @@ namespace polyvox cam.setModelMatrix(modelMatrix); } + void FilamentViewer::setCameraProjectionMatrix(const double *const matrix, double near, double far) + { + Camera &cam = _view->getCamera(); + + mat4 projectionMatrix( + matrix[0], + matrix[1], + matrix[2], + matrix[3], + matrix[4], + matrix[5], + matrix[6], + matrix[7], + matrix[8], + matrix[9], + matrix[10], + matrix[11], + matrix[12], + matrix[13], + matrix[14], + matrix[15]); + cam.setCustomProjection(projectionMatrix, near, far); + } + const math::mat4 FilamentViewer::getCameraModelMatrix() { const auto &cam = _view->getCamera(); @@ -1127,6 +1149,12 @@ namespace polyvox return cam.getProjectionMatrix(); } + const math::mat4 FilamentViewer::getCameraCullingProjectionMatrix() + { + const auto &cam = _view->getCamera(); + return cam.getCullingProjectionMatrix(); + } + const filament::Frustum FilamentViewer::getCameraFrustum() { const auto &cam = _view->getCamera(); diff --git a/ios/src/FlutterFilamentApi.cpp b/ios/src/FlutterFilamentApi.cpp index 69b4784d..edecde8c 100644 --- a/ios/src/FlutterFilamentApi.cpp +++ b/ios/src/FlutterFilamentApi.cpp @@ -139,6 +139,19 @@ extern "C" memcpy(array, matrix.asArray(), 16 * sizeof(double)); return array; } + + const double *const get_camera_culling_projection_matrix(const void *const viewer) + { + const auto &matrix = ((FilamentViewer *)viewer)->getCameraCullingProjectionMatrix(); + double *array = (double *)calloc(16, sizeof(double)); + memcpy(array, matrix.asArray(), 16 * sizeof(double)); + return array; + } + + void set_camera_projection_matrix(const void *const viewer, const double* const matrix, double near, double far) + { + ((FilamentViewer *)viewer)->setCameraProjectionMatrix(matrix, near, far); + } const double *const get_camera_frustum(const void *const viewer) { diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index 4c6a391e..e2b5c3f2 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -364,10 +364,15 @@ abstract class FilamentController { /// Future getCameraProjectionMatrix(); + /// + /// Get the camera's culling projection matrix. See Camera.h for more details. + /// + Future getCameraCullingProjectionMatrix(); + /// /// Get the camera's culling frustum in world space. Returns six Vector4s defining the left, right, bottom, top, far and near planes respectively. See Camera.h and Frustum.h for more details. /// - Future> getCameraFrustum(); + Future getCameraFrustum(); /// /// Set the camera position in world space. Note this is not persistent - any viewport navigation will reset the camera transform. diff --git a/lib/filament_controller_ffi.dart b/lib/filament_controller_ffi.dart index 2d22a66a..fe90c4d3 100644 --- a/lib/filament_controller_ffi.dart +++ b/lib/filament_controller_ffi.dart @@ -1097,18 +1097,25 @@ class FilamentControllerFFI extends FilamentController { } @override - Future> getCameraFrustum() async { + Future getCameraCullingProjectionMatrix() async { if (_viewer == null) { throw Exception("No viewer available"); } - var arrayPtr = get_camera_frustum(_viewer!); - var doubleList = arrayPtr.asTypedList(6 * 4); - var frustum = []; - for (int i = 0; i < 6; i++) { - var plane = Vector4.array(doubleList.sublist(i * 4, (i + 1) * 4)); - frustum.add(plane); - } + var arrayPtr = get_camera_culling_projection_matrix(_viewer!); + var doubleList = arrayPtr.asTypedList(16); + var projectionMatrix = Matrix4.fromList(doubleList); flutter_filament_free(arrayPtr.cast()); - return frustum; + return projectionMatrix; + } + + @override + Future getCameraFrustum() async { + if (_viewer == null) { + throw Exception("No viewer available"); + } + + var projectionMatrix = await getCameraProjectionMatrix(); + + return Frustum.matrix(projectionMatrix); } } diff --git a/lib/generated_bindings.dart b/lib/generated_bindings.dart index 4070ec09..d033becc 100644 --- a/lib/generated_bindings.dart +++ b/lib/generated_bindings.dart @@ -10,7 +10,7 @@ import 'dart:ffi' as ffi; ffi.Pointer, ffi.Pointer, ffi.Pointer)>( - symbol: 'create_filament_viewer', assetId: 'libflutter_filament') + symbol: 'create_filament_viewer', assetId: 'flutter_filament_plugin') external ffi.Pointer create_filament_viewer( ffi.Pointer context, ffi.Pointer loader, @@ -19,7 +19,7 @@ external ffi.Pointer create_filament_viewer( ); @ffi.Native)>( - symbol: 'destroy_filament_viewer', assetId: 'libflutter_filament') + symbol: 'destroy_filament_viewer', assetId: 'flutter_filament_plugin') external void destroy_filament_viewer( ffi.Pointer viewer, ); @@ -29,7 +29,7 @@ external void destroy_filament_viewer( LoadFilamentResourceFromOwner, FreeFilamentResourceFromOwner, ffi.Pointer)>( - symbol: 'make_resource_loader', assetId: 'libflutter_filament') + symbol: 'make_resource_loader', assetId: 'flutter_filament_plugin') external ffi.Pointer make_resource_loader( LoadFilamentResourceFromOwner loadFn, FreeFilamentResourceFromOwner freeFn, @@ -37,7 +37,7 @@ external ffi.Pointer make_resource_loader( ); @ffi.Native Function(ffi.Pointer)>( - symbol: 'get_asset_manager', assetId: 'libflutter_filament') + symbol: 'get_asset_manager', assetId: 'flutter_filament_plugin') external ffi.Pointer get_asset_manager( ffi.Pointer viewer, ); @@ -45,7 +45,7 @@ external ffi.Pointer get_asset_manager( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.IntPtr, ffi.Uint32, ffi.Uint32)>( - symbol: 'create_render_target', assetId: 'libflutter_filament') + symbol: 'create_render_target', assetId: 'flutter_filament_plugin') external void create_render_target( ffi.Pointer viewer, int texture, @@ -54,7 +54,7 @@ external void create_render_target( ); @ffi.Native)>( - symbol: 'clear_background_image', assetId: 'libflutter_filament') + symbol: 'clear_background_image', assetId: 'flutter_filament_plugin') external void clear_background_image( ffi.Pointer viewer, ); @@ -62,7 +62,7 @@ external void clear_background_image( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Pointer, ffi.Bool)>( - symbol: 'set_background_image', assetId: 'libflutter_filament') + symbol: 'set_background_image', assetId: 'flutter_filament_plugin') external void set_background_image( ffi.Pointer viewer, ffi.Pointer path, @@ -72,7 +72,7 @@ external void set_background_image( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Float, ffi.Float, ffi.Bool)>( - symbol: 'set_background_image_position', assetId: 'libflutter_filament') + symbol: 'set_background_image_position', assetId: 'flutter_filament_plugin') external void set_background_image_position( ffi.Pointer viewer, double x, @@ -83,7 +83,7 @@ external void set_background_image_position( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Float, ffi.Float, ffi.Float, ffi.Float)>( - symbol: 'set_background_color', assetId: 'libflutter_filament') + symbol: 'set_background_color', assetId: 'flutter_filament_plugin') external void set_background_color( ffi.Pointer viewer, double r, @@ -93,21 +93,21 @@ external void set_background_color( ); @ffi.Native, ffi.Int)>( - symbol: 'set_tone_mapping', assetId: 'libflutter_filament') + symbol: 'set_tone_mapping', assetId: 'flutter_filament_plugin') external void set_tone_mapping( ffi.Pointer viewer, int toneMapping, ); @ffi.Native, ffi.Float)>( - symbol: 'set_bloom', assetId: 'libflutter_filament') + symbol: 'set_bloom', assetId: 'flutter_filament_plugin') external void set_bloom( ffi.Pointer viewer, double strength, ); @ffi.Native, ffi.Pointer)>( - symbol: 'load_skybox', assetId: 'libflutter_filament') + symbol: 'load_skybox', assetId: 'flutter_filament_plugin') external void load_skybox( ffi.Pointer viewer, ffi.Pointer skyboxPath, @@ -115,7 +115,7 @@ external void load_skybox( @ffi.Native< ffi.Void Function(ffi.Pointer, ffi.Pointer, - ffi.Float)>(symbol: 'load_ibl', assetId: 'libflutter_filament') + ffi.Float)>(symbol: 'load_ibl', assetId: 'flutter_filament_plugin') external void load_ibl( ffi.Pointer viewer, ffi.Pointer iblPath, @@ -123,13 +123,13 @@ external void load_ibl( ); @ffi.Native)>( - symbol: 'remove_skybox', assetId: 'libflutter_filament') + symbol: 'remove_skybox', assetId: 'flutter_filament_plugin') external void remove_skybox( ffi.Pointer viewer, ); @ffi.Native)>( - symbol: 'remove_ibl', assetId: 'libflutter_filament') + symbol: 'remove_ibl', assetId: 'flutter_filament_plugin') external void remove_ibl( ffi.Pointer viewer, ); @@ -146,7 +146,7 @@ external void remove_ibl( ffi.Float, ffi.Float, ffi.Float, - ffi.Bool)>(symbol: 'add_light', assetId: 'libflutter_filament') + ffi.Bool)>(symbol: 'add_light', assetId: 'flutter_filament_plugin') external int add_light( ffi.Pointer viewer, int type, @@ -162,21 +162,21 @@ external int add_light( ); @ffi.Native, EntityId)>( - symbol: 'remove_light', assetId: 'libflutter_filament') + symbol: 'remove_light', assetId: 'flutter_filament_plugin') external void remove_light( ffi.Pointer viewer, int entityId, ); @ffi.Native)>( - symbol: 'clear_lights', assetId: 'libflutter_filament') + symbol: 'clear_lights', assetId: 'flutter_filament_plugin') external void clear_lights( ffi.Pointer viewer, ); @ffi.Native< EntityId Function(ffi.Pointer, ffi.Pointer, - ffi.Bool)>(symbol: 'load_glb', assetId: 'libflutter_filament') + ffi.Bool)>(symbol: 'load_glb', assetId: 'flutter_filament_plugin') external int load_glb( ffi.Pointer assetManager, ffi.Pointer assetPath, @@ -186,7 +186,7 @@ external int load_glb( @ffi.Native< EntityId Function(ffi.Pointer, ffi.Pointer, ffi.Pointer)>( - symbol: 'load_gltf', assetId: 'libflutter_filament') + symbol: 'load_gltf', assetId: 'flutter_filament_plugin') external int load_gltf( ffi.Pointer assetManager, ffi.Pointer assetPath, @@ -196,7 +196,7 @@ external int load_gltf( @ffi.Native< ffi.Bool Function( ffi.Pointer, EntityId, ffi.Pointer)>( - symbol: 'set_camera', assetId: 'libflutter_filament') + symbol: 'set_camera', assetId: 'flutter_filament_plugin') external bool set_camera( ffi.Pointer viewer, int asset, @@ -204,7 +204,7 @@ external bool set_camera( ); @ffi.Native, ffi.Bool)>( - symbol: 'set_view_frustum_culling', assetId: 'libflutter_filament') + symbol: 'set_view_frustum_culling', assetId: 'flutter_filament_plugin') external void set_view_frustum_culling( ffi.Pointer viewer, bool enabled, @@ -220,7 +220,7 @@ external void set_view_frustum_culling( ffi.Void Function(ffi.Pointer buf, ffi.Size size, ffi.Pointer data)>>, ffi.Pointer)>( - symbol: 'render', assetId: 'libflutter_filament') + symbol: 'render', assetId: 'flutter_filament_plugin') external void render( ffi.Pointer viewer, int frameTimeInNanos, @@ -236,7 +236,7 @@ external void render( @ffi.Native< ffi.Void Function(ffi.Pointer, ffi.Pointer, ffi.Uint32, ffi.Uint32)>( - symbol: 'create_swap_chain', assetId: 'libflutter_filament') + symbol: 'create_swap_chain', assetId: 'flutter_filament_plugin') external void create_swap_chain( ffi.Pointer viewer, ffi.Pointer window, @@ -245,13 +245,13 @@ external void create_swap_chain( ); @ffi.Native)>( - symbol: 'destroy_swap_chain', assetId: 'libflutter_filament') + symbol: 'destroy_swap_chain', assetId: 'flutter_filament_plugin') external void destroy_swap_chain( ffi.Pointer viewer, ); @ffi.Native, ffi.Float)>( - symbol: 'set_frame_interval', assetId: 'libflutter_filament') + symbol: 'set_frame_interval', assetId: 'flutter_filament_plugin') external void set_frame_interval( ffi.Pointer viewer, double interval, @@ -261,7 +261,7 @@ external void set_frame_interval( ffi.Void Function( ffi.Pointer, ffi.Uint32, ffi.Uint32, ffi.Float)>( symbol: 'update_viewport_and_camera_projection', - assetId: 'libflutter_filament') + assetId: 'flutter_filament_plugin') external void update_viewport_and_camera_projection( ffi.Pointer viewer, int width, @@ -270,14 +270,14 @@ external void update_viewport_and_camera_projection( ); @ffi.Native)>( - symbol: 'scroll_begin', assetId: 'libflutter_filament') + symbol: 'scroll_begin', assetId: 'flutter_filament_plugin') external void scroll_begin( ffi.Pointer viewer, ); @ffi.Native< ffi.Void Function(ffi.Pointer, ffi.Float, ffi.Float, - ffi.Float)>(symbol: 'scroll_update', assetId: 'libflutter_filament') + ffi.Float)>(symbol: 'scroll_update', assetId: 'flutter_filament_plugin') external void scroll_update( ffi.Pointer viewer, double x, @@ -286,14 +286,14 @@ external void scroll_update( ); @ffi.Native)>( - symbol: 'scroll_end', assetId: 'libflutter_filament') + symbol: 'scroll_end', assetId: 'flutter_filament_plugin') external void scroll_end( ffi.Pointer viewer, ); @ffi.Native< ffi.Void Function(ffi.Pointer, ffi.Float, ffi.Float, - ffi.Bool)>(symbol: 'grab_begin', assetId: 'libflutter_filament') + ffi.Bool)>(symbol: 'grab_begin', assetId: 'flutter_filament_plugin') external void grab_begin( ffi.Pointer viewer, double x, @@ -302,7 +302,7 @@ external void grab_begin( ); @ffi.Native, ffi.Float, ffi.Float)>( - symbol: 'grab_update', assetId: 'libflutter_filament') + symbol: 'grab_update', assetId: 'flutter_filament_plugin') external void grab_update( ffi.Pointer viewer, double x, @@ -310,7 +310,7 @@ external void grab_update( ); @ffi.Native)>( - symbol: 'grab_end', assetId: 'libflutter_filament') + symbol: 'grab_end', assetId: 'flutter_filament_plugin') external void grab_end( ffi.Pointer viewer, ); @@ -321,7 +321,7 @@ external void grab_end( EntityId, ffi.Pointer, ffi.Pointer, - ffi.Int)>(symbol: 'apply_weights', assetId: 'libflutter_filament') + ffi.Int)>(symbol: 'apply_weights', assetId: 'flutter_filament_plugin') external void apply_weights( ffi.Pointer assetManager, int asset, @@ -333,7 +333,7 @@ external void apply_weights( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Pointer, ffi.Pointer, ffi.Int)>( - symbol: 'set_morph_target_weights', assetId: 'libflutter_filament') + symbol: 'set_morph_target_weights', assetId: 'flutter_filament_plugin') external void set_morph_target_weights( ffi.Pointer assetManager, int asset, @@ -352,7 +352,7 @@ external void set_morph_target_weights( ffi.Int, ffi.Int, ffi.Float)>( - symbol: 'set_morph_animation', assetId: 'libflutter_filament') + symbol: 'set_morph_animation', assetId: 'flutter_filament_plugin') external bool set_morph_animation( ffi.Pointer assetManager, int asset, @@ -375,7 +375,7 @@ external bool set_morph_animation( ffi.Pointer>, ffi.Int, ffi.Float)>( - symbol: 'set_bone_animation', assetId: 'libflutter_filament') + symbol: 'set_bone_animation', assetId: 'flutter_filament_plugin') external void set_bone_animation( ffi.Pointer assetManager, int asset, @@ -389,14 +389,9 @@ external void set_bone_animation( ); @ffi.Native< - ffi.Void Function( - ffi.Pointer, - EntityId, - ffi.Int, - ffi.Bool, - ffi.Bool, - ffi.Bool, - ffi.Float)>(symbol: 'play_animation', assetId: 'libflutter_filament') + ffi.Void Function(ffi.Pointer, EntityId, ffi.Int, ffi.Bool, + ffi.Bool, ffi.Bool, ffi.Float)>( + symbol: 'play_animation', assetId: 'flutter_filament_plugin') external void play_animation( ffi.Pointer assetManager, int asset, @@ -409,7 +404,7 @@ external void play_animation( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Int, ffi.Int)>( - symbol: 'set_animation_frame', assetId: 'libflutter_filament') + symbol: 'set_animation_frame', assetId: 'flutter_filament_plugin') external void set_animation_frame( ffi.Pointer assetManager, int asset, @@ -418,7 +413,7 @@ external void set_animation_frame( ); @ffi.Native, EntityId, ffi.Int)>( - symbol: 'stop_animation', assetId: 'libflutter_filament') + symbol: 'stop_animation', assetId: 'flutter_filament_plugin') external void stop_animation( ffi.Pointer assetManager, int asset, @@ -426,15 +421,16 @@ external void stop_animation( ); @ffi.Native, EntityId)>( - symbol: 'get_animation_count', assetId: 'libflutter_filament') + symbol: 'get_animation_count', assetId: 'flutter_filament_plugin') external int get_animation_count( ffi.Pointer assetManager, int asset, ); @ffi.Native< - ffi.Void Function(ffi.Pointer, EntityId, ffi.Pointer, - ffi.Int)>(symbol: 'get_animation_name', assetId: 'libflutter_filament') + ffi.Void Function( + ffi.Pointer, EntityId, ffi.Pointer, ffi.Int)>( + symbol: 'get_animation_name', assetId: 'flutter_filament_plugin') external void get_animation_name( ffi.Pointer assetManager, int asset, @@ -443,7 +439,7 @@ external void get_animation_name( ); @ffi.Native, EntityId, ffi.Int)>( - symbol: 'get_animation_duration', assetId: 'libflutter_filament') + symbol: 'get_animation_duration', assetId: 'flutter_filament_plugin') external double get_animation_duration( ffi.Pointer assetManager, int asset, @@ -453,7 +449,7 @@ external double get_animation_duration( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Pointer, ffi.Pointer, ffi.Int)>( - symbol: 'get_morph_target_name', assetId: 'libflutter_filament') + symbol: 'get_morph_target_name', assetId: 'flutter_filament_plugin') external void get_morph_target_name( ffi.Pointer assetManager, int asset, @@ -465,7 +461,7 @@ external void get_morph_target_name( @ffi.Native< ffi.Int Function( ffi.Pointer, EntityId, ffi.Pointer)>( - symbol: 'get_morph_target_name_count', assetId: 'libflutter_filament') + symbol: 'get_morph_target_name_count', assetId: 'flutter_filament_plugin') external int get_morph_target_name_count( ffi.Pointer assetManager, int asset, @@ -473,14 +469,14 @@ external int get_morph_target_name_count( ); @ffi.Native, EntityId)>( - symbol: 'remove_asset', assetId: 'libflutter_filament') + symbol: 'remove_asset', assetId: 'flutter_filament_plugin') external void remove_asset( ffi.Pointer viewer, int asset, ); @ffi.Native)>( - symbol: 'clear_assets', assetId: 'libflutter_filament') + symbol: 'clear_assets', assetId: 'flutter_filament_plugin') external void clear_assets( ffi.Pointer viewer, ); @@ -495,7 +491,7 @@ external void clear_assets( ffi.Float, ffi.Float, ffi.Float)>( - symbol: 'set_material_color', assetId: 'libflutter_filament') + symbol: 'set_material_color', assetId: 'flutter_filament_plugin') external bool set_material_color( ffi.Pointer assetManager, int asset, @@ -508,7 +504,7 @@ external bool set_material_color( ); @ffi.Native, EntityId)>( - symbol: 'transform_to_unit_cube', assetId: 'libflutter_filament') + symbol: 'transform_to_unit_cube', assetId: 'flutter_filament_plugin') external void transform_to_unit_cube( ffi.Pointer assetManager, int asset, @@ -516,7 +512,7 @@ external void transform_to_unit_cube( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Float, ffi.Float, - ffi.Float)>(symbol: 'set_position', assetId: 'libflutter_filament') + ffi.Float)>(symbol: 'set_position', assetId: 'flutter_filament_plugin') external void set_position( ffi.Pointer assetManager, int asset, @@ -532,7 +528,7 @@ external void set_position( ffi.Float, ffi.Float, ffi.Float, - ffi.Float)>(symbol: 'set_rotation', assetId: 'libflutter_filament') + ffi.Float)>(symbol: 'set_rotation', assetId: 'flutter_filament_plugin') external void set_rotation( ffi.Pointer assetManager, int asset, @@ -543,7 +539,7 @@ external void set_rotation( ); @ffi.Native, EntityId, ffi.Float)>( - symbol: 'set_scale', assetId: 'libflutter_filament') + symbol: 'set_scale', assetId: 'flutter_filament_plugin') external void set_scale( ffi.Pointer assetManager, int asset, @@ -551,7 +547,7 @@ external void set_scale( ); @ffi.Native, EntityId)>( - symbol: 'move_camera_to_asset', assetId: 'libflutter_filament') + symbol: 'move_camera_to_asset', assetId: 'flutter_filament_plugin') external void move_camera_to_asset( ffi.Pointer viewer, int asset, @@ -560,7 +556,7 @@ external void move_camera_to_asset( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Float, ffi.Float, ffi.Float)>( - symbol: 'set_camera_exposure', assetId: 'libflutter_filament') + symbol: 'set_camera_exposure', assetId: 'flutter_filament_plugin') external void set_camera_exposure( ffi.Pointer viewer, double aperture, @@ -571,7 +567,7 @@ external void set_camera_exposure( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Float, ffi.Float, ffi.Float)>( - symbol: 'set_camera_position', assetId: 'libflutter_filament') + symbol: 'set_camera_position', assetId: 'flutter_filament_plugin') external void set_camera_position( ffi.Pointer viewer, double x, @@ -580,7 +576,7 @@ external void set_camera_position( ); @ffi.Native)>( - symbol: 'get_camera_position', assetId: 'libflutter_filament') + symbol: 'get_camera_position', assetId: 'flutter_filament_plugin') external void get_camera_position( ffi.Pointer viewer, ); @@ -588,7 +584,7 @@ external void get_camera_position( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Float, ffi.Float, ffi.Float, ffi.Float)>( - symbol: 'set_camera_rotation', assetId: 'libflutter_filament') + symbol: 'set_camera_rotation', assetId: 'flutter_filament_plugin') external void set_camera_rotation( ffi.Pointer viewer, double rads, @@ -598,45 +594,63 @@ external void set_camera_rotation( ); @ffi.Native, ffi.Pointer)>( - symbol: 'set_camera_model_matrix', assetId: 'libflutter_filament') + symbol: 'set_camera_model_matrix', assetId: 'flutter_filament_plugin') external void set_camera_model_matrix( ffi.Pointer viewer, ffi.Pointer matrix, ); @ffi.Native Function(ffi.Pointer)>( - symbol: 'get_camera_model_matrix', assetId: 'libflutter_filament') + symbol: 'get_camera_model_matrix', assetId: 'flutter_filament_plugin') external ffi.Pointer get_camera_model_matrix( ffi.Pointer viewer, ); @ffi.Native Function(ffi.Pointer)>( - symbol: 'get_camera_view_matrix', assetId: 'libflutter_filament') + symbol: 'get_camera_view_matrix', assetId: 'flutter_filament_plugin') external ffi.Pointer get_camera_view_matrix( ffi.Pointer viewer, ); @ffi.Native Function(ffi.Pointer)>( - symbol: 'get_camera_projection_matrix', assetId: 'libflutter_filament') + symbol: 'get_camera_projection_matrix', assetId: 'flutter_filament_plugin') external ffi.Pointer get_camera_projection_matrix( ffi.Pointer viewer, ); +@ffi.Native< + ffi.Void Function(ffi.Pointer, ffi.Pointer, + ffi.Double, ffi.Double)>( + symbol: 'set_camera_projection_matrix', assetId: 'flutter_filament_plugin') +external void set_camera_projection_matrix( + ffi.Pointer viewer, + ffi.Pointer matrix, + double near, + double far, +); + @ffi.Native Function(ffi.Pointer)>( - symbol: 'get_camera_frustum', assetId: 'libflutter_filament') + symbol: 'get_camera_culling_projection_matrix', + assetId: 'flutter_filament_plugin') +external ffi.Pointer get_camera_culling_projection_matrix( + ffi.Pointer viewer, +); + +@ffi.Native Function(ffi.Pointer)>( + symbol: 'get_camera_frustum', assetId: 'flutter_filament_plugin') external ffi.Pointer get_camera_frustum( ffi.Pointer viewer, ); @ffi.Native, ffi.Float)>( - symbol: 'set_camera_focal_length', assetId: 'libflutter_filament') + symbol: 'set_camera_focal_length', assetId: 'flutter_filament_plugin') external void set_camera_focal_length( ffi.Pointer viewer, double focalLength, ); @ffi.Native, ffi.Float)>( - symbol: 'set_camera_focus_distance', assetId: 'libflutter_filament') + symbol: 'set_camera_focus_distance', assetId: 'flutter_filament_plugin') external void set_camera_focus_distance( ffi.Pointer viewer, double focusDistance, @@ -645,7 +659,8 @@ external void set_camera_focus_distance( @ffi.Native< ffi.Void Function(ffi.Pointer, _ManipulatorMode, ffi.Double, ffi.Double, ffi.Double)>( - symbol: 'set_camera_manipulator_options', assetId: 'libflutter_filament') + symbol: 'set_camera_manipulator_options', + assetId: 'flutter_filament_plugin') external void set_camera_manipulator_options( ffi.Pointer viewer, int mode, @@ -657,7 +672,7 @@ external void set_camera_manipulator_options( @ffi.Native< ffi.Int Function( ffi.Pointer, EntityId, ffi.Pointer)>( - symbol: 'hide_mesh', assetId: 'libflutter_filament') + symbol: 'hide_mesh', assetId: 'flutter_filament_plugin') external int hide_mesh( ffi.Pointer assetManager, int asset, @@ -667,7 +682,7 @@ external int hide_mesh( @ffi.Native< ffi.Int Function( ffi.Pointer, EntityId, ffi.Pointer)>( - symbol: 'reveal_mesh', assetId: 'libflutter_filament') + symbol: 'reveal_mesh', assetId: 'flutter_filament_plugin') external int reveal_mesh( ffi.Pointer assetManager, int asset, @@ -675,15 +690,16 @@ external int reveal_mesh( ); @ffi.Native, ffi.Bool)>( - symbol: 'set_post_processing', assetId: 'libflutter_filament') + symbol: 'set_post_processing', assetId: 'flutter_filament_plugin') external void set_post_processing( ffi.Pointer viewer, bool enabled, ); @ffi.Native< - ffi.Void Function(ffi.Pointer, ffi.Int, ffi.Int, - ffi.Pointer)>(symbol: 'pick', assetId: 'libflutter_filament') + ffi.Void Function( + ffi.Pointer, ffi.Int, ffi.Int, ffi.Pointer)>( + symbol: 'pick', assetId: 'flutter_filament_plugin') external void pick( ffi.Pointer viewer, int x, @@ -692,18 +708,18 @@ external void pick( ); @ffi.Native Function(ffi.Pointer, EntityId)>( - symbol: 'get_name_for_entity', assetId: 'libflutter_filament') + symbol: 'get_name_for_entity', assetId: 'flutter_filament_plugin') external ffi.Pointer get_name_for_entity( ffi.Pointer assetManager, int entityId, ); @ffi.Native( - symbol: 'ios_dummy', assetId: 'libflutter_filament') + symbol: 'ios_dummy', assetId: 'flutter_filament_plugin') external void ios_dummy(); @ffi.Native)>( - symbol: 'flutter_filament_free', assetId: 'libflutter_filament') + symbol: 'flutter_filament_free', assetId: 'flutter_filament_plugin') external void flutter_filament_free( ffi.Pointer ptr, ); @@ -720,7 +736,7 @@ external void flutter_filament_free( ffi.Void Function( ffi.Pointer renderCallbackOwner)>>, ffi.Pointer)>( - symbol: 'create_filament_viewer_ffi', assetId: 'libflutter_filament') + symbol: 'create_filament_viewer_ffi', assetId: 'flutter_filament_plugin') external ffi.Pointer create_filament_viewer_ffi( ffi.Pointer context, ffi.Pointer platform, @@ -736,7 +752,7 @@ external ffi.Pointer create_filament_viewer_ffi( @ffi.Native< ffi.Void Function(ffi.Pointer, ffi.Pointer, ffi.Uint32, ffi.Uint32)>( - symbol: 'create_swap_chain_ffi', assetId: 'libflutter_filament') + symbol: 'create_swap_chain_ffi', assetId: 'flutter_filament_plugin') external void create_swap_chain_ffi( ffi.Pointer viewer, ffi.Pointer surface, @@ -745,7 +761,7 @@ external void create_swap_chain_ffi( ); @ffi.Native)>( - symbol: 'destroy_swap_chain_ffi', assetId: 'libflutter_filament') + symbol: 'destroy_swap_chain_ffi', assetId: 'flutter_filament_plugin') external void destroy_swap_chain_ffi( ffi.Pointer viewer, ); @@ -753,7 +769,7 @@ external void destroy_swap_chain_ffi( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.IntPtr, ffi.Uint32, ffi.Uint32)>( - symbol: 'create_render_target_ffi', assetId: 'libflutter_filament') + symbol: 'create_render_target_ffi', assetId: 'flutter_filament_plugin') external void create_render_target_ffi( ffi.Pointer viewer, int nativeTextureId, @@ -762,32 +778,33 @@ external void create_render_target_ffi( ); @ffi.Native)>( - symbol: 'destroy_filament_viewer_ffi', assetId: 'libflutter_filament') + symbol: 'destroy_filament_viewer_ffi', assetId: 'flutter_filament_plugin') external void destroy_filament_viewer_ffi( ffi.Pointer viewer, ); @ffi.Native)>( - symbol: 'render_ffi', assetId: 'libflutter_filament') + symbol: 'render_ffi', assetId: 'flutter_filament_plugin') external void render_ffi( ffi.Pointer viewer, ); @ffi.Native( - symbol: 'make_render_callback_fn_pointer', assetId: 'libflutter_filament') + symbol: 'make_render_callback_fn_pointer', + assetId: 'flutter_filament_plugin') external FilamentRenderCallback make_render_callback_fn_pointer( FilamentRenderCallback arg0, ); @ffi.Native, ffi.Bool)>( - symbol: 'set_rendering_ffi', assetId: 'libflutter_filament') + symbol: 'set_rendering_ffi', assetId: 'flutter_filament_plugin') external void set_rendering_ffi( ffi.Pointer viewer, bool rendering, ); @ffi.Native( - symbol: 'set_frame_interval_ffi', assetId: 'libflutter_filament') + symbol: 'set_frame_interval_ffi', assetId: 'flutter_filament_plugin') external void set_frame_interval_ffi( double frameInterval, ); @@ -796,7 +813,7 @@ external void set_frame_interval_ffi( ffi.Void Function( ffi.Pointer, ffi.Uint32, ffi.Uint32, ffi.Float)>( symbol: 'update_viewport_and_camera_projection_ffi', - assetId: 'libflutter_filament') + assetId: 'flutter_filament_plugin') external void update_viewport_and_camera_projection_ffi( ffi.Pointer viewer, int width, @@ -807,7 +824,7 @@ external void update_viewport_and_camera_projection_ffi( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Float, ffi.Float, ffi.Float, ffi.Float)>( - symbol: 'set_background_color_ffi', assetId: 'libflutter_filament') + symbol: 'set_background_color_ffi', assetId: 'flutter_filament_plugin') external void set_background_color_ffi( ffi.Pointer viewer, double r, @@ -817,7 +834,7 @@ external void set_background_color_ffi( ); @ffi.Native)>( - symbol: 'clear_background_image_ffi', assetId: 'libflutter_filament') + symbol: 'clear_background_image_ffi', assetId: 'flutter_filament_plugin') external void clear_background_image_ffi( ffi.Pointer viewer, ); @@ -825,7 +842,7 @@ external void clear_background_image_ffi( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Pointer, ffi.Bool)>( - symbol: 'set_background_image_ffi', assetId: 'libflutter_filament') + symbol: 'set_background_image_ffi', assetId: 'flutter_filament_plugin') external void set_background_image_ffi( ffi.Pointer viewer, ffi.Pointer path, @@ -835,7 +852,8 @@ external void set_background_image_ffi( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Float, ffi.Float, ffi.Bool)>( - symbol: 'set_background_image_position_ffi', assetId: 'libflutter_filament') + symbol: 'set_background_image_position_ffi', + assetId: 'flutter_filament_plugin') external void set_background_image_position_ffi( ffi.Pointer viewer, double x, @@ -844,21 +862,21 @@ external void set_background_image_position_ffi( ); @ffi.Native, ffi.Int)>( - symbol: 'set_tone_mapping_ffi', assetId: 'libflutter_filament') + symbol: 'set_tone_mapping_ffi', assetId: 'flutter_filament_plugin') external void set_tone_mapping_ffi( ffi.Pointer viewer, int toneMapping, ); @ffi.Native, ffi.Float)>( - symbol: 'set_bloom_ffi', assetId: 'libflutter_filament') + symbol: 'set_bloom_ffi', assetId: 'flutter_filament_plugin') external void set_bloom_ffi( ffi.Pointer viewer, double strength, ); @ffi.Native, ffi.Pointer)>( - symbol: 'load_skybox_ffi', assetId: 'libflutter_filament') + symbol: 'load_skybox_ffi', assetId: 'flutter_filament_plugin') external void load_skybox_ffi( ffi.Pointer viewer, ffi.Pointer skyboxPath, @@ -866,7 +884,7 @@ external void load_skybox_ffi( @ffi.Native< ffi.Void Function(ffi.Pointer, ffi.Pointer, - ffi.Float)>(symbol: 'load_ibl_ffi', assetId: 'libflutter_filament') + ffi.Float)>(symbol: 'load_ibl_ffi', assetId: 'flutter_filament_plugin') external void load_ibl_ffi( ffi.Pointer viewer, ffi.Pointer iblPath, @@ -874,13 +892,13 @@ external void load_ibl_ffi( ); @ffi.Native)>( - symbol: 'remove_skybox_ffi', assetId: 'libflutter_filament') + symbol: 'remove_skybox_ffi', assetId: 'flutter_filament_plugin') external void remove_skybox_ffi( ffi.Pointer viewer, ); @ffi.Native)>( - symbol: 'remove_ibl_ffi', assetId: 'libflutter_filament') + symbol: 'remove_ibl_ffi', assetId: 'flutter_filament_plugin') external void remove_ibl_ffi( ffi.Pointer viewer, ); @@ -897,7 +915,7 @@ external void remove_ibl_ffi( ffi.Float, ffi.Float, ffi.Float, - ffi.Bool)>(symbol: 'add_light_ffi', assetId: 'libflutter_filament') + ffi.Bool)>(symbol: 'add_light_ffi', assetId: 'flutter_filament_plugin') external int add_light_ffi( ffi.Pointer viewer, int type, @@ -913,21 +931,21 @@ external int add_light_ffi( ); @ffi.Native, EntityId)>( - symbol: 'remove_light_ffi', assetId: 'libflutter_filament') + symbol: 'remove_light_ffi', assetId: 'flutter_filament_plugin') external void remove_light_ffi( ffi.Pointer viewer, int entityId, ); @ffi.Native)>( - symbol: 'clear_lights_ffi', assetId: 'libflutter_filament') + symbol: 'clear_lights_ffi', assetId: 'flutter_filament_plugin') external void clear_lights_ffi( ffi.Pointer viewer, ); @ffi.Native< EntityId Function(ffi.Pointer, ffi.Pointer, - ffi.Bool)>(symbol: 'load_glb_ffi', assetId: 'libflutter_filament') + ffi.Bool)>(symbol: 'load_glb_ffi', assetId: 'flutter_filament_plugin') external int load_glb_ffi( ffi.Pointer assetManager, ffi.Pointer assetPath, @@ -937,7 +955,7 @@ external int load_glb_ffi( @ffi.Native< EntityId Function(ffi.Pointer, ffi.Pointer, ffi.Pointer)>( - symbol: 'load_gltf_ffi', assetId: 'libflutter_filament') + symbol: 'load_gltf_ffi', assetId: 'flutter_filament_plugin') external int load_gltf_ffi( ffi.Pointer assetManager, ffi.Pointer assetPath, @@ -945,14 +963,14 @@ external int load_gltf_ffi( ); @ffi.Native, EntityId)>( - symbol: 'remove_asset_ffi', assetId: 'libflutter_filament') + symbol: 'remove_asset_ffi', assetId: 'flutter_filament_plugin') external void remove_asset_ffi( ffi.Pointer viewer, int asset, ); @ffi.Native)>( - symbol: 'clear_assets_ffi', assetId: 'libflutter_filament') + symbol: 'clear_assets_ffi', assetId: 'flutter_filament_plugin') external void clear_assets_ffi( ffi.Pointer viewer, ); @@ -960,7 +978,7 @@ external void clear_assets_ffi( @ffi.Native< ffi.Bool Function( ffi.Pointer, EntityId, ffi.Pointer)>( - symbol: 'set_camera_ffi', assetId: 'libflutter_filament') + symbol: 'set_camera_ffi', assetId: 'flutter_filament_plugin') external bool set_camera_ffi( ffi.Pointer viewer, int asset, @@ -968,12 +986,9 @@ external bool set_camera_ffi( ); @ffi.Native< - ffi.Void Function( - ffi.Pointer, - EntityId, - ffi.Pointer, - ffi.Pointer, - ffi.Int)>(symbol: 'apply_weights_ffi', assetId: 'libflutter_filament') + ffi.Void Function(ffi.Pointer, EntityId, + ffi.Pointer, ffi.Pointer, ffi.Int)>( + symbol: 'apply_weights_ffi', assetId: 'flutter_filament_plugin') external void apply_weights_ffi( ffi.Pointer assetManager, int asset, @@ -985,7 +1000,7 @@ external void apply_weights_ffi( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Pointer, ffi.Pointer, ffi.Int)>( - symbol: 'set_morph_target_weights_ffi', assetId: 'libflutter_filament') + symbol: 'set_morph_target_weights_ffi', assetId: 'flutter_filament_plugin') external void set_morph_target_weights_ffi( ffi.Pointer assetManager, int asset, @@ -1004,7 +1019,7 @@ external void set_morph_target_weights_ffi( ffi.Int, ffi.Int, ffi.Float)>( - symbol: 'set_morph_animation_ffi', assetId: 'libflutter_filament') + symbol: 'set_morph_animation_ffi', assetId: 'flutter_filament_plugin') external bool set_morph_animation_ffi( ffi.Pointer assetManager, int asset, @@ -1027,7 +1042,7 @@ external bool set_morph_animation_ffi( ffi.Pointer>, ffi.Int, ffi.Float)>( - symbol: 'set_bone_animation_ffi', assetId: 'libflutter_filament') + symbol: 'set_bone_animation_ffi', assetId: 'flutter_filament_plugin') external void set_bone_animation_ffi( ffi.Pointer assetManager, int asset, @@ -1043,7 +1058,7 @@ external void set_bone_animation_ffi( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Int, ffi.Bool, ffi.Bool, ffi.Bool, ffi.Float)>( - symbol: 'play_animation_ffi', assetId: 'libflutter_filament') + symbol: 'play_animation_ffi', assetId: 'flutter_filament_plugin') external void play_animation_ffi( ffi.Pointer assetManager, int asset, @@ -1056,7 +1071,7 @@ external void play_animation_ffi( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Int, ffi.Int)>( - symbol: 'set_animation_frame_ffi', assetId: 'libflutter_filament') + symbol: 'set_animation_frame_ffi', assetId: 'flutter_filament_plugin') external void set_animation_frame_ffi( ffi.Pointer assetManager, int asset, @@ -1065,7 +1080,7 @@ external void set_animation_frame_ffi( ); @ffi.Native, EntityId, ffi.Int)>( - symbol: 'stop_animation_ffi', assetId: 'libflutter_filament') + symbol: 'stop_animation_ffi', assetId: 'flutter_filament_plugin') external void stop_animation_ffi( ffi.Pointer assetManager, int asset, @@ -1073,7 +1088,7 @@ external void stop_animation_ffi( ); @ffi.Native, EntityId)>( - symbol: 'get_animation_count_ffi', assetId: 'libflutter_filament') + symbol: 'get_animation_count_ffi', assetId: 'flutter_filament_plugin') external int get_animation_count_ffi( ffi.Pointer assetManager, int asset, @@ -1082,7 +1097,7 @@ external int get_animation_count_ffi( @ffi.Native< ffi.Void Function( ffi.Pointer, EntityId, ffi.Pointer, ffi.Int)>( - symbol: 'get_animation_name_ffi', assetId: 'libflutter_filament') + symbol: 'get_animation_name_ffi', assetId: 'flutter_filament_plugin') external void get_animation_name_ffi( ffi.Pointer assetManager, int asset, @@ -1093,7 +1108,7 @@ external void get_animation_name_ffi( @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Pointer, ffi.Pointer, ffi.Int)>( - symbol: 'get_morph_target_name_ffi', assetId: 'libflutter_filament') + symbol: 'get_morph_target_name_ffi', assetId: 'flutter_filament_plugin') external void get_morph_target_name_ffi( ffi.Pointer assetManager, int asset, @@ -1105,7 +1120,8 @@ external void get_morph_target_name_ffi( @ffi.Native< ffi.Int Function( ffi.Pointer, EntityId, ffi.Pointer)>( - symbol: 'get_morph_target_name_count_ffi', assetId: 'libflutter_filament') + symbol: 'get_morph_target_name_count_ffi', + assetId: 'flutter_filament_plugin') external int get_morph_target_name_count_ffi( ffi.Pointer assetManager, int asset, @@ -1113,7 +1129,7 @@ external int get_morph_target_name_count_ffi( ); @ffi.Native, ffi.Bool)>( - symbol: 'set_post_processing_ffi', assetId: 'libflutter_filament') + symbol: 'set_post_processing_ffi', assetId: 'flutter_filament_plugin') external void set_post_processing_ffi( ffi.Pointer viewer, bool enabled, @@ -1122,7 +1138,7 @@ external void set_post_processing_ffi( @ffi.Native< ffi.Void Function( ffi.Pointer, ffi.Int, ffi.Int, ffi.Pointer)>( - symbol: 'pick_ffi', assetId: 'libflutter_filament') + symbol: 'pick_ffi', assetId: 'flutter_filament_plugin') external void pick_ffi( ffi.Pointer viewer, int x, @@ -1131,7 +1147,7 @@ external void pick_ffi( ); @ffi.Native( - symbol: 'ios_dummy_ffi', assetId: 'libflutter_filament') + symbol: 'ios_dummy_ffi', assetId: 'flutter_filament_plugin') external void ios_dummy_ffi(); final class __mbstate_t extends ffi.Union { diff --git a/macos/include/FilamentViewer.hpp b/macos/include/FilamentViewer.hpp index e8f723bd..74fa1d48 100644 --- a/macos/include/FilamentViewer.hpp +++ b/macos/include/FilamentViewer.hpp @@ -101,8 +101,10 @@ namespace polyvox const math::mat4 getCameraModelMatrix(); const math::mat4 getCameraViewMatrix(); const math::mat4 getCameraProjectionMatrix(); + const math::mat4 getCameraCullingProjectionMatrix(); const filament::Frustum getCameraFrustum(); void setCameraModelMatrix(const float *const matrix); + void setCameraProjectionMatrix(const double *const matrix, double near, double far); void setCameraFocalLength(float fl); void setCameraFocusDistance(float focusDistance); void setCameraManipulatorOptions(filament::camutils::Mode mode, double orbitSpeedX, double orbitSpeedY, double zoomSpeed); diff --git a/macos/include/FlutterFilamentApi.h b/macos/include/FlutterFilamentApi.h index 882c595c..d53a0a71 100644 --- a/macos/include/FlutterFilamentApi.h +++ b/macos/include/FlutterFilamentApi.h @@ -152,6 +152,8 @@ FLUTTER_PLUGIN_EXPORT void set_camera_model_matrix(const void* const viewer, con 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_projection_matrix(const void* const viewer, const double *const matrix, double near, double far); +FLUTTER_PLUGIN_EXPORT const double* const get_camera_culling_projection_matrix(const void* const viewer); FLUTTER_PLUGIN_EXPORT const double* const get_camera_frustum(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); diff --git a/macos/src/AssetManager.cpp b/macos/src/AssetManager.cpp index 1a70f45d..8f8edfdf 100644 --- a/macos/src/AssetManager.cpp +++ b/macos/src/AssetManager.cpp @@ -112,14 +112,17 @@ EntityId AssetManager::loadGltf(const char *uri, } // load resources synchronously - if (!_gltfResourceLoader->loadResources(asset)) { - Log("Unknown error loading glTF asset"); + if (!_gltfResourceLoader->asyncBeginLoad(asset)) { + Log("Possible error loading glTF asset"); _resourceLoaderWrapper->free(rbuf); for(auto& rb : resourceBuffers) { _resourceLoaderWrapper->free(rb); } return 0; } + while(_gltfResourceLoader->asyncGetLoadProgress() < 1.0) { + // noop + } const utils::Entity *entities = asset->getEntities(); _scene->addEntities(asset->getEntities(), asset->getEntityCount()); diff --git a/macos/src/FilamentViewer.cpp b/macos/src/FilamentViewer.cpp index 1a17370f..701b0a8a 100644 --- a/macos/src/FilamentViewer.cpp +++ b/macos/src/FilamentViewer.cpp @@ -1109,6 +1109,30 @@ namespace polyvox cam.setModelMatrix(modelMatrix); } + void FilamentViewer::setCameraProjectionMatrix(const double *const matrix, double near, double far) + { + Camera &cam = _view->getCamera(); + + mat4 projectionMatrix( + matrix[0], + matrix[1], + matrix[2], + matrix[3], + matrix[4], + matrix[5], + matrix[6], + matrix[7], + matrix[8], + matrix[9], + matrix[10], + matrix[11], + matrix[12], + matrix[13], + matrix[14], + matrix[15]); + cam.setCustomProjection(projectionMatrix, near, far); + } + const math::mat4 FilamentViewer::getCameraModelMatrix() { const auto &cam = _view->getCamera(); @@ -1127,6 +1151,12 @@ namespace polyvox return cam.getProjectionMatrix(); } + const math::mat4 FilamentViewer::getCameraCullingProjectionMatrix() + { + const auto &cam = _view->getCamera(); + return cam.getCullingProjectionMatrix(); + } + const filament::Frustum FilamentViewer::getCameraFrustum() { const auto &cam = _view->getCamera(); diff --git a/macos/src/FlutterFilamentApi.cpp b/macos/src/FlutterFilamentApi.cpp index 69b4784d..edecde8c 100644 --- a/macos/src/FlutterFilamentApi.cpp +++ b/macos/src/FlutterFilamentApi.cpp @@ -139,6 +139,19 @@ extern "C" memcpy(array, matrix.asArray(), 16 * sizeof(double)); return array; } + + const double *const get_camera_culling_projection_matrix(const void *const viewer) + { + const auto &matrix = ((FilamentViewer *)viewer)->getCameraCullingProjectionMatrix(); + double *array = (double *)calloc(16, sizeof(double)); + memcpy(array, matrix.asArray(), 16 * sizeof(double)); + return array; + } + + void set_camera_projection_matrix(const void *const viewer, const double* const matrix, double near, double far) + { + ((FilamentViewer *)viewer)->setCameraProjectionMatrix(matrix, near, far); + } const double *const get_camera_frustum(const void *const viewer) { diff --git a/pubspec.yaml b/pubspec.yaml index 8851ea36..6c0af69a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,7 +29,7 @@ ffigen: entry-points: - 'ios/include/FlutterFilamentFFIApi.h' ffi-native: - asset: 'libflutter_filament' + asset: 'flutter_filament_plugin' flutter: plugin: platforms: