steelx
April 22, 2023, 1:08pm
1
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
steelx
April 22, 2023, 1:21pm
3
Hi,
I’m also using vite.
But seems the import itself doesn’t work
steelx
April 22, 2023, 1:23pm
4
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
2 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
steelx
April 22, 2023, 2:25pm
7
@samuelgirardin thanks this worked
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;
}
``
steelx
April 22, 2023, 2:48pm
8
@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?
Raggar
April 23, 2023, 12:08am
11
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
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
6 Likes
@thomasaull My Hero! that worked a treat!
1 Like
No, there is none. But I think I should create one.
1 Like