update example project

This commit is contained in:
Nick Fisher
2022-08-14 21:31:10 +10:00
parent 6a7499099d
commit 2aafbee92e

View File

@@ -43,119 +43,98 @@ class _MyAppState extends State<MyApp> {
child: FilamentWidget( child: FilamentWidget(
controller: _filamentController, controller: _filamentController,
))), ))),
Expanded( Align(
child: SingleChildScrollView( alignment: Alignment.bottomLeft,
child: Wrap( child: Container(
alignment: WrapAlignment.end, color: Colors.white,
crossAxisAlignment: WrapCrossAlignment.end, padding: const EdgeInsets.all(5),
children: [ child: PopupMenuButton<int>(
ElevatedButton( child: const Icon(Icons.menu),
child: const Text('load background image'), onSelected: (int item) async {
onPressed: () async { switch (item) {
await _filamentController case 0:
.setBackgroundImage('assets/background.png'); await _filamentController.setBackgroundImage(
}), 'assets/background.png');
ElevatedButton( break;
child: const Text('load skybox'), case 1:
onPressed: () async {
await _filamentController.loadSkybox( await _filamentController.loadSkybox(
'assets/default_env/default_env_skybox.ktx'); 'assets/default_env/default_env_skybox.ktx');
await _filamentController.loadSkybox( await _filamentController.loadSkybox(
'assets/default_env/default_env_ibl.ktx'); 'assets/default_env/default_env_ibl.ktx');
}), break;
ElevatedButton( case 2:
child: const Text('remove skybox'),
onPressed: () async {
await _filamentController.removeSkybox(); await _filamentController.removeSkybox();
}), break;
ElevatedButton( case 3:
child: const Text('load cube GLB'),
onPressed:() async {
_cube = await _filamentController _cube = await _filamentController
.loadGlb('assets/cube.glb'); .loadGlb('assets/cube.glb');
_animationNames = _animationNames = await _filamentController
await _filamentController
.getAnimationNames(_cube!); .getAnimationNames(_cube!);
}), break;
ElevatedButton( case 4:
child: const Text('load cube GLTF'), if (_cube != null) {
onPressed:() async {
if(_cube != null) {
await _filamentController.removeAsset(_cube!); await _filamentController.removeAsset(_cube!);
} }
_cube = await _filamentController _cube = await _filamentController.loadGltf(
.loadGltf('assets/cube.gltf', 'assets'); 'assets/cube.gltf', 'assets');
print(await _filamentController print(await _filamentController
.getAnimationNames(_cube!)); .getAnimationNames(_cube!));
}), break;
ElevatedButton( case 5:
child: const Text('load flight helmet'), if (_flightHelmet == null) {
onPressed:_flightHelmet != null ? null : () async { _flightHelmet =
_flightHelmet = await _filamentController.loadGltf( await _filamentController.loadGltf(
'assets/FlightHelmet/FlightHelmet.gltf', 'assets/FlightHelmet/FlightHelmet.gltf',
'assets/FlightHelmet'); 'assets/FlightHelmet');
}), }
ElevatedButton( break;
child: const Text('remove cube'), case 6:
onPressed: () async {
await _filamentController.removeAsset(_cube!); await _filamentController.removeAsset(_cube!);
}), break;
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);
});
}, case 7:
child: const Text('play animation')), await _filamentController.applyWeights(
ElevatedButton( _cube!, List.filled(8, 1.0));
onPressed: () { 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!); _filamentController.stopAnimation(_cube!);
}, break;
child: const Text('stop animation')), case 11:
Checkbox( setState(() {
onChanged: (_) => setState(() {
_loop = !_loop; _loop = !_loop;
}), });
value: _loop), break;
ElevatedButton( case 12:
onPressed: () {
_filamentController.zoom(-1.0); _filamentController.zoom(-1.0);
}, break;
child: const Text('zoom in')), case 13:
ElevatedButton(
onPressed: () {
_filamentController.zoom(1.0); _filamentController.zoom(1.0);
}, break;
child: const Text('zoom out')), case 14:
ElevatedButton( _filamentController.setCamera(
onPressed: () { _cube!, "Camera_Orientation");
_filamentController.setCamera(_cube!, "Camera_Orientation"); break;
}, case 15:
child: const Text('set camera')),
ElevatedButton(
onPressed: () {
final framerate = 30; final framerate = 30;
final totalSecs = 5; final totalSecs = 5;
final numWeights = 8; final numWeights = 8;
final totalFrames = framerate * totalSecs; final totalFrames = framerate * totalSecs;
final frames = List.generate( final frames = List.generate(
totalFrames, totalFrames,
(frame) => (frame) => List.filled(
List.filled(numWeights, frame / totalFrames)); numWeights, frame / totalFrames));
_filamentController.animate( _filamentController.animate(
_cube!, _cube!,
@@ -163,11 +142,8 @@ class _MyAppState extends State<MyApp> {
numWeights, numWeights,
totalFrames, totalFrames,
1000 / framerate.toDouble()); 1000 / framerate.toDouble());
}, break;
child: const Text('animate weights')), case 16:
Builder(
builder: (innerCtx) => ElevatedButton(
onPressed: () async {
final names = await _filamentController final names = await _filamentController
.getTargetNames(_cube!, "Cube"); .getTargetNames(_cube!, "Cube");
@@ -186,18 +162,16 @@ class _MyAppState extends State<MyApp> {
<Widget>[ <Widget>[
ElevatedButton( ElevatedButton(
onPressed: () => onPressed: () =>
Navigator.of(ctx).pop(), Navigator.of(ctx)
.pop(),
child: Text("Close")) child: Text("Close"))
])); ]));
}, },
context: innerCtx); context: context);
}, break;
child: const Text('get target names'))), case 17:
Builder( final names = await _filamentController
builder: (innerCtx) => ElevatedButton( .getAnimationNames(_cube!);
onPressed: () async {
final names =
await _filamentController.getAnimationNames(_cube!);
await showDialog( await showDialog(
builder: (ctx) { builder: (ctx) {
@@ -214,33 +188,84 @@ class _MyAppState extends State<MyApp> {
<Widget>[ <Widget>[
ElevatedButton( ElevatedButton(
onPressed: () => onPressed: () =>
Navigator.of(ctx).pop(), Navigator.of(ctx)
.pop(),
child: Text("Close")) child: Text("Close"))
])); ]));
}, },
context: innerCtx); context: context);
}, break;
child: const Text('get animation names'))), case 18:
ElevatedButton(
onPressed: () async {
await _filamentController.panStart(1, 1); await _filamentController.panStart(1, 1);
await _filamentController.panUpdate(1, 2); await _filamentController.panUpdate(1, 2);
await _filamentController.panEnd(); await _filamentController.panEnd();
}, break;
child: Text("Pan left")), case 19:
ElevatedButton(
onPressed: () async {
await _filamentController.panStart(1, 1); await _filamentController.panStart(1, 1);
await _filamentController.panUpdate(0, 0); await _filamentController.panUpdate(0, 0);
await _filamentController.panEnd(); await _filamentController.panEnd();
break;
case 20:
await _filamentController.clearAssets();
}
}, },
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')),
])))
])));
} }
} }