2022-11-04 09:18:44 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "MuCO/DefaultImageProvider.h"
|
|
|
|
|
|
2023-01-12 01:48:34 -05:00
|
|
|
#include "MuCO/CustomizableObject.h"
|
2022-11-04 09:18:44 -04:00
|
|
|
|
2023-01-26 05:27:35 -05:00
|
|
|
#include "MuR/Parameters.h"
|
|
|
|
|
|
2022-11-21 18:58:00 -05:00
|
|
|
#include UE_INLINE_GENERATED_CPP_BY_NAME(DefaultImageProvider)
|
|
|
|
|
|
2022-11-04 09:18:44 -04:00
|
|
|
|
|
|
|
|
namespace UDefaultImageProviderCVars
|
|
|
|
|
{
|
|
|
|
|
void CheckImageMode(IConsoleVariable* Var);
|
|
|
|
|
|
|
|
|
|
int32 ImageMode = 3;
|
|
|
|
|
FAutoConsoleVariableRef CVarImageMode(
|
|
|
|
|
TEXT("Mutable.DefaultImageProvider.ImageMode"),
|
|
|
|
|
ImageMode,
|
|
|
|
|
TEXT("0 = None: Texture is not provided by this provider.\n"
|
|
|
|
|
"2 = Unreal: Data will be provided from an unreal texture, loaded in the game thread and kept in memory.\n"
|
|
|
|
|
"3 = Unreal_Deferred (default): Data will be provided from an unreal texture. Will only be loaded when actually needed in the Mutable thread."),
|
|
|
|
|
FConsoleVariableDelegate::CreateStatic(CheckImageMode));
|
|
|
|
|
|
|
|
|
|
void CheckImageMode(IConsoleVariable* Var)
|
|
|
|
|
{
|
|
|
|
|
if ((ImageMode < 0 || ImageMode >= static_cast<int32>(UCustomizableSystemImageProvider::ValueType::Count)) &&
|
|
|
|
|
ImageMode == static_cast<int32>(UCustomizableSystemImageProvider::ValueType::Raw)) // Raw not supported.
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogMutable, Error, TEXT("DefaultImageProvider: Incorrect Image Mode. Setting Texture Mode to \"None\"."));
|
|
|
|
|
ImageMode = static_cast<int32>(UCustomizableSystemImageProvider::ValueType::None);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-07-31 03:24:06 -04:00
|
|
|
UCustomizableSystemImageProvider::ValueType UDefaultImageProvider::HasTextureParameterValue(const FName& ID)
|
2022-11-04 09:18:44 -04:00
|
|
|
{
|
2023-05-19 06:11:26 -04:00
|
|
|
const TObjectPtr<UTexture2D>* Texture = Textures.Find(ID);
|
2023-01-25 11:08:46 -05:00
|
|
|
|
2023-05-19 06:11:26 -04:00
|
|
|
return Texture ?
|
2022-11-04 09:18:44 -04:00
|
|
|
static_cast<ValueType>(UDefaultImageProviderCVars::ImageMode) :
|
|
|
|
|
ValueType::None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-07-31 03:24:06 -04:00
|
|
|
UTexture2D* UDefaultImageProvider::GetTextureParameterValue(const FName& ID)
|
2022-11-04 09:18:44 -04:00
|
|
|
{
|
2023-05-19 06:11:26 -04:00
|
|
|
return Textures[ID];
|
2022-11-04 09:18:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UDefaultImageProvider::GetTextureParameterValues(TArray<FCustomizableObjectExternalTexture>& OutValues)
|
|
|
|
|
{
|
2023-07-31 03:24:06 -04:00
|
|
|
for (TTuple<FName, TObjectPtr<UTexture2D>>& Pair : Textures)
|
2022-11-04 09:18:44 -04:00
|
|
|
{
|
2023-05-19 06:11:26 -04:00
|
|
|
FCustomizableObjectExternalTexture Data;
|
|
|
|
|
Data.Name = Pair.Value.GetName();
|
|
|
|
|
Data.Value = Pair.Key;
|
|
|
|
|
OutValues.Add(Data);
|
2022-11-04 09:18:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-05-19 06:11:26 -04:00
|
|
|
FString UDefaultImageProvider::Add(UTexture2D* Texture)
|
2022-11-04 09:18:44 -04:00
|
|
|
{
|
2023-02-01 04:04:06 -05:00
|
|
|
if (!Texture)
|
|
|
|
|
{
|
2023-07-31 03:24:06 -04:00
|
|
|
return FString();
|
2023-02-01 04:04:06 -05:00
|
|
|
}
|
2022-11-04 09:18:44 -04:00
|
|
|
|
2023-09-07 06:34:12 -04:00
|
|
|
const FName Id(Texture->GetPathName());
|
2023-05-19 06:11:26 -04:00
|
|
|
Textures.Add(Id, Texture);
|
2022-11-04 09:18:44 -04:00
|
|
|
|
2023-07-31 03:24:06 -04:00
|
|
|
return Id.ToString();
|
2022-11-04 09:18:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-05-19 06:11:26 -04:00
|
|
|
void UDefaultImageProvider::Remove(UTexture2D* Texture)
|
2022-11-04 09:18:44 -04:00
|
|
|
{
|
2023-05-19 06:11:26 -04:00
|
|
|
if (!Texture)
|
2022-11-04 09:18:44 -04:00
|
|
|
{
|
2023-05-19 06:11:26 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2023-01-26 05:27:35 -05:00
|
|
|
|
2023-07-31 03:24:06 -04:00
|
|
|
Textures.Remove(FName(Texture->GetFullName()));
|
2022-11-04 09:18:44 -04:00
|
|
|
}
|
|
|
|
|
|