diff --git a/ios/Classes/SwiftPolyvoxFilamentPlugin.swift b/ios/Classes/SwiftPolyvoxFilamentPlugin.swift index ecc765f3..0c903b64 100644 --- a/ios/Classes/SwiftPolyvoxFilamentPlugin.swift +++ b/ios/Classes/SwiftPolyvoxFilamentPlugin.swift @@ -305,7 +305,11 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture clear_background_image(viewer) result(true) case "setBackgroundImage": - set_background_image(viewer, call.arguments as! String) + let args = call.arguments as! [Any]; + + let path = args[0] as! String + let fillHeight = args[1] as! Bool + set_background_image(viewer, path, fillHeight) result(true) case "setBackgroundImagePosition": let args = call.arguments as! [Any] diff --git a/ios/include/FilamentViewer.hpp b/ios/include/FilamentViewer.hpp index 10dd8633..52c224dc 100644 --- a/ios/include/FilamentViewer.hpp +++ b/ios/include/FilamentViewer.hpp @@ -78,7 +78,7 @@ namespace polyvox { Renderer* getRenderer(); void setBackgroundColor(const float r, const float g, const float b, const float a); - void setBackgroundImage(const char* resourcePath); + void setBackgroundImage(const char* resourcePath, bool fillHeight); void clearBackgroundImage(); void setBackgroundImagePosition(float x, float y, bool clamp); void setCameraExposure(float aperture, float shutterSpeed, float sensitivity); diff --git a/ios/src/FilamentViewer.cpp b/ios/src/FilamentViewer.cpp index aef182f1..a9953318 100644 --- a/ios/src/FilamentViewer.cpp +++ b/ios/src/FilamentViewer.cpp @@ -426,7 +426,7 @@ void FilamentViewer::clearBackgroundImage() { } } -void FilamentViewer::setBackgroundImage(const char *resourcePath) { +void FilamentViewer::setBackgroundImage(const char *resourcePath, bool fillHeight) { string resourcePathString(resourcePath); @@ -440,7 +440,18 @@ void FilamentViewer::setBackgroundImage(const char *resourcePath) { // TODO - implement stretch/etc const Viewport& vp = _view->getViewport(); Log("Image width %d height %d vp width %d height %d", _imageWidth, _imageHeight, vp.width, vp.height); - _imageScale = mat4f { float(vp.width) / float(_imageWidth) , 0.0f, 0.0f, 0.0f, 0.0f, float(vp.height) / float(_imageHeight), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; + + + float xScale = float(vp.width) / float(_imageWidth); + + float yScale; + if(fillHeight) { + yScale = 1.0f; + } else { + yScale = float(vp.height) / float(_imageHeight); + } + + _imageScale = mat4f { xScale , 0.0f, 0.0f, 0.0f, 0.0f, yScale , 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; _imageMaterial->setDefaultParameter("transform", _imageScale); _imageMaterial->setDefaultParameter("image", _imageTexture, _imageSampler); diff --git a/ios/src/PolyvoxFilamentApi.cpp b/ios/src/PolyvoxFilamentApi.cpp index b4967de8..51b03cb0 100644 --- a/ios/src/PolyvoxFilamentApi.cpp +++ b/ios/src/PolyvoxFilamentApi.cpp @@ -40,8 +40,8 @@ extern "C" { ((FilamentViewer*)viewer)->clearBackgroundImage(); } - FLUTTER_PLUGIN_EXPORT void set_background_image(const void* const viewer, const char* path) { - ((FilamentViewer*)viewer)->setBackgroundImage(path); + 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_background_image_position(const void* const viewer, float x, float y, bool clamp) { diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index 88566ffa..f5b033b8 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -131,11 +131,11 @@ class FilamentController { await _channel.invokeMethod("clearBackgroundImage"); } - Future setBackgroundImage(String path) async { + Future setBackgroundImage(String path, {bool fillHeight = false}) async { if (_viewer == null || _resizing) { throw Exception("No viewer available, ignoring"); } - await _channel.invokeMethod("setBackgroundImage", path); + await _channel.invokeMethod("setBackgroundImage", [path, fillHeight]); } Future setBackgroundColor(Color color) async {