Refactor clothing visuals

This commit is contained in:
olehhapuk
2026-05-29 22:54:28 +03:00
parent 0cccb12b72
commit a61d4e2bd0
11 changed files with 187 additions and 481 deletions
+6 -111
View File
@@ -1,9 +1,9 @@
#include "PlayerImpostor.h"
#include "PlayerImpostor.h"
#include "NakedDesireCharacter.h"
#include "Kismet/GameplayStatics.h"
#include "NakedDesire/Clothing/ClothingItemDefinition.h"
#include "NakedDesire/Clothing/ClothingItemInstance.h"
#include "NakedDesire/Clothing/ClothingManager.h"
#include "NakedDesire/Clothing/ClothingVisualsComponent.h"
APlayerImpostor::APlayerImpostor()
@@ -16,44 +16,7 @@ APlayerImpostor::APlayerImpostor()
Mesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("RootMesh"));
Mesh->SetupAttachment(RootComponent);
NipplesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Nipples"));
NipplesMeshComponent->SetupAttachment(GetMesh());
AnalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Anal"));
AnalMeshComponent->SetupAttachment(GetMesh());
VaginaMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Vagina"));
VaginaMeshComponent->SetupAttachment(GetMesh());
HeadMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Head"));
HeadMeshComponent->SetupAttachment(GetMesh());
NeckMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Neck"));
NeckMeshComponent->SetupAttachment(GetMesh());
FaceMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Face"));
FaceMeshComponent->SetupAttachment(GetMesh());
EyesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Eyes"));
EyesMeshComponent->SetupAttachment(GetMesh());
BodyMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Body"));
BodyMeshComponent->SetupAttachment(GetMesh());
TopMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Top"));
TopMeshComponent->SetupAttachment(GetMesh());
BottomMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Bottom"));
BottomMeshComponent->SetupAttachment(GetMesh());
BraMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Bra"));
BraMeshComponent->SetupAttachment(GetMesh());
PantiesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Panties"));
PantiesMeshComponent->SetupAttachment(GetMesh());
SocksMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Socks"));
SocksMeshComponent->SetupAttachment(GetMesh());
ShoesMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Shoes"));
ShoesMeshComponent->SetupAttachment(GetMesh());
}
void APlayerImpostor::OnClothingEquip(UClothingItemInstance* ClothingItemInstance)
{
EquipClothing(ClothingItemInstance);
}
void APlayerImpostor::OnClothingUnequip(UClothingItemInstance* ClothingItemInstance)
{
UnequipClothing(ClothingItemInstance);
ClothingVisualsComponent = CreateDefaultSubobject<UClothingVisualsComponent>(TEXT("Clothing Visuals Component"));
}
void APlayerImpostor::BeginPlay()
@@ -66,73 +29,5 @@ void APlayerImpostor::BeginPlay()
return;
}
Player->ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &APlayerImpostor::OnClothingEquip);
Player->ClothingManager->OnClothingUnequip.AddUniqueDynamic(this, &APlayerImpostor::OnClothingUnequip);
for (const UClothingItemInstance* ClothingItemInstance : Player->ClothingManager->GetEquippedClothing())
{
EquipClothing(ClothingItemInstance);
}
}
USkeletalMeshComponent* APlayerImpostor::GetMeshByType(const EClothingSlotType SlotType) const
{
switch (SlotType)
{
case EClothingSlotType::Nipples:
return NipplesMeshComponent;
case EClothingSlotType::Anal:
return AnalMeshComponent;
case EClothingSlotType::Vagina:
return VaginaMeshComponent;
case EClothingSlotType::Head:
return HeadMeshComponent;
case EClothingSlotType::Neck:
return NeckMeshComponent;
case EClothingSlotType::Face:
return FaceMeshComponent;
case EClothingSlotType::Eyes:
return EyesMeshComponent;
case EClothingSlotType::Bodysuit:
return BodyMeshComponent;
case EClothingSlotType::Top:
return TopMeshComponent;
case EClothingSlotType::Bottom:
return BottomMeshComponent;
case EClothingSlotType::UnderwearTop:
return BraMeshComponent;
case EClothingSlotType::UnderwearBottom:
return PantiesMeshComponent;
case EClothingSlotType::Socks:
return SocksMeshComponent;
case EClothingSlotType::Footwear:
return ShoesMeshComponent;
default:
return NipplesMeshComponent;
}
}
void APlayerImpostor::EquipClothing(const UClothingItemInstance* ClothingItemInstance)
{
USkeletalMeshComponent* MeshComponent = GetMeshByType(ClothingItemInstance->GetClothingItemDefinition()->SlotType);
MeshComponent->SetSkeletalMesh(ClothingItemInstance->GetClothingItemDefinition()->SkeletalMesh);
if (ClothingItemInstance->GetClothingItemDefinition()->UseLeaderPose)
{
MeshComponent->SetLeaderPoseComponent(GetMesh());
}
if (!ClothingItemInstance->GetClothingItemDefinition()->Materials.IsEmpty())
{
for (const TPair<FName, UMaterialInstance*>& Material : ClothingItemInstance->GetClothingItemDefinition()->Materials)
{
MeshComponent->SetMaterialByName(Material.Key, Material.Value);
}
}
}
void APlayerImpostor::UnequipClothing(const UClothingItemInstance* ClothingItemInstance)
{
USkeletalMeshComponent* MeshComponent = GetMeshByType(ClothingItemInstance->GetClothingItemDefinition()->SlotType);
MeshComponent->SetSkeletalMesh(nullptr);
MeshComponent->SetLeaderPoseComponent(nullptr);
}
ClothingVisualsComponent->Initialize(GetMesh(), Player->ClothingManager);
}