I’m building a portal-esque project (for fun) - however, there is no way to create manifold modifiers w/ Havok in Babylon (to reject collision behind the portal plane). This means longer objects in the portal will collide with things behind the portal.
Would it be possible to allow for defining a collision clipping plane for rigid bodies (I think having a manifold callback would probably be too slow thanks to wasm marshalling and the like - as much as I would like to be able to!)
I don’t see a way for Havok to ignore collisions on clipped body portions directly. One idea is to filter collisions during callback based on which side of the plane the collision occur.
From within the collision callback, reset or offset the delta position, velocity, force, and/or impulse that havok applies.
Box3D can do this now! I just shipped it in babylon-box3d 0.8.0 as a clip plane per body:
// a portal on a wall, its normal pointing out of the wall: clip what is past it
const clip = BABYLON.Plane.FromPositionAndNormal(portalCenter, portalNormal.negate());
plugin.setBodyClipPlane(body, clip, ~PORTAL_RIM >>> 0); // null turns it off
Every contact point of that body past the plane gets dropped (same side Babylon’s own clip planes hide, so you can use the same plane to cut the mesh), so the part that went into the portal passes through the wall and whatever is behind it, while the rest of the body keeps colliding. It’s done per contact point inside the physics step, meshes and height fields included, with no callback into JS, so the marshalling cost you were worried about doesn’t come into it. The optional mask lets you leave some shapes unclipped, like the edges of the portal opening, so stuff hanging over the edge still rests on them.
Demo with a floor portal and a wall portal, long planks hanging half through: Box3D for Babylon.js (press `c` to toggle clipping and see the problem it solves). Source is demo/src/portal.ts.
One thing it doesn’t do for you: the part sticking out of the exit portal before the teleport is only drawn, it doesn’t collide yet. For that you’d add a second body at the exit.
Awesome! I actually ended up binding Box3d myself to get it working, but I had to monkeypatch b3d to make it happen because the presolve callback only received one point (and actually looking at what you did, you essentially had to do the same thing!)
I love your approach and how close it ended up being to what I did! That’s really cool!
Havok has callbacks for manifold (in C++, but not exposed in Babylon today) built in IIRC (it’s been ages since I’ve worked with Havok so I’m not 100% to be honest), but I’m probably going to end up sticking with box3d as it just seems to perform better anyway.
I’m stoked to have a new Box3d user!!! I really do think its better then Havok at least so far working with it has been.
Are you using the plugin I rolled up or is its new one since you said you did your own binding? Id like to see what you did and I could probably roll that up into the box3d plugin that is documented for BJS! That way we all don’t have to have separate packs being developed when we could pool our resources.
It’s my own because I’ve been experimenting with various higher performance modes (binding to CEF vs WASM, having the player controller more implemented in C then TS, - I don’t have any constraints or joints in my setup right now and I try to minimize the number of calls into WASM by maximizing use of shared memory where I can.
I might open source it soon but it is pretty prototypey, if that makes sense.
If you end up making some features for it or other modes Id love for you to do a PR to the babylon-box3d plugin and would totally be willing to wrap any relevant work into that.