Skip to content

Commit

Permalink
Force-reload tilesets when changing ellipsoid
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Jun 13, 2024
1 parent a425a7b commit 1859774
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
41 changes: 41 additions & 0 deletions Source/CesiumRuntime/Private/CesiumGeoreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "CesiumGeoreference.h"
#include "Camera/PlayerCameraManager.h"
#include "Cesium3DTileset.h"
#include "CesiumActors.h"
#include "CesiumCommon.h"
#include "CesiumCustomVersion.h"
Expand All @@ -18,6 +19,7 @@
#include "EngineUtils.h"
#include "GameFramework/PlayerController.h"
#include "GeoTransforms.h"
#include "Kismet/GameplayStatics.h"
#include "LevelInstance/LevelInstanceActor.h"
#include "Math/Matrix.h"
#include "Math/RotationTranslationMatrix.h"
Expand Down Expand Up @@ -252,6 +254,11 @@ void ACesiumGeoreference::SetSubLevelCamera(APlayerCameraManager* NewValue) {
this->SubLevelCamera_DEPRECATED = NewValue;
}

void ACesiumGeoreference::SetEllipsoid(UCesiumEllipsoid* NewEllipsoid) {
this->Ellipsoid = NewEllipsoid;
this->ForceReloadTilesets();
}

#if WITH_EDITOR
bool ACesiumGeoreference::GetShowLoadRadii() const {
return this->ShowLoadRadii;
Expand Down Expand Up @@ -680,6 +687,7 @@ void ACesiumGeoreference::PostEditChangeProperty(FPropertyChangedEvent& event) {
CESIUM_POST_EDIT_CHANGE(propertyName, ACesiumGeoreference, OriginLatitude);
CESIUM_POST_EDIT_CHANGE(propertyName, ACesiumGeoreference, OriginHeight);
CESIUM_POST_EDIT_CHANGE(propertyName, ACesiumGeoreference, Scale);
CESIUM_POST_EDIT_CHANGE(propertyName, ACesiumGeoreference, Ellipsoid);
}

namespace {
Expand Down Expand Up @@ -880,6 +888,39 @@ void ACesiumGeoreference::UpdateGeoreference() {
OnGeoreferenceUpdated.Broadcast();
}

void ACesiumGeoreference::ForceReloadTilesets() {
const UWorld* World = GetWorld();
if (!IsValid(World)) {
UE_LOG(
LogCesium,
Warning,
TEXT(
"Couldn't reload tileset because GetWorld() returned invalid ptr"));
return;
}

// Find all tilesets
TArray<AActor*> TilesetActors;
UGameplayStatics::GetAllActorsOfClass(
World,
ACesium3DTileset::StaticClass(),
TilesetActors);

for (AActor* Actor : TilesetActors) {
ACesium3DTileset* Tileset = Cast<ACesium3DTileset>(Actor);
if (!IsValid(Tileset)) {
continue;
}

// We don't need to resolve the georeference if the property isn't already
// set, since LoadTileset won't run without one, and if the tileset hasn't
// run LoadTileset yet we don't need to reload it
if (Tileset->GetGeoreference() == this) {
Tileset->RefreshTileset();
}
}
}

GeoTransforms ACesiumGeoreference::GetGeoTransforms() const noexcept {
// Because GeoTransforms is deprecated, we only lazily update it.
return GeoTransforms(
Expand Down
33 changes: 23 additions & 10 deletions Source/CesiumRuntime/Public/CesiumGeoreference.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,6 @@ class CESIUMRUNTIME_API ACesiumGeoreference : public AActor {
UPROPERTY(BlueprintAssignable, Category = "Cesium")
FGeoreferenceUpdated OnGeoreferenceUpdated;

/**
* Returns a pointer to the UCesiumEllipsoid currently being used by this
* georeference.
*
* If no ellipsoid has been created yet, this method will attempt to create
* one based on the value of {@link EllipsoidPath}.
*/
UFUNCTION(BlueprintCallable, Category = "Cesium")
UCesiumEllipsoid* GetEllipsoid() const;

#pragma region Properties

private:
Expand All @@ -107,6 +97,8 @@ class CESIUMRUNTIME_API ACesiumGeoreference : public AActor {
Category = "Cesium",
EditAnywhere,
BlueprintReadWrite,
BlueprintGetter = GetEllipsoid,
BlueprintSetter = SetEllipsoid,
meta = (AllowPrivateAccess))
UCesiumEllipsoid* Ellipsoid = nullptr;

Expand Down Expand Up @@ -404,6 +396,22 @@ class CESIUMRUNTIME_API ACesiumGeoreference : public AActor {
return this->SubLevelSwitcher;
}

/**
* Returns a pointer to the UCesiumEllipsoid currently being used by this
* georeference.
*/
UFUNCTION(BlueprintCallable, BlueprintGetter, Category = "Cesium")
UCesiumEllipsoid* GetEllipsoid() const;

/**
* Sets the UCesiumEllipsoid used by this georeference.
*
* Calling this will cause all tilesets under this georeference to be
* reloaded.
*/
UFUNCTION(BlueprintSetter, Category = "Cesium")
void SetEllipsoid(UCesiumEllipsoid* NewEllipsoid);

#if WITH_EDITOR
/**
* Gets whether to visualize the level loading radii in the editor. Helpful
Expand Down Expand Up @@ -820,6 +828,11 @@ class CESIUMRUNTIME_API ACesiumGeoreference : public AActor {
*/
void UpdateGeoreference();

/**
* Forces all the tilesets under this georeference to be completely reloaded.
*/
void ForceReloadTilesets();

/**
* A tag that is assigned to Georeferences when they are created
* as the "default" Georeference for a certain world.
Expand Down

0 comments on commit 1859774

Please sign in to comment.