Ammo.JS Not Properly Loaded On Playground

Hey @Deltakosh … It seems that our Playgrounds (Both JS and TS) do not have Ammo.JS properly loaded on the page.

There is now valid Ammo.btVector3 class on playground:

1 Like

this is why you did the PR. I get it now :slight_smile:

I see the problem… We are not Initializing Ammo correctly on the playground as well.

we need to call Ammo().then() after the DOMContentLoaded and before our main function that kicks of the playground.

In my projects… the defaultSceneLoader function kicks off things on the page (Actually loads the scene).

I handle like this:

window.addEventListener("DOMContentLoaded", function() {
            if (enablephysics === true && window.Ammo !== undefined) {
                Ammo().then(function() { defaultSceneLoader(scenepath, scenename); });
            } else {
                defaultSceneLoader(scenepath, scenename);

we need to add something like:


Can you please apply that to index.html and ts.html of the playground project… If i knew what function actually kicks off the playground, i would make the PR myself :slight_smile:

1 Like

Yo @trevordev … What do you think ???

Just to understand better, Ammo initializes async, and you want to start with scene creation only after ammo was initialized. Is that correct?

I dont think Ammo.JS will work at all they way it is currently loaded on the playground. According to Ammo.js docs (I read somewhere) you have to use then to init the lib. Just including it on the page with a script tag does not work.

Just try to create an instance of ANY Ammo class… Like:

var btv = new Ammo.btVector3(0,0,0);

You will get an error.

I hacked a tiny work around for a test playground. But it should only be handled once on the host page.

public static async CreateScene(engine: BABYLON.Engine, canvas: HTMLCanvasElement): Promise<BABYLON.Scene> {
        // This creates a basic scene object (non-mesh)
        var scene = new BABYLON.Scene(engine);

        // This creates a temp camera object (non-mesh)
        // var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
        // camera.setTarget(BABYLON.Vector3.Zero());

        // This initializes bullet physics (non-mesh)
        const wnd:any = window;
        if (!wnd.ammoLoaded) {
                wnd.ammoLoaded = true;
        } else {

        // This save current scene for debugging
        (<any>window).scene = scene;
        return scene;

    public static async LoadScene(scene:BABYLON.Scene):Promise<void> {

Yep it needs to be initialized so I think what you are dooing seems fine, you can see how it is done in the ammoJS plugin