Files
UnrealEngineUWP/Engine/Source/Developer/MeshMergeUtilities/Private/StaticMeshComponentAdapter.cpp
Richard TalbotWatkin 21ecacd4d6 Deprecated direct access to UStaticMesh::SourceModels, SectionInfoMap and OriginalSectionInfoMap.
Added new accessors for getting individual SourceModels, or the entire array.
#rb none
#jira none

[CL 7668562 by Richard TalbotWatkin in 4.23 branch]
2019-07-31 03:40:28 -04:00

99 lines
3.0 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "StaticMeshComponentAdapter.h"
#include "MaterialBakingStructures.h"
#include "Engine/MapBuildDataRegistry.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/StaticMesh.h"
#include "MeshMergeUtilities.h"
#include "MeshMergeHelpers.h"
#include "UObject/Package.h"
FStaticMeshComponentAdapter::FStaticMeshComponentAdapter(UStaticMeshComponent* InStaticMeshComponent)
: StaticMeshComponent(InStaticMeshComponent), StaticMesh(InStaticMeshComponent->GetStaticMesh())
{
checkf(StaticMesh != nullptr, TEXT("Invalid static mesh in adapter"));
NumLODs = StaticMesh->GetNumLODs();
}
int32 FStaticMeshComponentAdapter::GetNumberOfLODs() const
{
return NumLODs;
}
void FStaticMeshComponentAdapter::RetrieveRawMeshData(int32 LODIndex, FMeshDescription& InOutRawMesh, bool bPropogateMeshData) const
{
FMeshMergeHelpers::RetrieveMesh(StaticMeshComponent, LODIndex, InOutRawMesh, bPropogateMeshData);
}
void FStaticMeshComponentAdapter::RetrieveMeshSections(int32 LODIndex, TArray<FSectionInfo>& InOutSectionInfo) const
{
FMeshMergeHelpers::ExtractSections(StaticMeshComponent, LODIndex, InOutSectionInfo);
}
int32 FStaticMeshComponentAdapter::GetMaterialIndex(int32 LODIndex, int32 SectionIndex) const
{
return StaticMesh->GetSectionInfoMap().Get(LODIndex, SectionIndex).MaterialIndex;
}
void FStaticMeshComponentAdapter::ApplySettings(int32 LODIndex, FMeshData& InOutMeshData) const
{
if (StaticMeshComponent->LODData.IsValidIndex(LODIndex))
{
// Retrieve lightmap reference from the static mesh component (if it exists)
const FStaticMeshComponentLODInfo& ComponentLODInfo = StaticMeshComponent->LODData[LODIndex];
const FMeshMapBuildData* MeshMapBuildData = StaticMeshComponent->GetMeshMapBuildData(ComponentLODInfo);
if (MeshMapBuildData)
{
InOutMeshData.LightMap = MeshMapBuildData->LightMap;
InOutMeshData.LightMapIndex = StaticMeshComponent->GetStaticMesh()->LightMapCoordinateIndex;
InOutMeshData.LightmapResourceCluster = MeshMapBuildData->ResourceCluster;
}
}
}
UPackage* FStaticMeshComponentAdapter::GetOuter() const
{
return nullptr;
}
FString FStaticMeshComponentAdapter::GetBaseName() const
{
return StaticMesh->GetOutermost()->GetName();
}
void FStaticMeshComponentAdapter::SetMaterial(int32 MaterialIndex, UMaterialInterface* Material)
{
StaticMeshComponent->SetMaterial(MaterialIndex, Material);
}
void FStaticMeshComponentAdapter::RemapMaterialIndex(int32 LODIndex, int32 SectionIndex, int32 NewMaterialIndex)
{
}
int32 FStaticMeshComponentAdapter::AddMaterial(UMaterialInterface* Material)
{
return INDEX_NONE;
}
void FStaticMeshComponentAdapter::UpdateUVChannelData()
{
StaticMesh->UpdateUVChannelData(false);
}
bool FStaticMeshComponentAdapter::IsAsset() const
{
return false;
}
int32 FStaticMeshComponentAdapter::LightmapUVIndex() const
{
return StaticMesh->LightMapCoordinateIndex;
}
FBoxSphereBounds FStaticMeshComponentAdapter::GetBounds() const
{
return StaticMeshComponent->Bounds;
}