Could not find a declaration file for module '@babylonjs/havok'

even after installing “@babylonjs/havok”: “^1.0.0”, Im getting this error.

Could not find a declaration file for module '@babylonjs/havok'. '/Users/aborade/projects/javascript/babylon/bjs-parkover/node_modules/@babylonjs/havok/lib/esm/HavokPhysics_es.js' implicitly has an 'any' type.
  There are types at '/Users/aborade/projects/javascript/babylon/bjs-parkover/node_modules/@babylonjs/havok/HavokPhysics.d.ts', but this result could not be resolved when respecting package.json "exports". The '@babylonjs/havok' library may need to update its package.json or typings.

Hi , this works for me in a Vite project :

import { HavokPlugin, Scene, Vector3 } from "@babylonjs/core";
import HavokPhysics from "@babylonjs/havok";

export class Phy {
    havok: HavokPlugin;
    constructor(scene: Scene) {
        this.initEngine(scene);
    }

    async initEngine(scene: Scene) {

        const gravity = new Vector3(0, -10, 0);
        const hk = await HavokPhysics();
        this.havok = new HavokPlugin(true, hk);
        scene.enablePhysics(gravity, this.havok);
        console.log('havok',this.havok) ; 
    }
}
2 Likes

Hi,
I’m also using vite.
But seems the import itself doesn’t work

Can you share your ts config and package json file please

I forget to say , I had to copy HavokPhysics.wasm to node_modules.vite\deps

3 Likes

package.json :

{
  "name": "",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "tsc && vite build",
    "preview": "vite preview"
  },
  "devDependencies": {
    "typescript": "^4.9.3",
    "vite": "^4.1.0"
  },
  "dependencies": {
    "@babylonjs/core": "^6.0.0",
    "@babylonjs/gui": "^6.0.0",
    "@babylonjs/havok": "^1.0.0",
    "@babylonjs/inspector": "^6.0.0" 
  }
}

2 Likes

@samuelgirardin thanks this worked :slight_smile:
also if you can help me what this would become ? How to use heightmapData with new PhysicsAggregate ?

constructor(name: string, game: Game) {
super(name, game)// this is extending Mesh
const heightmapData = this.getHeightmapData(vertexData);
        // this.physicsImpostor = new PhysicsImpostor(this, PhysicsImpostor.HeightmapImpostor, { mass: 0, restitution: 0.9, heightmapData, friction: 1 }, game.scene);

        this.aggregate = new PhysicsAggregate(this, PhysicsShapeType.BOX, { mass: 0 }, game.scene);
...


...
private getHeightmapData(vertexData: VertexData): number[][] {
        const positions = vertexData.positions!;
        const subdivisions = Math.sqrt(positions.length / 3) - 1;
        const heightmapData = [];

        for (let z = 0; z <= subdivisions; z++) {
            const row = [];
            for (let x = 0; x <= subdivisions; x++) {
                const index = (x + z * (subdivisions + 1)) * 3;
                const height = positions[index + 1];
                row.push(height);
            }
            heightmapData.push(row);
        }

        return heightmapData;
    }
``

@samuelgirardin Im using Mesh type for now, not sure how heavy it is on performance. thanks again

// const heightmapData = this.getHeightmapData(vertexData);
this.aggregate = new PhysicsAggregate(this, PhysicsShapeType.MESH, { mass: 0, restitution: 0.01, friction: 1 }, game.scene);

Height fields are not yet supported by Havok as physical shapes, but they will be!

1 Like

How does it do it in the stress test then?

Do you know if there’s a roadmap of sorts for the Havok plugin? Like future feature implementations etc.

The type of the shape is “Mesh”, not “Height field”.

2 Likes

cc @Cedric

Regarding vite-config, just in case it helps anybody: I got an error when initializing the havok plugin in my project: “Uncaught (in promise) RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.”

The solution was to put:

optimizeDeps: {
  exclude: ['@babylonjs/havok'],
}

in my vite.config.ts

10 Likes

@thomasaull My Hero! that worked a treat!

1 Like

No, there is none. But I think I should create one.

1 Like

good, get it

I had the same problem…I’ve been manually doing it, do you know if there’s a way to make this happen automatically?

Hi, @Mike_Mainguy unfortunately I did not look further,

Also, to make sure it works properly when you install packages (npm install will occasionally redelete the wasm file)…add a “postinstall” script in package.json.
“postinstall”: “cp ./node_modules/@babylonjs/havok/lib/esm/HavokPhysics.wasm ./node_modules/.vite/deps”

I “thought” I had it fixed, then did production build/deploy and realized I needed this. Hours of “huh, what the heck is going on here?” Probably a newbie/obvious thing, but as a newbie…was super confusing.

1 Like