Accomplished: Rendering with BabylonJS (Single WebGL context!)

This works, and is only a proof of concept, but it works!

Cesium is never passed a webgl context and never makes a viewer object. It does not do the multiple-canvas method, or other work arounds like that.

Babylon is in charge of the render loop, and timing of cesium processing loop. Tile/Map glb are loaded into babylon context, and fully interactable in babylon.

Main code creates a framestate and cesiumcamera based on babyloncamera values, so cesium has all the data it needs to process and manage the state of tiles.

Try it yourself! I’ve got the demo published to my list of demos. Demo here: Cesium with Babylon.js

Keys:

F - Show frustum

B - Show tile bounding sphere volumes

Space - Pause cesium updates, to examine the scene “third person view”

GitHub - techtruth/cesium_in_babylon at mars – Here is the source. Its on the mars branch, not the main branch.

I’ve seen this asked around the forums for years, and I think this is a promising start. Code posted below.

The real obstacle here was the DynamicEnvironmentMapManager - Cesium Documentation – it requires a webgl context to initialize, and is in the constructor of the native 3dtileset class. I’ll work up a PR to cesium so that can be made optionally.

The camera rotation in this is not very pretty, so I have disabled mouse-based movement. Apparently babylon’s universalcamera’s mouse controls have their own idea of “up” that is different than the camera’s up. But that just makes it ugly, not bad :smiley:

Happy to answer questions or collaborate on this.

PS - Please don’t kill my quota by visiting the demo site too much… I already killed my quota last month and would like to keep developing this month!

2 Likes

PR created here: Optional dynamic environment map manager by techtruth · Pull Request #13077 · CesiumGS/cesium · GitHub

This will allow me to not extract-hack the cesium 3dtilesets. It creates a WebGL-requiring component in the 3dtileset constructor, and it prevents easy integration where cesium doesn’t need a WebGL context.

I felt the mars demo was a bit too constrained… so I made a better controls interface for the camera in babylon. Its a 5.5 degree of freedom keyset WASD/QE and IJKL/UO. This is a much better experience, as far as a demo goes. (5.5 DoF because forward and backward are replaced with Q/E keys, being that they are boosts to the motion and rotation keys)

This is much more ‘feelable’ than the mars demo I think. :slight_smile: Hint: The higher you are, the faster you go.

I am struggling a bit, and needed to make the cesium frustum almost double the babylon frustum, so that there wouldn’t be gaps in the edges of the view. I suspect it has something to do with the motion culling cesium does.

1 Like