update quickstart to use new API
This commit is contained in:
@@ -4,7 +4,6 @@ import 'package:thermion_flutter/thermion_flutter.dart';
|
||||
import 'package:vector_math/vector_math_64.dart' as v;
|
||||
import 'dart:math';
|
||||
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
@@ -35,40 +34,59 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
bool _loaded = false;
|
||||
late ThermionFlutterPlugin _thermionFlutterPlugin;
|
||||
late Future<ThermionViewer> _thermionViewer;
|
||||
ThermionViewer? _thermionViewer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_thermionFlutterPlugin = ThermionFlutterPlugin();
|
||||
_thermionViewer = _thermionFlutterPlugin.initialize();
|
||||
}
|
||||
|
||||
ThermionFlutterTexture? _texture;
|
||||
|
||||
Future _load() async {
|
||||
var viewer = await ThermionFlutterPlugin.createViewer();
|
||||
_thermionViewer = viewer;
|
||||
_thermionViewer!.loadSkybox("assets/default_env_skybox.ktx");
|
||||
_thermionViewer!.loadGlb("assets/cube.glb");
|
||||
|
||||
_thermionViewer!.setCameraPosition(0, 1, 10);
|
||||
_thermionViewer!.setCameraRotation(
|
||||
v.Quaternion.axisAngle(v.Vector3(1, 0, 0), -30 / 180 * pi) *
|
||||
v.Quaternion.axisAngle(v.Vector3(0, 1, 0), 15 / 180 * pi));
|
||||
_thermionViewer!.addLight(LightType.SUN, 7500, 50000, 0, 0, 0, 1, -1, -1);
|
||||
_thermionViewer!.setRendering(true);
|
||||
_loaded = true;
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Future _unload() async {
|
||||
await ThermionFlutterPlugin.destroyTexture(_texture!);
|
||||
var viewer = _thermionViewer!;
|
||||
_thermionViewer = null;
|
||||
setState(() {});
|
||||
await viewer.dispose();
|
||||
_loaded = false;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget _loadButton() {
|
||||
return Center(
|
||||
child: ElevatedButton(child: const Text("Load"), onPressed: _load));
|
||||
}
|
||||
|
||||
Widget _unloadButton() {
|
||||
return Center(
|
||||
child: ElevatedButton(child: const Text("Unload"), onPressed: _unload));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(children: [
|
||||
Positioned.fill(child: ThermionWidget(plugin: _thermionFlutterPlugin)),
|
||||
if (!_loaded)
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
child: const Text("Load"),
|
||||
onPressed: () async {
|
||||
var viewer = await _thermionViewer;
|
||||
await viewer.loadSkybox("assets/default_env_skybox.ktx");
|
||||
await viewer.loadGlb("assets/cube.glb");
|
||||
|
||||
await viewer.setCameraPosition(0, 1, 10);
|
||||
await viewer.setCameraRotation(v.Quaternion.axisAngle(
|
||||
v.Vector3(1, 0, 0), -30 / 180 * pi) *
|
||||
v.Quaternion.axisAngle(
|
||||
v.Vector3(0, 1, 0), 15 / 180 * pi));
|
||||
await viewer.addLight(
|
||||
LightType.SUN, 7500, 50000, 0, 0, 0, 1, -1, -1);
|
||||
await viewer.setRendering(true);
|
||||
_loaded = true;
|
||||
setState(() {});
|
||||
}))
|
||||
if (_thermionViewer != null)
|
||||
Positioned.fill(child: ThermionWidget(viewer: _thermionViewer!)),
|
||||
if (!_loaded) _loadButton(),
|
||||
if (_loaded) _unloadButton(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user