Skip to content

Commit

Permalink
Provide result even if tileset sampling fails completely.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Sep 30, 2024
1 parent c66231a commit b5f44cc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 16 deletions.
17 changes: 15 additions & 2 deletions Tests/TestCesium3DTileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,20 @@ public IEnumerator SampleHeightMostDetailedFailsIfTilesetFailsToLoad()

yield return new WaitForTask(task);

Assert.NotNull(task.Exception);
Assert.IsTrue(task.Exception.Message.Contains("failed to load"));
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, 1);

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);

Assert.IsTrue(result.warnings[0].Contains("failed to load"));
}
}
37 changes: 24 additions & 13 deletions native~/Runtime/src/Cesium3DTilesetImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,30 @@ Cesium3DTilesetImpl::SampleHeightMostDetailed(
position.z));
}

size_t count = positions.size();

CesiumAsync::Future<SampleHeightResult> future =
this->getTileset()
? this->getTileset()->sampleHeightMostDetailed(positions)
: getAsyncSystem().createResolvedFuture(
Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::vector<bool>(count, false),
{"Could not sample heights from tileset because it has not "
"been created."}});

std::move(future)
auto sampleHeights = [this, &positions]() mutable {
if (this->getTileset()) {
return this->getTileset()
->sampleHeightMostDetailed(positions)
.catchImmediately([positions = std::move(positions)](
std::exception&& exception) mutable {
std::vector<bool> sampleSuccess(positions.size(), false);
return Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::move(sampleSuccess),
{exception.what()}};
});
} else {
std::vector<bool> sampleSuccess(positions.size(), false);
return getAsyncSystem().createResolvedFuture(
Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::move(sampleSuccess),
{"Could not sample heights from tileset because it has not "
"been created."}});
}
};

sampleHeights()
.thenImmediately(
[promise](Cesium3DTilesSelection::SampleHeightResult&& result) {
System::Array1<Unity::Mathematics::double3> positions(
Expand Down

0 comments on commit b5f44cc

Please sign in to comment.