VirtualSky icon indicating copy to clipboard operation
VirtualSky copied to clipboard

How to know when planetarium is ready?

Open jumpjack opened this issue 2 years ago • 2 comments

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)

jumpjack avatar Oct 04 '22 10:10 jumpjack

I see a "loadedPlanets" event triggered , but how can I detect it?

https://github.com/slowe/VirtualSky/blob/8632b5ce8174578f4f104b7d6de00e9aeda95b39/virtualsky.js#L1248

jumpjack avatar Oct 04 '22 11:10 jumpjack

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);

meNeither avatar Oct 08 '22 13:10 meNeither