CelticCraft/Plugins/VoxelFree/Source/Voxel/Private/VoxelRender/MaterialCollections/VoxelCachedMaterialCollection.cpp

21 lines
684 B
C++
Raw Permalink Normal View History

2023-07-03 16:17:13 +00:00
// Copyright 2020 Phyronnaz
#include "VoxelRender/MaterialCollections/VoxelCachedMaterialCollection.h"
UMaterialInterface* UVoxelCachedMaterialCollection::GetVoxelMaterial(const FVoxelMaterialIndices& Indices, uint64 UniqueIdForErrors) const
{
const FVoxelMaterialIndices Key{ Indices };
TObjectPtr<UMaterialInterface>& Material = CachedMaterials.FindOrAdd(Key);
if (!Material)
{
// Note: if this errors out and return nullptr, we want to call it again next time
Material = GetVoxelMaterial_NotCached(Indices, UniqueIdForErrors);
}
return Material;
}
void UVoxelCachedMaterialCollection::InitializeCollection()
{
// Make sure to apply changes
CachedMaterials.Empty();
}