Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom ellipsoids #1432

Merged
merged 28 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0ddf04c
Add Ellipsoid class, remove hardcoded WGS84
azrogers May 24, 2024
b9fe927
Merge branch 'main' of github.com:CesiumGS/cesium-unreal into custom-…
azrogers May 24, 2024
6d109eb
Merge branch 'fix-feature-id' of github.com:CesiumGS/cesium-unreal in…
azrogers May 24, 2024
ff6ec64
Update cesium-native
azrogers May 24, 2024
da9a5b4
Fixes for ellipsoid
azrogers May 24, 2024
fa8798b
More ellipsoid changes
azrogers May 31, 2024
91428e8
Update cesium-native
azrogers Jun 6, 2024
31665c9
Merge branch 'main' of github.com:CesiumGS/cesium-unreal into custom-…
azrogers Jun 6, 2024
a425a7b
Update cesium-native, format
azrogers Jun 11, 2024
1859774
Force-reload tilesets when changing ellipsoid
azrogers Jun 13, 2024
5a32f5c
Update cesium-native
azrogers Jun 13, 2024
696d7fa
Add SetRadii, clang-format
azrogers Jun 14, 2024
734ac9d
Update cesium-native
azrogers Jun 14, 2024
450c09b
Use ResolvedGeoreference, fix tests
azrogers Jun 17, 2024
7d2bc70
Merge branch 'main' of github.com:CesiumGS/cesium-unreal into custom-…
azrogers Jun 17, 2024
c2f8cae
Formatting...
azrogers Jun 17, 2024
5c12906
Add test, fix globe anchor tests
azrogers Jun 17, 2024
1cf8e4b
Hopefully fix test crash in CI
azrogers Jun 17, 2024
0491763
Create WGS84.uasset in 5.2
azrogers Jun 18, 2024
b83e365
Update cesium-native
azrogers Jun 20, 2024
dcd2455
Merge branch 'main' of github.com:CesiumGS/cesium-unreal into custom-…
azrogers Jun 20, 2024
001db81
Review, fix crashes
azrogers Jun 26, 2024
dbffa54
Merge branch 'main' of github.com:CesiumGS/cesium-unreal into custom-…
azrogers Jun 26, 2024
826a20d
Update CHANGES.md
azrogers Jun 26, 2024
d4f0240
Revert package-lock.json
azrogers Jun 26, 2024
3312d38
Remove shared ptr
azrogers Jun 27, 2024
e9b8b55
Update cesium-native
azrogers Jun 27, 2024
27d80a7
Hopefully final review changes
azrogers Jun 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

### ? - ?

##### Additions :tada:
- Cesium for Unreal now supports using non-WGS84 ellipsoids.
- An `UCesiumEllipsoid` asset should be specified on the `Ellipsoid` field of an `ACesiumGeoreference`.
- To create a `UCesiumEllipsoid` asset, right-click in the Content Drawer and select "Data Asset" under "Miscellaneous." Choose "Cesium Ellipsoid" from the menu that appears.

##### Fixes :wrench:

- Removed unnecessary alpha check when selecting translucent base materials.
Expand Down
Binary file added Content/WGS84.uasset
Binary file not shown.
103 changes: 70 additions & 33 deletions Source/CesiumEditor/Private/CesiumGlobeAnchorCustomization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DetailCategoryBuilder.h"
#include "DetailLayoutBuilder.h"
#include "IDetailGroup.h"
#include "Widgets/SToolTip.h"

FName FCesiumGlobeAnchorCustomization::RegisteredLayoutName;

Expand Down Expand Up @@ -201,32 +202,63 @@ void UCesiumGlobeAnchorDerivedProperties::PostEditChangeProperty(
this->GlobeAnchor->Modify();
this->GlobeAnchor->MoveToEarthCenteredEarthFixedPosition(
FVector(this->X, this->Y, this->Z));
} else if (
propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Longitude) ||
propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Latitude) ||
propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Height)) {
this->GlobeAnchor->Modify();
this->GlobeAnchor->MoveToLongitudeLatitudeHeight(
FVector(this->Longitude, this->Latitude, this->Height));
} else if (
propertyName ==
GET_MEMBER_NAME_CHECKED(UCesiumGlobeAnchorDerivedProperties, Pitch) ||
propertyName ==
GET_MEMBER_NAME_CHECKED(UCesiumGlobeAnchorDerivedProperties, Yaw) ||
propertyName ==
GET_MEMBER_NAME_CHECKED(UCesiumGlobeAnchorDerivedProperties, Roll)) {
this->GlobeAnchor->Modify();
this->GlobeAnchor->SetEastSouthUpRotation(
FRotator(this->Pitch, this->Yaw, this->Roll).Quaternion());
} else if (true) {
if (propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Longitude) ||
propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Latitude) ||
propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Height)) {
this->GlobeAnchor->Modify();
this->GlobeAnchor->MoveToLongitudeLatitudeHeight(
FVector(this->Longitude, this->Latitude, this->Height));
} else if (
propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Pitch) ||
propertyName ==
GET_MEMBER_NAME_CHECKED(UCesiumGlobeAnchorDerivedProperties, Yaw) ||
propertyName == GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Roll)) {
this->GlobeAnchor->Modify();
this->GlobeAnchor->SetEastSouthUpRotation(
FRotator(this->Pitch, this->Yaw, this->Roll).Quaternion());
}
}
}

bool UCesiumGlobeAnchorDerivedProperties::CanEditChange(
const FProperty* InProperty) const {
const FName Name = InProperty->GetFName();

// Valid georeference, nothing to disable
if (IsValid(this->GlobeAnchor->ResolveGeoreference())) {
return true;
}

return Name != GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Longitude) &&
Name != GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Latitude) &&
Name != GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Height) &&
Name != GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Pitch) &&
Name != GET_MEMBER_NAME_CHECKED(
UCesiumGlobeAnchorDerivedProperties,
Yaw) &&
Name !=
GET_MEMBER_NAME_CHECKED(UCesiumGlobeAnchorDerivedProperties, Roll);
}

void UCesiumGlobeAnchorDerivedProperties::Initialize(
UCesiumGlobeAnchorComponent* GlobeAnchorComponent) {
this->GlobeAnchor = GlobeAnchorComponent;
Expand All @@ -240,16 +272,21 @@ void UCesiumGlobeAnchorDerivedProperties::Tick(float DeltaTime) {
this->Y = position.Y;
this->Z = position.Z;

FVector llh = this->GlobeAnchor->GetLongitudeLatitudeHeight();
this->Longitude = llh.X;
this->Latitude = llh.Y;
this->Height = llh.Z;

FQuat rotation = this->GlobeAnchor->GetEastSouthUpRotation();
FRotator rotator = rotation.Rotator();
this->Roll = rotator.Roll;
this->Pitch = rotator.Pitch;
this->Yaw = rotator.Yaw;
// We can't transform the GlobeAnchor's ECEF coordinates back to
// cartographic & rotation without a valid georeference to know what
// ellipsoid to use.
if (IsValid(this->GlobeAnchor->ResolveGeoreference())) {
FVector llh = this->GlobeAnchor->GetLongitudeLatitudeHeight();
this->Longitude = llh.X;
this->Latitude = llh.Y;
this->Height = llh.Z;

FQuat rotation = this->GlobeAnchor->GetEastSouthUpRotation();
FRotator rotator = rotation.Rotator();
this->Roll = rotator.Roll;
this->Pitch = rotator.Pitch;
this->Yaw = rotator.Yaw;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class UCesiumGlobeAnchorDerivedProperties : public UObject,

virtual void PostEditChangeProperty(
struct FPropertyChangedEvent& PropertyChangedEvent) override;
virtual bool CanEditChange(const FProperty* InProperty) const override;

void Initialize(UCesiumGlobeAnchorComponent* GlobeAnchor);

Expand Down
51 changes: 43 additions & 8 deletions Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ ACesiumGeoreference* ACesium3DTileset::ResolveGeoreference() {
this->ResolvedGeoreference->OnGeoreferenceUpdated.AddUniqueDynamic(
pRoot,
&UCesium3DTilesetRoot::HandleGeoreferenceUpdated);
this->ResolvedGeoreference->OnEllipsoidChanged.AddUniqueDynamic(
this,
&ACesium3DTileset::HandleOnGeoreferenceEllipsoidChanged);

// Update existing tile positions, if any.
pRoot->HandleGeoreferenceUpdated();
Expand Down Expand Up @@ -471,10 +474,14 @@ void ACesium3DTileset::OnFocusEditorViewportOnThis() {
*this->GetName());

struct CalculateECEFCameraPosition {
const CesiumGeospatial::Ellipsoid& ellipsoid;

glm::dvec3 operator()(const CesiumGeometry::BoundingSphere& sphere) {
const glm::dvec3& center = sphere.getCenter();
glm::dmat4 ENU =
CesiumGeospatial::GlobeTransforms::eastNorthUpToFixedFrame(center);
CesiumGeospatial::GlobeTransforms::eastNorthUpToFixedFrame(
center,
ellipsoid);
glm::dvec3 offset =
sphere.getRadius() *
glm::normalize(
Expand All @@ -487,7 +494,9 @@ void ACesium3DTileset::OnFocusEditorViewportOnThis() {
operator()(const CesiumGeometry::OrientedBoundingBox& orientedBoundingBox) {
const glm::dvec3& center = orientedBoundingBox.getCenter();
glm::dmat4 ENU =
CesiumGeospatial::GlobeTransforms::eastNorthUpToFixedFrame(center);
CesiumGeospatial::GlobeTransforms::eastNorthUpToFixedFrame(
center,
ellipsoid);
const glm::dmat3& halfAxes = orientedBoundingBox.getHalfAxes();
glm::dvec3 offset =
glm::length(halfAxes[0] + halfAxes[1] + halfAxes[2]) *
Expand Down Expand Up @@ -525,9 +534,12 @@ void ACesium3DTileset::OnFocusEditorViewportOnThis() {

ACesiumGeoreference* pGeoreference = this->ResolveGeoreference();

const CesiumGeospatial::Ellipsoid& ellipsoid =
pGeoreference->GetEllipsoid()->GetNativeEllipsoid();

// calculate unreal camera position
glm::dvec3 ecefCameraPosition =
std::visit(CalculateECEFCameraPosition{}, boundingVolume);
std::visit(CalculateECEFCameraPosition{ellipsoid}, boundingVolume);
FVector unrealCameraPosition =
pGeoreference->TransformEarthCenteredEarthFixedPositionToUnreal(
VecMath::createVector(ecefCameraPosition));
Expand Down Expand Up @@ -591,6 +603,13 @@ void ACesium3DTileset::UpdateTransformFromCesium() {
}
}

void ACesium3DTileset::HandleOnGeoreferenceEllipsoidChanged(
UCesiumEllipsoid* OldEllipsoid,
UCesiumEllipsoid* NewEllpisoid) {
UE_LOG(LogCesium, Warning, TEXT("Ellipsoid changed"));
this->RefreshTileset();
}

// Called when the game starts or when spawned
void ACesium3DTileset::BeginPlay() {
Super::BeginPlay();
Expand Down Expand Up @@ -708,8 +727,13 @@ class UnrealResourcePreparer
&(*this->_pActor->_metadataDescription_DEPRECATED);
}

const CesiumGeospatial::Ellipsoid& ellipsoid = tileLoadResult.ellipsoid;

TUniquePtr<UCesiumGltfComponent::HalfConstructed> pHalf =
UCesiumGltfComponent::CreateOffGameThread(transform, options);
UCesiumGltfComponent::CreateOffGameThread(
transform,
options,
ellipsoid);

return asyncSystem.createResolvedFuture(
Cesium3DTilesSelection::TileLoadResultAndRenderResources{
Expand Down Expand Up @@ -1052,6 +1076,9 @@ void ACesium3DTileset::LoadTileset() {
this->BoundingVolumePoolComponent->initPool(this->OcclusionPoolSize);
}

CesiumGeospatial::Ellipsoid pNativeEllipsoid =
this->ResolveGeoreference()->GetEllipsoid()->GetNativeEllipsoid();

ACesiumCreditSystem* pCreditSystem = this->ResolvedCreditSystem;

Cesium3DTilesSelection::TilesetExternals externals{
Expand All @@ -1072,6 +1099,8 @@ void ACesium3DTileset::LoadTileset() {

Cesium3DTilesSelection::TilesetOptions options;

options.ellipsoid = pNativeEllipsoid;

options.enableOcclusionCulling =
GetDefault<UCesiumRuntimeSettings>()
->EnableExperimentalOcclusionCullingFeature &&
Expand Down Expand Up @@ -1545,7 +1574,8 @@ std::vector<FCesiumCamera> ACesium3DTileset::GetSceneCaptures() const {
/*static*/ Cesium3DTilesSelection::ViewState
ACesium3DTileset::CreateViewStateFromViewParameters(
const FCesiumCamera& camera,
const glm::dmat4& unrealWorldToTileset) {
const glm::dmat4& unrealWorldToTileset,
UCesiumEllipsoid* ellipsoid) {

double horizontalFieldOfView =
FMath::DegreesToRadians(camera.FieldOfViewDegrees);
Expand Down Expand Up @@ -1595,7 +1625,8 @@ ACesium3DTileset::CreateViewStateFromViewParameters(
tilesetCameraUp,
size,
horizontalFieldOfView,
verticalFieldOfView);
verticalFieldOfView,
ellipsoid->GetNativeEllipsoid());
}

#if WITH_EDITOR
Expand Down Expand Up @@ -2044,10 +2075,14 @@ void ACesium3DTileset::Tick(float DeltaTime) {
return;
}

UCesiumEllipsoid* ellipsoid = this->ResolveGeoreference()->GetEllipsoid();

std::vector<Cesium3DTilesSelection::ViewState> frustums;
for (const FCesiumCamera& camera : cameras) {
frustums.push_back(
CreateViewStateFromViewParameters(camera, unrealWorldToCesiumTileset));
frustums.push_back(CreateViewStateFromViewParameters(
camera,
unrealWorldToCesiumTileset,
ellipsoid));
}

const Cesium3DTilesSelection::ViewUpdateResult* pResult;
Expand Down
Loading