70 lines
2.7 KiB
C++
70 lines
2.7 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "MuCO/UnrealToMutableTextureConversionUtils.h"
|
|
#include "MuR/Image.h"
|
|
#include "MuR/System.h"
|
|
#include "UObject/GCObject.h"
|
|
#include "Containers/Ticker.h"
|
|
#include "Containers/Map.h"
|
|
#include "Containers/Queue.h"
|
|
#include "PixelFormat.h"
|
|
#include "Tasks/Task.h"
|
|
|
|
class UCustomizableObject;
|
|
class UTexture;
|
|
class USkeletalMesh;
|
|
|
|
/** Implementation of a mutable core provider for image parameters that are application-specific. */
|
|
class FUnrealMutableResourceProvider : public TSharedFromThis<FUnrealMutableResourceProvider>, public mu::FExternalResourceProvider, public FGCObject
|
|
{
|
|
|
|
public:
|
|
// mu::ExternalResourceProvider interface
|
|
// Thread: worker
|
|
virtual TTuple<UE::Tasks::FTask, TFunction<void()>> GetImageAsync(UTexture* Texture, uint8 MipmapsToSkip, TFunction<void(TSharedPtr<mu::FImage>)>& ResultCallback) override;
|
|
virtual TTuple<UE::Tasks::FTask, TFunction<void()>> GetReferencedImageAsync(const void* ModelPtr, int32 Id, uint8 MipmapsToSkip, TFunction<void(TSharedPtr<mu::FImage>)>& ResultCallback) override;
|
|
virtual mu::FExtendedImageDesc GetImageDesc(UTexture* Texture) override;
|
|
virtual TTuple<UE::Tasks::FTask, TFunction<void()>> GetMeshAsync(USkeletalMesh* SkeletalMesh, int32 LODIndex, int32 SectionIndex, TFunction<void(TSharedPtr<mu::FMesh>)>& ResultCallback) override;
|
|
|
|
#if WITH_EDITOR
|
|
void CacheRuntimeReferencedImages(const TSharedRef<const mu::FModel>& Model, const TArray<TSoftObjectPtr<UTexture2D>>& RuntimeReferencedTextures);
|
|
#endif
|
|
|
|
// Register and unregister the current CO that we are working on. This is called by internal code when building instances.
|
|
void SetCurrentObject(const TWeakObjectPtr<UCustomizableObject>&);
|
|
|
|
// FGCObject interface
|
|
virtual void AddReferencedObjects(FReferenceCollector& Collector) override;
|
|
virtual FString GetReferencerName() const override
|
|
{
|
|
return TEXT("FUnrealMutableImageProvider");
|
|
}
|
|
|
|
private:
|
|
/** Runtime reference to the CO being updated. It is needed for example for mesh conversion, to access to the bone id map. */
|
|
TWeakObjectPtr<UCustomizableObject> CurrentCustomizableObject;
|
|
|
|
static inline const mu::FImageDesc DUMMY_IMAGE_DESC =
|
|
mu::FImageDesc {mu::FImageSize(32, 32), mu::EImageFormat::RGBA_UByte, 1};
|
|
|
|
/** This will be called if an image Id has been requested by Mutable core but it has not been provided by any provider. */
|
|
static TSharedPtr<mu::FImage> CreateDummy();
|
|
static mu::FExtendedImageDesc CreateDummyDesc();
|
|
|
|
#if WITH_EDITOR
|
|
struct FRuntimeReferencedImages
|
|
{
|
|
TWeakPtr<const mu::FModel> Model;
|
|
TArray<TStrongObjectPtr<UTexture>> Images;
|
|
};
|
|
|
|
TMap<const void*, FRuntimeReferencedImages> RuntimeReferencedImages;
|
|
#endif
|
|
|
|
#if WITH_EDITOR
|
|
FCriticalSection RuntimeReferencedLock;
|
|
#endif
|
|
};
|