question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

camera.flyTo goes underground

See original GitHub issue

camera.flyTo ends up underground in a location where the globe does not have a height.

The expected result is that that camera flys to 100 meters above the ground at the given location and the vehicle is visible on the surface of the ground.

Sandcastle example

Browser: Chrome 103.0.5060.114

Operating System: MacOS

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
lilleysecommented, Jul 19, 2022

@j9liu is going to open a PR with the fix mentioned above so that ModelExperimental behaves like Model, but there’s still a separate underlying issue.

0reactions
sanjeetsuhagcommented, Aug 3, 2022

Here’s some of my notes on this issue so far.

How does <tt>HeightReference</tt> work with <tt>ModelGraphics</tt>?
  1. When the Entity is created, the ModelGraphics object can be assigned a HeightReference.
  2. Per-tick, the DataSourceDisplay calls the update function of each Visualizer, including ModelVisualizer. This is where the Model/ModelExperimental object is initialized and all relevant properties are propagated, including heightReference. The heightRefence is not passed into the constructor, instead, the public setter for the value is used.
  3. Per-tick flow for ModelExperimental.update:
    • updateClamping
      • Check if _heightDirty, which can be set by any of the following:
        1. heightReference public setter is used
        2. scene.terrainProviderChanged event is raised
        3. getUpdateHeightCallback is called
      • The cartographic position of the model is computed
      • The getUpdateHeightCallback is registered with the QuadtreePrimitive.updateHeight function to be called (from the endFrame function of QuadtreePrimitive) whenever a new tile is rendered that contains the cartographic position of the model. The value returned from updateHeight is a function to be called to remove this callback from being called whenever updateHeight is called.
      • A new Cartesian3 position is computed from the the current height for the cartographic position of the model, which is obtained from globe.getHeight.
      • The getUpdateHeightCallback is called.
        • The model._clampedModelMatrix is updated with the new position.
        • The model._heightDirty flag is set.
    • The updateBoundingSphereAndScale updates the bounding sphere from model._clampedModelMatrix.
    • The updateReferenceMatrices updates all relevant matrices from model._clampedModelMatrix.
How does flyTo work with an Entity with ModelGraphics with HeightReference?
  • The zoomToOrFly function cancels any existing zoom and assigns a new Viewer._zoomTarget.
  • Per-tick flow for the Viewer._postRender function:
    • If the _zoomTarget is an array of entities, loop through all the entities.
      • Check the DataSourceDisplay.getBoundingSphere for the entity and see if the state is BoundingSphereState.DONE. If it is BoundingSphereState.PENDING, the function returns.
    • Compute the bouding sphere from the combination of bounding sphere of all entities.
    • Clear the current zoom in flight.
    • Call camera.flyToBoundingSphere.

Why does flyTo go under the ground when called for an Entity with ModelGraphics with HeightReference?

If the camera is far away, the bounding sphere computed for Model/ModelExperimental will be based on the lower LOD terrain tile. This initial position computed will be enough to complete the updateZoomTarget function called in Viewer._postRender. Essentially, there’s no correction for the recomputation of the bounding sphere based on the higher LOD tiles loading during the flight of the camera to the initial position.

Potential Fix 1: Store the current target bounding spheres that are being flown to and in the per-tick update of Viewer, check if they have been updated. If so, update the bounding sphere the camera is flying to. The issue here is that there needs to be some sort of termination condition i.e. at some distance, we’re close enough stop receiving height update and finish the promise. I tried implementing this one and it seems kinda clunky. Having to cancel and begin a new camera flight doesn’t look very nice.

Potential Fix 2: Compute an estimate of the bounding sphere in the model that uses sampleHeightMostDetailed and use this as the initial bounding sphere for the flyTo function. This is the one I am currently pursuing. The code changes here are so far limited to ModelVisualizer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Camera go underground after camera.flyto() complete
I use camera.flyTo(), and then tilt the camera, the view goes underground. (even in the sandcastle Camera example, I met the same problem)....
Read more >
When the camera flies into the ground, it will automatically fly ...
I set a camera to fly to the ground, after a few seconds after the camera will ... is loaded in or the...
Read more >
KML viewer.flyTo placemark goes underground #4327 - GitHub
Using viewer.flyTo for a pin created by this KML file results in the camera going under ground. var viewer = new Cesium.
Read more >
This tiny camera can show the world from a bug's point of view
Steerable arm helps save energy while capturing panoramic views Read the research: https://scim.ag/3fVOotOCreditproducerMeagan ...
Read more >
ALL 80 Lumenspar Locations (SUPER DETAILED) - YouTube
ALL 80 Lumenspar Locations (SUPER DETAILED) | The Chasm: Underground Mines |【Genshin Impact】 · Chapters. View all · Chapters · Description.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found