Anyone used the havok physics engine for three?

Moderation scrolling past this thread on the list, assuming all these new posts are a part of a heated, constructive discussion about which physics engine is working best with three.js (it’s ammo.js ofc.)

4 Likes

someone is really missing his green color

Yes, I hate the api design of babylon.js.

Thanks for sharing the great project!

All the merits goes to the author. To bridge all features of Havok or physX with Javascript is not a piece of cake. And seem it’s actively worked on, now updated to officialy include Cannon-es
( give this person some github stars :grin:)

3 Likes

I’ve recently made another demo using Havok. It was quite fun, but the lack of an official documentation is definitely a noticeable limitation. At least, I couldn’t find any (at the time of writing), even a minimalistic one like Ammo’s, so if anyone has more luck with that, please share, it would be much appreciated!

I haven’t tried Rapier nor Oimo or Cannon (yet), but working with Havok feels quite similar to working with Ammo. In some cases even nicer 'cause it has these neat HP_Body_SetMassProperties and HP_Shape_SetMaterial methods based on body’s pointer and body’s shape pointer respectively.

Oh, there’s also an issue with camera’s near clipping plane when used with three.js > 0.150.1. It causes all physics bodies to disappear when too close to the camera. I haven’t figured out why though yet, so I just used v. 0.150.1.

Anyway, for anyone interested, here are some links to this mini-project:
GitHub
Live Demo

It’s based on N8python’s havokDemo, so kudos to that!

3 Likes

The disappearing object thing might just be a frustum culling issue on the instanced objects. You might just need to set frustumCulled = false on your InstancedMeshes.

1 Like

Thanks for your suggestion, @manthrax! :heart:
I will definitely check that as soon as I find some time to get back to this.

P.S.: I forgot to mention that at the moment, the best way to experiment with Havok in three.js, beside console.logging the engine instance to check all available methods in it, is to “reverse engineer” Babylon’s APIs and abstractions in order to adapt them for three.js. At least that worked quite well for me. Here are some useful links:

Simple SceneHavokPlugin & PhysicsAggregatePhysicsEnginePhysicsBody

1 Like

Hello, I’m playing with Havok in Three.js myself right now. Is there any documentation for the havok methods? I’ve been trying to use just reverse engineer with no documentation but am struggling, right now I’m attempting to get my ball to have some restitution and mass. It’s a sphere which has default physics from HP_Shape_CreateSphere and moves with HP_Body_ApplyImpulse, but I don’t quite understand HP_Shape_SetMaterial which when I looked in the Babylon.js forums seems to be the likely function for applying restitution and mass so I can add some bounce.

Any ideas? This is the only place I found someone else using three.js that mentioned HP_Shape_SetMaterial was you in this thread. I’ve actually looked at your demo before as well and didn’t notice that your ball bounced when you dropped it before.

Thanks for the demo/code.
I played around with your code and Havoc feels about 2 times faster than Rapier on a big amount of items (~8000 boxes). Honestly, I didn’t make a fair comparison, so maybe it’s just me.

Also, in your demo, if you set a big amount of boxes, and do noting (remove the falling ball), and wait about 10 seconds, Havoc does some optimizations, and fps grows twice (I assume it sends physic bodies to sleep).


Besides, there are few things that bothering me in Rapier and I’d like to know if it’s the same in havoc.

  1. Rapier doesn’t have any kind of “grid”, so all objects in scene are calculated against each other. No way to tell it not to calculate agains distant objects in another cell.

  2. Rapier wasn’t designed in mind with dynamically add/remove objects to the physics scene. Means, if you removed object from a physical world, you cannot add it again, just create a new one instead. It maks things a bit complex due to memory references, especially in wasm version.

But of course, the main question – if they are planning to add a documentation. And when

1 Like

Hey! Sorry for the late reply, I didn’t get any notification for some reason. You’re right about HP_Shape_SetMaterial, it can set restitution proprieties indeed. As for applying the mass, I think you need to use HP_Body_SetMassProperties, at least it worked in my case. Here are some lines where I’ve set those proprieties in my demo. Check also the commented ones since they might give you a hint about additional material proprieties you might need. Sorry, I still haven’t found any extensive documentation about Havok Engine APIs…, not that I’ve been looking into it in the last year, tbh. :smile:

Setting Mass & Restitution Proprieties

All good questions, but unfortunately, I have answers to none of them. :smile:
The only thing I wanted to point out is that I think you’ve right about better performance in Havok due to the fact that bodies go to sleep after some time. I remember reading this feature was present in Havok and PhysX, but missing in Rapier and Ammo.js, even I’m not 100% sure about the last one, it’s been a while I saw that post…, but it makes sense if you think about it 'cause Bullet is more general purpose and wasn’t designed with game physics in mind.

1 Like

Both ammo and rapier have sleeping in the simulation.
But the hueristics they use for putting things to sleep may vary, and the techniques used for integration vary as well, which can in turn affect how effectively bodies can be put to sleep.

In my limited experience, havok is tuned for slightly less realism, for the sake of stability and performance, so it might be more aggressive in putting objects to sleep.

Another cool physics engine to check out is Jolt.

https://136.24.178.125/JoltPhysics.js/Examples/index.html

We have lots of good options nowadays.