From f0683b0b24114d044962274ec0173b05926d5f46 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Sun, 19 Nov 2023 18:12:38 +0800 Subject: [PATCH] remove morph animation FFI-specific methods (regular methods are OK to use outside the engine thread) --- ios/include/FlutterFilamentFFIApi.h | 17 +-------------- ios/src/FlutterFilamentFFIApi.cpp | 7 +----- lib/filament_controller.dart | 2 ++ lib/filament_controller_ffi.dart | 6 +++-- lib/generated_bindings.dart | 34 ----------------------------- 5 files changed, 8 insertions(+), 58 deletions(-) diff --git a/ios/include/FlutterFilamentFFIApi.h b/ios/include/FlutterFilamentFFIApi.h index a8d634f1..78431162 100644 --- a/ios/include/FlutterFilamentFFIApi.h +++ b/ios/include/FlutterFilamentFFIApi.h @@ -50,22 +50,7 @@ FLUTTER_PLUGIN_EXPORT void apply_weights_ffi( float *const weights, int count ); -FLUTTER_PLUGIN_EXPORT void set_morph_target_weights_ffi( - void* const assetManager, - EntityId asset, - const char *const entityName, - const float *const morphData, - int numWeights - ); -FLUTTER_PLUGIN_EXPORT bool set_morph_animation_ffi( - void* const assetManager, - EntityId asset, - const char *const entityName, - const float *const morphData, - const int* const morphIndices, - int numMorphTargets, - int numFrames, - float frameLengthInMs); + FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void* const assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade); FLUTTER_PLUGIN_EXPORT void set_animation_frame_ffi(void* const assetManager, EntityId asset, int animationIndex, int animationFrame); FLUTTER_PLUGIN_EXPORT void stop_animation_ffi(void* const assetManager, EntityId asset, int index); diff --git a/ios/src/FlutterFilamentFFIApi.cpp b/ios/src/FlutterFilamentFFIApi.cpp index b875deb7..fd7eee6a 100644 --- a/ios/src/FlutterFilamentFFIApi.cpp +++ b/ios/src/FlutterFilamentFFIApi.cpp @@ -352,12 +352,7 @@ get_morph_target_name_count_ffi(void *assetManager, EntityId asset, return fut.get(); } -void set_morph_target_weights_ffi(void *const assetManager, EntityId asset, - const char *const entityName, - const float *const morphData, - int numWeights) { - // TODO -} + FLUTTER_PLUGIN_EXPORT void play_animation_ffi(void *const assetManager, EntityId asset, int index, diff --git a/lib/filament_controller.dart b/lib/filament_controller.dart index 2443c899..4992859e 100644 --- a/lib/filament_controller.dart +++ b/lib/filament_controller.dart @@ -247,6 +247,8 @@ abstract class FilamentController { /// /// Set the weights for all morph targets under node [meshName] in [entity] to [weights]. + /// Note that [weights] must contain values for ALL morph targets, but no exception will be thrown if you don't do so (you'll just get incorrect results). + /// If you only want to set one value, set all others to zero (check [getMorphTargetNames] if you need the get a list of all morph targets.) /// Future setMorphTargetWeights( FilamentEntity entity, String meshName, List weights); diff --git a/lib/filament_controller_ffi.dart b/lib/filament_controller_ffi.dart index 4511780c..0f44203a 100644 --- a/lib/filament_controller_ffi.dart +++ b/lib/filament_controller_ffi.dart @@ -595,9 +595,11 @@ class FilamentControllerFFI extends FilamentController { for (int i = 0; i < weights.length; i++) { weightsPtr.elementAt(i).value = weights[i]; } - set_morph_target_weights_ffi(_assetManager!, entity, - meshName.toNativeUtf8().cast(), weightsPtr, weights.length); + var meshNamePtr = meshName.toNativeUtf8(allocator: calloc).cast(); + set_morph_target_weights( + _assetManager!, entity, meshNamePtr, weightsPtr, weights.length); calloc.free(weightsPtr); + calloc.free(meshNamePtr); } @override diff --git a/lib/generated_bindings.dart b/lib/generated_bindings.dart index 292c028f..a3eea5e1 100644 --- a/lib/generated_bindings.dart +++ b/lib/generated_bindings.dart @@ -1019,40 +1019,6 @@ external void apply_weights_ffi( int count, ); -@ffi.Native< - ffi.Void Function(ffi.Pointer, EntityId, - ffi.Pointer, ffi.Pointer, ffi.Int)>( - symbol: 'set_morph_target_weights_ffi', assetId: 'flutter_filament_plugin') -external void set_morph_target_weights_ffi( - ffi.Pointer assetManager, - int asset, - ffi.Pointer entityName, - ffi.Pointer morphData, - int numWeights, -); - -@ffi.Native< - ffi.Bool Function( - ffi.Pointer, - EntityId, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Int, - ffi.Int, - ffi.Float)>( - symbol: 'set_morph_animation_ffi', assetId: 'flutter_filament_plugin') -external bool set_morph_animation_ffi( - ffi.Pointer assetManager, - int asset, - ffi.Pointer entityName, - ffi.Pointer morphData, - ffi.Pointer morphIndices, - int numMorphTargets, - int numFrames, - double frameLengthInMs, -); - @ffi.Native< ffi.Void Function(ffi.Pointer, EntityId, ffi.Int, ffi.Bool, ffi.Bool, ffi.Bool, ffi.Float)>(