From c059a57d0962574e743d375b13067a14c2d21c9c Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 13 Dec 2022 10:14:30 +0800 Subject: [PATCH 1/6] update iOS libs --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 352f1492..92a93511 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ +windows/lib/** filter=lfs diff=lfs merge=lfs -text *.a filter=lfs diff=lfs merge=lfs -text From 555a7b7a4277e716e0f1c82da0829982e0dcabe1 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 13 Dec 2022 10:15:21 +0800 Subject: [PATCH 2/6] update example iOS project files --- example/ios/Runner.xcodeproj/project.pbxproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 90696464..969bf9ad 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -345,6 +345,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + OTHER_CFLAGS = "-fvisibility=default"; PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -476,6 +477,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + OTHER_CFLAGS = "-fvisibility=default"; PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; @@ -499,6 +501,7 @@ "$(inherited)", "@executable_path/Frameworks", ); + OTHER_CFLAGS = "-fvisibility=default"; PRODUCT_BUNDLE_IDENTIFIER = app.polyvox.example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; From 495fa549c166866a680741079c0f441f9b8ee42d Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 13 Dec 2022 10:22:35 +0800 Subject: [PATCH 3/6] LFS lib pull --- .gitattributes | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitattributes b/.gitattributes index 352f1492..92a93511 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ +windows/lib/** filter=lfs diff=lfs merge=lfs -text *.a filter=lfs diff=lfs merge=lfs -text From 35f2b1a0e23a7ae5834ff0ec85519a8c8b4daab2 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 13 Dec 2022 10:56:22 +0800 Subject: [PATCH 4/6] fix pinch zoom on mobile --- lib/filament_gesture_detector.dart | 104 ++++++++++++++--------------- 1 file changed, 50 insertions(+), 54 deletions(-) diff --git a/lib/filament_gesture_detector.dart b/lib/filament_gesture_detector.dart index 1b973176..76d0d957 100644 --- a/lib/filament_gesture_detector.dart +++ b/lib/filament_gesture_detector.dart @@ -83,65 +83,61 @@ class _FilamentGestureDetectorState extends State { Widget build(BuildContext context) { return Stack(children: [ Positioned.fill( - child: Listener( - onPointerSignal: (pointerSignal) async { - if (pointerSignal is PointerScrollEvent) { - _scrollTimer?.cancel(); + // pinch zoom on mobile + // couldn't find any equivalent for pointerCount in Listener so we use two widgets: + // - outer is a GestureDetector only for pinch zoom + // - inner is a Listener for all other gestures + child: GestureDetector( + onScaleStart: (d) async { + if (d.pointerCount == 2) { + await widget.controller.zoomEnd(); await widget.controller.zoomBegin(); - await widget.controller.zoomUpdate( - pointerSignal.scrollDelta.dy > 0 ? 100 : -100); - _scrollTimer = Timer(Duration(milliseconds: 100), () { - widget.controller.zoomEnd(); - _scrollTimer = null; - }); - } else { - print(pointerSignal); } }, - onPointerPanZoomStart: (pzs) { - print(pzs); + onScaleEnd: (d) async { + if (d.pointerCount == 2) { + _lastScale = 0; + await widget.controller.zoomEnd(); + } }, - onPointerDown: (d) async { - await _functionStart(d.localPosition.dx, d.localPosition.dy); + onScaleUpdate: (d) async { + if (d.pointerCount == 2) { + if (_lastScale != 0) { + await widget.controller + .zoomUpdate(100 * (_lastScale - d.scale)); + } + } + _lastScale = d.scale; }, - onPointerMove: (d) async { - await _functionUpdate(d.localPosition.dx, d.localPosition.dy); - }, - onPointerUp: (d) async { - await _functionEnd(); - }, - // on - // onScaleStart: (d) async { - // print("SCALE START"); - // if (d.pointerCount == 2) { - // await widget.controller.zoomEnd(); - // await widget.controller.zoomBegin(); - // } else { - // await _functionStart(d.focalPoint.dx, d.focalPoint.dy); - // } - // }, - // onScaleEnd: (d) async { - // print("SCALE END"); - - // if (d.pointerCount == 2) { - // _lastScale = 0; - // await widget.controller.zoomEnd(); - // } else { - // await _functionEnd(); - // } - // }, - // onScaleUpdate: (d) async { - // if (d.pointerCount == 2) { - // if (_lastScale != 0) { - // await widget.controller - // .zoomUpdate(100 * (_lastScale - d.scale)); - // } - // } else { - // await _functionUpdate(d.focalPoint.dx, d.focalPoint.dy); - // } - // _lastScale = d.scale; - // }, - child: widget.child)), + child: Listener( + onPointerSignal: (pointerSignal) async { + // scroll-wheel zoom on desktop + if (pointerSignal is PointerScrollEvent) { + _scrollTimer?.cancel(); + await widget.controller.zoomBegin(); + await widget.controller.zoomUpdate( + pointerSignal.scrollDelta.dy > 0 ? 100 : -100); + _scrollTimer = Timer(Duration(milliseconds: 100), () { + widget.controller.zoomEnd(); + _scrollTimer = null; + }); + } else { + print(pointerSignal); + } + }, + onPointerPanZoomStart: (pzs) {}, + onPointerDown: (d) async { + await _functionStart( + d.localPosition.dx, d.localPosition.dy); + }, + onPointerMove: (d) async { + await _functionUpdate( + d.localPosition.dx, d.localPosition.dy); + }, + onPointerUp: (d) async { + await _functionEnd(); + }, + child: widget.child))), widget.showControls ? Align( alignment: Alignment.bottomRight, From 5eb5304aa3cd762923d799048819aaeb2061d0c1 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 13 Dec 2022 10:56:52 +0800 Subject: [PATCH 5/6] add create_swap_chain/new viewer creation API bindings to iOS --- ios/Classes/SwiftPolyvoxFilamentPlugin.swift | 16 ++++++++++------ ios/include/PolyvoxFilamentApi.h | 2 +- ios/include/PolyvoxFilamentIOSApi.h | 1 - .../SwiftPolyvoxFilamentPlugin-Bridging-Header.h | 2 +- ios/src/ios/PolyvoxFilamentIOSApi.cpp | 3 --- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ios/Classes/SwiftPolyvoxFilamentPlugin.swift b/ios/Classes/SwiftPolyvoxFilamentPlugin.swift index b26a9b2e..ffa1b85f 100644 --- a/ios/Classes/SwiftPolyvoxFilamentPlugin.swift +++ b/ios/Classes/SwiftPolyvoxFilamentPlugin.swift @@ -119,11 +119,6 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture kCVPixelFormatType_32BGRA, pixelBufferAttrs, &targetPixelBuffer) != kCVReturnSuccess) { print("Error allocating pixel buffer") } - if(self.viewer != nil) { - create_swap_chain(self.viewer, unsafeBitCast(targetPixelBuffer!, to: UnsafeMutableRawPointer.self)) - update_viewport_and_camera_projection(self.viewer!, Int32(width), Int32(height), 1.0); - } - print("Pixel buffer created") } @@ -136,12 +131,17 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture freeResourcePtr = unsafeBitCast(freeResource, to: UnsafeMutableRawPointer.self) viewer = filament_viewer_new_ios( - unsafeBitCast(targetPixelBuffer!, to: UnsafeMutableRawPointer.self), + nil, loadResourcePtr!, freeResourcePtr!, Unmanaged.passUnretained(self).toOpaque() ) + create_swap_chain( + self.viewer, + unsafeBitCast(targetPixelBuffer!, to: UnsafeMutableRawPointer.self), + UInt32(width), UInt32(height)) + update_viewport_and_camera_projection(self.viewer!, Int32(width), Int32(height), 1.0); createDisplayLink() @@ -285,6 +285,10 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture let width = Int(args[0]) let height = Int(args[1]) createPixelBuffer(width: width, height:height) + create_swap_chain( + self.viewer, + unsafeBitCast(targetPixelBuffer!, to: UnsafeMutableRawPointer.self), + UInt32(width), UInt32(height)) result("OK") case "rotateStart": let args = call.arguments as! Array diff --git a/ios/include/PolyvoxFilamentApi.h b/ios/include/PolyvoxFilamentApi.h index 1dfd1b34..334b4444 100644 --- a/ios/include/PolyvoxFilamentApi.h +++ b/ios/include/PolyvoxFilamentApi.h @@ -22,7 +22,7 @@ void* load_glb(void* viewer, const char* assetPath); void* load_gltf(void* viewer, const char* assetPath, const char* relativePath); bool set_camera(void* viewer, void* asset, const char* nodeName); void render(void* viewer, uint64_t frameTimeInNanos); -void create_swap_chain(void* viewer, void* surface = nullptr, uint32_t width = 0, uint32_t height = 0); +void create_swap_chain(void* viewer, void* surface, uint32_t width, uint32_t height); void destroy_swap_chain(void* viewer); void set_frame_interval(void* viewer, float interval); void* get_renderer(void* viewer); diff --git a/ios/include/PolyvoxFilamentIOSApi.h b/ios/include/PolyvoxFilamentIOSApi.h index aa80a94b..5da32c15 100644 --- a/ios/include/PolyvoxFilamentIOSApi.h +++ b/ios/include/PolyvoxFilamentIOSApi.h @@ -1,3 +1,2 @@ void* filament_viewer_new_ios(void* texture, void* loadResource, void* freeResource, void* resources); -void create_swap_chain(void* viewer, void* texture); diff --git a/ios/include/SwiftPolyvoxFilamentPlugin-Bridging-Header.h b/ios/include/SwiftPolyvoxFilamentPlugin-Bridging-Header.h index 6ec7b624..aa250e53 100644 --- a/ios/include/SwiftPolyvoxFilamentPlugin-Bridging-Header.h +++ b/ios/include/SwiftPolyvoxFilamentPlugin-Bridging-Header.h @@ -1,7 +1,7 @@ #ifndef SwiftPolyvoxFilamentPlugin_Bridging_Header_h #define SwiftPolyvoxFilamentPlugin_Bridging_Header_h -void* filament_viewer_new_ios(void* texture, void* loadResource, void* freeResource, void* resources); +// void* filament_viewer_new_ios(void* texture, void* loadResource, void* freeResource, void* resources); #import "PolyvoxFilamentIOSApi.h" #import "PolyvoxFilamentApi.h" diff --git a/ios/src/ios/PolyvoxFilamentIOSApi.cpp b/ios/src/ios/PolyvoxFilamentIOSApi.cpp index 849f0fdf..f12bf46f 100644 --- a/ios/src/ios/PolyvoxFilamentIOSApi.cpp +++ b/ios/src/ios/PolyvoxFilamentIOSApi.cpp @@ -26,7 +26,4 @@ extern "C" { return (void*)viewer; } - void create_swap_chain(void* viewer, void* texture) { - ((FilamentViewer*)viewer)->createSwapChain(texture); - } } From 65e51edc421caa95a2b25ab91736df5e1b68b37e Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Tue, 13 Dec 2022 10:59:37 +0800 Subject: [PATCH 6/6] LFS track windows libs