From e1edb6299aee9533b2b6e10f2ee97272e064a64e Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Thu, 24 Aug 2023 09:36:30 +0800 Subject: [PATCH] add setBloom method --- ios/include/FilamentViewer.hpp | 1 + ios/include/PolyvoxFilamentApi.h | 1 + ios/src/FilamentViewer.cpp | 12 ++++++++---- ios/src/PolyvoxFilamentApi.cpp | 5 +++++ lib/filament_controller.dart | 6 ++++++ linux/polyvox_filament_plugin.cc | 8 ++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ios/include/FilamentViewer.hpp b/ios/include/FilamentViewer.hpp index 70fd6eee..373f92b6 100644 --- a/ios/include/FilamentViewer.hpp +++ b/ios/include/FilamentViewer.hpp @@ -53,6 +53,7 @@ namespace polyvox { ~FilamentViewer(); void setToneMapping(ToneMapping toneMapping); + void setBloom(float strength); void loadSkybox(const char* const skyboxUri); void removeSkybox(); diff --git a/ios/include/PolyvoxFilamentApi.h b/ios/include/PolyvoxFilamentApi.h index 7f0be856..f6c24029 100644 --- a/ios/include/PolyvoxFilamentApi.h +++ b/ios/include/PolyvoxFilamentApi.h @@ -15,6 +15,7 @@ void set_background_image(const void* const viewer, const char *path); void set_background_image_position(const void* const viewer, float x, float y, bool clamp); void set_background_color(const void* const viewer, const float r, const float g, const float b, const float a); void set_tone_mapping(const void* const viewer, int toneMapping); +void set_bloom(const void* const viewer, float strength); void load_skybox(const void* const viewer, const char *skyboxPath); void load_ibl(const void* const viewer, const char *iblPath, float intensity); void remove_skybox(const void* const viewer); diff --git a/ios/src/FilamentViewer.cpp b/ios/src/FilamentViewer.cpp index 9a73b7b0..ba5abb0e 100644 --- a/ios/src/FilamentViewer.cpp +++ b/ios/src/FilamentViewer.cpp @@ -138,10 +138,7 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper* setToneMapping(ToneMapping::ACES); - decltype(_view->getBloomOptions()) opts; - opts.enabled = true; - opts.strength = 0.6f; - _view->setBloomOptions(opts); + setBloom(0.6f); _view->setScene(_scene); _view->setCamera(_mainCamera); @@ -238,6 +235,13 @@ FilamentViewer::FilamentViewer(const void* context, const ResourceLoaderWrapper* _scene->addEntity(imageEntity); } +void FilamentViewer::setBloom(float strength) { + decltype(_view->getBloomOptions()) opts; + opts.enabled = true; + opts.strength = strength; + _view->setBloomOptions(opts); +} + void FilamentViewer::setToneMapping(ToneMapping toneMapping) { ToneMapper* tm; diff --git a/ios/src/PolyvoxFilamentApi.cpp b/ios/src/PolyvoxFilamentApi.cpp index 808bdb36..c97b4c9b 100644 --- a/ios/src/PolyvoxFilamentApi.cpp +++ b/ios/src/PolyvoxFilamentApi.cpp @@ -52,6 +52,11 @@ extern "C" { ((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); } diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index 5c5e4b60..c54058db 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -366,6 +366,12 @@ class FilamentController { } } + void setBloom(double bloom) async { + if (!await _channel.invokeMethod("setBloom", bloom)) { + throw Exception("Failed to set bloom"); + } + } + void setCameraFocalLength(double focalLength) async { await _channel.invokeMethod("setCameraFocalLength", focalLength); } diff --git a/linux/polyvox_filament_plugin.cc b/linux/polyvox_filament_plugin.cc index b36f7745..71303bde 100644 --- a/linux/polyvox_filament_plugin.cc +++ b/linux/polyvox_filament_plugin.cc @@ -703,6 +703,12 @@ static FlMethodResponse* _set_tone_mapping(PolyvoxFilamentPlugin* self, FlMethod return FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_bool(true))); } +static FlMethodResponse* _set_bloom(PolyvoxFilamentPlugin* self, FlMethodCall* method_call) { + FlValue* args = fl_method_call_get_args(method_call); + set_bloom(self->viewer, fl_value_get_float(args)); + return FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_bool(true))); +} + // Called when a method call is received from Flutter. static void polyvox_filament_plugin_handle_method_call( PolyvoxFilamentPlugin* self, @@ -722,6 +728,8 @@ static void polyvox_filament_plugin_handle_method_call( response = _get_asset_manager(self, method_call); } else if(strcmp(method, "setToneMapping") == 0) { response = _set_tone_mapping(self, method_call); + } else if(strcmp(method, "setBloom") == 0) { + response = _set_bloom(self, method_call); } else if(strcmp(method, "resize") == 0) { response = _resize(self, method_call); } else if(strcmp(method, "getContext") == 0) {