How to get a Better Bounding Box (B^3) with curved Ribbon?

Hello friends!

I’m generating an open Ribbon mesh from a Path3D curve to make a space-road, and everything looks great (yay!). What doesn’t work so great is physics bounding box calculations (boo!). You can access the site for reproducing this here - make sure to include the query string ?testDrive unless you want to make your own route…

This screenshot shows the BB of the road for the testDrive route – you can see that because the path curves into the distance, the bounding box is far, far larger than the width of the road itself!

I’m using Ammo.js, FWIW. @RaananW @Cedric

Here’s the code that generates the route - it’s located here

calculateRouteParameters(routeData) {
        let pathPoints = => {
            return (typeof p.position !== 'Vector3' ? 
               new Vector3(p.position.x, p.position.y, p.position.z) : p)
        let path3d = new Path3D(pathPoints, new Vector3(0, 1, 0), false, false);
        let curve = path3d.getCurve();
        let displayLines = MeshBuilder.CreateLines("displayLines", 
                { points: curve }, this.scene);
        let pathA = [];
        let pathB = [];
        for (let i = 0; i < curve.length; i++) {
            let p = curve[i];
            let pA = new Vector3(p.x + 20, p.y, p.z + 20);
            let pB = new Vector3(p.x - 20, p.y, p.z - 20);
        this.path = path3d;
        this.curve = curve;
        return [pathB, curve, pathA];

So my question is three-fold:

  1. Is there something I’m doing (or not) that could cause or correct this?
  2. Is this a bug in the physics/BB computations?
  3. If the previous two are all nil, then what are some of my options to construct a BBB?

My thought is that if I had to, I suppose I could subdivide the road into multiple segments that are all more-or-less straight enough to have well-aligned bounding boxes, or I could convert the routeData into a height map and use DynamicTerrain instead of Ribbon (which is actually still using Ribbon internally lol!).

Both of those options involve no small amount of effort, so I’m hoping there’s a more simpler way to make the bounds work “correctly”.

Sorry for not having a PG, if we can determine that this isn’t something in my local setup I can try to isolate this into a PG if that is useful.

ed: yikes, maybe providing some directions might be helpful – SHIFT+ALT+I opens inspector

1 Like

Yes, nothing magic can be done here unfortunately. Well, maybe one thing:
For the physics, you don’t have to bring your whole mesh as a static body.
Maybe you can physicalize the portion around the truck and update it depending on the distance.
With 2 or 3 physic mesh, you can recycle the one that’s too far.
the road would be physicalized by small portion depending on the truck position.

1 Like

Thanks for the thoughts! I think you may be onto something -

this would allow for some interesting localized effects, like a twisted path where gravity is always normal to the velocity tangent or something!

How do you think is the best way to find the optimal size for these physics meshes?

Asking that question and thinking about updating the physics around the truck made me realize that that’s the sort of problem that Dynamic Terrain has already solved. Despite the interesting possibilities opened up, this makes me feel like maybe converting the route data to a heightmap might be the better approach in the long run?

Not sure. terrain is axis aligned (if I’m not wrong). I think it will be harder to get the curvy look and feel.

1 Like

Ok, back again – trying to set up a PG to quickly work on this problem, and I’m finding that no matter what I do, my box always falls through the ribbon!

This doesn’t happen in my local build, even after updating to the latest preview build, so not sure what’s changed.

I created a greatly simplified PG to demonstrate this frustrating behavior - I’m sure it’s something silly and small that I’m missing! Any help is appreciated :slight_smile:

No, there is something wrong with ribbon and physics. I’m adding this issue to my list.


@Cedric do we have a Github issue for it?

@carolhmj nop

I’m working on this issue. I’ll get a fix hopefully today.


PR is live Ribbon physics by CedricGuillemet · Pull Request #11404 · BabylonJS/Babylon.js · GitHub