-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from CesiumGS/height-query
Height query API for Unity
- Loading branch information
Showing
16 changed files
with
405 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Unity.Mathematics; | ||
|
||
namespace CesiumForUnity | ||
{ | ||
/// <summary> | ||
/// The asynchronous result of a call to <see cref="Cesium3DTileset.SampleHeightMostDetailed"/>. | ||
/// </summary> | ||
public class CesiumSampleHeightResult | ||
{ | ||
/// <summary> | ||
/// The positions and their sampled heights. The X component is Longitude (degrees), | ||
/// the Y component is Latitude (degrees), and the Z component is Height (meters) | ||
/// above the ellipsoid (usually WGS84). | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// For each resulting position, its longitude and latitude values will match | ||
/// values from its input. Its height will either be the height sampled from | ||
/// the tileset at that position, or the original input height if the sample | ||
/// was unsuccessful. To determine which, look at the value of | ||
/// <see cref="CesiumSampleHeightResult.sampleSuccess"/> at the same index. | ||
/// </para> | ||
/// <para> | ||
/// The returned height is measured from the ellipsoid (usually WGS84) and | ||
/// should not be confused with a height above Mean Sea Level. | ||
/// </para> | ||
/// </remarks> | ||
public double3[] longitudeLatitudeHeightPositions { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates whether the height for the position at the corresponding index was sampled | ||
/// successfully. | ||
/// </summary> | ||
/// <remarks> | ||
/// If true, then the corresponding position in | ||
/// <see cref="CesiumSampleHeightResult.longitudeLatitudeHeightPositions"/> uses | ||
/// the height sampled from the tileset. If false, the height could not be sampled for | ||
/// the position, so its height is the same as the original input height. | ||
/// </remarks> | ||
public bool[] sampleSuccess { get; set; } | ||
|
||
/// <summary> | ||
/// Any warnings that occurred while sampling heights. | ||
/// </summary> | ||
public string[] warnings { get; set; } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace CesiumForUnity | ||
{ | ||
/// <summary> | ||
/// A YieldInstruction that can be yielded from a coroutine in order to wait | ||
/// until a given task completes. | ||
/// </summary> | ||
public class WaitForTask : CustomYieldInstruction | ||
{ | ||
private IAsyncResult _task; | ||
|
||
/// <summary> | ||
/// Initializes a new instance. | ||
/// </summary> | ||
/// <param name="task">The task to wait for.</param> | ||
public WaitForTask(IAsyncResult task) | ||
{ | ||
this._task = task; | ||
} | ||
|
||
public override bool keepWaiting => !this._task.IsCompleted; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using CesiumForUnity; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections; | ||
using System.Threading.Tasks; | ||
using Unity.Mathematics; | ||
using UnityEngine; | ||
using UnityEngine.TestTools; | ||
|
||
public class TestCesium3DTileset | ||
{ | ||
[UnityTest] | ||
public IEnumerator SampleHeightMostDetailedWorksWithAnEmptyArrayOfPositions() | ||
{ | ||
GameObject go = new GameObject(); | ||
go.name = "Cesium World Terrain"; | ||
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>(); | ||
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? ""; | ||
tileset.ionAssetID = 1; | ||
|
||
Task<CesiumSampleHeightResult> task = tileset.SampleHeightMostDetailed(); | ||
|
||
yield return new WaitForTask(task); | ||
|
||
CesiumSampleHeightResult result = task.Result; | ||
Assert.IsNotNull(result); | ||
Assert.IsNotNull(result.longitudeLatitudeHeightPositions); | ||
Assert.IsNotNull(result.sampleSuccess); | ||
Assert.IsNotNull(result.warnings); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions.Length, 0); | ||
Assert.AreEqual(result.sampleSuccess.Length, 0); | ||
Assert.AreEqual(result.warnings.Length, 0); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator SampleHeightMostDetailedWorksWithASinglePosition() | ||
{ | ||
GameObject go = new GameObject(); | ||
go.name = "Cesium World Terrain"; | ||
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>(); | ||
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? ""; | ||
tileset.ionAssetID = 1; | ||
|
||
Task<CesiumSampleHeightResult> task = tileset.SampleHeightMostDetailed(new double3(-105.1, 40.1, 1.0)); | ||
|
||
yield return new WaitForTask(task); | ||
|
||
CesiumSampleHeightResult result = task.Result; | ||
Assert.IsNotNull(result); | ||
Assert.IsNotNull(result.longitudeLatitudeHeightPositions); | ||
Assert.IsNotNull(result.sampleSuccess); | ||
Assert.IsNotNull(result.warnings); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions.Length, 1); | ||
Assert.AreEqual(result.sampleSuccess.Length, 1); | ||
Assert.AreEqual(result.warnings.Length, 0); | ||
|
||
Assert.AreEqual(result.sampleSuccess[0], true); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].x, -105.1, 1e-12); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].y, 40.1, 1e-12); | ||
// Returned height should be different from the original height (1.0) by at least one meter. | ||
Assert.IsTrue(math.abs(result.longitudeLatitudeHeightPositions[0].z - 1.0) > 1.0); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator SampleHeightMostDetailedWorksWithMultiplePositions() | ||
{ | ||
GameObject go = new GameObject(); | ||
go.name = "Cesium World Terrain"; | ||
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>(); | ||
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? ""; | ||
tileset.ionAssetID = 1; | ||
|
||
Task<CesiumSampleHeightResult> task = tileset.SampleHeightMostDetailed( | ||
new double3(-105.1, 40.1, 1.0), | ||
new double3(105.1, -40.1, 1.0)); | ||
|
||
yield return new WaitForTask(task); | ||
|
||
CesiumSampleHeightResult result = task.Result; | ||
Assert.IsNotNull(result); | ||
Assert.IsNotNull(result.longitudeLatitudeHeightPositions); | ||
Assert.IsNotNull(result.sampleSuccess); | ||
Assert.IsNotNull(result.warnings); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions.Length, 2); | ||
Assert.AreEqual(result.sampleSuccess.Length, 2); | ||
Assert.AreEqual(result.warnings.Length, 0); | ||
|
||
Assert.AreEqual(result.sampleSuccess[0], true); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].x, -105.1, 1e-12); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].y, 40.1, 1e-12); | ||
// Returned height should be different from the original height (1.0) by at least one meter. | ||
Assert.IsTrue(math.abs(result.longitudeLatitudeHeightPositions[0].z - 1.0) > 1.0); | ||
|
||
Assert.AreEqual(result.sampleSuccess[1], true); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[1].x, 105.1, 1e-12); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[1].y, -40.1, 1e-12); | ||
// Returned height should be different from the original height (1.0) by at least one meter. | ||
Assert.IsTrue(math.abs(result.longitudeLatitudeHeightPositions[1].z - 1.0) > 1.0); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator SampleHeightMostDetailedIndicatesNotSampledForPositionOutsideTileset() | ||
{ | ||
GameObject go = new GameObject(); | ||
go.name = "Melbourne Photogrammetry"; | ||
Cesium3DTileset tileset = go.AddComponent<Cesium3DTileset>(); | ||
tileset.ionAccessToken = Environment.GetEnvironmentVariable("CESIUM_ION_TOKEN_FOR_TESTS") ?? ""; | ||
tileset.ionAssetID = 69380; | ||
|
||
// Somewhere in Sydney, not Melbourne | ||
Task<CesiumSampleHeightResult> task = tileset.SampleHeightMostDetailed(new double3(151.20972, -33.87100, 1.0)); | ||
|
||
yield return new WaitForTask(task); | ||
|
||
CesiumSampleHeightResult result = task.Result; | ||
Assert.IsNotNull(result); | ||
Assert.IsNotNull(result.longitudeLatitudeHeightPositions); | ||
Assert.IsNotNull(result.sampleSuccess); | ||
Assert.IsNotNull(result.warnings); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions.Length, 1); | ||
Assert.AreEqual(result.sampleSuccess.Length, 1); | ||
Assert.AreEqual(result.warnings.Length, 0); | ||
|
||
Assert.AreEqual(result.sampleSuccess[0], false); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].x, 151.20972, 1e-12); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].y, -33.87100, 1e-12); | ||
Assert.AreEqual(result.longitudeLatitudeHeightPositions[0].z, 1.0, 1e-12); | ||
} | ||
} |
Oops, something went wrong.