Skip to content

Commit

Permalink
Hopefully final review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
azrogers committed Jun 28, 2024
1 parent e9b8b55 commit 27d80a7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
1 change: 1 addition & 0 deletions Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ void ACesium3DTileset::UpdateTransformFromCesium() {
void ACesium3DTileset::HandleOnGeoreferenceEllipsoidChanged(
UCesiumEllipsoid* OldEllipsoid,
UCesiumEllipsoid* NewEllpisoid) {
UE_LOG(LogCesium, Warning, TEXT("Ellipsoid changed"));
this->RefreshTileset();
}

Expand Down
43 changes: 39 additions & 4 deletions Source/CesiumRuntime/Private/CesiumEllipsoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

#include "CesiumEllipsoid.h"
#include "CesiumEllipsoidFunctions.h"
#include "CesiumGeoreference.h"
#include "CesiumRuntime.h"
#include "VecMath.h"

#include "EngineUtils.h"
#include "MathUtil.h"
#include "UObject/ConstructorHelpers.h"
#include "UObject/ObjectSaveContext.h"

#if WITH_EDITOR
#include "Editor.h"
#include "LevelEditor.h"
#endif

#include <CesiumGeospatial/Ellipsoid.h>

Expand Down Expand Up @@ -80,10 +88,10 @@ UCesiumEllipsoid::CreateCoordinateSystem(const FVector& Center, double Scale) {
}
}

Ellipsoid& UCesiumEllipsoid::GetNativeEllipsoid() {
const Ellipsoid& UCesiumEllipsoid::GetNativeEllipsoid() {
const double MinRadiiValue = TMathUtilConstants<double>::Epsilon;

if (!this->NativeEllipsoid.IsValid()) {
if (!this->NativeEllipsoid.IsSet()) {
// Radii of zero will throw Infs and NaNs into our calculations which will
// cause Unreal to crash when the values reach a transform.
if (this->Radii.X < MinRadiiValue || this->Radii.Y < MinRadiiValue ||
Expand All @@ -95,11 +103,38 @@ Ellipsoid& UCesiumEllipsoid::GetNativeEllipsoid() {
"Radii must be greater than 0 - clamping to minimum value to avoid crashes."));
}

this->NativeEllipsoid = MakeUnique<CesiumGeospatial::Ellipsoid>(
this->NativeEllipsoid.Emplace(Ellipsoid(
FMath::Max(this->Radii.X, MinRadiiValue),
FMath::Max(this->Radii.Y, MinRadiiValue),
FMath::Max(this->Radii.Z, MinRadiiValue));
FMath::Max(this->Radii.Z, MinRadiiValue)));
}

return *this->NativeEllipsoid;
}

#if WITH_EDITOR
void UCesiumEllipsoid::PostSaveRoot(
FObjectPostSaveRootContext ObjectSaveContext) {
if (!IsValid(GEditor)) {
return;
}

GEditor->GetWorld();

UWorld* World = GEditor->GetEditorWorldContext().World();
if (!IsValid(World)) {
return;
}

// Go through every georeference and update its ellipsoid if it's this
// ellipsoid, since we might have modified values after saving.
if (ObjectSaveContext.SaveSucceeded()) {
for (TActorIterator<ACesiumGeoreference> It(World); It; ++It) {
ACesiumGeoreference* Georeference = *It;
if (Georeference->GetEllipsoid() == this) {
Georeference->SetEllipsoid(this);
}
}
}
}
#endif
2 changes: 1 addition & 1 deletion Source/CesiumRuntime/Private/CesiumSubLevelComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void UCesiumSubLevelComponent::PlaceOriginAtEcef(const FVector& NewOriginEcef) {
UCesiumEllipsoid* pEllipsoid = pGeoreference->GetEllipsoid();
check(IsValid(pEllipsoid));

Ellipsoid& pNativeEllipsoid = pEllipsoid->GetNativeEllipsoid();
const Ellipsoid& pNativeEllipsoid = pEllipsoid->GetNativeEllipsoid();

// Another sub-level might be active right now, so we construct the correct
// GeoTransforms instead of using the CesiumGeoreference's.
Expand Down
2 changes: 1 addition & 1 deletion Source/CesiumRuntime/Public/Cesium3DTileset.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ class CESIUMRUNTIME_API ACesium3DTileset : public AActor {
/**
* The event handler for ACesiumGeoreference::OnEllipsoidChanged.
*/
UFUNCTION()
UFUNCTION(CallInEditor)
void HandleOnGeoreferenceEllipsoidChanged(
UCesiumEllipsoid* OldEllipsoid,
UCesiumEllipsoid* NewEllpisoid);
Expand Down
10 changes: 8 additions & 2 deletions Source/CesiumRuntime/Public/CesiumEllipsoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include "Engine/DataAsset.h"
#include "Misc/Optional.h"
#include <CesiumGeospatial/LocalHorizontalCoordinateSystem.h>
#include "CesiumEllipsoid.generated.h"

Expand Down Expand Up @@ -122,7 +123,7 @@ class CESIUMRUNTIME_API UCesiumEllipsoid : public UDataAsset {
/**
* Returns the underlying {@link CesiumGeospatial::Ellipsoid}
*/
CesiumGeospatial::Ellipsoid& GetNativeEllipsoid();
const CesiumGeospatial::Ellipsoid& GetNativeEllipsoid();

protected:
/**
Expand All @@ -138,5 +139,10 @@ class CESIUMRUNTIME_API UCesiumEllipsoid : public UDataAsset {
FVector Radii;

private:
TUniquePtr<CesiumGeospatial::Ellipsoid> NativeEllipsoid = nullptr;
#if WITH_EDITOR
virtual void
PostSaveRoot(FObjectPostSaveRootContext ObjectSaveContext) override;
#endif

TOptional<CesiumGeospatial::Ellipsoid> NativeEllipsoid;
};
2 changes: 1 addition & 1 deletion Source/CesiumRuntime/Public/CesiumGlobeAnchorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class CESIUMRUNTIME_API UCesiumGlobeAnchorComponent : public UActorComponent {
* Height. The Actor's position and orientation are recomputed from the
* Component's globe (ECEF) position and orientation.
*/
UFUNCTION()
UFUNCTION(CallInEditor)
void _onGeoreferenceChanged();

friend class FCesiumGlobeAnchorCustomization;
Expand Down

0 comments on commit 27d80a7

Please sign in to comment.