Issues loading Babylon at runtime

Lately I’ve been working on a Dart interop package for Babylon, and while it’s not essential, I would like to be able to load the Babylon js file from the package via code on demand at runtime.

Problem is, nothing I have tried has worked. My current method is creating a script element, setting the src, appending it to the document head and waiting for onload to fire, which works with a test script I wrote to contrast, but not with Babylon.
Adding it to the page manually via the chrome console does work, but appending it from code (dart script or js via console) does not, which has me confused. No error is generated, so it’s not that it’s a wrong url or anything…

I don’t understand enough about how the code loads normally to know exactly what’s going wrong with it, but wondered if anyone here has advice how to proceed.
Ultimately if it just can’t be done it can still be added to the page manually, so no huge loss, but that’s another step and kind of a drag.

I would assume this has something to do with the environment you are using to deploy it to. Our package has a UMD signature that “decides” for you how babylon will be injected. If Neither common JS nor AMD is available, the global namespace (window) will be populated by BABYLON (so you will have window.BABYLON) available. If, however, you have either one of the two, babylon wil be registered with them and you will need to use your package manager to load it.

It is hard to say what the issue is without seeing some code, so I hope this gets you searching in the right places

After sleeping on it and doing a little more looking into the subject from that angle, I’m thinking it might be that the dart dev compiler uses require.js to load its modular code for hot-swapping, but what confuses me is why babylon ends up in the global scope after everything including require is loaded when I uncomment it as a script tag from within chrome’s console.

And after some testing just now without the dart code in the page at all, it does, indeed, end up in the global scope when loading by script from the console… damn.

I don’t suppose there’s any way to force it to load one way or the other, is there? Require wouldn’t be there in the dart production compiler’s output.

The whole html with stuff commented out, the various tests were just with one or the other in:

<!DOCTYPE html>
<html lang="en">
        <meta charset="UTF-8">
        <title>Babylon Dart Testbed</title>

        <!--<script src="packages/CubeLib/js/babylon.js"></script>
        <script defer src="dart_testbed.dart.js" type="application/javascript"></script>-->
        <canvas id="canvas" width="800" height="600"></canvas>

The contents of the dart function which was used to load scripts, where the src resolves to /packages/CubeLib/js/babylon.js, which worked with a different test script (and presumably babylon, since there was no error):

final Completer<ScriptElement> completer = new Completer<ScriptElement>();

final ScriptElement script = new ScriptElement();
script.onLoad.listen((Event e) => completer.complete(script));
script.src = _getFullPath(path, absoluteRoot);

return completer.future;

the only way to load is without require is loading it before require is loaded. Not sure about your environment, but in the playground (for example) we are first loading the babylon files and only later the amd loader. You can also “unset” require , load babylon, and re-set it, but this is an ugly hack with (probably) a few downsides.

Fair enough, I’ll take that as an effective “no” then, since I can’t really add it via dart when the dev compiler puts require in there to load the compiled dart itself - guess it’ll just have to be added into the page manually (not really a problem, just a bit less convenient), thanks for the insight.