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 'package:vector_math/vector_math_64.dart' as v;
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
@@ -35,40 +34,59 @@ class MyHomePage extends StatefulWidget {
|
|||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
bool _loaded = false;
|
bool _loaded = false;
|
||||||
late ThermionFlutterPlugin _thermionFlutterPlugin;
|
ThermionViewer? _thermionViewer;
|
||||||
late Future<ThermionViewer> _thermionViewer;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Stack(children: [
|
return Stack(children: [
|
||||||
Positioned.fill(child: ThermionWidget(plugin: _thermionFlutterPlugin)),
|
if (_thermionViewer != null)
|
||||||
if (!_loaded)
|
Positioned.fill(child: ThermionWidget(viewer: _thermionViewer!)),
|
||||||
Center(
|
if (!_loaded) _loadButton(),
|
||||||
child: ElevatedButton(
|
if (_loaded) _unloadButton(),
|
||||||
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(() {});
|
|
||||||
}))
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user