update example project

This commit is contained in:
Nick Fisher
2022-08-14 21:31:10 +10:00
parent e778c097db
commit c00fb90b66

View File

@@ -32,215 +32,240 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
color: Colors.transparent,
home: Scaffold(
backgroundColor: Colors.transparent,
body: Column(children: [
Expanded(
child: SizedBox(
height: 200,
width: 200,
child: FilamentWidget(
controller: _filamentController,
))),
Expanded(
child: SingleChildScrollView(
child: Wrap(
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.end,
children: [
ElevatedButton(
child: const Text('load background image'),
onPressed: () async {
await _filamentController
.setBackgroundImage('assets/background.png');
}),
ElevatedButton(
child: const Text('load skybox'),
onPressed: () async {
await _filamentController.loadSkybox(
'assets/default_env/default_env_skybox.ktx');
await _filamentController.loadSkybox(
'assets/default_env/default_env_ibl.ktx');
}),
ElevatedButton(
child: const Text('remove skybox'),
onPressed: () async {
await _filamentController.removeSkybox();
}),
ElevatedButton(
child: const Text('load cube GLB'),
onPressed:() async {
_cube = await _filamentController
.loadGlb('assets/cube.glb');
_animationNames =
await _filamentController
.getAnimationNames(_cube!);
}),
ElevatedButton(
child: const Text('load cube GLTF'),
onPressed:() async {
if(_cube != null) {
await _filamentController.removeAsset(_cube!);
}
_cube = await _filamentController
.loadGltf('assets/cube.gltf', 'assets');
print(await _filamentController
.getAnimationNames(_cube!));
}),
ElevatedButton(
child: const Text('load flight helmet'),
onPressed:_flightHelmet != null ? null : () async {
_flightHelmet = await _filamentController.loadGltf(
'assets/FlightHelmet/FlightHelmet.gltf',
'assets/FlightHelmet');
}),
ElevatedButton(
child: const Text('remove cube'),
onPressed: () async {
await _filamentController.removeAsset(_cube!);
}),
ElevatedButton(
child: const Text('set all weights to 1'),
onPressed: () async {
await _filamentController
.applyWeights(_cube!, List.filled(8, 1.0));
}),
ElevatedButton(
child: const Text('set all weights to 0'),
onPressed: () async {
await _filamentController
.applyWeights(_cube!, List.filled(8, 0));
}),
ElevatedButton(
onPressed: () {
_animationNames.asMap().forEach((idx, element) {
_filamentController.playAnimation(_cube!, idx, loop: _loop);
});
color: Colors.transparent,
home: Scaffold(
backgroundColor: Colors.transparent,
body: Column(children: [
Expanded(
child: SizedBox(
height: 200,
width: 200,
child: FilamentWidget(
controller: _filamentController,
))),
Align(
alignment: Alignment.bottomLeft,
child: Container(
color: Colors.white,
padding: const EdgeInsets.all(5),
child: PopupMenuButton<int>(
child: const Icon(Icons.menu),
onSelected: (int item) async {
switch (item) {
case 0:
await _filamentController.setBackgroundImage(
'assets/background.png');
break;
case 1:
await _filamentController.loadSkybox(
'assets/default_env/default_env_skybox.ktx');
await _filamentController.loadSkybox(
'assets/default_env/default_env_ibl.ktx');
break;
case 2:
await _filamentController.removeSkybox();
break;
case 3:
_cube = await _filamentController
.loadGlb('assets/cube.glb');
},
child: const Text('play animation')),
ElevatedButton(
onPressed: () {
_filamentController.stopAnimation(_cube!);
},
child: const Text('stop animation')),
Checkbox(
onChanged: (_) => setState(() {
_loop = !_loop;
}),
value: _loop),
ElevatedButton(
onPressed: () {
_filamentController.zoom(-1.0);
},
child: const Text('zoom in')),
ElevatedButton(
onPressed: () {
_filamentController.zoom(1.0);
},
child: const Text('zoom out')),
ElevatedButton(
onPressed: () {
_filamentController.setCamera(_cube!, "Camera_Orientation");
},
child: const Text('set camera')),
ElevatedButton(
onPressed: () {
final framerate = 30;
final totalSecs = 5;
final numWeights = 8;
final totalFrames = framerate * totalSecs;
final frames = List.generate(
totalFrames,
(frame) =>
List.filled(numWeights, frame / totalFrames));
_animationNames = await _filamentController
.getAnimationNames(_cube!);
break;
case 4:
if (_cube != null) {
await _filamentController.removeAsset(_cube!);
}
_cube = await _filamentController.loadGltf(
'assets/cube.gltf', 'assets');
print(await _filamentController
.getAnimationNames(_cube!));
break;
case 5:
if (_flightHelmet == null) {
_flightHelmet =
await _filamentController.loadGltf(
'assets/FlightHelmet/FlightHelmet.gltf',
'assets/FlightHelmet');
}
break;
case 6:
await _filamentController.removeAsset(_cube!);
break;
_filamentController.animate(
_cube!,
frames.reduce((a, b) => a + b),
numWeights,
totalFrames,
1000 / framerate.toDouble());
},
child: const Text('animate weights')),
Builder(
builder: (innerCtx) => ElevatedButton(
onPressed: () async {
final names = await _filamentController
.getTargetNames(_cube!, "Cube");
case 7:
await _filamentController.applyWeights(
_cube!, List.filled(8, 1.0));
break;
case 8:
await _filamentController.applyWeights(
_cube!, List.filled(8, 0));
break;
case 9:
_filamentController.playAnimations(
_cube!,
List.generate(
_animationNames.length, (i) => i),
loop: _loop);
break;
case 10:
_filamentController.stopAnimation(_cube!);
break;
case 11:
setState(() {
_loop = !_loop;
});
break;
case 12:
_filamentController.zoom(-1.0);
break;
case 13:
_filamentController.zoom(1.0);
break;
case 14:
_filamentController.setCamera(
_cube!, "Camera_Orientation");
break;
case 15:
final framerate = 30;
final totalSecs = 5;
final numWeights = 8;
final totalFrames = framerate * totalSecs;
final frames = List.generate(
totalFrames,
(frame) => List.filled(
numWeights, frame / totalFrames));
await showDialog(
builder: (ctx) {
return Container(
color: Colors.white,
height: 200,
width: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
children: names
.map((name) => Text(name))
.cast<Widget>()
.toList() +
<Widget>[
ElevatedButton(
onPressed: () =>
Navigator.of(ctx).pop(),
child: Text("Close"))
]));
},
context: innerCtx);
_filamentController.animate(
_cube!,
frames.reduce((a, b) => a + b),
numWeights,
totalFrames,
1000 / framerate.toDouble());
break;
case 16:
final names = await _filamentController
.getTargetNames(_cube!, "Cube");
await showDialog(
builder: (ctx) {
return Container(
color: Colors.white,
height: 200,
width: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
children: names
.map((name) => Text(name))
.cast<Widget>()
.toList() +
<Widget>[
ElevatedButton(
onPressed: () =>
Navigator.of(ctx)
.pop(),
child: Text("Close"))
]));
},
context: context);
break;
case 17:
final names = await _filamentController
.getAnimationNames(_cube!);
await showDialog(
builder: (ctx) {
return Container(
color: Colors.white,
height: 200,
width: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
children: names
.map((name) => Text(name))
.cast<Widget>()
.toList() +
<Widget>[
ElevatedButton(
onPressed: () =>
Navigator.of(ctx)
.pop(),
child: Text("Close"))
]));
},
context: context);
break;
case 18:
await _filamentController.panStart(1, 1);
await _filamentController.panUpdate(1, 2);
await _filamentController.panEnd();
break;
case 19:
await _filamentController.panStart(1, 1);
await _filamentController.panUpdate(0, 0);
await _filamentController.panEnd();
break;
case 20:
await _filamentController.clearAssets();
}
},
child: const Text('get target names'))),
Builder(
builder: (innerCtx) => ElevatedButton(
onPressed: () async {
final names =
await _filamentController.getAnimationNames(_cube!);
await showDialog(
builder: (ctx) {
return Container(
color: Colors.white,
height: 200,
width: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
children: names
.map((name) => Text(name))
.cast<Widget>()
.toList() +
<Widget>[
ElevatedButton(
onPressed: () =>
Navigator.of(ctx).pop(),
child: Text("Close"))
]));
},
context: innerCtx);
},
child: const Text('get animation names'))),
ElevatedButton(
onPressed: () async {
await _filamentController.panStart(1, 1);
await _filamentController.panUpdate(1, 2);
await _filamentController.panEnd();
},
child: Text("Pan left")),
ElevatedButton(
onPressed: () async {
await _filamentController.panStart(1, 1);
await _filamentController.panUpdate(0, 0);
await _filamentController.panEnd();
},
child: Text("Pan right"))
],
),
)),
])),
);
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<int>>[
const PopupMenuItem(
value: 0,
child: Text("load background image")),
const PopupMenuItem(
value: 1,
child: Text('load skybox'),
),
const PopupMenuItem(
value: 2,
child: Text('remove skybox'),
),
const PopupMenuItem(
value: 3, child: Text('load cube GLB')),
const PopupMenuItem(
value: 4, child: Text('load cube GLTF')),
const PopupMenuItem(
value: 5,
child: Text('load flight helmet')),
const PopupMenuItem(
value: 6, child: Text('remove cube')),
const PopupMenuItem(
value: 20, child: Text('remove all assets')),
const PopupMenuItem(
value: 7,
child: Text('set all weights to 1')),
const PopupMenuItem(
value: 8,
child: Text('set all weights to 0')),
const PopupMenuItem(
value: 9,
child: Text('play all animations')),
const PopupMenuItem(
value: 10, child: Text('stop animations')),
PopupMenuItem(
value: 11,
child: Text(
"toggle animation loop (currently $_loop!)")),
const PopupMenuItem(
value: 12, child: Text('zoom in')),
const PopupMenuItem(
value: 13, child: Text('zoom out')),
const PopupMenuItem(
value: 14, child: Text('set camera')),
const PopupMenuItem(
value: 15, child: Text('animate weights')),
const PopupMenuItem(
value: 16, child: Text('get target names')),
const PopupMenuItem(
value: 17,
child: Text('get animation names')),
const PopupMenuItem(
value: 18, child: Text('pan left')),
const PopupMenuItem(
value: 19, child: Text('pan right')),
])))
])));
}
}