(example) update viewer example + docs

This commit is contained in:
Nick Fisher
2025-07-03 14:22:01 +08:00
parent b023e2fb97
commit edb7538c36
3 changed files with 17 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
## Quickstart (Flutter) ## Quickstart (Flutter)
> You can find the entire project below in the [examples/flutter/quickstart](https://github.com/nmfisher/thermion/tree/master/examples/flutter/quickstart) folder of the repository. > You can find the entire project below in the [examples/flutter/viewer](https://github.com/nmfisher/thermion/tree/master/examples/flutter/viewer) folder of the repository.
1. Switch to Flutter master channel, upgrade Flutter, create a new project, then add `thermion_flutter` as a dependency 1. Switch to Flutter master channel, upgrade Flutter, create a new project, then add `thermion_flutter` as a dependency
@@ -53,11 +53,11 @@ flutter
```dart ```dart
class _MyAppState extends State<MyApp> { class _MyAppState extends State<MyApp> {
  late ThermionFlutterPlugin _thermionFlutterPlugin; 
late Future<ThermionViewer> _thermionViewer; late Future<ThermionViewer> _thermionViewer;
  void initState() {      void initState() {   
_thermionFlutterPlugin = ThermionFlutterPlugin();    ThermionFlutterPlugin.createViewer().then((viewer) {
_thermionViewer = _thermionFlutterPlugin.createViewer();  _thermionViewer = viewer;
});
} }
} }

View File

@@ -80,7 +80,7 @@ class _MyHomePageState extends State<MyHomePage> {
await _thermionViewer!.loadSkybox("assets/default_env_skybox.ktx"); await _thermionViewer!.loadSkybox("assets/default_env_skybox.ktx");
await _thermionViewer!.loadIbl("assets/default_env_ibl.ktx"); await _thermionViewer!.loadIbl("assets/default_env_ibl.ktx");
await _thermionViewer!.setBackgroundColor(0, 0, 1, 1); // await _thermionViewer!.setBackgroundColor(0, 0, 1, 1);
// The underlying Filament rendering engine exposes a number of // The underlying Filament rendering engine exposes a number of
// post-processing options (anti-aliasing, bloom, etc). // post-processing options (anti-aliasing, bloom, etc).
@@ -93,13 +93,6 @@ class _MyHomePageState extends State<MyHomePage> {
// false is designed to allow you to pause rendering to conserve battery life // false is designed to allow you to pause rendering to conserve battery life
await _thermionViewer!.setRendering(true); await _thermionViewer!.setRendering(true);
// Timer.periodic(Duration(seconds: 1), (_) async {
// final rnd = Random();
// await camera.setLensProjection();
// await _thermionViewer!.setBackgroundColor(rnd.nextDouble(),rnd.nextDouble(), 0, 1.0);
// });
setState(() {}); setState(() {});
} }
@@ -120,25 +113,16 @@ class _MyHomePageState extends State<MyHomePage> {
child: ElevatedButton(onPressed: _load, child: const Text("Load"))); child: ElevatedButton(onPressed: _load, child: const Text("Load")));
} }
Widget _renderButton() { Widget _changeBgColor() {
return Center( return Center(
child: ElevatedButton( child: ElevatedButton(
onPressed: () async { onPressed: () async {
// final rnd = Random(); final rnd = Random();
// await FilamentApp.instance!.setClearColor( await _thermionViewer!.removeSkybox();
// rnd.nextDouble(), rnd.nextDouble(), rnd.nextDouble(), 1.0); await _thermionViewer!.setBackgroundColor(
// final camera = await _thermionViewer!.getActiveCamera(); rnd.nextDouble(), rnd.nextDouble(), rnd.nextDouble(), 1.0);
// await _thermionViewer!.setRendering(false);
// // await camera.setLensProjection();
// await _thermionViewer!.removeSkybox();
// // await _thermionViewer!.setBackgroundColor(rnd.nextDouble(), 1.0, 0, 1.0);
// await _thermionViewer!.clearBackgroundImage(destroy: true);
// // await _thermionViewer!.setBackgroundImage("/Users/nickfisher/Documents/thermion/thermion_dart/test/assets/cube_texture_512x512.png");
// await FilamentApp.instance!.render();
}, },
child: const Text("Render"))); child: const Text("Change background color")));
} }
Widget _unloadButton() { Widget _unloadButton() {
@@ -153,9 +137,9 @@ class _MyHomePageState extends State<MyHomePage> {
body: Stack(children: [ body: Stack(children: [
if (_thermionViewer != null) if (_thermionViewer != null)
Positioned.fill( Positioned.fill(
child: ThermionWidget( child: ThermionListenerWidget(inputHandler: DelegateInputHandler.fixedOrbit(_thermionViewer!), child:ThermionWidget(
viewer: _thermionViewer!, viewer: _thermionViewer!,
)), ))),
Align( Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
child: Padding( child: Padding(
@@ -165,7 +149,7 @@ class _MyHomePageState extends State<MyHomePage> {
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
if (_thermionViewer == null) _loadButton(), if (_thermionViewer == null) _loadButton(),
if (_thermionViewer != null) _renderButton(), if (_thermionViewer != null) _changeBgColor(),
if (_thermionViewer != null) _unloadButton(), if (_thermionViewer != null) _unloadButton(),
]))) ])))
])); ]));

View File

@@ -558,7 +558,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14; MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule; SWIFT_COMPILATION_MODE = wholemodule;
@@ -641,7 +641,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14; MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = YES; MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx; SDKROOT = macosx;
@@ -691,7 +691,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES; GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.14; MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO; MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx; SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule; SWIFT_COMPILATION_MODE = wholemodule;