Skip to content

Commit

Permalink
revert all changes, prepare new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakobzs committed Feb 21, 2024
1 parent d02fb94 commit 930f3a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 152 deletions.
46 changes: 0 additions & 46 deletions Source/glTFRuntime/Private/glTFRuntimeAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FString, UAnimSequence*> UglTFRuntimeAsset::LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig)
{
TMap<FString, UAnimSequence*> 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);
Expand Down
104 changes: 21 additions & 83 deletions Source/glTFRuntime/Private/glTFRuntimeParserSkeletalMeshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TSharedPtr<FJsonValue>>* JsonAnimations;
if (!Root->TryGetArrayField("animations", JsonAnimations))
{
Expand All @@ -1757,88 +1762,21 @@ UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimationByName(USkeleton* Skelet
{
if (JsonAnimationName == AnimationName)
{
return LoadSkeletonAnimation(Skeleton, AnimationIndex, PreviewSkeletalMesh, SkeletalAnimationConfig);
return LoadSkeletalAnimation(SkeletalMesh, AnimationIndex, SkeletalAnimationConfig);
}
}
}

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)
{
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<FString, UAnimSequence*> FglTFRuntimeParser::LoadNodeSkeletalAnimationsMap(USkeletalMesh* SkeletalMesh, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig)
{
TMap<FString, UAnimSequence*> 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<FString, FRawAnimSequenceTrack>& Tracks, TMap<FName, TArray<TPair<float, float>>>& 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))
{
Expand Down Expand Up @@ -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<FString, UAnimSequence*> FglTFRuntimeParser::LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig)
TMap<FString, UAnimSequence*> FglTFRuntimeParser::LoadNodeSkeletalAnimationsMap(USkeletalMesh* SkeletalMesh, const int32 NodeIndex, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig)
{
TMap<FString, UAnimSequence*> SkeletalAnimationsMap;

if (!Skeleton)
if (!SkeletalMesh)
{
return SkeletalAnimationsMap;
}
Expand Down Expand Up @@ -1999,7 +1937,7 @@ TMap<FString, UAnimSequence*> 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);
Expand All @@ -2011,16 +1949,16 @@ TMap<FString, UAnimSequence*> FglTFRuntimeParser::LoadNodeSkeletonAnimationsMap(
return SkeletalAnimationsMap;
}

UAnimSequence* FglTFRuntimeParser::LoadSkeletonAnimationFromTracksAndMorphTargets(USkeleton* Skeleton, USkeletalMesh* PreviewSkeletalMesh, TMap<FString, FRawAnimSequenceTrack>& Tracks, TMap<FName, TArray<TPair<float, float>>>& MorphTargetCurves, const float Duration, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig)
UAnimSequence* FglTFRuntimeParser::LoadSkeletalAnimationFromTracksAndMorphTargets(USkeletalMesh* SkeletalMesh, TMap<FString, FRawAnimSequenceTrack>& Tracks, TMap<FName, TArray<TPair<float, float>>>& MorphTargetCurves, const float Duration, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig)
{
int32 NumFrames = FMath::Max<int32>(Duration * SkeletalAnimationConfig.FramesPerSecond, 1);
UAnimSequence* AnimSequence = NewObject<UAnimSequence>(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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions Source/glTFRuntime/Public/glTFRuntimeAsset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FString, UAnimSequence*> 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);
Expand Down
8 changes: 0 additions & 8 deletions Source/glTFRuntime/Public/glTFRuntimeParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2111,14 +2111,6 @@ class GLTFRUNTIME_API FglTFRuntimeParser : public FGCObject, public TSharedFromT

UAnimSequence* LoadSkeletalAnimationFromTracksAndMorphTargets(USkeletalMesh* SkeletalMesh, TMap<FString, FRawAnimSequenceTrack>& Tracks, TMap<FName, TArray<TPair<float, float>>>& 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<FString, UAnimSequence*> LoadNodeSkeletonAnimationsMap(USkeleton* Skeleton, const int32 NodeIndex, USkeletalMesh* PreviewSkeletalMesh, const FglTFRuntimeSkeletalAnimationConfig& SkeletalAnimationConfig);
UAnimSequence* LoadSkeletonAnimationFromTracksAndMorphTargets(USkeleton* Skeleton, USkeletalMesh* PreviewSkeletalMesh, TMap<FString, FRawAnimSequenceTrack>& Tracks, TMap<FName, TArray<TPair<float, float>>>& 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);

Expand Down

0 comments on commit 930f3a4

Please sign in to comment.