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

@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

will you be able to share a project that requires copying the wasm to a different directory? This should be solved by your build tool so I will be interested in trying out the build tool you are using and see how it can be fixed better.

Yeah, just knowing general things such as the road map for cloth sim, maybe fluid sim, and the height field shape types would be great to know about in advance. For the moment, I’m thinking just running fluid and cloth sims on a compute shader that can take values fed to it from a cpu side program that reads out havok physics body properties is the way to go.

Just to clarify, vite does the “right” thing when you do a production build, but somehow doesn’t detect it properly when running in “dev” (aka hot reload) mode.

Reviving this…does the above work for you when running in dev mode? I tried half a dozen variations of this, and for whatever reason the wasm model would not copy over in dev mode.

I have no clue how vite works internally but maybe @samuelgirardin has a nice workaround for it ?

Hey sorry, late response, hiking … As I said before, I do not investigate further. I just did a very quick test with the git repo above, and by copying HavokPhysics.wasm to yourproject\node_modules.vite\deps solve the issue I think. HavokPhysics is correctly downloaded and initialized versus the original git repo. (npm run dev)