Forbid camera access below 3DTiles

Acoording to this official example, due to that 3dtiles are not fit perfectly into the terrain, the camera may move under 3dtiles, So is there any ways to forbid this behavior?

Out of the box, probably not, but writing a small handler that 1) checks camera position (maybe on the Cesium render event), and b) sets it to whatever limit (ie. if lower than limit, set it to that limit to force it to that bottom limit), should be easy enough. The trick is to know the height of that limit. Some clouds come with an accurate min and max (so, for example, so I’d pick that plus a meter or so, but if you haven’t got it you could attempt to sample a few points and take the lower values as a guide.



@Alexander_Johannesen Thanks for relpy, it inspired me. I will try it.

@Alexander_Johannesen Hi Alex

I made it finally with height test of camera. But as I was being happy with the result, I also found a issue that if viewer.trackedEntity is not undefined, the height of camera will be a -637XXXX which seemed to minus 6378*1000 which is radius of the earth.

So I change height to 20 - 6378000 if something is being tracked. But I found that when height changed, the distance, the level of map aslo changed so that the transition is very abrupt.

I think it might be better to not set the camera height on a tracked item, no? So, if ( viewer.trackedEntity ) { return; } just don’t do anything as the camera follows? Or do you still want to prohibit the camera to go below when tracked as well? For tracked entities I think it’s smarter to get the height of the entity, and use that to offset the camera height instead of a fixed value.




But, I have to add limit for camera when entity is tracked. It’s too easy to see from below, just drag the mouse:

And I didn’t understand this very well, could you show me some code please?


You can’t set a camera position of a tracked entity, as there’s a controller for the camera now that will interfere with your forced values. If you want to control the movements of the camera of a tracked entity, I suggest you don’t use the Cesium tracker, but make your own that you can control. You hook into the Cesium render cycle, and move the camera according to the entity the way you like it. More on this at the following links;

Own tracking; Tracked Entity + camera heading - #7 by Hyper_Sonic

Specific angle; How make camera follow tracked entity from behind?

Restrict moving around; Do not move camera when setting trackedEntity - #3 by vrana



1 Like