From a2b284ee427d2b19bc604eb5eb37f06fa666b37c Mon Sep 17 00:00:00 2001 From: Ashley Rogers Date: Wed, 22 Jan 2025 15:28:55 -0500 Subject: [PATCH 1/3] Add UpdateTimeZoneFromLongitude to ACesiumSunSky --- CHANGES.md | 2 ++ .../Private/CesiumGeoreference.cpp | 18 ++++++++++++++++++ Source/CesiumRuntime/Private/CesiumSunSky.cpp | 5 +++++ Source/CesiumRuntime/Public/CesiumSunSky.h | 15 +++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 706a1577c..ef575ff9e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,8 @@ ##### Additions :tada: - Added `CesiumUrlTemplateRasterOverlay`, allowing a raster overlay to be added using tiles requested based on a specified URL template. +- Added `UpdateTimeZoneFromLongitude` method to `ACesiumSunSky` to naively update the `ACesiumSunSky`'s `TimeZone` property based on a given longitude. +- The "Place Georeference Origin Here" button on `ACesiumGeoreference` will now update the time zone of any `ACesiumSunSky` instances using that georeference based on the new origin's longitude. ##### Fixes :wrench: diff --git a/Source/CesiumRuntime/Private/CesiumGeoreference.cpp b/Source/CesiumRuntime/Private/CesiumGeoreference.cpp index 19e0f9e9d..0e3dd544e 100644 --- a/Source/CesiumRuntime/Private/CesiumGeoreference.cpp +++ b/Source/CesiumRuntime/Private/CesiumGeoreference.cpp @@ -7,10 +7,12 @@ #include "CesiumCommon.h" #include "CesiumCustomVersion.h" #include "CesiumGeospatial/Cartographic.h" +#include "CesiumGlobeAnchorComponent.h" #include "CesiumOriginShiftComponent.h" #include "CesiumRuntime.h" #include "CesiumSubLevelComponent.h" #include "CesiumSubLevelSwitcherComponent.h" +#include "CesiumSunSky.h" #include "CesiumTransforms.h" #include "CesiumUtility/Math.h" #include "Engine/LevelStreaming.h" @@ -426,6 +428,22 @@ void ACesiumGeoreference::PlaceGeoreferenceOriginHere() { .Rotator()); pEditorViewportClient->SetViewLocation( this->GetActorTransform().TransformPosition(FVector::ZeroVector)); + + const double NewLongitude = this->GetOriginLongitude(); + + // Find all CesiumSunSky instances using this georeference and update their + // time zones based on the new origin. + for (TActorIterator It(pWorld); It; ++It) { + if (!IsValid(It->GlobeAnchor)) { + continue; + } + + ACesiumGeoreference* ResolvedGeoreference = + It->GlobeAnchor->GetResolvedGeoreference(); + if (IsValid(ResolvedGeoreference) && ResolvedGeoreference == this) { + It->UpdateTimeZoneFromLongitude(NewLongitude); + } + } } void ACesiumGeoreference::CreateSubLevelHere() { diff --git a/Source/CesiumRuntime/Private/CesiumSunSky.cpp b/Source/CesiumRuntime/Private/CesiumSunSky.cpp index 4f09410e8..bce385472 100644 --- a/Source/CesiumRuntime/Private/CesiumSunSky.cpp +++ b/Source/CesiumRuntime/Private/CesiumSunSky.cpp @@ -567,6 +567,11 @@ void ACesiumSunSky::UpdateAtmosphereRadius() { } } +void ACesiumSunSky::UpdateTimeZoneFromLongitude(double InLongitude) { + this->TimeZone = FMath::Clamp(InLongitude, -180.0, 180.0) / 15.0; + this->UpdateSun(); +} + void ACesiumSunSky::GetHMSFromSolarTime( double InSolarTime, int32& Hour, diff --git a/Source/CesiumRuntime/Public/CesiumSunSky.h b/Source/CesiumRuntime/Public/CesiumSunSky.h index e49fd6753..0ef61a4cd 100644 --- a/Source/CesiumRuntime/Public/CesiumSunSky.h +++ b/Source/CesiumRuntime/Public/CesiumSunSky.h @@ -444,6 +444,21 @@ class CESIUMRUNTIME_API ACesiumSunSky : public AActor { UFUNCTION(CallInEditor, BlueprintCallable, Category = "Cesium") void UpdateAtmosphereRadius(); + /** + * Updates the time zone of this CesiumSunSky based on the given longitude. + * + * The time zone calculated here is naively based on the longitude, where + * every 15 degrees longitude equals 1 hour. This won't necessarily line up + * with the officially designated time zone at the location given. + * + * This method will call @ref UpdateSun automatically. + * + * @param InLongitude The longitude that the calculated time zone will be + * based on in degrees in the range [-180, 180]. + */ + UFUNCTION(CallInEditor, BlueprintCallable, Category = "Cesium") + void UpdateTimeZoneFromLongitude(double InLongitude); + /** * Convert solar time to Hours:Minutes:Seconds. Copied the implementation * from the engine SunSkyBP class. From 7cec6da45b118bca2a5abd2b85752a62ec39e0ee Mon Sep 17 00:00:00 2001 From: Ashley Rogers Date: Fri, 31 Jan 2025 16:56:25 -0500 Subject: [PATCH 2/3] Update based on review --- CHANGES.md | 4 ++-- Source/CesiumRuntime/Private/CesiumGeoreference.cpp | 8 +++++--- Source/CesiumRuntime/Private/CesiumSunSky.cpp | 2 +- Source/CesiumRuntime/Public/CesiumSunSky.h | 11 ++++++----- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index b7e41352b..11252a216 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,8 +5,8 @@ ##### Additions :tada: - Added `CesiumUrlTemplateRasterOverlay`, allowing a raster overlay to be added using tiles requested based on a specified URL template. -- Added `UpdateTimeZoneFromLongitude` method to `ACesiumSunSky` to naively update the `ACesiumSunSky`'s `TimeZone` property based on a given longitude. -- The "Place Georeference Origin Here" button on `ACesiumGeoreference` will now update the time zone of any `ACesiumSunSky` instances using that georeference based on the new origin's longitude. +- Added `EstimateTimeZoneForLongitude` method to `ACesiumSunSky` to set a reasonable `TimeZone` value at the given longitude. +- The "Place Georeference Origin Here" button on `ACesiumGeoreference` will now adjust the time zone of the `ACesiumSunSky` instances that reference it, based on the new origin's longitude. This improves user experience when moving the origin to locations where it would be nighttime in the current time zone. - Added `RequestHeaders` property to `Cesium3DTileset`, allowing per-tileset headers to be specified. - Added `RequestHeaders` properties to `CesiumTileMapServiceRasterOverlay`, `CesiumUrlTemplateRasterOverlay`, `CesiumWebMapServiceRasterOverlay`, and `CesiumWebMapTileServiceRasterOverlay`, allowing per-raster-overlay HTTP headers to be specified. diff --git a/Source/CesiumRuntime/Private/CesiumGeoreference.cpp b/Source/CesiumRuntime/Private/CesiumGeoreference.cpp index 0e3dd544e..bf374f3d5 100644 --- a/Source/CesiumRuntime/Private/CesiumGeoreference.cpp +++ b/Source/CesiumRuntime/Private/CesiumGeoreference.cpp @@ -431,8 +431,10 @@ void ACesiumGeoreference::PlaceGeoreferenceOriginHere() { const double NewLongitude = this->GetOriginLongitude(); - // Find all CesiumSunSky instances using this georeference and update their - // time zones based on the new origin. + // The georeference origin may have moved to a location across the world + // where it is nighttime in the currently set time zone. To improve user + // experience, we update the timezones of all the CesiumSunSky instances using + // this georeference so that the view is not completely dark. for (TActorIterator It(pWorld); It; ++It) { if (!IsValid(It->GlobeAnchor)) { continue; @@ -441,7 +443,7 @@ void ACesiumGeoreference::PlaceGeoreferenceOriginHere() { ACesiumGeoreference* ResolvedGeoreference = It->GlobeAnchor->GetResolvedGeoreference(); if (IsValid(ResolvedGeoreference) && ResolvedGeoreference == this) { - It->UpdateTimeZoneFromLongitude(NewLongitude); + It->EstimateTimeZoneForLongitude(NewLongitude); } } } diff --git a/Source/CesiumRuntime/Private/CesiumSunSky.cpp b/Source/CesiumRuntime/Private/CesiumSunSky.cpp index bce385472..9015652e5 100644 --- a/Source/CesiumRuntime/Private/CesiumSunSky.cpp +++ b/Source/CesiumRuntime/Private/CesiumSunSky.cpp @@ -567,7 +567,7 @@ void ACesiumSunSky::UpdateAtmosphereRadius() { } } -void ACesiumSunSky::UpdateTimeZoneFromLongitude(double InLongitude) { +void ACesiumSunSky::EstimateTimeZoneForLongitude(double InLongitude) { this->TimeZone = FMath::Clamp(InLongitude, -180.0, 180.0) / 15.0; this->UpdateSun(); } diff --git a/Source/CesiumRuntime/Public/CesiumSunSky.h b/Source/CesiumRuntime/Public/CesiumSunSky.h index 0ef61a4cd..73aaf43bc 100644 --- a/Source/CesiumRuntime/Public/CesiumSunSky.h +++ b/Source/CesiumRuntime/Public/CesiumSunSky.h @@ -445,11 +445,12 @@ class CESIUMRUNTIME_API ACesiumSunSky : public AActor { void UpdateAtmosphereRadius(); /** - * Updates the time zone of this CesiumSunSky based on the given longitude. + * Adjusts the time zone of this CesiumSunSky to an estimate based on the + * given longitude. * - * The time zone calculated here is naively based on the longitude, where - * every 15 degrees longitude equals 1 hour. This won't necessarily line up - * with the officially designated time zone at the location given. + * The time zone is naively calculated from the longitude, where every + * 15 degrees equals 1 hour. This may not necessarily match the official + * time zone at a given location within that longitude. * * This method will call @ref UpdateSun automatically. * @@ -457,7 +458,7 @@ class CESIUMRUNTIME_API ACesiumSunSky : public AActor { * based on in degrees in the range [-180, 180]. */ UFUNCTION(CallInEditor, BlueprintCallable, Category = "Cesium") - void UpdateTimeZoneFromLongitude(double InLongitude); + void EstimateTimeZoneForLongitude(double InLongitude); /** * Convert solar time to Hours:Minutes:Seconds. Copied the implementation From acac332c3c7d3d76bc8146927477cc8058cc4ccc Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Sun, 2 Feb 2025 18:44:06 +1100 Subject: [PATCH 3/3] Remove unnecessary file. --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index b1c19b8f3..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "cmake.sourceDirectory": "D:/Dev/cesium-unreal/extern" -} \ No newline at end of file