If I attempt to load a BABYLON.Sound using a NullEngine in a WebWorker, I get the error “Oe.a.audioEngine is undefined”. Is this expected behavior?
Obviously the sound isn’t actually doing anything here, but for simplicity the webworker has some code copied from the main window thread and it’d be nice not to have to create a separate version safe for this webworker context.
As a bit of background, this WebWorker is responsible for creating custom meshes in the background to avoid freezing the world.
I know this is a bit of an odd use-case, and obviously isn’t vital, just wanted to clarify on expected behavior.
I have not looked at sound.ts in a while, but I think this is not going to work. Web audio uses a context, just like Webgl. Even if this did load, it cannot be transferred to a different context, especially if it needs to be decoded, like a mp3.
You might be able to just get the file, and transfer that. I would do nothing. Down loading occurs on its own thread. Web audio also runs on its own thread. No reason to really do this, I think.
I don’t think I phrased this one particularly well, sorry! I’m just getting my head around contexts & shared-workers myself (in truth, I think I’ve taken on far too big a project for my first time with Babylon).
Basically I just thought a NullEngine would be like a headless version of Babylon, and we could make all the same calls even though they may essentially be ‘ignored’ and nothing happens. Since it doesn’t look like this is the case when it comes to audio, I’ll make a separate version of the code to run on the webworker stripped of all non-essential stuff (a few sound effects) that was only there for the main thread.
I think you can do it. All the rest of us can do is learn with you.
I actually don’t know what a NullEngine entails, that’s a good question.
A reluctance to turn over I imagine.
Do you want to hold on to the audio slug until the last moment? I need further study of unpackaging audio formats. I once proposed an album format before DRM
That’s the basic idea behind the null engine. But sometimes context is needed and if it’s missing in the environment you are working at you will need to either emulate it or mock it for Babylon to work.