gltf animation names are immutable, so cache these in a local copy in FFIAsset

This commit is contained in:
Nick Fisher
2025-06-04 11:10:45 +08:00
parent c024efb8cd
commit 1d697037c0

View File

@@ -644,26 +644,30 @@ class FFIAsset extends ThermionAsset {
return names; return names;
} }
List<String>? _gltfAnimationNames;
/// ///
/// ///
/// ///
@override @override
Future<List<String>> getGltfAnimationNames() async { Future<List<String>> getGltfAnimationNames() async {
var animationCount = if (_gltfAnimationNames == null) {
AnimationManager_getGltfAnimationCount(animationManager, asset); var animationCount =
if (animationCount == -1) { AnimationManager_getGltfAnimationCount(animationManager, asset);
throw Exception("This is not a glTF asset"); if (animationCount == -1) {
throw Exception("This is not a glTF asset");
}
_gltfAnimationNames = [];
var outPtr = allocate<Char>(255);
for (int i = 0; i < animationCount; i++) {
AnimationManager_getGltfAnimationName(
animationManager, asset, outPtr, i);
_gltfAnimationNames!.add(outPtr.cast<Utf8>().toDartString());
}
free(outPtr);
} }
var names = <String>[]; return _gltfAnimationNames!;
var outPtr = allocate<Char>(255);
for (int i = 0; i < animationCount; i++) {
AnimationManager_getGltfAnimationName(animationManager, asset, outPtr, i);
names.add(outPtr.cast<Utf8>().toDartString());
}
free(outPtr);
return names;
} }
/// ///