update example project
This commit is contained in:
@@ -32,215 +32,240 @@ class _MyAppState extends State<MyApp> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
body: Column(children: [
|
body: Column(children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
width: 200,
|
width: 200,
|
||||||
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;
|
||||||
}),
|
case 2:
|
||||||
ElevatedButton(
|
await _filamentController.removeSkybox();
|
||||||
child: const Text('remove skybox'),
|
break;
|
||||||
onPressed: () async {
|
case 3:
|
||||||
await _filamentController.removeSkybox();
|
_cube = await _filamentController
|
||||||
}),
|
.loadGlb('assets/cube.glb');
|
||||||
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);
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
_animationNames = await _filamentController
|
||||||
child: const Text('play animation')),
|
.getAnimationNames(_cube!);
|
||||||
ElevatedButton(
|
break;
|
||||||
onPressed: () {
|
case 4:
|
||||||
_filamentController.stopAnimation(_cube!);
|
if (_cube != null) {
|
||||||
},
|
await _filamentController.removeAsset(_cube!);
|
||||||
child: const Text('stop animation')),
|
}
|
||||||
Checkbox(
|
_cube = await _filamentController.loadGltf(
|
||||||
onChanged: (_) => setState(() {
|
'assets/cube.gltf', 'assets');
|
||||||
_loop = !_loop;
|
print(await _filamentController
|
||||||
}),
|
.getAnimationNames(_cube!));
|
||||||
value: _loop),
|
break;
|
||||||
ElevatedButton(
|
case 5:
|
||||||
onPressed: () {
|
if (_flightHelmet == null) {
|
||||||
_filamentController.zoom(-1.0);
|
_flightHelmet =
|
||||||
},
|
await _filamentController.loadGltf(
|
||||||
child: const Text('zoom in')),
|
'assets/FlightHelmet/FlightHelmet.gltf',
|
||||||
ElevatedButton(
|
'assets/FlightHelmet');
|
||||||
onPressed: () {
|
}
|
||||||
_filamentController.zoom(1.0);
|
break;
|
||||||
},
|
case 6:
|
||||||
child: const Text('zoom out')),
|
await _filamentController.removeAsset(_cube!);
|
||||||
ElevatedButton(
|
break;
|
||||||
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));
|
|
||||||
|
|
||||||
_filamentController.animate(
|
case 7:
|
||||||
_cube!,
|
await _filamentController.applyWeights(
|
||||||
frames.reduce((a, b) => a + b),
|
_cube!, List.filled(8, 1.0));
|
||||||
numWeights,
|
break;
|
||||||
totalFrames,
|
case 8:
|
||||||
1000 / framerate.toDouble());
|
await _filamentController.applyWeights(
|
||||||
},
|
_cube!, List.filled(8, 0));
|
||||||
child: const Text('animate weights')),
|
break;
|
||||||
Builder(
|
case 9:
|
||||||
builder: (innerCtx) => ElevatedButton(
|
_filamentController.playAnimations(
|
||||||
onPressed: () async {
|
_cube!,
|
||||||
final names = await _filamentController
|
List.generate(
|
||||||
.getTargetNames(_cube!, "Cube");
|
_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(
|
_filamentController.animate(
|
||||||
builder: (ctx) {
|
_cube!,
|
||||||
return Container(
|
frames.reduce((a, b) => a + b),
|
||||||
color: Colors.white,
|
numWeights,
|
||||||
height: 200,
|
totalFrames,
|
||||||
width: 200,
|
1000 / framerate.toDouble());
|
||||||
child: Column(
|
break;
|
||||||
mainAxisSize: MainAxisSize.min,
|
case 16:
|
||||||
children: names
|
final names = await _filamentController
|
||||||
.map((name) => Text(name))
|
.getTargetNames(_cube!, "Cube");
|
||||||
.cast<Widget>()
|
|
||||||
.toList() +
|
await showDialog(
|
||||||
<Widget>[
|
builder: (ctx) {
|
||||||
ElevatedButton(
|
return Container(
|
||||||
onPressed: () =>
|
color: Colors.white,
|
||||||
Navigator.of(ctx).pop(),
|
height: 200,
|
||||||
child: Text("Close"))
|
width: 200,
|
||||||
]));
|
child: Column(
|
||||||
},
|
mainAxisSize: MainAxisSize.min,
|
||||||
context: innerCtx);
|
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'))),
|
itemBuilder: (BuildContext context) =>
|
||||||
Builder(
|
<PopupMenuEntry<int>>[
|
||||||
builder: (innerCtx) => ElevatedButton(
|
const PopupMenuItem(
|
||||||
onPressed: () async {
|
value: 0,
|
||||||
final names =
|
child: Text("load background image")),
|
||||||
await _filamentController.getAnimationNames(_cube!);
|
const PopupMenuItem(
|
||||||
|
value: 1,
|
||||||
await showDialog(
|
child: Text('load skybox'),
|
||||||
builder: (ctx) {
|
),
|
||||||
return Container(
|
const PopupMenuItem(
|
||||||
color: Colors.white,
|
value: 2,
|
||||||
height: 200,
|
child: Text('remove skybox'),
|
||||||
width: 200,
|
),
|
||||||
child: Column(
|
const PopupMenuItem(
|
||||||
mainAxisSize: MainAxisSize.min,
|
value: 3, child: Text('load cube GLB')),
|
||||||
children: names
|
const PopupMenuItem(
|
||||||
.map((name) => Text(name))
|
value: 4, child: Text('load cube GLTF')),
|
||||||
.cast<Widget>()
|
const PopupMenuItem(
|
||||||
.toList() +
|
value: 5,
|
||||||
<Widget>[
|
child: Text('load flight helmet')),
|
||||||
ElevatedButton(
|
const PopupMenuItem(
|
||||||
onPressed: () =>
|
value: 6, child: Text('remove cube')),
|
||||||
Navigator.of(ctx).pop(),
|
const PopupMenuItem(
|
||||||
child: Text("Close"))
|
value: 20, child: Text('remove all assets')),
|
||||||
]));
|
const PopupMenuItem(
|
||||||
},
|
value: 7,
|
||||||
context: innerCtx);
|
child: Text('set all weights to 1')),
|
||||||
},
|
const PopupMenuItem(
|
||||||
child: const Text('get animation names'))),
|
value: 8,
|
||||||
ElevatedButton(
|
child: Text('set all weights to 0')),
|
||||||
onPressed: () async {
|
const PopupMenuItem(
|
||||||
await _filamentController.panStart(1, 1);
|
value: 9,
|
||||||
await _filamentController.panUpdate(1, 2);
|
child: Text('play all animations')),
|
||||||
await _filamentController.panEnd();
|
const PopupMenuItem(
|
||||||
},
|
value: 10, child: Text('stop animations')),
|
||||||
child: Text("Pan left")),
|
PopupMenuItem(
|
||||||
ElevatedButton(
|
value: 11,
|
||||||
onPressed: () async {
|
child: Text(
|
||||||
await _filamentController.panStart(1, 1);
|
"toggle animation loop (currently $_loop!)")),
|
||||||
await _filamentController.panUpdate(0, 0);
|
const PopupMenuItem(
|
||||||
await _filamentController.panEnd();
|
value: 12, child: Text('zoom in')),
|
||||||
},
|
const PopupMenuItem(
|
||||||
child: Text("Pan right"))
|
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')),
|
||||||
|
])))
|
||||||
|
])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user