From 9db4b939a2daef16aa9759ee0e8f15c52796dbd4 Mon Sep 17 00:00:00 2001 From: Brian L <130494071+csciguy8@users.noreply.github.com> Date: Fri, 25 Aug 2023 13:53:37 -0600 Subject: [PATCH] Refactor and add logic to stop reset tilesets before loop start --- .../Private/Tests/CesiumLoadTest.cpp | 96 ++++++++++++------- 1 file changed, 62 insertions(+), 34 deletions(-) diff --git a/Source/CesiumRuntime/Private/Tests/CesiumLoadTest.cpp b/Source/CesiumRuntime/Private/Tests/CesiumLoadTest.cpp index fea3913da..4826252d5 100644 --- a/Source/CesiumRuntime/Private/Tests/CesiumLoadTest.cpp +++ b/Source/CesiumRuntime/Private/Tests/CesiumLoadTest.cpp @@ -62,46 +62,34 @@ void tickWorld(UWorld* world, double time) { }; } -void setupForGoogleTiles(UWorld* world) { - ACesiumCameraManager* cameraManager = - ACesiumCameraManager::GetDefaultCameraManager(world); - ACesiumGeoreference* georeference = - ACesiumGeoreference::GetDefaultGeoreference(world); - ACesiumSunSky* sunSky = world->SpawnActor(); - ACesium3DTileset* tileset = world->SpawnActor(); - APlayerStart* playerStart = world->SpawnActor(); - - FSoftObjectPath objectPath( - TEXT("Class'/CesiumForUnreal/DynamicPawn.DynamicPawn_C'")); - TSoftObjectPtr DynamicPawn = TSoftObjectPtr(objectPath); - AGlobeAwareDefaultPawn* pawn = world->SpawnActor( - Cast(DynamicPawn.LoadSynchronous())); - pawn->AutoPossessPlayer = EAutoReceiveInput::Player0; +void setupForGoogleTiles( + UWorld* world, + ACesiumGeoreference* georeference, + AGlobeAwareDefaultPawn* pawn, + std::vector& createdTilesets) { FVector targetOrigin(-122.083969, 37.424492, 142.859116); FString targetUrl( "https://tile.googleapis.com/v1/3dtiles/root.json?key=AIzaSyCnRPXWDIj1LuX6OWIweIqZFHHoXVgdYss"); georeference->SetGeoreferenceOriginLongitudeLatitudeHeight(targetOrigin); - tileset->SetUrl(targetUrl); - tileset->SetTilesetSource(ETilesetSource::FromUrl); + pawn->SetActorLocation(FVector(0, 0, 0)); pawn->SetActorRotation(FRotator(-25, 95, 0)); + + ACesium3DTileset* tileset = world->SpawnActor(); + tileset->SetUrl(targetUrl); + tileset->SetTilesetSource(ETilesetSource::FromUrl); + tileset->SetActorLabel(TEXT("Google Photorealistic 3D Tiles")); + + createdTilesets.push_back(tileset); } -void setupForDenver(UWorld* world) { - ACesiumCameraManager* cameraManager = - ACesiumCameraManager::GetDefaultCameraManager(world); - ACesiumGeoreference* georeference = - ACesiumGeoreference::GetDefaultGeoreference(world); - ACesiumSunSky* sunSky = world->SpawnActor(); - APlayerStart* playerStart = world->SpawnActor(); - FSoftObjectPath objectPath( - TEXT("Class'/CesiumForUnreal/DynamicPawn.DynamicPawn_C'")); - TSoftObjectPtr DynamicPawn = TSoftObjectPtr(objectPath); - AGlobeAwareDefaultPawn* pawn = world->SpawnActor( - Cast(DynamicPawn.LoadSynchronous())); - pawn->AutoPossessPlayer = EAutoReceiveInput::Player0; +void setupForDenver( + UWorld* world, + ACesiumGeoreference* georeference, + AGlobeAwareDefaultPawn* pawn, + std::vector& createdTilesets) { FVector targetOrigin(-104.988892, 39.743462, 1798.679443); FString ionToken( @@ -137,6 +125,9 @@ void setupForDenver(UWorld* world) { aerometrexTileset->SetIonAccessToken(ionToken); aerometrexTileset->SetMaximumScreenSpaceError(2.0); aerometrexTileset->SetActorLabel(TEXT("Aerometrex Denver")); + + createdTilesets.push_back(worldTerrainTileset); + createdTilesets.push_back(aerometrexTileset); } bool FCesiumLoadTest::RunTest(const FString& Parameters) { @@ -154,11 +145,48 @@ bool FCesiumLoadTest::RunTest(const FString& Parameters) { #endif TestNotNull("world is valid", world); - // Configure similar to Google Tiles sample - // setupForGoogleTiles(world); - setupForDenver(world); + // Create common objects across all locations + ACesiumCameraManager* cameraManager = + ACesiumCameraManager::GetDefaultCameraManager(world); + ACesiumGeoreference* georeference = + ACesiumGeoreference::GetDefaultGeoreference(world); + ACesiumSunSky* sunSky = world->SpawnActor(); + APlayerStart* playerStart = world->SpawnActor(); + + FSoftObjectPath objectPath( + TEXT("Class'/CesiumForUnreal/DynamicPawn.DynamicPawn_C'")); + TSoftObjectPtr DynamicPawn = TSoftObjectPtr(objectPath); + AGlobeAwareDefaultPawn* pawn = world->SpawnActor( + Cast(DynamicPawn.LoadSynchronous())); + pawn->AutoPossessPlayer = EAutoReceiveInput::Player0; - world->BeginPlay(); + // Configure location specific objects + std::vector tilesets; + const size_t locationIndex = 1; + switch (locationIndex) { + case 0: + setupForGoogleTiles(world, georeference, pawn, tilesets); + break; + case 1: + setupForDenver(world, georeference, pawn, tilesets); + break; + default: + break; + } + + // Halt tileset updates and reset them + std::vector::iterator it; + for (it = tilesets.begin(); it != tilesets.end(); ++it) { + ACesium3DTileset* tileset = *it; + tileset->SuspendUpdate = true; + tileset->RefreshTileset(); + } + + // Turn updates back on + for (it = tilesets.begin(); it != tilesets.end(); ++it) { + ACesium3DTileset* tileset = *it; + tileset->SuspendUpdate = false; + } // Spin for 5 seconds, letting our game objects tick const double testMaxTime = 5.0;