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 height-query function to Tileset #783

Merged
merged 82 commits into from
Sep 27, 2024
Merged

Add height-query function to Tileset #783

merged 82 commits into from
Sep 27, 2024

Conversation

joseph-kaile
Copy link
Collaborator

@joseph-kaile joseph-kaile commented Jan 2, 2024

Adds new functionality to Tileset to enable terrain height queries.

Builds on previous cesium-native work for ray / triangle and ray / gltf intersections.

Approach

To find the height at a latitude / longitude, we must first load the terrain data for this location, construct a ray at that coordinate pointing towards the center of the earth, then intersect all the content in the tile, using the closest hit as our discovered height.

Height queries can happen for tiles not selected from a camera, so we introduce a parallel tile loading strategy that builds on the same system. Just as we use a camera frustum for _visitTileIfNeeded, we use our new height query requests and call visitHeightRequests. This discovers which tiles are needed to load and adds them to the same priority queues that the camera-based tiles go to.

Once all relevant tiles are loaded, we ray intersect against all of their contents.

Fixes #636

TO DO

  • Solve priority questions, how does it co-exist with camera tile loads?
  • Reuse addTileToLoadQueue for tiles added from query traversal
  • Performance - How do we know how much time is loading vs. intersecting? Intersect code should be minimal compared to url content requests. How can we verify this?
  • Performance - Are we wasting time creating physics meshes on the game engine side? (Ex. Unreal).
  • Fix incremental findCandidateTiles for additive-refined tilesets.
  • Support for implicit tilesets
  • Support for instanced models Wrote an issue: Add support for height queries against instanced models #948
  • Return all heights, not just the highest Not urgent at this time.
  • Write unit tests
  • Peer review
  • Merge

@joseph-kaile joseph-kaile changed the base branch from main to gltf-ray-intersect January 2, 2024 20:05
@kring kring marked this pull request as ready for review September 16, 2024 10:31
@kring
Copy link
Member

kring commented Sep 16, 2024

I believe this is now ready to merge. However, because I've now done a fair bit of work on it, it's probably a good idea to get someone else's eyes on it first.

@kring kring added this to the October 2024 Release milestone Sep 16, 2024
@j9liu j9liu self-requested a review September 19, 2024 14:25
Copy link
Contributor

@j9liu j9liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kring this looks good to me! I didn't look over the tests or the algorithm too closely, but I'm sure I can verify correctness when I look at the corresponding Unity / Unreal PRs.

Most of my comments are doc / understanding related. I'm pushing a commit that addresses some of these, but I wanted to leave some up for input. But none of these have to hold up the PR before the release!

Cesium3DTilesSelection/src/Tileset.cpp Outdated Show resolved Hide resolved
Cesium3DTilesSelection/src/TilesetContentManager.cpp Outdated Show resolved Hide resolved
* {@link SampleHeightResult::positions} is unchanged from the original input
* height.
*/
std::vector<bool> heightSampled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I read heightSampled my brain first thinks "oh, this is the height that was sampled," instead of "this was whether the sample actually happened." What do you think of this alternative?

Suggested change
std::vector<bool> heightSampled;
std::vector<bool> sampleSuccessful;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I kind of prefer sampleSuccess more, since that's briefer.
Other suggestions I could think of are

  • successfulSample
  • successfullySampled
  • heightWasSampled
  • wasHeightChanged / heightWasChanged.

Cesium3DTilesSelection/src/TilesetHeightQuery.h Outdated Show resolved Hide resolved
Cesium3DTilesSelection/src/TilesetHeightQuery.h Outdated Show resolved Hide resolved
Cesium3DTilesSelection/src/TilesetHeightQuery.h Outdated Show resolved Hide resolved
Comment on lines 16 to 22
* @brief The positions and sampled heights.
*
* The longitudes and latitudes will match the values at the same index in the
* original input positions. Each height will either be the height sampled
* from the tileset at that position, or the original input height if the
* height could not be sampled. To determine which, look at the value of
* {@link SampleHeightResult::heightSampled} at the same index.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @brief The positions and sampled heights.
*
* The longitudes and latitudes will match the values at the same index in the
* original input positions. Each height will either be the height sampled
* from the tileset at that position, or the original input height if the
* height could not be sampled. To determine which, look at the value of
* {@link SampleHeightResult::heightSampled} at the same index.
* @brief The positions and their sampled heights.
*
* 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
* {@link SampleHeightResult::sampleSuccessful} at the same index.

@j9liu
Copy link
Contributor

j9liu commented Sep 26, 2024

One thing I noticed while testing CesiumGS/cesium-unreal#1421: if the tileset is invalid (e.g., invalid ion asset ID), it never completes the async action, and the "Height requests could not complete because the tileset failed to load." message never gets printed. It doesn't have to hold up this PR, since we're low on time, but I think we should address it shortly after, since it will be confusing to the user to not have feedback.

@kring
Copy link
Member

kring commented Sep 27, 2024

if the tileset is invalid (e.g., invalid ion asset ID), it never completes the async action, and the "Height requests could not complete because the tileset failed to load." message never gets printed

I believe I fixed this in this commit, but cesium-unreal wasn't updated to use it yet:
4850751

I'll write a test in cesium-native for this case, though.

@kring
Copy link
Member

kring commented Sep 27, 2024

Thanks for the review @j9liu, this should be ready for another look.

@j9liu
Copy link
Contributor

j9liu commented Sep 27, 2024

Looks great, thanks @kring ! 😄

@j9liu j9liu merged commit f646271 into main Sep 27, 2024
24 checks passed
@j9liu j9liu deleted the height-query branch September 27, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a function to compute the terrain height at a point
6 participants