add getAnimationDuration method

This commit is contained in:
Nick Fisher
2023-08-08 14:34:15 +08:00
parent fb53881183
commit fa8c6b1ca0
6 changed files with 40 additions and 4 deletions

View File

@@ -447,6 +447,18 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
play_animation(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, Int32(index), loop, reverse, crossfade)
result(true)
case "getAnimationDuration":
guard let args = call.arguments as? [Any], args.count == 3,
let assetManager = args[0] as? Int64,
let asset = args[1] as? EntityId,
let animationIndex = args[2] as? Int else {
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for getAnimationDuration", details: nil))
return
}
let dur = get_animation_duration(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, Int32(animationIndex))
result(dur)
case "setAnimationFrame":
guard let args = call.arguments as? [Any], args.count == 4,
let assetManager = args[0] as? Int64,

View File

@@ -28,6 +28,7 @@ namespace polyvox {
void remove(EntityId entity);
void destroyAll();
unique_ptr<vector<string>> getAnimationNames(EntityId entity);
float getAnimationDuration(EntityId entity, int animationIndex);
unique_ptr<vector<string>> getMorphTargetNames(EntityId entity, const char *meshName);
void transformToUnitCube(EntityId e);
inline void updateTransform(EntityId e);

View File

@@ -73,6 +73,7 @@ void set_animation_frame(void* assetManager, EntityId asset, int animationIndex,
void stop_animation(void* assetManager, EntityId asset, int index);
int get_animation_count(void* assetManager, EntityId asset);
void get_animation_name(void* assetManager, EntityId asset, char *const outPtr, int index);
float get_animation_duration(void* assetManager, EntityId asset, int index);
void get_morph_target_name(void* assetManager, EntityId asset, const char *meshName, char *const outPtr, int index);
int get_morph_target_name_count(void* assetManager, EntityId asset, const char *meshName);
void remove_asset(const void* const viewer, EntityId asset);

View File

@@ -708,6 +708,20 @@ void AssetManager::setAnimationFrame(EntityId entity, int animationIndex, int an
asset.mAnimator->updateBoneMatrices();
}
float AssetManager::getAnimationDuration(EntityId entity, int animationIndex) {
const auto& pos = _entityIdLookup.find(entity);
unique_ptr<vector<string>> names = make_unique<vector<string>>();
if(pos == _entityIdLookup.end()) {
Log("ERROR: asset not found for entity id.");
return -1.0f;
}
auto& asset = _assets[pos->second];
return asset.mAnimator->getAnimationDuration(animationIndex);
}
unique_ptr<vector<string>> AssetManager::getAnimationNames(EntityId entity) {
const auto& pos = _entityIdLookup.find(entity);

View File

@@ -280,15 +280,16 @@ extern "C" {
// ((AssetManager*)assetManager)->setAnimationFrame(asset, animationIndex, animationFrame);
}
FLUTTER_PLUGIN_EXPORT float get_animation_duration(void* assetManager, EntityId asset, int animationIndex) {
return ((AssetManager*)assetManager)->getAnimationDuration(asset, animationIndex);
}
FLUTTER_PLUGIN_EXPORT int get_animation_count(
void* assetManager,
EntityId asset) {
//std::packaged_task<int()> lambda([=]() mutable {
auto names = ((AssetManager*)assetManager)->getAnimationNames(asset);
return names->size();
//return fut.get();
}
FLUTTER_PLUGIN_EXPORT void get_animation_name(

View File

@@ -246,6 +246,13 @@ class FilamentController {
return names.cast<String>();
}
Future<double> getAnimationDuration(
FilamentEntity asset, int animationIndex) async {
var duration = await _channel.invokeMethod(
"getAnimationDuration", [_assetManager, asset, animationIndex]);
return duration as double;
}
///
/// Animates morph target weights/bone transforms (where each frame requires a duration of [frameLengthInMs].
/// [morphWeights] is a list of doubles in frame-major format.