Skip to content

Commit

Permalink
Merge pull request #1590 from CesiumGS/sun-sky-time-zone
Browse files Browse the repository at this point in the history
Add `UpdateTimeZoneFromLongitude` to `ACesiumSunSky`
  • Loading branch information
kring authored Feb 2, 2025
2 parents ff64bb7 + 3d8bc59 commit 43cbb03
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `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.
Expand Down
20 changes: 20 additions & 0 deletions Source/CesiumRuntime/Private/CesiumGeoreference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -426,6 +428,24 @@ void ACesiumGeoreference::PlaceGeoreferenceOriginHere() {
.Rotator());
pEditorViewportClient->SetViewLocation(
this->GetActorTransform().TransformPosition(FVector::ZeroVector));

const double NewLongitude = this->GetOriginLongitude();

// 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<ACesiumSunSky> It(pWorld); It; ++It) {
if (!IsValid(It->GlobeAnchor)) {
continue;
}

ACesiumGeoreference* ResolvedGeoreference =
It->GlobeAnchor->GetResolvedGeoreference();
if (IsValid(ResolvedGeoreference) && ResolvedGeoreference == this) {
It->EstimateTimeZoneForLongitude(NewLongitude);
}
}
}

void ACesiumGeoreference::CreateSubLevelHere() {
Expand Down
5 changes: 5 additions & 0 deletions Source/CesiumRuntime/Private/CesiumSunSky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,11 @@ void ACesiumSunSky::UpdateAtmosphereRadius() {
}
}

void ACesiumSunSky::EstimateTimeZoneForLongitude(double InLongitude) {
this->TimeZone = FMath::Clamp(InLongitude, -180.0, 180.0) / 15.0;
this->UpdateSun();
}

void ACesiumSunSky::GetHMSFromSolarTime(
double InSolarTime,
int32& Hour,
Expand Down
16 changes: 16 additions & 0 deletions Source/CesiumRuntime/Public/CesiumSunSky.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,22 @@ class CESIUMRUNTIME_API ACesiumSunSky : public AActor {
UFUNCTION(CallInEditor, BlueprintCallable, Category = "Cesium")
void UpdateAtmosphereRadius();

/**
* Adjusts the time zone of this CesiumSunSky to an estimate based on the
* given longitude.
*
* 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.
*
* @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 EstimateTimeZoneForLongitude(double InLongitude);

/**
* Convert solar time to Hours:Minutes:Seconds. Copied the implementation
* from the engine SunSkyBP class.
Expand Down

0 comments on commit 43cbb03

Please sign in to comment.