From 781fa086e117e4bd0b3dfee7626cb70088ce12d6 Mon Sep 17 00:00:00 2001 From: Jakobzs <31919330+Jakobzs@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:48:06 +0100 Subject: [PATCH] awer --- .../glTFRuntime/Private/glTFRuntimeAsset.cpp | 46 -------- .../glTFRuntimeParserSkeletalMeshes.cpp | 104 ++++-------------- Source/glTFRuntime/Public/glTFRuntimeAsset.h | 15 --- Source/glTFRuntime/Public/glTFRuntimeParser.h | 8 -- 4 files changed, 21 insertions(+), 152 deletions(-) diff --git a/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp b/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp index 13a240b7..d5561d2e 100644 --- a/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp +++ b/Source/glTFRuntime/Private/glTFRuntimeAsset.cpp @@ -632,52 +632,6 @@ UAnimSequence* UglTFRuntimeAsset::LoadSkeletalAnimationByName(USkeletalMesh* Ske return Parser->LoadSkeletalAnimationByName(SkeletalMesh, AnimationName, SkeletalAnimationConfig); } -UAnimSequence* UglTFRuntimeAsset::LoadSkeletonAnimation(USkeleton* Skeleton, const int32 AnimationIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - GLTF_CHECK_PARSER(nullptr); - - return Parser->LoadSkeletonAnimation(Skeleton, AnimationIndex, nullptr, SkeletalAnimationConfig); -} - -UAnimSequence* UglTFRuntimeAsset::LoadSkeletonAnimationByName(USkeleton* Skeleton, const FString& AnimationName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - GLTF_CHECK_PARSER(nullptr); - - return Parser->LoadSkeletonAnimationByName(Skeleton, AnimationName, nullptr, SkeletalAnimationConfig); -} - -UAnimSequence* UglTFRuntimeAsset::LoadNodeSkeletonAnimation(USkeleton* Skeleton, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - GLTF_CHECK_PARSER(nullptr); - - return Parser->LoadNodeSkeletonAnimation(Skeleton, NodeIndex, nullptr, SkeletalAnimationConfig); -} - -TMap UglTFRuntimeAsset::LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - TMap EmptyMap; - GLTF_CHECK_PARSER(EmptyMap); - - return Parser->LoadNodeSkeletonAnimationsMap(Skeleton, NodeIndex, nullptr, SkeletalAnimationConfig); -} - -UAnimMontage* UglTFRuntimeAsset::LoadSkeletonAnimationAsMontage(USkeleton* Skeleton, const int32 AnimationIndex, const FString& SlotNodeName, const FglTFRuntimeSkeletalAnimationConfig& AnimationConfig) -{ - UAnimSequence* AnimSequence = LoadSkeletonAnimation(Skeleton, AnimationIndex, AnimationConfig); - if (!AnimSequence) - { - return nullptr; - } - - UAnimMontage* AnimMontage = UAnimMontage::CreateSlotAnimationAsDynamicMontage(AnimSequence, FName(SlotNodeName), 0, 0, 1); - if (!AnimMontage) - { - return nullptr; - } - - return AnimMontage; -} - bool UglTFRuntimeAsset::BuildTransformFromNodeBackward(const int32 NodeIndex, FTransform& Transform) { GLTF_CHECK_PARSER(false); diff --git a/Source/glTFRuntime/Private/glTFRuntimeParserSkeletalMeshes.cpp b/Source/glTFRuntime/Private/glTFRuntimeParserSkeletalMeshes.cpp index 6842e292..23171096 100644 --- a/Source/glTFRuntime/Private/glTFRuntimeParserSkeletalMeshes.cpp +++ b/Source/glTFRuntime/Private/glTFRuntimeParserSkeletalMeshes.cpp @@ -1735,8 +1735,13 @@ void FglTFRuntimeParser::LoadSkeletalMeshRecursiveAsync(const FString& NodeName, }); } -UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimationByName(USkeleton* Skeleton, const FString AnimationName, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +UAnimSequence* FglTFRuntimeParser::LoadSkeletalAnimationByName(USkeletalMesh* SkeletalMesh, const FString AnimationName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) { + if (!SkeletalMesh) + { + return nullptr; + } + const TArray>* JsonAnimations; if (!Root->TryGetArrayField("animations", JsonAnimations)) { @@ -1757,7 +1762,7 @@ UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimationByName(USkeleton* Skelet { if (JsonAnimationName == AnimationName) { - return LoadSkeletonAnimation(Skeleton, AnimationIndex, PreviewSkeletalMesh, SkeletalAnimationConfig); + return LoadSkeletalAnimation(SkeletalMesh, AnimationIndex, SkeletalAnimationConfig); } } } @@ -1765,20 +1770,6 @@ UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimationByName(USkeleton* Skelet return nullptr; } -UAnimSequence* FglTFRuntimeParser::LoadSkeletalAnimationByName(USkeletalMesh* SkeletalMesh, const FString AnimationName, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - if (!SkeletalMesh) - { - return nullptr; - } - -#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 - return LoadSkeletonAnimationByName(SkeletalMesh->GetSkeleton(), AnimationName, SkeletalMesh, SkeletalAnimationConfig); -#else - return LoadSkeletonAnimationByName(SkeletalMesh->Skeleton, AnimationName, SkeletalMesh, SkeletalAnimationConfig); -#endif -} - UAnimSequence* FglTFRuntimeParser::LoadNodeSkeletalAnimation(USkeletalMesh* SkeletalMesh, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) { if (!SkeletalMesh) @@ -1786,59 +1777,6 @@ UAnimSequence* FglTFRuntimeParser::LoadNodeSkeletalAnimation(USkeletalMesh* Skel return nullptr; } -#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 - return LoadNodeSkeletonAnimation(SkeletalMesh->GetSkeleton(), NodeIndex, SkeletalMesh, SkeletalAnimationConfig); -#else - return LoadNodeSkeletonAnimation(SkeletalMesh->Skeleton, AnimationName, SkeletalMesh, SkeletalAnimationConfig); -#endif -} - -TMap FglTFRuntimeParser::LoadNodeSkeletalAnimationsMap(USkeletalMesh* SkeletalMesh, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - TMap SkeletalAnimationsMap; - - if (!SkeletalMesh) - { - return SkeletalAnimationsMap; - } - -#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 - return LoadNodeSkeletonAnimationsMap(SkeletalMesh->GetSkeleton(), NodeIndex, SkeletalMesh, SkeletalAnimationConfig); -#else - return LoadNodeSkeletonAnimationsMap(SkeletalMesh->Skeleton, AnimationName, SkeletalMesh, SkeletalAnimationConfig); -#endif -} - -UAnimSequence* FglTFRuntimeParser::LoadSkeletalAnimationFromTracksAndMorphTargets(USkeletalMesh* SkeletalMesh, TMap& Tracks, TMap>>& MorphTargetCurves, const float Duration, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - if (!SkeletalMesh) - { - return nullptr; - } - -#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 - return LoadSkeletonAnimationFromTracksAndMorphTargets(SkeletalMesh->GetSkeleton(), SkeletalMesh, Tracks, MorphTargetCurves, Duration, SkeletalAnimationConfig); -#else - return LoadSkeletonAnimationFromTracksAndMorphTargets(SkeletalMesh->Skeleton, SkeletalMesh, Tracks, MorphTargetCurves, Duration, SkeletalAnimationConfig); -#endif -} - -UAnimSequence* FglTFRuntimeParser::LoadSkeletalAnimation(USkeletalMesh* SkeletalMesh, const int32 AnimationIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ - if (!SkeletalMesh) - { - return nullptr; - } - -#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 - return LoadSkeletonAnimation(SkeletalMesh->GetSkeleton(), AnimationIndex, SkeletalMesh, SkeletalAnimationConfig); -#else - return LoadSkeletonAnimation(SkeletalMesh->Skeleton, AnimationIndex, SkeletalMesh, SkeletalAnimationConfig); -#endif -} - -UAnimSequence* FglTFRuntimeParser::LoadNodeSkeletonAnimation(USkeleton* Skeleton, const int32 NodeIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) -{ FglTFRuntimeNode Node; if (!LoadNode(NodeIndex, Node)) { @@ -1907,18 +1845,18 @@ UAnimSequence* FglTFRuntimeParser::LoadNodeSkeletonAnimation(USkeleton* Skeleton { // this is very inefficient as we parse the tracks twice // TODO: refactor it - return LoadSkeletonAnimation(Skeleton, JsonAnimationIndex, PreviewSkeletalMesh, SkeletalAnimationConfig); + return LoadSkeletalAnimation(SkeletalMesh, JsonAnimationIndex, SkeletalAnimationConfig); } } return nullptr; } -TMap FglTFRuntimeParser::LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +TMap FglTFRuntimeParser::LoadNodeSkeletalAnimationsMap(USkeletalMesh* SkeletalMesh, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) { TMap SkeletalAnimationsMap; - if (!Skeleton) + if (!SkeletalMesh) { return SkeletalAnimationsMap; } @@ -1999,7 +1937,7 @@ TMap FglTFRuntimeParser::LoadNodeSkeletonAnimationsMap( { // this is very inefficient as we parse the tracks twice // TODO: refactor it - UAnimSequence* NewAnimation = LoadSkeletalAnimation(PreviewSkeletalMesh, JsonAnimationIndex, SkeletalAnimationConfig); + UAnimSequence* NewAnimation = LoadSkeletalAnimation(SkeletalMesh, JsonAnimationIndex, SkeletalAnimationConfig); if (NewAnimation) { UAnimSequence*& AnimationSlot = SkeletalAnimationsMap.FindOrAdd(AnimationName); @@ -2011,16 +1949,16 @@ TMap FglTFRuntimeParser::LoadNodeSkeletonAnimationsMap( return SkeletalAnimationsMap; } -UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimationFromTracksAndMorphTargets(USkeleton* Skeleton, USkeletalMesh* PreviewSkeletalMesh, TMap& Tracks, TMap>>& MorphTargetCurves, const float Duration, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +UAnimSequence* FglTFRuntimeParser::LoadSkeletalAnimationFromTracksAndMorphTargets(USkeletalMesh* SkeletalMesh, TMap& Tracks, TMap>>& MorphTargetCurves, const float Duration, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) { int32 NumFrames = FMath::Max(Duration * SkeletalAnimationConfig.FramesPerSecond, 1); UAnimSequence* AnimSequence = NewObject(GetTransientPackage(), NAME_None, RF_Public); - AnimSequence->SetSkeleton(Skeleton); - if (PreviewSkeletalMesh) - { - AnimSequence->SetPreviewMesh(PreviewSkeletalMesh); - } - +#if ENGINE_MAJOR_VERSION > 4 || ENGINE_MINOR_VERSION > 26 + AnimSequence->SetSkeleton(SkeletalMesh->GetSkeleton()); +#else + AnimSequence->SetSkeleton(SkeletalMesh->Skeleton); +#endif + AnimSequence->SetPreviewMesh(SkeletalMesh); #if ENGINE_MAJOR_VERSION > 4 #if WITH_EDITOR FFrameRate FrameRate(SkeletalAnimationConfig.FramesPerSecond, 1); @@ -2431,9 +2369,9 @@ UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimationFromTracksAndMorphTarget return AnimSequence; } -UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimation(USkeleton* Skeleton, const int32 AnimationIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) +UAnimSequence* FglTFRuntimeParser::LoadSkeletalAnimation(USkeletalMesh* SkeletalMesh, const int32 AnimationIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) { - if (!Skeleton) + if (!SkeletalMesh) { return nullptr; } @@ -2454,7 +2392,7 @@ UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimation(USkeleton* Skeleton, co return nullptr; } - return LoadSkeletonAnimationFromTracksAndMorphTargets(Skeleton, nullptr, Tracks, MorphTargetCurves, Duration, SkeletalAnimationConfig); + return LoadSkeletalAnimationFromTracksAndMorphTargets(SkeletalMesh, Tracks, MorphTargetCurves, Duration, SkeletalAnimationConfig); } UAnimSequence* FglTFRuntimeParser::CreateAnimationFromPose(USkeletalMesh* SkeletalMesh, const int32 SkinIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig) diff --git a/Source/glTFRuntime/Public/glTFRuntimeAsset.h b/Source/glTFRuntime/Public/glTFRuntimeAsset.h index 1956b2d7..3c0a8db9 100644 --- a/Source/glTFRuntime/Public/glTFRuntimeAsset.h +++ b/Source/glTFRuntime/Public/glTFRuntimeAsset.h @@ -108,21 +108,6 @@ 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); diff --git a/Source/glTFRuntime/Public/glTFRuntimeParser.h b/Source/glTFRuntime/Public/glTFRuntimeParser.h index c4672fea..38fb190d 100644 --- a/Source/glTFRuntime/Public/glTFRuntimeParser.h +++ b/Source/glTFRuntime/Public/glTFRuntimeParser.h @@ -2111,14 +2111,6 @@ class GLTFRUNTIME_API FglTFRuntimeParser : public FGCObject, public TSharedFromT UAnimSequence* LoadSkeletalAnimationFromTracksAndMorphTargets(USkeletalMesh* SkeletalMesh, TMap& Tracks, TMap>>& MorphTargetCurves, const float Duration, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); - // START CUSTOM LOADING FOR SKELETON ANIMATION - UAnimSequence* LoadSkeletonAnimation(USkeleton* Skeleton, const int32 AnimationIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); - UAnimSequence* LoadSkeletonAnimationByName(USkeleton* Skeleton, const FString AnimationName, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); - UAnimSequence* LoadNodeSkeletonAnimation(USkeleton* Skeleton, const int32 NodeIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); - TMap LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); - UAnimSequence* LoadSkeletonAnimationFromTracksAndMorphTargets(USkeleton* Skeleton, USkeletalMesh* PreviewSkeletalMesh, TMap& Tracks, TMap>>& MorphTargetCurves, const float Duration, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig); - // STOP CUSTOM LOADING FOR SKELETON ANIMATION - void LoadSkeletalMeshAsync(const int32 MeshIndex, const int32 SkinIndex, const FglTFRuntimeSkeletalMeshAsync& AsyncCallback, const FglTFRuntimeSkeletalMeshConfig& SkeletalMeshConfig); void LoadStaticMeshAsync(const int32 MeshIndex, const FglTFRuntimeStaticMeshAsync& AsyncCallback, const FglTFRuntimeStaticMeshConfig& StaticMeshConfig);