Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Source/CesiumEditor/CesiumEditor.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ public CesiumEditor(ReadOnlyTargetRules Target) : base(Target)
}
);

#if UE_5_7_OR_LATER
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
#else
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_2;
#endif
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
CppStandard = CppStandardVersion.Cpp20;
}
Expand Down
10 changes: 8 additions & 2 deletions Source/CesiumRuntime/CesiumRuntime.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public CesiumRuntime(ReadOnlyTargetRules Target) : base(Target)
"Json",
"JsonUtilities",
"Slate",
"SlateCore"
"SlateCore",
"ChaosCore"
}
);

Expand Down Expand Up @@ -156,8 +157,13 @@ public CesiumRuntime(ReadOnlyTargetRules Target) : base(Target)
}
);

ShadowVariableWarningLevel = WarningLevel.Off;
#if UE_5_7_OR_LATER
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
CppCompileWarningSettings.ShadowVariableWarningLevel = WarningLevel.Off;
#else
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_4;
ShadowVariableWarningLevel = WarningLevel.Off;
#endif
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

CppStandard = CppStandardVersion.Cpp20;
Expand Down
29 changes: 29 additions & 0 deletions Source/CesiumRuntime/Private/CesiumCompat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "CesiumCompat.h"
#include "CesiumCommon.h"

FSceneInterfaceWrapper::FSceneInterfaceWrapper(
FSceneInterface* InSceneInterface) {
#if ENGINE_VERSION_5_7_OR_HIGHER
this->ShaderPlatform = InSceneInterface->GetShaderPlatform();
#endif
this->RHIFeatureLevelType = InSceneInterface->GetFeatureLevel();
}

FMaterialRelevance FSceneInterfaceWrapper::GetMaterialRelevance(
UMeshComponent* InMeshComponent) const {
#if ENGINE_VERSION_5_7_OR_HIGHER
return InMeshComponent->GetMaterialRelevance(this->ShaderPlatform);
#else
return InMeshComponent->GetMaterialRelevance(this->RHIFeatureLevelType);
#endif
}

void ALevelInstance_SetDesiredRuntimeBehavior(
ALevelInstance* Instance,
ELevelInstanceRuntimeBehavior RuntimeBehavior) {
#if WITH_EDITORONLY_DATA && ENGINE_VERSION_5_6_OR_HIGHER
Instance->SetDesiredRuntimeBehavior(RuntimeBehavior);
#elif WITH_EDITORONLY_DATA
Instance->DesiredRuntimeBehavior = RuntimeBehavior;
#endif
}
36 changes: 36 additions & 0 deletions Source/CesiumRuntime/Private/CesiumCompat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2020 - 2025 CesiumGS, Inc.and Contributors

#pragma once

#include "CesiumCommon.h"
#include "Components/MeshComponent.h"
#include "LevelInstance/LevelInstanceActor.h"
#include "RHIFeatureLevel.h"
#include "RHIShaderPlatform.h"
#include "SceneInterface.h"

/**
* Wrapper around FSceneInterface to deal with the switch to EShaderPlatform in
* Unreal 5.7.
*/
struct FSceneInterfaceWrapper {
FSceneInterfaceWrapper(FSceneInterface* SceneInterface);

FMaterialRelevance
GetMaterialRelevance(UMeshComponent* InMeshComponent) const;

ERHIFeatureLevel::Type RHIFeatureLevelType;

#if ENGINE_VERSION_5_7_OR_HIGHER
private:
EShaderPlatform ShaderPlatform;
#endif
};

/**
* Compatibility fix for the DesiredRuntimeBehavior -> SetDesiredRuntimeBehavior
* change in Unreal 5.7.
*/
void ALevelInstance_SetDesiredRuntimeBehavior(
ALevelInstance* Instance,
ELevelInstanceRuntimeBehavior RuntimeBehavior);
6 changes: 4 additions & 2 deletions Source/CesiumRuntime/Private/CesiumGeoreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Cesium3DTileset.h"
#include "CesiumActors.h"
#include "CesiumCommon.h"
#include "CesiumCompat.h"
#include "CesiumCustomVersion.h"
#include "CesiumGeospatial/Cartographic.h"
#include "CesiumGlobeAnchorComponent.h"
Expand Down Expand Up @@ -781,8 +782,9 @@ void ACesiumGeoreference::_createSubLevelsFromWorldComposition() {
FRotator::ZeroRotator,
spawnParameters);
pLevelInstance->SetIsSpatiallyLoaded(false);
pLevelInstance->DesiredRuntimeBehavior =
ELevelInstanceRuntimeBehavior::LevelStreaming;
ALevelInstance_SetDesiredRuntimeBehavior(
pLevelInstance,
ELevelInstanceRuntimeBehavior::LevelStreaming);
pLevelInstance->SetActorLabel(pFound->LevelName);

FString levelPath = level.PackageName.ToString() + "." +
Expand Down
5 changes: 3 additions & 2 deletions Source/CesiumRuntime/Private/CesiumGltfComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CesiumTransforms.h"
#include "Chaos/AABBTree.h"
#include "Chaos/CollisionConvexMesh.h"
#include "Chaos/Core.h"
#include "Chaos/TriangleMeshImplicitObject.h"
#include "CreateGltfOptions.h"
#include "EncodedFeaturesMetadata.h"
Expand Down Expand Up @@ -3259,7 +3260,7 @@ static void loadPrimitiveGameThreadPart(
NAME_None,
RF_Transactional);
pBaseAsMaterialInstance->AddAssetUserData(pCesiumData);
pCesiumData->PostEditChangeOwner();
pCesiumData->UpdateLayerNames();
}
}
#endif
Expand Down Expand Up @@ -3853,7 +3854,7 @@ static Chaos::FTriangleMeshImplicitObjectPtr BuildChaosTriangleMeshes(
Chaos::TParticles<Chaos::FRealSingle, 3> vertices;
vertices.AddParticles(vertexCount);
for (uint32 i = 0; i < vertexCount; ++i) {
vertices.X(int32(i)) = positionBuffer.VertexPosition(i);
vertices.SetX(int32(i), positionBuffer.VertexPosition(i));
}

int32 triangleCount = indices.Num() / 3;
Expand Down
4 changes: 3 additions & 1 deletion Source/CesiumRuntime/Private/CesiumGltfLinesComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ FPrimitiveSceneProxy* UCesiumGltfLinesComponent::CreateSceneProxy() {
return nullptr;
}

return new FCesiumGltfLinesSceneProxy(this, GetScene()->GetFeatureLevel());
return new FCesiumGltfLinesSceneProxy(
this,
FSceneInterfaceWrapper(GetScene()));
}
5 changes: 3 additions & 2 deletions Source/CesiumRuntime/Private/CesiumGltfLinesSceneProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ SIZE_T FCesiumGltfLinesSceneProxy::GetTypeHash() const {

FCesiumGltfLinesSceneProxy::FCesiumGltfLinesSceneProxy(
UCesiumGltfLinesComponent* InComponent,
ERHIFeatureLevel::Type InFeatureLevel)
FSceneInterfaceWrapper InSceneInterfaceParams)
: FPrimitiveSceneProxy(InComponent),
RenderData(InComponent->GetStaticMesh()->GetRenderData()),
NumLines(RenderData->LODResources[0].IndexBuffer.GetNumIndices() / 2),
Material(InComponent->GetMaterial(0)),
MaterialRelevance(InComponent->GetMaterialRelevance(InFeatureLevel)) {}
MaterialRelevance(
InSceneInterfaceParams.GetMaterialRelevance(InComponent)) {}

FCesiumGltfLinesSceneProxy::~FCesiumGltfLinesSceneProxy() {}

Expand Down
3 changes: 2 additions & 1 deletion Source/CesiumRuntime/Private/CesiumGltfLinesSceneProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once

#include "CesiumCompat.h"
#include "PrimitiveSceneProxy.h"

class UCesiumGltfLinesComponent;
Expand All @@ -17,7 +18,7 @@ class FCesiumGltfLinesSceneProxy final : public FPrimitiveSceneProxy {

FCesiumGltfLinesSceneProxy(
UCesiumGltfLinesComponent* InComponent,
ERHIFeatureLevel::Type InFeatureLevel);
FSceneInterfaceWrapper InSceneInterfaceParams);

virtual ~FCesiumGltfLinesSceneProxy();

Expand Down
3 changes: 2 additions & 1 deletion Source/CesiumRuntime/Private/CesiumGltfPointsComponent.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020-2024 CesiumGS, Inc. and Contributors

#include "CesiumGltfPointsComponent.h"
#include "CesiumCompat.h"
#include "CesiumGltfPointsSceneProxy.h"
#include "SceneInterface.h"

Expand All @@ -18,7 +19,7 @@ FPrimitiveSceneProxy* UCesiumGltfPointsComponent::CreateSceneProxy() {
}

FCesiumGltfPointsSceneProxy* Proxy =
new FCesiumGltfPointsSceneProxy(this, GetScene()->GetFeatureLevel());
new FCesiumGltfPointsSceneProxy(this, FSceneInterfaceWrapper(GetScene()));

FCesiumGltfPointsSceneProxyTilesetData TilesetData;
TilesetData.UpdateFromComponent(this);
Expand Down
7 changes: 4 additions & 3 deletions Source/CesiumRuntime/Private/CesiumGltfPointsSceneProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ SIZE_T FCesiumGltfPointsSceneProxy::GetTypeHash() const {

FCesiumGltfPointsSceneProxy::FCesiumGltfPointsSceneProxy(
UCesiumGltfPointsComponent* InComponent,
ERHIFeatureLevel::Type InFeatureLevel)
FSceneInterfaceWrapper InSceneInterfaceParams)
: FPrimitiveSceneProxy(InComponent),
RenderData(InComponent->GetStaticMesh()->GetRenderData()),
NumPoints(RenderData->LODResources[0].IndexBuffer.GetNumIndices()),
bAttenuationSupported(
RHISupportsManualVertexFetch(GetScene().GetShaderPlatform())),
TilesetData(),
AttenuationVertexFactory(
InFeatureLevel,
InSceneInterfaceParams.RHIFeatureLevelType,
&RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer),
AttenuationIndexBuffer(NumPoints, bAttenuationSupported),
Material(InComponent->GetMaterial(0)),
MaterialRelevance(InComponent->GetMaterialRelevance(InFeatureLevel)) {}
MaterialRelevance(
InSceneInterfaceParams.GetMaterialRelevance(InComponent)) {}

FCesiumGltfPointsSceneProxy::~FCesiumGltfPointsSceneProxy() {}

Expand Down
3 changes: 2 additions & 1 deletion Source/CesiumRuntime/Private/CesiumGltfPointsSceneProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once

#include "CesiumCompat.h"
#include "CesiumPointAttenuationVertexFactory.h"
#include "CesiumPointCloudShading.h"
#include "PrimitiveSceneProxy.h"
Expand Down Expand Up @@ -36,7 +37,7 @@ class FCesiumGltfPointsSceneProxy final : public FPrimitiveSceneProxy {

FCesiumGltfPointsSceneProxy(
UCesiumGltfPointsComponent* InComponent,
ERHIFeatureLevel::Type InFeatureLevel);
FSceneInterfaceWrapper InSceneInterfaceParams);

virtual ~FCesiumGltfPointsSceneProxy();

Expand Down
14 changes: 14 additions & 0 deletions Source/CesiumRuntime/Private/CesiumMaterialUserData.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
// Copyright 2020-2024 CesiumGS, Inc. and Contributors

#include "CesiumMaterialUserData.h"
#include "CesiumCommon.h"
#include "Materials/MaterialInstance.h"
#include "Runtime/Launch/Resources/Version.h"

#if ENGINE_VERSION_5_6_OR_HIGHER
void UCesiumMaterialUserData::PostEditChangeOwner(
const FPropertyChangedEvent& PropertyChangedEvent) {
Super::PostEditChangeOwner(PropertyChangedEvent);

this->UpdateLayerNames();
}
#else
void UCesiumMaterialUserData::PostEditChangeOwner() {
Super::PostEditChangeOwner();

this->UpdateLayerNames();
}
#endif

void UCesiumMaterialUserData::UpdateLayerNames() {
#if WITH_EDITORONLY_DATA
this->LayerNames.Empty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "CesiumPointAttenuationVertexFactory.h"

#include "CesiumCommon.h"
#include "DataDrivenShaderPlatformInfo.h"
#include "MaterialDomain.h"
#include "MeshBatch.h"
Expand All @@ -10,6 +11,29 @@
#include "RenderCommandFence.h"
#include "Runtime/Launch/Resources/Version.h"

namespace {
FBufferRHIRef CreatePointAttenuationBuffer(
FRHICommandListBase& RHICmdList,
const TCHAR* Name,
int32 Size,
int32 Stride,
EBufferUsageFlags Flags) {
#if ENGINE_VERSION_5_6_OR_HIGHER
FRHIBufferCreateDesc CreateDesc(Name, Size, Stride, Flags);
CreateDesc.SetInitialState(ERHIAccess::VertexOrIndexBuffer);
return RHICmdList.CreateBuffer(CreateDesc);
#else
FRHIResourceCreateInfo CreateInfo(Name);
return RHICmdList.CreateBuffer(
Size,
Flags,
Stride,
ERHIAccess::VertexOrIndexBuffer,
CreateInfo);
#endif
}
} // namespace

void FCesiumPointAttenuationIndexBuffer::InitRHI(
FRHICommandListBase& RHICmdList) {
if (!bAttenuationSupported) {
Expand All @@ -19,16 +43,15 @@ void FCesiumPointAttenuationIndexBuffer::InitRHI(
// This must be called from Rendering thread
check(IsInRenderingThread());

FRHIResourceCreateInfo CreateInfo(TEXT("FCesiumPointAttenuationIndexBuffer"));
const uint32 NumIndices = NumPoints * 6;
const uint32 Size = NumIndices * sizeof(uint32);

IndexBufferRHI = RHICmdList.CreateBuffer(
IndexBufferRHI = CreatePointAttenuationBuffer(
RHICmdList,
TEXT("FCesiumPointAttenuationIndexBuffer"),
Size,
BUF_Static | BUF_IndexBuffer,
sizeof(uint32),
ERHIAccess::VertexOrIndexBuffer,
CreateInfo);
BUF_Static | BUF_IndexBuffer);

uint32* Data =
(uint32*)RHICmdList.LockBuffer(IndexBufferRHI, 0, Size, RLM_WriteOnly);
Expand Down Expand Up @@ -125,14 +148,12 @@ class FCesiumPointAttenuationDummyVertexBuffer : public FVertexBuffer {

void FCesiumPointAttenuationDummyVertexBuffer::InitRHI(
FRHICommandListBase& RHICmdList) {
FRHIResourceCreateInfo CreateInfo(
TEXT("FCesiumPointAttenuationDummyVertexBuffer"));
VertexBufferRHI = RHICmdList.CreateBuffer(
VertexBufferRHI = CreatePointAttenuationBuffer(
RHICmdList,
TEXT("FCesiumPointAttenuationDummyVertexBuffer"),
sizeof(FVector3f) * 4,
BUF_Static | BUF_VertexBuffer,
0,
ERHIAccess::VertexOrIndexBuffer,
CreateInfo);
BUF_Static | BUF_VertexBuffer);
FVector3f* DummyContents = (FVector3f*)RHICmdList.LockBuffer(
VertexBufferRHI,
0,
Expand Down
8 changes: 5 additions & 3 deletions Source/CesiumRuntime/Private/CesiumSubLevelComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "CesiumSubLevelComponent.h"
#include "Cesium3DTileset.h"
#include "CesiumActors.h"
#include "CesiumCompat.h"
#include "CesiumGeoreference.h"
#include "CesiumGeospatial/LocalHorizontalCoordinateSystem.h"
#include "CesiumRuntime.h"
Expand Down Expand Up @@ -484,7 +485,7 @@ void UCesiumSubLevelComponent::OnRegister() {

#if WITH_EDITOR
if (pOwner->GetIsSpatiallyLoaded() ||
pOwner->DesiredRuntimeBehavior !=
pOwner->GetDesiredRuntimeBehavior() !=
ELevelInstanceRuntimeBehavior::LevelStreaming) {
pOwner->Modify();

Expand All @@ -498,8 +499,9 @@ void UCesiumSubLevelComponent::OnRegister() {
// (Partitioned), will dump the actors in the sub-level into the main
// level, which will prevent us from being to turn the sub-level on and
// off at runtime.
pOwner->DesiredRuntimeBehavior =
ELevelInstanceRuntimeBehavior::LevelStreaming;
ALevelInstance_SetDesiredRuntimeBehavior(
pOwner,
ELevelInstanceRuntimeBehavior::LevelStreaming);

UE_LOG(
LogCesium,
Expand Down
Loading