From 7d5a97d8025aa451e07e6c1fd5412714f653de53 Mon Sep 17 00:00:00 2001 From: Jakob <31919330+Jakobzs@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:07:34 +0100 Subject: [PATCH] Add loading of skeleton animations --- .../glTFRuntime/Private/glTFRuntimeAsset.cpp | 60 +++++++++++++++++++ Source/glTFRuntime/Public/glTFRuntimeAsset.h | 15 +++++ 2 files changed, 75 insertions(+) diff --git a/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp b/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp index d5561d2e..b9ffbaa4 100644 --- a/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp +++ b/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp @@ -719,6 +719,66 @@ UAnimMontage* UglTFRuntimeAsset::LoadSkeletalAnimationAsMontage(USkeletalMesh* S return AnimMontage; } +UAnimSequence* UglTFRuntimeAsset::LoadSkeletonAnimation(USkeleton* Skeleton, const int32 AnimationIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +{ + USkeletalMesh* SkeletalMesh = NewObject(GetTransientPackage(), NAME_None, RF_Public); +#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 + SkeletalMesh->SetSkeleton(Skeleton); +#else + SkeletalMesh->Skeleton = Skeleton; +#endif + + return LoadSkeletalAnimation(SkeletalMesh, AnimationIndex, SkeletalAnimationConfig); +} + +UAnimSequence* UglTFRuntimeAsset::LoadSkeletonAnimationByName(USkeleton* Skeleton, const FString& AnimationName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +{ + USkeletalMesh* SkeletalMesh = NewObject(GetTransientPackage(), NAME_None, RF_Public); +#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 + SkeletalMesh->SetSkeleton(Skeleton); +#else + SkeletalMesh->Skeleton = Skeleton; +#endif + + return LoadSkeletalAnimationByName(SkeletalMesh, AnimationName, SkeletalAnimationConfig); +} + +UAnimSequence* UglTFRuntimeAsset::LoadNodeSkeletonAnimation(USkeleton* Skeleton, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +{ + USkeletalMesh* SkeletalMesh = NewObject(GetTransientPackage(), NAME_None, RF_Public); +#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 + SkeletalMesh->SetSkeleton(Skeleton); +#else + SkeletalMesh->Skeleton = Skeleton; +#endif + + return LoadNodeSkeletalAnimation(SkeletalMesh, NodeIndex, SkeletalAnimationConfig); +} + +TMap UglTFRuntimeAsset::LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +{ + USkeletalMesh* SkeletalMesh = NewObject(GetTransientPackage(), NAME_None, RF_Public); +#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 + SkeletalMesh->SetSkeleton(Skeleton); +#else + SkeletalMesh->Skeleton = Skeleton; +#endif + + return LoadNodeSkeletalAnimationsMap(SkeletalMesh, NodeIndex, SkeletalAnimationConfig); +} + +UAnimMontage* UglTFRuntimeAsset::LoadSkeletonAnimationAsMontage(USkeleton* Skeleton, const int32 AnimationIndex, const FString& SlotNodeName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +{ + USkeletalMesh* SkeletalMesh = NewObject(GetTransientPackage(), NAME_None, RF_Public); +#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 + SkeletalMesh->SetSkeleton(Skeleton); +#else + SkeletalMesh->Skeleton = Skeleton; +#endif + + return LoadSkeletalAnimationAsMontage(SkeletalMesh, AnimationIndex, SlotNodeName, SkeletalAnimationConfig); +} + UglTFRuntimeAnimationCurve* UglTFRuntimeAsset::LoadNodeAnimationCurve(const int32 NodeIndex) { GLTF_CHECK_PARSER(nullptr); diff --git a/Source/glTFRuntime/Public/glTFRuntimeAsset.h b/Source/glTFRuntime/Public/glTFRuntimeAsset.h index 3c0a8db9..0259fbf8 100644 --- a/Source/glTFRuntime/Public/glTFRuntimeAsset.h +++ b/Source/glTFRuntime/Public/glTFRuntimeAsset.h @@ -109,6 +109,21 @@ class GLTFRUNTIME_API UglTFRuntimeAsset : public UObject UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "SkeletalAnimationConfig", AutoCreateRefTerm = "SkeletalAnimationConfig"), Category = "glTFRuntime") UAnimMontage* LoadSkeletalAnimationAsMontage(USkeletalMesh* SkeletalMesh, const int32 AnimationIndex, const FString& SlotNodeName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); + UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "SkeletalAnimationConfig", AutoCreateRefTerm = "SkeletalAnimationConfig"), Category = "glTFRuntime") + UAnimSequence* LoadSkeletonAnimation(USkeleton* Skeleton, const int32 AnimationIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); + + UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "SkeletalAnimationConfig", AutoCreateRefTerm = "SkeletalAnimationConfig"), Category = "glTFRuntime") + UAnimSequence* LoadSkeletonAnimationByName(USkeleton* Skeleton, const FString& AnimationName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); + + UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "SkeletalAnimationConfig", AutoCreateRefTerm = "SkeletalAnimationConfig"), Category = "glTFRuntime") + UAnimSequence* LoadNodeSkeletonAnimation(USkeleton* Skeleton, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); + + UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "SkeletalAnimationConfig", AutoCreateRefTerm = "SkeletalAnimationConfig"), Category = "glTFRuntime") + TMap LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); + + UFUNCTION(BlueprintCallable, meta = (AdvancedDisplay = "SkeletalAnimationConfig", AutoCreateRefTerm = "SkeletalAnimationConfig"), Category = "glTFRuntime") + UAnimMontage* LoadSkeletonAnimationAsMontage(USkeleton* Skeleton, const int32 AnimationIndex, const FString& SlotNodeName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); + UFUNCTION(BlueprintCallable, Category = "glTFRuntime") UglTFRuntimeAnimationCurve* LoadNodeAnimationCurve(const int32 NodeIndex);