cesium
cesium copied to clipboard
Scene ready event
This is something frequently requested on the forum. Users would like an event that is fired when the scene is fully loaded.
https://groups.google.com/forum/?hl=en#!topic/cesium-dev/FTHsjxL8rS4
We have a bit of a start for this but its just for 3D Tiles at the moment: https://github.com/AnalyticalGraphicsInc/cesium/pull/4405.
Yes, this would be great!
Agreed this would be very useful!
FYI, some of our apps use the below logic to detect this. We can probably tweak the code and have it work out of the box in CesiumJS. The main issue is that there is primitive-level way to detect if the primitive is "done" so we have to specifically track and check 3D Tiles tilesets. It would be easier to have a clearly defined Primitive API to make this easy to do.
const viewer = this._viewer;
const tilesets = this._tilesetCollection;
const surface = viewer.scene.globe._surface;
//A rather obtuse check to see if Entity geometry is complete. (CZML/KML/GeoJSON)
const entitiesComplete = viewer.clockViewModel.canAnimate;
let complete =
entitiesComplete &&
viewer.scene.globe.tilesLoaded &&
surface._debug.tilesWaitingForChildren === 0 &&
RequestScheduler.statistics.numberOfActiveRequests === 0;
//If not, check all of the 3D tilesets.
if (complete) {
const length = tilesets.length;
for (let i = 0; i < length; i++) {
const tileset = tilesets.get(i);
complete = tileset.tilesLoaded;
if (!complete) {
break;
}
}
}
A related request same in at https://community.cesium.com/t/events-to-track-bulk-polygon-loading-triangulation-complete/25944 specifically for geometry. I provided workaround (below). The same data that drives canAnimate can also support a viewer level property for indicating geometry completeness. (But this only works for the entity API)
await new Promise((resolve) => {
const removeEvent = viewer.scene.postRender.addEventListener(() => {
if (viewer.clockViewModel.canAnimate) {
removeEvent();
resolve();
}
});
});