// Copyright 2020 Phyronnaz #pragma once #include "CoreMinimal.h" #include "StaticMeshResources.h" #include "PrimitiveSceneProxy.h" #include "VoxelMinimal.h" #if RHI_RAYTRACING #include "RayTracingDefinitions.h" #include "RayTracingInstance.h" #endif class FVoxelToolRenderingManager; class UVoxelProceduralMeshComponent; class FVoxelMaterialInterface; struct FVoxelProcMeshBuffers; DECLARE_VOXEL_MEMORY_STAT(TEXT("Voxel Mesh Distance Field Memory"), STAT_VoxelMeshDistanceFieldMemory, STATGROUP_VoxelMemory, VOXEL_API); class FVoxelProcMeshBuffersRenderData : public TVoxelSharedFromThis { public: const TVoxelSharedRef Buffers; FLocalVertexFactory VertexFactory; #if RHI_RAYTRACING FRayTracingGeometry RayTracingGeometry; #endif static TVoxelSharedRef GetRenderData( const TVoxelSharedRef& Buffers, ERHIFeatureLevel::Type FeatureLevel); ~FVoxelProcMeshBuffersRenderData(); private: explicit FVoxelProcMeshBuffersRenderData( const TVoxelSharedRef& Buffers, ERHIFeatureLevel::Type FeatureLevel); }; struct FVoxelProcMeshProxySection { TVoxelSharedPtr Material; TVoxelSharedPtr Buffers; TVoxelSharedPtr RenderData; bool bSectionVisible = true; bool bRequiresAdjacencyInformation = false; bool bEnableCollisions_Debug = false; bool bEnableNavmesh_Debug = false; }; class FVoxelProceduralMeshSceneProxy : public FPrimitiveSceneProxy { public: explicit FVoxelProceduralMeshSceneProxy(UVoxelProceduralMeshComponent* Component); ~FVoxelProceduralMeshSceneProxy(); //~ Begin FPrimitiveSceneProxy Interface virtual void CreateRenderThreadResources() override; virtual void DestroyRenderThreadResources() override; virtual void GetDynamicMeshElements(const TArray& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const override; #if RHI_RAYTRACING virtual bool IsRayTracingRelevant() const override { return true; } virtual void GetDynamicRayTracingInstances(FRayTracingMaterialGatheringContext& Context, TArray& OutRayTracingInstances) override; #endif virtual FPrimitiveViewRelevance GetViewRelevance(const FSceneView* View) const override; virtual bool CanBeOccluded() const override; virtual uint32 GetMemoryFootprint() const override; virtual SIZE_T GetTypeHash() const override; uint32 GetAllocatedSize() const; //~ End FPrimitiveSceneProxy Interface private: UVoxelProceduralMeshComponent* const Component; const FMaterialRelevance MaterialRelevance; const int32 LOD; const uint32 DebugChunkId; const TVoxelWeakPtr WeakToolRenderingManager; const FCollisionResponseContainer CollisionResponse; const ECollisionTraceFlag CollisionTraceFlag; TArray Sections; TVoxelSharedPtr DistanceFieldData; double FinishSectionsUpdatesTime = 0; double CreateSceneProxyTime = 0; mutable bool bLoggedTime = false; FMeshBatch& DrawSection( FMeshElementCollector& Collector, const FVoxelProcMeshProxySection& Section, const FMaterialRenderProxy* MaterialRenderProxy, bool bEnableTessellation, bool bWireframe) const; bool ShouldDrawComplexCollisions(const FEngineShowFlags& EngineShowFlags) const; };