Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into vcpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Aug 14, 2024
2 parents e4fd568 + 4b00429 commit 8a4ed88
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## v1.11.1 - 2024-08-01

##### Fixes :wrench:

- Fixed a bug that caused a `NullReferenceException` when attempting to get or set the `longitudeLatitudeHeight` property on a disabled `CesiumGlobeAnchor`.
- Fixed a bug introduced in v1.11.0 that caused `CesiumCartographicPolygon` positions to be interpreted incorrectly, making polygon clipping unusable.

This release updates [cesium-native](https://github.com/CesiumGS/cesium-native) from v0.37.0 to v0.38.0. See the [changelog](https://github.com/CesiumGS/cesium-native/blob/main/CHANGES.md) for a complete list of changes in cesium-native.

### v1.11.0 - 2024-07-01

##### Additions :tada:
Expand Down
6 changes: 6 additions & 0 deletions Runtime/CesiumCameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ void FixedUpdate()

private bool RaycastTowardsEarthCenter(out float hitDistance)
{
if (this._georeference == null)
{
hitDistance = 0.0f;
return false;
}

double3 center =
this._georeference.TransformEarthCenteredEarthFixedPositionToUnity(new double3(0.0));

Expand Down
2 changes: 1 addition & 1 deletion Runtime/CesiumCartographicPolygon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ internal List<double2> GetCartographicPoints(Matrix4x4 worldToTileset)
float3 worldPosition = knot.Transform(localToWorld).Position;
float3 unityPosition = worldToTileset.MultiplyPoint3x4(worldPosition);
double3 ecefPosition = georeference.TransformUnityPositionToEarthCenteredEarthFixed(unityPosition);
double3 cartographicPosition = georeference.ellipsoid.LongitudeLatitudeHeightToCenteredFixed(ecefPosition);
double3 cartographicPosition = georeference.ellipsoid.CenteredFixedToLongitudeLatitudeHeight(ecefPosition);

cartographicPoints.Add(cartographicPosition.xy);
}
Expand Down
29 changes: 24 additions & 5 deletions Runtime/CesiumGlobeAnchor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,28 @@ public double4x4 localToGlobeFixedMatrix
/// </remarks>
public double3 longitudeLatitudeHeight
{
get => this._georeference.ellipsoid.CenteredFixedToLongitudeLatitudeHeight(this.positionGlobeFixed);
get
{
this.UpdateGeoreferenceIfNecessary();

if (this._georeference == null || this._georeference.ellipsoid == null)
{
// Cannot get property if there is no georeference, or the georeference has no ellipsoid.
return new double3(0.0, 0.0, 0.0);
}

return this._georeference.ellipsoid.CenteredFixedToLongitudeLatitudeHeight(this.positionGlobeFixed);
}
set
{
this.UpdateGeoreferenceIfNecessary();

if (this._georeference == null || this._georeference.ellipsoid == null)
{
// Cannot set property if there is no georeference, or the georeference has no ellipsoid.
return;
}

this.positionGlobeFixed = this._georeference.ellipsoid.LongitudeLatitudeHeightToCenteredFixed(value);
}
}
Expand Down Expand Up @@ -449,10 +468,10 @@ public void Sync()
{
// If the ellipsoid changed since last sync, we need to update from transform since our ECEF mapping
// is going to be invalid.
bool isEllipsoidChanged = _lastEllipsoidRadii.HasValue ?
(_lastEllipsoidRadii.Value.x != _georeference.ellipsoid.radii.x ||
_lastEllipsoidRadii.Value.y != _georeference.ellipsoid.radii.y ||
_lastEllipsoidRadii.Value.z != _georeference.ellipsoid.radii.z) : true;
bool isEllipsoidChanged = this._lastEllipsoidRadii.HasValue && this._georeference != null ?
(this._lastEllipsoidRadii.Value.x != this._georeference.ellipsoid.radii.x ||
this._lastEllipsoidRadii.Value.y != this._georeference.ellipsoid.radii.y ||
this._lastEllipsoidRadii.Value.z != this._georeference.ellipsoid.radii.z) : true;

// If we don't have a local -> globe fixed matrix yet, we must update from the Transform
bool updateFromTransform = !this._localToGlobeFixedMatrixIsValid;
Expand Down
6 changes: 6 additions & 0 deletions Runtime/CesiumOriginShift.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ void LateUpdate()
{
CesiumGeoreference georeference = this.GetComponentInParent<CesiumGeoreference>();

if (georeference == null)
{
Debug.LogWarning("CesiumOriginShift is doing nothing because it is not nested inside a game object with a CesiumGeoreference component.");
return;
}

CesiumGlobeAnchor anchor = this.GetComponent<CesiumGlobeAnchor>();

// The RequireComponent attribute should ensure the globe anchor exists, but it may not be active.
Expand Down
11 changes: 9 additions & 2 deletions Tests/CesiumTests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"CesiumRuntime",
"Unity.Mathematics"
"Unity.Mathematics",
"Unity.Splines"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand All @@ -18,6 +19,12 @@
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.splines",
"expression": "1.0.0",
"define": "SUPPORTS_SPLINES"
}
],
"noEngineReferences": false
}
62 changes: 62 additions & 0 deletions Tests/TestCesiumCartographicPolygon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using CesiumForUnity;
using NUnit.Framework;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;

#if SUPPORTS_SPLINES
using UnityEngine.Splines;
#endif

public class TestCesiumCartographicPolygon
{
#if SUPPORTS_SPLINES
[Test]
public void GetCartographicPoints()
{
GameObject go = new GameObject("Game Object");

CesiumGeoreference georeference = go.AddComponent<CesiumGeoreference>();
georeference.SetOriginLongitudeLatitudeHeight(12.0, 23.0, 456.0);

CesiumCartographicPolygon polygonComponent = go.AddComponent<CesiumCartographicPolygon>();
SplineContainer splineContainer = go.GetComponent<SplineContainer>();

// Remove existing spline(s).
IReadOnlyList<Spline> splines = splineContainer.Splines;
for (int i = splines.Count - 1; i >= 0; i--)
{
splineContainer.RemoveSpline(splines[i]);
}

// Add a new spline.
Spline defaultSpline = new Spline();

BezierKnot[] knots = new BezierKnot[] {
new BezierKnot(new float3(-100.0f, 0f, -100.0f)),
new BezierKnot(new float3(100.0f, 0f, -100.0f)),
new BezierKnot(new float3(100.0f, 0f, 100.0f)),
new BezierKnot(new float3(-100.0f, 0f, 100.0f)),
};

defaultSpline.Knots = knots;
defaultSpline.Closed = true;
defaultSpline.SetTangentMode(TangentMode.Linear);

splineContainer.AddSpline(defaultSpline);

List<double2> cartographicPoints = polygonComponent.GetCartographicPoints(Matrix4x4.identity);
Assert.AreEqual(cartographicPoints.Count, 4);

// All points are near the georeference origin
Assert.AreEqual(cartographicPoints[0].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[0].y, 23.0, 0.01);
Assert.AreEqual(cartographicPoints[1].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[1].y, 23.0, 0.01);
Assert.AreEqual(cartographicPoints[2].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[2].y, 23.0, 0.01);
Assert.AreEqual(cartographicPoints[3].x, 12.0, 0.01);
Assert.AreEqual(cartographicPoints[3].y, 23.0, 0.01);
}
#endif
}
11 changes: 11 additions & 0 deletions Tests/TestCesiumCartographicPolygon.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Tests/TestCesiumGlobeAnchor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,27 @@ public void GivesCorrectResultsForDifferentEllipsoids()
anchor.Sync();
Assert.That(anchor.positionGlobeFixed, Is.EqualTo(actualPosEcef).Using(epsilon6));
}

[Test]
public void CanChangePositionWhileDisabled()
{
IEqualityComparer<double3> epsilon6 = Comparers.Double3(1e-6, 1e-4);

double3 positionLlh = new double3(-20, -10, 1000.0);

GameObject goGeoreference = new GameObject("Georeference");
CesiumGeoreference georeference = goGeoreference.AddComponent<CesiumGeoreference>();
georeference.ellipsoid = CesiumEllipsoid.WGS84;
georeference.SetOriginLongitudeLatitudeHeight(positionLlh.x, positionLlh.y, positionLlh.z);

GameObject goAnchored = new GameObject("Anchored");
goAnchored.transform.parent = goGeoreference.transform;
goAnchored.transform.SetPositionAndRotation(new Vector3(0, 0, 0), Quaternion.identity);
goAnchored.SetActive(false);

CesiumGlobeAnchor anchor = goAnchored.AddComponent<CesiumGlobeAnchor>();
anchor.enabled = false;
anchor.longitudeLatitudeHeight = new double3(1, 1, 1);
Assert.That(anchor.longitudeLatitudeHeight, Is.EqualTo(new double3(1, 1, 1)).Using(epsilon6));
}
}
10 changes: 5 additions & 5 deletions native~/Runtime/src/CesiumGlobeAnchorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ namespace {

const CesiumGeospatial::Ellipsoid&
getAnchorEllipsoid(const ::DotNet::CesiumForUnity::CesiumGlobeAnchor& anchor) {

anchor.UpdateGeoreferenceIfNecessary();
return anchor._georeference()
.ellipsoid()
.NativeImplementation()
.GetEllipsoid();
CesiumForUnity::CesiumGeoreference georeference = anchor._georeference();
if (georeference == nullptr) {
return CesiumGeospatial::Ellipsoid::WGS84;
}
return georeference.ellipsoid().NativeImplementation().GetEllipsoid();
}

GlobeAnchor createOrUpdateNativeGlobeAnchorFromEcef(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.cesium.unity",
"version": "1.11.0",
"version": "1.11.1",
"displayName": "Cesium for Unity",
"description": "Cesium for Unity brings the 3D geospatial ecosystem to Unity. By combining a high-accuracy full-scale WGS84 globe, open APIs and open standards for spatial indexing such as 3D Tiles, and cloud-based real-world content from [Cesium ion](https://cesium.com/cesium-ion) with Unity, this plugin enables 3D geospatial workflows and applications in Unity.",
"license": "Apache-2.0",
Expand Down

0 comments on commit 8a4ed88

Please sign in to comment.