VirtualSky
VirtualSky copied to clipboard
How to know when planetarium is ready?
How can I know when everything is loaded and I can access all objects? (specifically, planets).
Document being ready is not enough, it's ready before planetarium loading is completed, so console.log("planetarium.planets", planetarium.planets);
will result in "undefined". (being planetarium = S.virtualsky)
I see a "loadedPlanets" event triggered , but how can I detect it?
https://github.com/slowe/VirtualSky/blob/8632b5ce8174578f4f104b7d6de00e9aeda95b39/virtualsky.js#L1248
Unfortunately, I don't know if there is a better way, but my solution was to add hooks to VirtualSky: https://github.com/meNeither/VirtualSky/blob/starlitter/virtualsky.js#L310
After that, the following is possible:
(function(S){
function mainLoop() {
// …
}
S.virtualsky.hooks.startClip.push({
init: mainLoop,
name: 'mainLoop',
version: '1.0'
});
})(S);