From 6d5a63d398e3956033d90cb26653b972566ab477 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Sun, 30 Jan 2022 15:59:39 +0800 Subject: [PATCH] add preparation for windows platform view --- .../polyvox_filament/PolyvoxFilamentPlugin.kt | 35 -------- ios/Classes/FilamentMethodCallHandler.h | 2 +- ios/Classes/PolyvoxFilamentPlugin.mm | 2 +- lib/filament_controller.dart | 6 +- lib/view/filament_view.dart | 5 +- mimetic_avatar.iml | 19 ----- mimetic_filament.iml | 19 ----- pubspec.yaml | 8 +- viewer/lib/main.dart | 79 ++----------------- 9 files changed, 19 insertions(+), 156 deletions(-) delete mode 100644 android/src/main/kotlin/app/polyvox/polyvox_filament/PolyvoxFilamentPlugin.kt delete mode 100644 mimetic_avatar.iml delete mode 100644 mimetic_filament.iml diff --git a/android/src/main/kotlin/app/polyvox/polyvox_filament/PolyvoxFilamentPlugin.kt b/android/src/main/kotlin/app/polyvox/polyvox_filament/PolyvoxFilamentPlugin.kt deleted file mode 100644 index 76df32b8..00000000 --- a/android/src/main/kotlin/app/polyvox/polyvox_filament/PolyvoxFilamentPlugin.kt +++ /dev/null @@ -1,35 +0,0 @@ -package app.polyvox.polyvox_filament - -import androidx.annotation.NonNull - -import io.flutter.embedding.engine.plugins.FlutterPlugin -import io.flutter.plugin.common.MethodCall -import io.flutter.plugin.common.MethodChannel -import io.flutter.plugin.common.MethodChannel.MethodCallHandler -import io.flutter.plugin.common.MethodChannel.Result - -/** PolyvoxFilamentPlugin */ -class PolyvoxFilamentPlugin: FlutterPlugin, MethodCallHandler { - /// The MethodChannel that will the communication between Flutter and native Android - /// - /// This local reference serves to register the plugin with the Flutter Engine and unregister it - /// when the Flutter Engine is detached from the Activity - private lateinit var channel : MethodChannel - - override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { - channel = MethodChannel(flutterPluginBinding.binaryMessenger, "polyvox_filament") - channel.setMethodCallHandler(this) - } - - override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { - if (call.method == "getPlatformVersion") { - result.success("Android ${android.os.Build.VERSION.RELEASE}") - } else { - result.notImplemented() - } - } - - override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { - channel.setMethodCallHandler(null) - } -} diff --git a/ios/Classes/FilamentMethodCallHandler.h b/ios/Classes/FilamentMethodCallHandler.h index e797312c..c5bfddb5 100644 --- a/ios/Classes/FilamentMethodCallHandler.h +++ b/ios/Classes/FilamentMethodCallHandler.h @@ -7,7 +7,7 @@ #include "FilamentViewer.hpp" -static const id VIEW_TYPE = @"holovox.app/filament_view"; +static const id VIEW_TYPE = @"app.polyvox.filament/filament_view"; @interface FilamentMethodCallHandler : FlutterMethodChannel - (void)handleMethodCall:(FlutterMethodCall* _Nonnull)call result:( FlutterResult _Nonnull)result; diff --git a/ios/Classes/PolyvoxFilamentPlugin.mm b/ios/Classes/PolyvoxFilamentPlugin.mm index c9d256d1..daa00fa0 100644 --- a/ios/Classes/PolyvoxFilamentPlugin.mm +++ b/ios/Classes/PolyvoxFilamentPlugin.mm @@ -7,6 +7,6 @@ FilamentNativeViewFactory* factory; + (void)registerWithRegistrar:(NSObject*)registrar { factory = [[FilamentNativeViewFactory alloc] initWithRegistrar:registrar]; - [registrar registerViewFactory:factory withId:@"holovox.app/filament_view"]; + [registrar registerViewFactory:factory withId:@"app.polyvox.filament/filament_view"]; } @end diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index 89b43a47..c356935b 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -41,9 +41,9 @@ class PolyvoxFilamentController extends FilamentController { @override void onFilamentViewCreated(int id) async { _id = id; - _channel = MethodChannel("holovox.app/filament_view_$id"); + _channel = MethodChannel("app.polyvox.filament/filament_view_$id"); _channel.setMethodCallHandler((call) async { - await Future.delayed(Duration( + await Future.delayed(const Duration( seconds: 1)); // todo - need a better way to know when the GL context is actually ready await _initialize(); @@ -52,7 +52,7 @@ class PolyvoxFilamentController extends FilamentController { }); } - @override + Future _initialize() async { await _channel.invokeMethod("initialize", [ "packages/polyvox_filament/assets/lit_opaque.filamat", diff --git a/lib/view/filament_view.dart b/lib/view/filament_view.dart index 1db6a458..348b585e 100644 --- a/lib/view/filament_view.dart +++ b/lib/view/filament_view.dart @@ -8,7 +8,7 @@ import '../../filament_controller.dart'; import 'filament_view_platform.dart'; class FilamentView extends FilamentViewPlatform { - static const FILAMENT_VIEW_ID = 'holovox.app/filament_view'; + static const FILAMENT_VIEW_ID = 'app.polyvox.filament/filament_view'; @override Widget buildView( @@ -50,6 +50,9 @@ class FilamentView extends FilamentViewPlatform { onFilamentViewCreated(id); }, ); + case TargetPlatform.windows: + return Text( + "Flutter doesn't support platform view on Windows yet."); default: return Text( '$defaultTargetPlatform is not yet implemented by Filament plugin.'); diff --git a/mimetic_avatar.iml b/mimetic_avatar.iml deleted file mode 100644 index 429df7da..00000000 --- a/mimetic_avatar.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mimetic_filament.iml b/mimetic_filament.iml deleted file mode 100644 index 429df7da..00000000 --- a/mimetic_filament.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 8443df98..1952a398 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,10 +21,10 @@ dev_dependencies: flutter: - assets: - - assets/compiled.mat - - assets/lit_opaque.filamat - - assets/lit_fade.filamat + #assets: + #- assets/compiled.mat + ##- assets/lit_opaque.filamat + #- assets/lit_fade.filamat plugin: platforms: ios: diff --git a/viewer/lib/main.dart b/viewer/lib/main.dart index 202509be..e0a1a954 100644 --- a/viewer/lib/main.dart +++ b/viewer/lib/main.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:polyvox_filament/filament_controller.dart'; +import 'package:polyvox_filament/view/filament_widget.dart'; void main() { runApp(const MyApp()); @@ -13,15 +15,6 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( - // This is the theme of your application. - // - // Try running your application with "flutter run". You'll see the - // application has a blue toolbar. Then, without quitting the app, try - // changing the primarySwatch below to Colors.green and then invoke - // "hot reload" (press "r" in the console where you ran "flutter run", - // or simply save your changes to "hot reload" in a Flutter IDE). - // Notice that the counter didn't reset back to zero; the application - // is not restarted. primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), @@ -32,15 +25,6 @@ class MyApp extends StatelessWidget { class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - final String title; @override @@ -48,68 +32,17 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } + + final _controller = PolyvoxFilamentController(); @override Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. return Scaffold( appBar: AppBar( - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Invoke "debug painting" (press "p" in the console, choose the - // "Toggle Debug Paint" action from the Flutter Inspector in Android - // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) - // to see the wireframe for each widget. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - ); + child: FilamentWidget(controller: _controller) + )); } }