separate Gltf/Morph/BoneAnimationComponentManager definitions

move gltf animation instantiation to GltfAnimationComponentManager (this helps ensure we are creating the component on the correct entity)
This commit is contained in:
Nick Fisher
2025-05-20 14:57:26 +08:00
parent d61723dee2
commit 1fb68b20e9
24 changed files with 629 additions and 354 deletions

View File

@@ -51,24 +51,25 @@ class _MyHomePageState extends State<MyHomePage> {
await _thermionViewer!.destroyAsset(_asset!);
_asset = null;
}
if (uri == null) {
return;
}
_asset = await _thermionViewer!.loadGltf(uri);
await _asset!.transformToUnitCube();
final animations = await _asset!.getGltfAnimationNames();
final durations = await Future.wait(List.generate(
animations.length, (i) => _asset!.getGltfAnimationDuration(i)));
final labels = animations
.asMap()
.map((index, animation) =>
MapEntry(index, "$animation (${durations[index]}s"))
.values;
gltfAnimations.clear();
gltfAnimations.addAll(labels);
selectedGltfAnimation = 0;
_loaded = uri;
if (uri != null) {
_asset = await _thermionViewer!.loadGltf(uri);
await _asset!.transformToUnitCube();
final animations = await _asset!.getGltfAnimationNames();
final durations = await Future.wait(List.generate(
animations.length, (i) => _asset!.getGltfAnimationDuration(i)));
final labels = animations
.asMap()
.map((index, animation) =>
MapEntry(index, "$animation (${durations[index]}s"))
.values;
gltfAnimations.clear();
gltfAnimations.addAll(labels);
selectedGltfAnimation = 0;
}
setState(() {});
}
@@ -123,19 +124,19 @@ class _MyHomePageState extends State<MyHomePage> {
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: Row(children: [
Text("Asset: "),
DropdownButton<String>(
const Text("Asset: "),
DropdownButton<String?>(
value: _loaded,
items: [_droneUri, _cubeUri]
.map((uri) => DropdownMenuItem<String>(
items: [_droneUri, _cubeUri, null]
.map((uri) => DropdownMenuItem<String?>(
value: uri,
child: Text(
uri,
style: TextStyle(fontSize: 12),
uri ?? "None",
style: const TextStyle(fontSize: 12),
)))
.toList(),
onChanged: _load),
Text("Animation: "),
const Text("Animation: "),
DropdownButton<String>(
value: selectedGltfAnimation == -1
? null
@@ -143,9 +144,9 @@ class _MyHomePageState extends State<MyHomePage> {
items: gltfAnimations
.map((animation) => DropdownMenuItem<String>(
value: animation,
child: Text(
child: Text(
animation,
style: TextStyle(fontSize: 12),
style: const TextStyle(fontSize: 12),
)))
.toList(),
onChanged: (value) {
@@ -160,7 +161,7 @@ class _MyHomePageState extends State<MyHomePage> {
icon: const Icon(Icons.play_arrow)),
IconButton(
onPressed: _stopGltfAnimation, icon: const Icon(Icons.stop))
])))
]))),
]);
}
}

View File

@@ -19,19 +19,23 @@
<title>quickstart</title>
<link rel="manifest" href="manifest.json">
<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<script src="flutter.js" defer></script>
<script type="text/javascript" src="./thermion_dart.js"></script>
<script type="module">
<script type="module">
try {
window.thermion_dart = await thermion_dart();
console.log("set thermion_dart");
} catch(err) {
console.error(err);
}
</script>
<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<script src="flutter.js" defer></script>
</head>
<body>