// Copyright 2020 Phyronnaz #pragma once #include "CoreMinimal.h" #include "VoxelEnums.h" #include "Engine/EngineTypes.h" #include "VoxelGenerators/VoxelGenerator.h" #include "VoxelHeightmapAsset.generated.h" class UTexture2D; template struct TVoxelHeightmapAssetData; template class TVoxelHeightmapAssetInstance; UENUM() enum class EVoxelHeightmapImporterMaterialConfig : uint8 { RGB, FourWayBlend, FiveWayBlend, SingleIndex, MultiIndex }; /** * Asset that holds 2D information. */ UCLASS(Abstract, BlueprintType) class VOXEL_API UVoxelHeightmapAsset : public UVoxelTransformableGeneratorWithBounds { GENERATED_BODY() public: // XY Scale of the heightmap UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Heightmap Asset Settings", meta = (ClampMin = 0, DisplayName = "XY Scale")) float Scale = 1; // Height multiplier UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Heightmap Asset Settings", DisplayName = "Z Scale") float HeightScale = 1; // In voxels, applied after Z Scale UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Heightmap Asset Settings") float HeightOffset = 0; // If false, will have meshes on the sides. If true, will extend infinitely. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Heightmap Generator Settings") bool bInfiniteExtent = false; // Additional thickness in voxels below the heightmap UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Heightmap Generator Settings", meta = (EditCondition = "!bInfiniteExtent")) float AdditionalThickness = 0; // Higher precision can improve render quality, but voxel values are lower (hardness not constant) // Set this to the max delta height you can have between 2 adjacent pixels, in voxels // Need to be increased if the shadows/normals aren't nice, and decreased if the edit speed isn't coherent UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Heightmap Generator Settings", meta = (ClampMin = 1)) float Precision = 4; UFUNCTION(BlueprintCallable, Category = "Voxel|Heightmap Asset") int32 GetWidth() const { return Width; } UFUNCTION(BlueprintCallable, Category = "Voxel|Heightmap Asset") int32 GetHeight() const { return Height; } protected: template void TryLoad(TVoxelHeightmapAssetData& Data); template void SaveData(const TVoxelHeightmapAssetData& Data); template void LoadData(TVoxelHeightmapAssetData& Data); template void SyncProperties(const TVoxelHeightmapAssetData& Data); template FVoxelIntBox GetBoundsImpl() const; protected: virtual void Serialize(FArchive& Ar) override; private: UPROPERTY(VisibleAnywhere, Category = "Heightmap Info") int32 Width; UPROPERTY(VisibleAnywhere, Category = "Heightmap Info") int32 Height; UPROPERTY() int32 VoxelCustomVersion; UPROPERTY() uint32 MaterialConfigFlag; TArray CompressedData; private: #if WITH_EDITORONLY_DATA UPROPERTY(NonTransactional) TArray ThumbnailSave; UPROPERTY(Transient) TObjectPtr ThumbnailTexture; #endif #if WITH_EDITOR protected: template UTexture2D* GetThumbnailInternal(); public: UTexture2D* GetThumbnail(); #endif }; UCLASS(HideDropdown) class VOXEL_API UVoxelHeightmapAssetFloat : public UVoxelHeightmapAsset { GENERATED_BODY() public: UVoxelHeightmapAssetFloat(); TVoxelHeightmapAssetData& GetData(); TVoxelSharedRef> GetDataSharedPtr(); void Save(); TVoxelSharedRef> GetInstanceImpl(); //~ Begin UVoxelGenerator Interface virtual TVoxelSharedRef GetInstance() override; virtual TVoxelSharedRef GetTransformableInstance() override; virtual FVoxelIntBox GetBounds() const override; //~ End UVoxelGenerator Interface private: TVoxelSharedPtr> Data; }; USTRUCT() struct FVoxelHeightmapImporterWeightmapInfos { GENERATED_BODY() // The weightmap UPROPERTY(EditAnywhere, Category = "Voxel") FFilePath File; UPROPERTY(EditAnywhere, Category = "Voxel") EVoxelRGBA Layer = EVoxelRGBA::R; UPROPERTY(EditAnywhere, Category = "Voxel") uint8 Index = 0; }; UCLASS(HideDropdown) class VOXEL_API UVoxelHeightmapAssetUINT16 : public UVoxelHeightmapAsset { GENERATED_BODY() public: UPROPERTY(VisibleAnywhere, Category = "Import configuration") FString Heightmap; UPROPERTY(VisibleAnywhere, Category = "Import configuration") EVoxelHeightmapImporterMaterialConfig MaterialConfig; UPROPERTY(VisibleAnywhere, Category = "Import configuration") TArray Weightmaps; UPROPERTY() TArray WeightmapsInfos; public: UVoxelHeightmapAssetUINT16(); TVoxelHeightmapAssetData& GetData(); TVoxelSharedRef> GetDataSharedPtr(); void Save(); TVoxelSharedRef> GetInstanceImpl(); //~ Begin UVoxelGenerator Interface virtual TVoxelSharedRef GetInstance() override; virtual TVoxelSharedRef GetTransformableInstance() override; virtual FVoxelIntBox GetBounds() const override; //~ End UVoxelGenerator Interface private: TVoxelSharedPtr> Data; };