From 1d697037c014a23eb39db3eb4a37645dc1c5264f Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 4 Jun 2025 11:10:45 +0800 Subject: [PATCH] gltf animation names are immutable, so cache these in a local copy in FFIAsset --- .../src/implementation/ffi_asset.dart | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart b/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart index ef2cd78c..acc2460d 100644 --- a/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart +++ b/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart @@ -644,26 +644,30 @@ class FFIAsset extends ThermionAsset { return names; } + List? _gltfAnimationNames; + /// /// /// @override Future> getGltfAnimationNames() async { - var animationCount = - AnimationManager_getGltfAnimationCount(animationManager, asset); - if (animationCount == -1) { - throw Exception("This is not a glTF asset"); + if (_gltfAnimationNames == null) { + var animationCount = + AnimationManager_getGltfAnimationCount(animationManager, asset); + if (animationCount == -1) { + throw Exception("This is not a glTF asset"); + } + _gltfAnimationNames = []; + var outPtr = allocate(255); + for (int i = 0; i < animationCount; i++) { + AnimationManager_getGltfAnimationName( + animationManager, asset, outPtr, i); + _gltfAnimationNames!.add(outPtr.cast().toDartString()); + } + free(outPtr); } - var names = []; - var outPtr = allocate(255); - for (int i = 0; i < animationCount; i++) { - AnimationManager_getGltfAnimationName(animationManager, asset, outPtr, i); - names.add(outPtr.cast().toDartString()); - } - free(outPtr); - - return names; + return _gltfAnimationNames!; } ///