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 {
if (_gltfAnimationNames == null) {
var animationCount = var animationCount =
AnimationManager_getGltfAnimationCount(animationManager, asset); AnimationManager_getGltfAnimationCount(animationManager, asset);
if (animationCount == -1) { if (animationCount == -1) {
throw Exception("This is not a glTF asset"); throw Exception("This is not a glTF asset");
} }
_gltfAnimationNames = [];
var names = <String>[];
var outPtr = allocate<Char>(255); var outPtr = allocate<Char>(255);
for (int i = 0; i < animationCount; i++) { for (int i = 0; i < animationCount; i++) {
AnimationManager_getGltfAnimationName(animationManager, asset, outPtr, i); AnimationManager_getGltfAnimationName(
names.add(outPtr.cast<Utf8>().toDartString()); animationManager, asset, outPtr, i);
_gltfAnimationNames!.add(outPtr.cast<Utf8>().toDartString());
} }
free(outPtr); free(outPtr);
}
return names; return _gltfAnimationNames!;
} }
/// ///