Files
UnrealEngine/Engine/Plugins/Mutable/Source/CustomizableObject/Private/MuCO/CustomizableObjectSkeletalMesh.cpp
Brandyn / Techy fcc1b09210 init
2026-04-04 15:40:51 -05:00

96 lines
3.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "MuCO/CustomizableObjectSkeletalMesh.h"
#include "MuCO/CustomizableObjectSystemPrivate.h"
#include "MuCO/CustomizableObject.h"
#include "MuCO/CustomizableObjectInstancePrivate.h"
#include "MuCO/CustomizableObjectMeshUpdate.h"
#include "Rendering/SkeletalMeshRenderData.h"
#include "Animation/SkinWeightProfile.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(CustomizableObjectSkeletalMesh)
void UCustomizableObjectSkeletalMesh::InitMutableStreamingData(const TSharedRef<FUpdateContextPrivate>& InOperationData, const FName& ComponentName, const int32 InstanceUpdateFirstLOD, const int32 LODCount)
{
UCustomizableObject& CustomizableObject = *InOperationData->Object;
ModelStreamableBulkData = CustomizableObject.GetPrivate()->GetModelStreamableBulkData();
// Debug info
CustomizableObjectPathName = GetNameSafe(&CustomizableObject);
// Init properties
Model = CustomizableObject.GetPrivate()->GetModel();
MeshIdRegistry = CustomizableObject.GetPrivate()->MeshIdRegistry;
ImageIdRegistry = CustomizableObject.GetPrivate()->ImageIdRegistry;
MaterialIdRegistry = CustomizableObject.GetPrivate()->MaterialIdRegistry;
ExternalResourceProvider = InOperationData->ExternalResourceProvider;
Parameters = InOperationData->Parameters;
State = InOperationData->GetCapturedDescriptor().GetState();
MeshIDs.Init({}, MAX_MESH_LOD_COUNT);
SurfaceIDs.SetNum(MAX_MESH_LOD_COUNT);
const int32 FirstLOD = InOperationData->bStreamMeshLODs ?
InOperationData->FirstLODAvailable[ComponentName] :
InOperationData->GetFirstRequestedLOD()[ComponentName];
for (int32 LODIndex = FirstLOD; LODIndex < LODCount; ++LODIndex)
{
const FInstanceUpdateData::FLOD& LOD = InOperationData->InstanceUpdateData.LODs[InstanceUpdateFirstLOD + LODIndex];
MeshIDs[LODIndex] = LOD.MeshId;
SurfaceIDs[LODIndex].SetNum(LOD.SurfaceCount);
check(LOD.Mesh && LOD.Mesh->GetSurfaceCount() == LOD.SurfaceCount);
for (int32 SurfaceIndex = 0; SurfaceIndex < LOD.SurfaceCount; ++SurfaceIndex)
{
SurfaceIDs[LODIndex][SurfaceIndex] = LOD.Mesh->GetSurfaceId(SurfaceIndex);
}
}
const UModelResources& ModelResources = CustomizableObject.GetPrivate()->GetModelResourcesChecked();
for (const FSkinWeightProfileInfo& SkinWeightProfile : GetSkinWeightProfiles())
{
const FMutableSkinWeightProfileInfo* ProfileInfo = ModelResources.SkinWeightProfilesInfo.FindByPredicate(
[&SkinWeightProfile](const FMutableSkinWeightProfileInfo& P) { return P.Name == SkinWeightProfile.Name; });
if (ensure(ProfileInfo))
{
SkinWeightProfileIDs.Add({ ProfileInfo->NameId, ProfileInfo->Name });
}
}
}
bool UCustomizableObjectSkeletalMesh::StreamIn(int32 NewMipCount, bool bHighPrio)
{
check(IsInGameThread());
FSkeletalMeshRenderData* RenderData = GetResourceForRendering();
if (!RenderData || !RenderData->IsInitialized())
{
return false;
}
if (!HasPendingInitOrStreaming() && CachedSRRState.StreamIn(NewMipCount))
{
FRenderAssetUpdate::EThreadType CreateResourcesThread = GRHISupportsAsyncTextureCreation
? FRenderAssetUpdate::TT_Async
: FRenderAssetUpdate::TT_Render;
PendingUpdate = new FCustomizableObjectMeshStreamIn(this, CreateResourcesThread, ModelStreamableBulkData);
return !PendingUpdate->IsCancelled();
}
return false;
}