Dad72
April 20, 2023, 8:56pm
1
I wanted to try this new Havok physics engine which is an incredible engine. But my first try failed.
Maybe I rushed too quickly and not everything was deployed.
I get an error here:
const havok = new BABYLON.HavokPlugin(true); // Error hpInjection
scene.enablePhysics(new BABYLON.Vector3(0, -9.81, 0), havok);
I added the file: HavokPhysics_umd.js
And I have this error :
caught (in promise) ReferenceError: HK is not defined
at new HavokPlugin (babylon.max.js?1682022887:218628:39)
Dad72
April 20, 2023, 9:13pm
3
Yes, I added it locally from the zip
it has to go first. can you share a repro?
Dad72
April 20, 2023, 9:16pm
7
In the playground it works.
I saw this on the forum: Should I also add this?
globalThis.HK = await HavokPhysics();
Maybe that’s my oversight. Because it is not indicated in the documentation that this must be added.
That should not be the case. @Cedric @carolhmj @RaananW
In the meantime please use your hack (to define HK). We will fix that asap
2 Likes
Is there no node
-ish way to add Havok atm?
edit: Found @babylonjs /Havok - I assume that’s it?
2 Likes
import { Engine } from "@babylonjs/core/Engines/engine";
import { Scene } from "@babylonjs/core/scene";
import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";
import { Quaternion, Vector3 } from "@babylonjs/core/Maths/math.vector";
import { HemisphericLight } from "@babylonjs/core/Lights/hemisphericLight";
import { CreateSphere } from "@babylonjs/core/Meshes/Builders/sphereBuilder";
import { CreateGround } from "@babylonjs/core/Meshes/Builders/groundBuilder";
import "@babylonjs/core/Physics/physicsEngineComponent";
// If you don't need the standard material you will still need to import it since the scene requires it.
import "@babylonjs/core/Materials/standardMaterial";
import { CreateSceneClass } from "../createScene";
import { havokModule } from "../externals/havok";
import { PhysicsShapeBox, PhysicsShapeSphere } from "@babylonjs/core/Physics/v2/physicsShape";
import { PhysicsBody } from "@babylonjs/core/Physics/v2/physicsBody";
import { PhysicsMotionType } from "@babylonjs/core/Physics/v2/IPhysicsEnginePlugin";
import { HavokPlugin } from "@babylonjs/core/Physics/v2/Plugins/havokPlugin";
class PhysicsSceneWithAmmo implements CreateSceneClass {
preTasks = [havokModule];
This file has been truncated. show original
You can see an example here
there is no change though - it still says
ReferenceError
HK is not defined
Call Stack
new HavokPlugin
vendors-node_modules_qoretechnologies_reqore_dist_index_js-node_modules_storybook_addon-actio-12a578.iframe.bundle.js:427451:61
StorybookGameHandler._setupEngine
main.iframe.bundle.js:152:101
Do I need to import the HavokPlugin
from @babylonjs/core
or HavokPhysics
from @babylonjs/havok
?
Check the code example, it will explain everything.
I’ll write the full docs tomorrow
You need to initialize the engine and pass it as a variable to the plugin itself. Second variable.
Full docs tomorrow, promised
1 Like
Dad72
April 20, 2023, 11:23pm
17
I corrected it like this at home :
async createScene()
{
...
const gravity = new BABYLON.Vector3(0, -10, 0);
const hk = await HavokPhysics();
const babylonPlugin = new BABYLON.HavokPlugin(true, hk);
scene.enablePhysics(gravity, babylonPlugin);
}
add the HavokPhysics_umd.js and HavokPhysics.wasm files in the same directory locally
And in the htaccess file I put
AddType application/wasm wasm
And it works
8 Likes