// Copyright 2020-2024 CesiumGS, Inc. and Contributors #include "CesiumGltfLinesSceneProxy.h" #include "CesiumGltfLinesComponent.h" #include "DataDrivenShaderPlatformInfo.h" #include "Engine/StaticMesh.h" #include "RHIResources.h" #include "Runtime/Launch/Resources/Version.h" #include "SceneInterface.h" #include "SceneView.h" SIZE_T FCesiumGltfLinesSceneProxy::GetTypeHash() const { static size_t UniquePointer; return reinterpret_cast(&UniquePointer); } FCesiumGltfLinesSceneProxy::FCesiumGltfLinesSceneProxy( UCesiumGltfLinesComponent* InComponent, FSceneInterfaceWrapper InSceneInterfaceParams) : FPrimitiveSceneProxy(InComponent), RenderData(InComponent->GetStaticMesh()->GetRenderData()), NumLines(RenderData->LODResources[0].IndexBuffer.GetNumIndices() / 2), Material(InComponent->GetMaterial(0)), MaterialRelevance( InSceneInterfaceParams.GetMaterialRelevance(InComponent)) {} FCesiumGltfLinesSceneProxy::~FCesiumGltfLinesSceneProxy() {} void FCesiumGltfLinesSceneProxy::DrawStaticElements( FStaticPrimitiveDrawInterface* PDI) { if (!HasViewDependentDPG()) { FMeshBatch Mesh; CreateMesh(Mesh); PDI->DrawMesh(Mesh, FLT_MAX); } } void FCesiumGltfLinesSceneProxy::GetDynamicMeshElements( const TArray& Views, const FSceneViewFamily& ViewFamily, uint32 VisibilityMap, FMeshElementCollector& Collector) const { QUICK_SCOPE_CYCLE_COUNTER(STAT_GltfLinesSceneProxy_GetDynamicMeshElements); for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++) { if (VisibilityMap & (1 << ViewIndex)) { const FSceneView* View = Views[ViewIndex]; FMeshBatch& Mesh = Collector.AllocateMesh(); CreateMesh(Mesh); Collector.AddMesh(ViewIndex, Mesh); } } } FPrimitiveViewRelevance FCesiumGltfLinesSceneProxy::GetViewRelevance(const FSceneView* View) const { FPrimitiveViewRelevance Result; Result.bDrawRelevance = IsShown(View); if (HasViewDependentDPG()) { Result.bDynamicRelevance = true; } else { Result.bStaticRelevance = true; } Result.bRenderCustomDepth = ShouldRenderCustomDepth(); Result.bRenderInMainPass = ShouldRenderInMainPass(); Result.bRenderInDepthPass = ShouldRenderInDepthPass(); Result.bUsesLightingChannels = GetLightingChannelMask() != GetDefaultLightingChannelMask(); Result.bShadowRelevance = IsShadowCast(View); Result.bVelocityRelevance = IsMovable() & Result.bOpaque & Result.bRenderInMainPass; MaterialRelevance.SetPrimitiveViewRelevance(Result); return Result; } uint32 FCesiumGltfLinesSceneProxy::GetMemoryFootprint(void) const { return (sizeof(*this) + GetAllocatedSize()); } void FCesiumGltfLinesSceneProxy::CreateMesh(FMeshBatch& Mesh) const { Mesh.VertexFactory = &RenderData->LODVertexFactories[0].VertexFactory; Mesh.MaterialRenderProxy = Material->GetRenderProxy(); Mesh.ReverseCulling = IsLocalToWorldDeterminantNegative(); Mesh.Type = PT_LineList; Mesh.DepthPriorityGroup = SDPG_World; Mesh.LODIndex = 0; Mesh.bCanApplyViewModeOverrides = false; Mesh.bUseAsOccluder = false; Mesh.bWireframe = false; FMeshBatchElement& BatchElement = Mesh.Elements[0]; BatchElement.IndexBuffer = &RenderData->LODResources[0].IndexBuffer; BatchElement.NumPrimitives = NumLines; BatchElement.FirstIndex = 0; BatchElement.MinVertexIndex = 0; BatchElement.MaxVertexIndex = BatchElement.NumPrimitives; }