Cesium: Camera Controller can go underground

Created on 18 Sep 2017  路  28Comments  路  Source: CesiumGS/cesium

Move the camera while terrain is still loading in:

image

Appeared after https://github.com/AnalyticalGraphicsInc/cesium/pull/5603

Reported on the forum: https://groups.google.com/forum/#!topic/cesium-dev/50CK4haCIiw

category - camera type - bug

Most helpful comment

I think the adjustment for terrain would be better if it were invoked by the ScreenSpaceCameraController instead of the camera itself. When programmatically controlling the camera, you don't want the camera doing things you didn't tell it explicitly to do. So the responsibility is ill-placed, it should be with the user control of the camera.

Meanwhile this can fixed like so:

var viewer = new Cesium.Viewer('cesiumContainer');

viewer.camera.changed.addEventListener(
function() {
if (viewer.camera._suspendTerrainAdjustment && viewer.scene.mode === Cesium.SceneMode.SCENE3D) {
viewer.camera._suspendTerrainAdjustment = false;
viewer.camera._adjustHeightForTerrain();
}
}
);

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=jVFdS8MwFP0roQ9bC3KL+Lh2KHXiw9SHiU8FuUtut2iajHx0TPG/m64bbArieUnuyfm4kA4t6yRtybKSadqyipwMLbzsuXTM92NltEepyY6zSa1rPTiAY0sWga9Rr0gACjHrSPu5dJ6iOK01i2iC5l4anWbsc2B6yIal5zGvLrgNafFM1sayG/EWnG9jHhuNDjuC4zEYWiOIlWV5XHbRsw+RhEU1e5xd3Z419fhvU8kaVI4mf7pxr78nuVr7O2MPKWl24voarvHIJslFUji/UzQdyGvZboz1LFiVAuSe2o1CTy5fBv5OHrhzfVSRH02FkB2ToqyTH79RJ4wrdC6+NEGphfygOpkWedSf2ZRBIfXqqSOrcNdL1pfT+UACQJHH8bfLG6OWaE8SvwE

All 28 comments

Are you sure #5603 caused this? We specifically allow the camera to go underground during load because otherwise flights and abrupt camera changes wouldn't work correctly. See #4105. If this is differently, please explain how.

@mramato If this is intended behavior, I'm fine with closing this.

Please feel free to re-open if there is some additional context I'm missing. You might also want to follow up on the forum post. Thanks.

Congratulations on closing the issue! I found these Cesium forum links in the comments above:

https://groups.google.com/forum/#!topic/cesium-dev/50CK4haCIiw

If this issue affects any of these threads, please post a comment like the following:

The issue at https://github.com/AnalyticalGraphicsInc/cesium/issues/5837 has just been closed and may resolve your issue. Look for the change in the next stable release of Cesium or get it now in the master branch on GitHub https://github.com/AnalyticalGraphicsInc/cesium.

__I am a bot who helps you make Cesium awesome!__ Thanks again.

5603 absolutely caused a change in behavior.

I commented in #5603 but I'll copy it here:

The additional call to camera.setView() should not affect its position, at least according to how I understand the documentation. However, it most certainly is affecting the position as commenting out that one line fixes the problem (but leaves #4639 unresolved in some cases).

Any update on this issue?

@ZacBrownBand, no additional updates. If you could contribute a fix, or continue to narrow down what the problem is, it would help move things along and we would greatly appreciate it!

@ZacBrownBand, I created https://github.com/AnalyticalGraphicsInc/cesium/pull/6012 which also fixes this.

Reported on the forum: https://groups.google.com/forum/#!topic/cesium-dev/cPbtbShkSOQ

Reported on the forum: https://groups.google.com/forum/#!topic/cesium-dev/Sn5R5FzOr1k

Reported on the forum: https://groups.google.com/forum/#!topic/cesium-dev/TDMwlbT0xBE

Also reported by @fgamezc in #6581

Also reported by @safa833 in #6623

Also reported by @miniergouzi in #6856

Reported in this forum thread with a video and how to recreate.

Came up again in the context of navigating around a point cloud and ending up underground accidentally. I'm curious if anyone knows of any workarounds for this.

@lilleyse the problem is pretty nuanced, You can modify the end of Camera.update to always set _suspendTerrainAdjustment to false and always call _adjustHeightForTerrain and that would prevent the camera from ever going under terrain, however functions like zoomTo/FlyTo will not work as expected near the ground because they will "bump into" lower res terrain and end up at a higher altitude than desired.

We also tweaked this behavior in master to be better, so I would try that out if you aren't already.

Yeah I can see some of the tradeoffs.

That workaround is good for the case I'm describing. It would be nice if the camera could apply terrain adjustment if being acted upon by the user but otherwise not. The details may be more complicated than that though.

I think the adjustment for terrain would be better if it were invoked by the ScreenSpaceCameraController instead of the camera itself. When programmatically controlling the camera, you don't want the camera doing things you didn't tell it explicitly to do. So the responsibility is ill-placed, it should be with the user control of the camera.

Meanwhile this can fixed like so:

var viewer = new Cesium.Viewer('cesiumContainer');

viewer.camera.changed.addEventListener(
function() {
if (viewer.camera._suspendTerrainAdjustment && viewer.scene.mode === Cesium.SceneMode.SCENE3D) {
viewer.camera._suspendTerrainAdjustment = false;
viewer.camera._adjustHeightForTerrain();
}
}
);

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=jVFdS8MwFP0roQ9bC3KL+Lh2KHXiw9SHiU8FuUtut2iajHx0TPG/m64bbArieUnuyfm4kA4t6yRtybKSadqyipwMLbzsuXTM92NltEepyY6zSa1rPTiAY0sWga9Rr0gACjHrSPu5dJ6iOK01i2iC5l4anWbsc2B6yIal5zGvLrgNafFM1sayG/EWnG9jHhuNDjuC4zEYWiOIlWV5XHbRsw+RhEU1e5xd3Z419fhvU8kaVI4mf7pxr78nuVr7O2MPKWl24voarvHIJslFUji/UzQdyGvZboz1LFiVAuSe2o1CTy5fBv5OHrhzfVSRH02FkB2ToqyTH79RJ4wrdC6+NEGphfygOpkWedSf2ZRBIfXqqSOrcNdL1pfT+UACQJHH8bfLG6OWaE8SvwE

@bmr74

This problem occurs when the mouse pulley is indented.

64b0euqw67k nrt d alm 9

@miniergouzi my fix should help, but is not a complete solution. You can still go under the terrain, it just recovers much faster. One thing I did was to also limit the pitch, which is fine for my particular application. You could also add a min zoom distance, if that is acceptable in your application.

I can't see the full stack trace and I have not seen that problem. What browser/version are you using? Can you provide the complete stack trace?

https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/#c=rVRdb5swFP0rVh5akDqTrW8Fok1Zpk1rl6qJuhekyIFL8GZsZBu6fuS/zwYSAmmrappfMJdzju8995qKSFRRuAOJQsThDk1B0TLHt3XMOY3r16ngmlAO8tT1Ix7xyrByyq+pjjPDe9eSrojO8PW31fx2drNa/pz7LZL82SHH/p78Fegm0yb2YTxuROsjcUxykATHGeEbSDBJklkFXF9SpcFk4EQcmZWWPNZUcMdFj03ELpoipy+zUqUqgCdLkNJU8Cn5VSqdGz10ctIWjlVshHEuEkBhGO4cWNjolQnixXT2Y3b+uXeSXW89KUQpYQr8V9mkxjemfBGyVXHcA9a223Y7z0PfAQrU6CDKEUESiBKcrBmgojZeWi87ju1A0Xakn0YdrbtxaGmDnXSNfHpq+cF+DF5ypzFXxRKALwoSw7Q+yU6UFIwZBNSZLik7dKqvZYqMGckLpLO2pP53mh7naBJCfZRdu7J3MH+A2SIwCXSCrxTYk2tBgx5vh4VY5xNQmnJipxftp21KpDY7ws9xKkV+QxKzV87xiYN+CUWtkKWLjSRFRmPMBN9QXSZw9m90k9oL7PqCG+ucN8hk9SifdVfddY/62pdRoO1vx3nG5wPPLg5fnslRSGouXQt9bDp00TZqO2iP6/+PmdWyhONrah6uPzobBUrfM5g0wY80L4TUqJTMwdjTkBfGblDeuox/g8axUjanwNuRgoRWiCZhNBr8iaORvRJKmS9pydiCPkA0mgSewfdoTJhR4pt5BZKRewvJ3k8umyDGOPDM6zFLC8HWRB4o/gU

viewer.camera.changed.addEventListener(
function() {
if (viewer.camera._suspendTerrainAdjustment && viewer.scene.mode === Cesium.SceneMode.SCENE3D) {
viewer.camera._suspendTerrainAdjustment = false;
viewer.camera._adjustHeightForTerrain();
}
}
);

That's work great! it fix the problem.

I'm still able to get the camera to go under the terrain in Cesium v1.55. Is the fix mentioned by @bmr74 going to be permanent? Seems incorrect to use 'private' class members.

Also see this error occur using @bmr74 workaround

seems to only happen when

if (viewer.camera._suspendTerrainAdjustment && viewer.scene.mode === Cesium.SceneMode.SCENE3D)

is added

TypeError: Cannot read property 'southwest' of undefined
TypeError: Cannot read property 'southwest' of undefined
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154816:40)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154839:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154843:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154843:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154837:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154843:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154844:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154837:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154843:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154837:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154837:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154830:9)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154837:7)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154824:9)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154824:9)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154830:9)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)
at visitIfVisible (http://192.168.56.4:3000/static/js/17.chunk.js:154859:14)
at visitVisibleChildrenNearToFar (http://192.168.56.4:3000/static/js/17.chunk.js:154824:9)
at visitTile (http://192.168.56.4:3000/static/js/17.chunk.js:154733:7)

I still have this problem with the latest version. In the default exemple, just press the center button on a mouse, drag the mouse around, and release, you will have such a wierd view that was not at all what is intended to be.

@bmr74 your answer does work锛孲trong!

Congratulations on closing the issue! I found these Cesium forum links in the comments above:

https://groups.google.com/forum/#!topic/cesium-dev/50CK4haCIiw
https://groups.google.com/forum/#!topic/cesium-dev/cPbtbShkSOQ
https://groups.google.com/forum/#!topic/cesium-dev/Sn5R5FzOr1k
https://groups.google.com/forum/#!topic/cesium-dev/TDMwlbT0xBE
https://groups.google.com/d/msg/cesium-dev/Mq4i8gC6eAE/-jeRGSn6CAAJ

If this issue affects any of these threads, please post a comment like the following:

The issue at https://github.com/AnalyticalGraphicsInc/cesium/issues/5837 has just been closed and may resolve your issue. Look for the change in the next stable release of Cesium or get it now in the master branch on GitHub https://github.com/AnalyticalGraphicsInc/cesium.

Was this page helpful?
0 / 5 - 0 ratings