Skip to content

Commit

Permalink
Refactor scene setup code into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
csciguy8 committed Sep 1, 2023
1 parent b9f594f commit 9c9ef24
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 179 deletions.
192 changes: 13 additions & 179 deletions Source/CesiumRuntime/Private/Tests/CesiumLoadTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@
#include "Tests/AutomationCommon.h"
#include "Tests/AutomationEditorCommon.h"

#include "Editor.h"
#include "Engine/World.h"
#include "EngineUtils.h"
#include "GameFramework/PlayerStart.h"

#include "Cesium3DTileset.h"
#include "CesiumCameraManager.h"
#include "CesiumGeoreference.h"
#include "CesiumTestHelpers.h"
#include "CesiumSceneGeneration.h"
#include "CesiumGltfComponent.h"
#include "CesiumIonRasterOverlay.h"
#include "CesiumRuntime.h"
#include "CesiumSunSky.h"
#include "CesiumTestHelpers.h"
#include "GlobeAwareDefaultPawn.h"

FString testIonToken(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3NjU3OGE4Zi0xOGM4LTQ4NjYtODc4ZS02YWNkMDZmY2Y1M2YiLCJpZCI6MjU5LCJpYXQiOjE2OTA4Nzg3MjB9.uxePYJL59S4pG5aqJHb9goikVSO-Px6xA7kZH8oM1eM");
using namespace Cesium;

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
FCesiumLoadTestDenver,
Expand All @@ -39,40 +29,9 @@ IMPLEMENT_SIMPLE_AUTOMATION_TEST(
"Cesium.Performance.LoadTestMontrealPointCloud",
EAutomationTestFlags::EditorContext | EAutomationTestFlags::PerfFilter)

struct LoadTestContext {
UWorld* world;
ACesiumGeoreference* georeference;
ACesiumCameraManager* cameraManager;
AGlobeAwareDefaultPawn* pawn;
std::vector<ACesium3DTileset*> tilesets;
FRequestPlaySessionParams playSessionParams;

void setCamera(const FCesiumCamera& camera) {
// Take over first camera, or add if it doesn't exist
const TMap<int32, FCesiumCamera> cameras = cameraManager->GetCameras();
if (cameras.IsEmpty()) {
cameraManager->AddCamera(camera);
} else {
cameraManager->UpdateCamera(0, camera);
}
}

void refreshTilesets() {
std::vector<ACesium3DTileset*>::iterator it;
for (it = tilesets.begin(); it != tilesets.end(); ++it)
(*it)->RefreshTileset();
}

void setSuspendUpdate(bool suspend) {
std::vector<ACesium3DTileset*>::iterator it;
for (it = tilesets.begin(); it != tilesets.end(); ++it)
(*it)->SuspendUpdate = suspend;
}
};

bool neverBreak(LoadTestContext& context) { return false; }
bool neverBreak(SceneGenerationContext& context) { return false; }

bool breakWhenTilesetsLoaded(LoadTestContext& context) {
bool breakWhenTilesetsLoaded(SceneGenerationContext& context) {
std::vector<ACesium3DTileset*>::const_iterator it;
for (it = context.tilesets.begin(); it != context.tilesets.end(); ++it) {
ACesium3DTileset* tileset = *it;
Expand All @@ -85,9 +44,9 @@ bool breakWhenTilesetsLoaded(LoadTestContext& context) {
}

bool tickWorldUntil(
LoadTestContext& context,
SceneGenerationContext& context,
size_t timeoutSecs,
std::function<bool(LoadTestContext&)> breakFunction) {
std::function<bool(SceneGenerationContext&)> breakFunction) {
const double minStepTime = 0.050; // Don't loop faster than 20 fps

const double testStartMark = FPlatformTime::Seconds();
Expand Down Expand Up @@ -137,114 +96,16 @@ bool tickWorldUntil(
};
}

void setupForGoogleTiles(LoadTestContext& context) {

FVector targetOrigin(-122.083969, 37.424492, 142.859116);
FString targetUrl(
"https://tile.googleapis.com/v1/3dtiles/root.json?key=AIzaSyCnRPXWDIj1LuX6OWIweIqZFHHoXVgdYss");

FCesiumCamera camera;
camera.ViewportSize = FVector2D(1024, 768);
camera.Location = FVector(0, 0, 0);
camera.Rotation = FRotator(-25, 95, 0);
camera.FieldOfViewDegrees = 90;
context.setCamera(camera);

context.georeference->SetGeoreferenceOriginLongitudeLatitudeHeight(
targetOrigin);

context.pawn->SetActorLocation(FVector(0, 0, 0));
context.pawn->SetActorRotation(FRotator(-25, 95, 0));

ACesium3DTileset* tileset = context.world->SpawnActor<ACesium3DTileset>();
tileset->SetUrl(targetUrl);
tileset->SetTilesetSource(ETilesetSource::FromUrl);
tileset->SetActorLabel(TEXT("Google Photorealistic 3D Tiles"));

context.tilesets.push_back(tileset);
}

void setupForDenver(LoadTestContext& context) {

FVector targetOrigin(-104.988892, 39.743462, 1798.679443);

FCesiumCamera camera;
camera.ViewportSize = FVector2D(1024, 768);
camera.Location = FVector(0, 0, 0);
camera.Rotation = FRotator(-5.2, -149.4, 0);
camera.FieldOfViewDegrees = 90;
context.setCamera(camera);

context.georeference->SetGeoreferenceOriginLongitudeLatitudeHeight(
targetOrigin);

context.pawn->SetActorLocation(FVector(0, 0, 0));
context.pawn->SetActorRotation(FRotator(-5.2, -149.4, 0));

// Add Cesium World Terrain
ACesium3DTileset* worldTerrainTileset =
context.world->SpawnActor<ACesium3DTileset>();
worldTerrainTileset->SetTilesetSource(ETilesetSource::FromCesiumIon);
worldTerrainTileset->SetIonAssetID(1);
worldTerrainTileset->SetIonAccessToken(testIonToken);
worldTerrainTileset->SetActorLabel(TEXT("Cesium World Terrain"));

// Bing Maps Aerial overlay
UCesiumIonRasterOverlay* pOverlay = NewObject<UCesiumIonRasterOverlay>(
worldTerrainTileset,
FName("Bing Maps Aerial"),
RF_Transactional);
pOverlay->MaterialLayerKey = TEXT("Overlay0");
pOverlay->IonAssetID = 2;
pOverlay->SetActive(true);
pOverlay->OnComponentCreated();
worldTerrainTileset->AddInstanceComponent(pOverlay);

// Aerometrex Denver
ACesium3DTileset* aerometrexTileset =
context.world->SpawnActor<ACesium3DTileset>();
aerometrexTileset->SetTilesetSource(ETilesetSource::FromCesiumIon);
aerometrexTileset->SetIonAssetID(354307);
aerometrexTileset->SetIonAccessToken(testIonToken);
aerometrexTileset->SetMaximumScreenSpaceError(2.0);
aerometrexTileset->SetActorLabel(TEXT("Aerometrex Denver"));

context.tilesets.push_back(worldTerrainTileset);
context.tilesets.push_back(aerometrexTileset);
}

void createCommonWorldObjects(LoadTestContext& context) {

context.world = FAutomationEditorCommonUtils::CreateNewMap();

ACesiumSunSky* sunSky = context.world->SpawnActor<ACesiumSunSky>();
APlayerStart* playerStart = context.world->SpawnActor<APlayerStart>();

context.cameraManager =
ACesiumCameraManager::GetDefaultCameraManager(context.world);

FSoftObjectPath objectPath(
TEXT("Class'/CesiumForUnreal/DynamicPawn.DynamicPawn_C'"));
TSoftObjectPtr<UObject> DynamicPawn = TSoftObjectPtr<UObject>(objectPath);

context.georeference =
ACesiumGeoreference::GetDefaultGeoreference(context.world);
context.pawn = context.world->SpawnActor<AGlobeAwareDefaultPawn>(
Cast<UClass>(DynamicPawn.LoadSynchronous()));

context.pawn->AutoPossessPlayer = EAutoReceiveInput::Player0;
}

bool RunLoadTest(
std::function<void(LoadTestContext&)> locationSetup,
std::function<void(LoadTestContext&)> afterTest = {}) {
std::function<void(SceneGenerationContext&)> locationSetup,
std::function<void(SceneGenerationContext&)> afterTest = {}) {

//
// Programmatically set up the world
//
UE_LOG(LogCesium, Display, TEXT("Creating world objects..."));
LoadTestContext context;
createCommonWorldObjects(context);
Cesium::SceneGenerationContext context;
Cesium::createCommonWorldObjects(context);

// Configure location specific objects
locationSetup(context);
Expand Down Expand Up @@ -321,35 +182,8 @@ bool FCesiumLoadTestGoogleplex::RunTest(const FString& Parameters) {
}

bool FCesiumLoadTestMontrealPointCloud::RunTest(const FString& Parameters) {
auto setup = [this](LoadTestContext& context) {
FVector targetOrigin(-73.616526, 45.57335, 95.048859);

FCesiumCamera camera;
camera.ViewportSize = FVector2D(1024, 768);
camera.Location = FVector(0, 0, 0);
camera.Rotation = FRotator(-90.0, 0.0, 0.0);
camera.FieldOfViewDegrees = 90;
context.setCamera(camera);

context.georeference->SetGeoreferenceOriginLongitudeLatitudeHeight(
targetOrigin);

context.pawn->SetActorLocation(FVector(0, 0, 0));
context.pawn->SetActorRotation(FRotator(-90.0, 0.0, 0.0));

// Montreal Point Cloud
ACesium3DTileset* montrealTileset =
context.world->SpawnActor<ACesium3DTileset>();
montrealTileset->SetTilesetSource(ETilesetSource::FromCesiumIon);
montrealTileset->SetIonAssetID(28945);
montrealTileset->SetIonAccessToken(testIonToken);
montrealTileset->SetMaximumScreenSpaceError(16.0);
montrealTileset->SetActorLabel(TEXT("Montreal Point Cloud"));

context.tilesets.push_back(montrealTileset);
};

auto after = [this](LoadTestContext& context) {
auto after = [this](SceneGenerationContext& context) {
// Zoom way out
FCesiumCamera zoomedOut;
zoomedOut.ViewportSize = FVector2D(1024, 768);
Expand Down Expand Up @@ -389,7 +223,7 @@ bool FCesiumLoadTestMontrealPointCloud::RunTest(const FString& Parameters) {
}
};

return RunLoadTest(setup, after);
return RunLoadTest(setupForMelbourne, after);
}

#endif
Loading

0 comments on commit 9c9ef24

Please sign in to comment.