Unable to load Havok plugin (error while loading .wasm file from browser)

Hi,

I wanted to avoid manually copying the file, and I’d like to share this solution which worked for me:

1.: Call the following function in your scene initialization:


private async setupPhysics(scene: Scene) {
        // locates the wasm file copied during build process
        const havok = await HavokPhysics({
            locateFile: (file) => {
                return "assets/HavokPhysics.wasm"
            }
        });
        const gravityVector: Vector3 = new Vector3(0, -9.81, 0);
        const havokPlugin: HavokPlugin = new HavokPlugin(true, havok);
        scene.enablePhysics(gravityVector, havokPlugin);
    }

2.: Make the “HavokPhysics.wasm” file available by adding it to your Angular assets configuration:

"assets": [
              // all your other assets
              {
                "glob": "HavokPhysics.wasm",
                "input": "node_modules/@babylonjs/havok/lib/esm/",
                "output": "assets/"
              }
            ],

I hope this helps!

Cheers

4 Likes