Files
UnrealEngineUWP/Engine/Source/Developer/MeshMergeUtilities/Private/StaticMeshComponentAdapter.cpp
marcus wassmer b259f65406 Copying //UE4/Dev-Rendering[at]4854522 to Dev-Main (//UE4/Dev-Main)
#rb none

#ROBOMERGE-OWNER: ryan.vance
#ROBOMERGE-AUTHOR: marcus.wassmer
#ROBOMERGE-SOURCE: CL 4854553 in //UE4/Main/...
#ROBOMERGE-BOT: DEVVR (Main -> Dev-VR)

[CL 4854570 by marcus wassmer in Dev-VR branch]
2019-01-30 21:24:04 -05: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->SectionInfoMap.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;
}