Skip to content
Snippets Groups Projects
Commit c8e4bd89 authored by Konstantin Kühlem's avatar Konstantin Kühlem
Browse files

refractor(VirtuaHuman): Refractor code to match formating guidelines

parent 4d97dedf
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "Helper/CharacterPluginLogging.h" #include "Helper/CharacterPluginLogging.h"
// Sets default values // Sets default values
AVirtualHuman::AVirtualHuman() AVirtualHuman::AVirtualHuman()
{ {
...@@ -53,8 +52,10 @@ void AVirtualHuman::Tick(float DeltaTime) ...@@ -53,8 +52,10 @@ void AVirtualHuman::Tick(float DeltaTime)
// Furthermore 0.001f is used and not 0.0f since this value is used for blending and once the animation played in the default slot // Furthermore 0.001f is used and not 0.0f since this value is used for blending and once the animation played in the default slot
// is blended with 0.0f GetSlotMontageLocalWeight() always returns 0.0f since the animation played is not actually used // is blended with 0.0f GetSlotMontageLocalWeight() always returns 0.0f since the animation played is not actually used
// so we would have a circular dependency problem. // so we would have a circular dependency problem.
GetBodyAnimInstance()->IsDefaultSlotPlayingAnimation = GetBodyAnimInstance()->GetSlotMontageLocalWeight("DefaultSlot") == 0.0f ? 0.001f : 1.0f; GetBodyAnimInstance()->IsDefaultSlotPlayingAnimation =
GetBodyAnimInstance()->IsCustomIdleSlotPlayingAnimation = GetBodyAnimInstance()->GetSlotMontageLocalWeight("CustomIdleSlot") == 0.0f ? 0.001f : 1.0f; GetBodyAnimInstance()->GetSlotMontageLocalWeight("DefaultSlot") == 0.0f ? 0.001f : 1.0f;
GetBodyAnimInstance()->IsCustomIdleSlotPlayingAnimation =
GetBodyAnimInstance()->GetSlotMontageLocalWeight("CustomIdleSlot") == 0.0f ? 0.001f : 1.0f;
if (bFirstTick && CustomIdleAnimations.Num() > 0) if (bFirstTick && CustomIdleAnimations.Num() > 0)
{ {
...@@ -67,17 +68,19 @@ void AVirtualHuman::Tick(float DeltaTime) ...@@ -67,17 +68,19 @@ void AVirtualHuman::Tick(float DeltaTime)
void AVirtualHuman::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) void AVirtualHuman::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{ {
Super::SetupPlayerInputComponent(PlayerInputComponent); Super::SetupPlayerInputComponent(PlayerInputComponent);
} }
USkeletalMeshComponent* AVirtualHuman::GetBodyMesh() USkeletalMeshComponent* AVirtualHuman::GetBodyMesh()
{ {
if (BodyType == EBodyType::CC3) { if (BodyType == EBodyType::CC3)
{
return GetMesh(); return GetMesh();
} }
else if (BodyType == EBodyType::MetaHuman) { else if (BodyType == EBodyType::MetaHuman)
{
UObject* body_obj = GetDefaultSubobjectByName(TEXT("Body")); UObject* body_obj = GetDefaultSubobjectByName(TEXT("Body"));
if (body_obj != nullptr) { if (body_obj != nullptr)
{
return Cast<USkeletalMeshComponent>(body_obj); return Cast<USkeletalMeshComponent>(body_obj);
} }
} }
...@@ -87,12 +90,15 @@ USkeletalMeshComponent* AVirtualHuman::GetBodyMesh() ...@@ -87,12 +90,15 @@ USkeletalMeshComponent* AVirtualHuman::GetBodyMesh()
USkeletalMeshComponent* AVirtualHuman::GetFaceMesh() USkeletalMeshComponent* AVirtualHuman::GetFaceMesh()
{ {
if (BodyType == EBodyType::CC3) { if (BodyType == EBodyType::CC3)
{
return GetMesh(); return GetMesh();
} }
else if (BodyType == EBodyType::MetaHuman) { else if (BodyType == EBodyType::MetaHuman)
{
UObject* face_obj = GetDefaultSubobjectByName(TEXT("Face")); UObject* face_obj = GetDefaultSubobjectByName(TEXT("Face"));
if (face_obj != nullptr) { if (face_obj != nullptr)
{
return Cast<USkeletalMeshComponent>(face_obj); return Cast<USkeletalMeshComponent>(face_obj);
} }
} }
...@@ -102,12 +108,15 @@ USkeletalMeshComponent* AVirtualHuman::GetFaceMesh() ...@@ -102,12 +108,15 @@ USkeletalMeshComponent* AVirtualHuman::GetFaceMesh()
UVHAnimInstance* AVirtualHuman::GetBodyAnimInstance() UVHAnimInstance* AVirtualHuman::GetBodyAnimInstance()
{ {
if (BodyType == EBodyType::CC3) { if (BodyType == EBodyType::CC3)
{
return Cast<UVHAnimInstance>(GetMesh()->GetAnimInstance()); return Cast<UVHAnimInstance>(GetMesh()->GetAnimInstance());
} }
else if (BodyType == EBodyType::MetaHuman) { else if (BodyType == EBodyType::MetaHuman)
{
UObject* body_obj = GetDefaultSubobjectByName(TEXT("Body")); UObject* body_obj = GetDefaultSubobjectByName(TEXT("Body"));
if (body_obj != nullptr) { if (body_obj != nullptr)
{
USkeletalMeshComponent* body = Cast<USkeletalMeshComponent>(body_obj); USkeletalMeshComponent* body = Cast<USkeletalMeshComponent>(body_obj);
return Cast<UVHAnimInstance>(body->GetAnimInstance()); return Cast<UVHAnimInstance>(body->GetAnimInstance());
} }
...@@ -118,12 +127,15 @@ UVHAnimInstance* AVirtualHuman::GetBodyAnimInstance() ...@@ -118,12 +127,15 @@ UVHAnimInstance* AVirtualHuman::GetBodyAnimInstance()
UVHAnimInstance* AVirtualHuman::GetFaceAnimInstance() UVHAnimInstance* AVirtualHuman::GetFaceAnimInstance()
{ {
if (BodyType == EBodyType::CC3) { if (BodyType == EBodyType::CC3)
{
return Cast<UVHAnimInstance>(GetMesh()->GetAnimInstance()); return Cast<UVHAnimInstance>(GetMesh()->GetAnimInstance());
} }
else if (BodyType == EBodyType::MetaHuman) { else if (BodyType == EBodyType::MetaHuman)
{
UObject* face_obj = GetDefaultSubobjectByName(TEXT("Face")); UObject* face_obj = GetDefaultSubobjectByName(TEXT("Face"));
if (face_obj != nullptr) { if (face_obj != nullptr)
{
USkeletalMeshComponent* face = Cast<USkeletalMeshComponent>(face_obj); USkeletalMeshComponent* face = Cast<USkeletalMeshComponent>(face_obj);
return Cast<UVHAnimInstance>(face->GetAnimInstance()); return Cast<UVHAnimInstance>(face->GetAnimInstance());
} }
...@@ -158,13 +170,14 @@ bool AVirtualHuman::SupportsMorphs() ...@@ -158,13 +170,14 @@ bool AVirtualHuman::SupportsMorphs()
void AVirtualHuman::SetUpBodyType() void AVirtualHuman::SetUpBodyType()
{ {
if (BodyType == EBodyType::CC3)
if (BodyType == EBodyType::CC3) { {
if (BodyAnimInstanceToUse != nullptr)
if (BodyAnimInstanceToUse != nullptr) { {
GetBodyMesh()->SetAnimInstanceClass(BodyAnimInstanceToUse); GetBodyMesh()->SetAnimInstanceClass(BodyAnimInstanceToUse);
} }
else { else
{
GetBodyMesh()->SetAnimInstanceClass(CC3AnimInstanceClass); GetBodyMesh()->SetAnimInstanceClass(CC3AnimInstanceClass);
} }
//AnimationInstance = Cast<UVHAnimInstance>(GetMesh()->GetAnimInstance()); //AnimationInstance = Cast<UVHAnimInstance>(GetMesh()->GetAnimInstance());
...@@ -204,22 +217,25 @@ void AVirtualHuman::SetUpBodyType() ...@@ -204,22 +217,25 @@ void AVirtualHuman::SetUpBodyType()
BoneNames.foot_l = TEXT("foot_l"); BoneNames.foot_l = TEXT("foot_l");
BoneNames.foot_socket_r = TEXT("foot_rSocket"); BoneNames.foot_socket_r = TEXT("foot_rSocket");
BoneNames.foot_socket_l = TEXT("foot_lSocket"); BoneNames.foot_socket_l = TEXT("foot_lSocket");
} }
else if (BodyType == EBodyType::MetaHuman) { else if (BodyType == EBodyType::MetaHuman)
{
UObject* root_obj = GetDefaultSubobjectByName(TEXT("Root")); UObject* root_obj = GetDefaultSubobjectByName(TEXT("Root"));
USkeletalMeshComponent* body = GetBodyMesh(); USkeletalMeshComponent* body = GetBodyMesh();
USkeletalMeshComponent* face = GetFaceMesh(); USkeletalMeshComponent* face = GetFaceMesh();
FStreamableManager AssetLoader; FStreamableManager AssetLoader;
FSoftObjectPath AssetRef(FPaths::ConvertRelativePathToFull("/CharacterPlugin/Characters/MetaHuman/metahuman_base_skel.metahuman_base_skel")); FSoftObjectPath AssetRef(
FPaths::ConvertRelativePathToFull(
"/CharacterPlugin/Characters/MetaHuman/metahuman_base_skel.metahuman_base_skel"));
UObject* body_skeleton_obj = AssetLoader.LoadSynchronous(AssetRef); UObject* body_skeleton_obj = AssetLoader.LoadSynchronous(AssetRef);
FStreamableManager AssetLoader2; FStreamableManager AssetLoader2;
FSoftObjectPath AssetRef2(FPaths::ConvertRelativePathToFull("/CharacterPlugin/Characters/MetaHuman/Face_Archetype53_Skeleton.Face_Archetype53_Skeleton")); FSoftObjectPath AssetRef2(FPaths::ConvertRelativePathToFull(
"/CharacterPlugin/Characters/MetaHuman/Face_Archetype53_Skeleton.Face_Archetype53_Skeleton"));
UObject* face_skeleton_obj = AssetLoader2.LoadSynchronous(AssetRef2); UObject* face_skeleton_obj = AssetLoader2.LoadSynchronous(AssetRef2);
if (root_obj != nullptr && body != nullptr && body_skeleton_obj != nullptr && face != nullptr && face_skeleton_obj != nullptr) { if (root_obj != nullptr && body != nullptr && body_skeleton_obj != nullptr && face != nullptr &&
face_skeleton_obj != nullptr)
{
USceneComponent* root = Cast<USceneComponent>(root_obj); USceneComponent* root = Cast<USceneComponent>(root_obj);
USkeleton* body_skel = Cast<USkeleton>(body_skeleton_obj); USkeleton* body_skel = Cast<USkeleton>(body_skeleton_obj);
USkeleton* face_skel = Cast<USkeleton>(face_skeleton_obj); USkeleton* face_skel = Cast<USkeleton>(face_skeleton_obj);
...@@ -227,18 +243,22 @@ void AVirtualHuman::SetUpBodyType() ...@@ -227,18 +243,22 @@ void AVirtualHuman::SetUpBodyType()
root->SetRelativeLocationAndRotation(FVector(0, 0, -87), FRotator(0, -90, 0)); root->SetRelativeLocationAndRotation(FVector(0, 0, -87), FRotator(0, -90, 0));
body->GetSkeletalMeshAsset()->SetSkeleton(body_skel); body->GetSkeletalMeshAsset()->SetSkeleton(body_skel);
if (BodyAnimInstanceToUse != nullptr) { if (BodyAnimInstanceToUse != nullptr)
{
body->SetAnimInstanceClass(BodyAnimInstanceToUse); body->SetAnimInstanceClass(BodyAnimInstanceToUse);
} }
else { else
{
body->SetAnimInstanceClass(MetaHumanBodyAnimInstanceClass); body->SetAnimInstanceClass(MetaHumanBodyAnimInstanceClass);
} }
face->GetSkeletalMeshAsset()->SetSkeleton(face_skel); face->GetSkeletalMeshAsset()->SetSkeleton(face_skel);
if (FaceAnimInstanceToUse != nullptr) { if (FaceAnimInstanceToUse != nullptr)
{
face->SetAnimInstanceClass(FaceAnimInstanceToUse); face->SetAnimInstanceClass(FaceAnimInstanceToUse);
} }
else { else
{
face->SetAnimInstanceClass(MetaHumanFaceAnimInstanceClass); face->SetAnimInstanceClass(MetaHumanFaceAnimInstanceClass);
} }
...@@ -278,14 +298,13 @@ void AVirtualHuman::SetUpBodyType() ...@@ -278,14 +298,13 @@ void AVirtualHuman::SetUpBodyType()
BoneNames.foot_l = TEXT("foot_l"); BoneNames.foot_l = TEXT("foot_l");
BoneNames.foot_socket_r = TEXT("ball_r"); BoneNames.foot_socket_r = TEXT("ball_r");
BoneNames.foot_socket_l = TEXT("ball_l"); BoneNames.foot_socket_l = TEXT("ball_l");
} }
else { else
VH_WARN("The structure in the skeletal mesh components does not fit a typical meta human structure! Some features may not work.\n"); {
VH_WARN(
"The structure in the skeletal mesh components does not fit a typical meta human structure! Some features may not work.\n");
} }
} }
} }
void AVirtualHuman::PlayRandomIdleAnimation() void AVirtualHuman::PlayRandomIdleAnimation()
...@@ -295,15 +314,19 @@ void AVirtualHuman::PlayRandomIdleAnimation() ...@@ -295,15 +314,19 @@ void AVirtualHuman::PlayRandomIdleAnimation()
return; return;
} }
// play arandom idle animation // play random idle animation
int Random = IdleRandomStream.RandRange(0, CustomIdleAnimations.Num() - 1); int Random = IdleRandomStream.RandRange(0, CustomIdleAnimations.Num() - 1);
UAnimSequence* IdleAnim = CustomIdleAnimations[Random]; UAnimSequence* IdleAnim = CustomIdleAnimations[Random];
if (IdleAnim) if (IdleAnim)
{ {
float BlendTime = 0.25f; float BlendTime = 0.25f;
UAnimMontage* DynamicMontage = GetBodyAnimInstance()->PlaySlotAnimationAsDynamicMontage(IdleAnim, "CustomIdleSlot", BlendTime, BlendTime); UAnimMontage* DynamicMontage = GetBodyAnimInstance()->PlaySlotAnimationAsDynamicMontage(
IdleAnim, "CustomIdleSlot", BlendTime, BlendTime);
// start timer for next random pick (make it a bit shorter to allow for blending, but only by a defined minimal amount for the animations) // start timer for next random pick (make it a bit shorter to allow for blending, but only by a defined minimal amount for the animations)
GetWorld()->GetTimerManager().SetTimer(NextIdleTimerHandle, this, &AVirtualHuman::PlayRandomIdleAnimation, DynamicMontage->GetPlayLength()- fmin(2.0*BlendTime, (DynamicMontage->GetPlayLength())*MinBlendTime), false); GetWorld()->GetTimerManager().SetTimer(NextIdleTimerHandle, this, &AVirtualHuman::PlayRandomIdleAnimation,
DynamicMontage->GetPlayLength() - fmin(
2.0 * BlendTime, (DynamicMontage->GetPlayLength()) * MinBlendTime),
false);
} }
else else
{ {
...@@ -317,10 +340,10 @@ void AVirtualHuman::PostEditChangeProperty(FPropertyChangedEvent& PropertyChange ...@@ -317,10 +340,10 @@ void AVirtualHuman::PostEditChangeProperty(FPropertyChangedEvent& PropertyChange
Super::PostEditChangeProperty(PropertyChangedEvent); Super::PostEditChangeProperty(PropertyChangedEvent);
FProperty* prop = PropertyChangedEvent.Property; FProperty* prop = PropertyChangedEvent.Property;
if (prop != nullptr && prop->GetNameCPP().Compare(TEXT("BodyType")) == 0) { if (prop != nullptr && prop->GetNameCPP().Compare(TEXT("BodyType")) == 0)
{
SetUpBodyType(); SetUpBodyType();
} }
} }
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment