Custom polyhedra mesh collider

Hi, I’ve been playing with the various polyhedra that are out there and they are amazing. The MeshCollider works out of the box with all predefined shapes.

One of the shapes that was missing for me was a variant of the pentagonal dipyramid, so I took a stab at implementing that myself with custom vertex info.

It looks as what I want, but the MeshCollider behaves very odd on the shape, so I feel like I’m missing something.

This is my playground example: Babylon.js Playground

The d12 and d20 work as expected, but the d10 bounces in a very strange fashion. Also when I give no angular velocity it just stays on its point instead of rolling over.

Hey @Kruptein. Haven’t done any physics with BabylonJS yet, but you got me curious so took a quick look at your code. Couldn’t see anything obvious so modified values to get bit more predicable behaviour, thinking it might be easy to see what’s going on.

https://playground.babylonjs.com/#NQXR4F#2

From what I can tell, it seems that weight is not distributed correctly during simulation. Is there a way you can change the centre of gravity somehow? It looks like it is currently at the tip of the mesh, which perhaps would explain weird turbulence from your first example.

Well one thing I did notice in the meanwhile, is that if I go to the inspector and enable ‘physics’.
The wireframe is completely off for all shapes, so maybe I’m doing something wrong there as well. :confused:

Not sure if I am helping with this but see the object center in the alert. https://playground.babylonjs.com/#NQXR4F#4

Yeah that doesn’t seem right…

Perhaps a material issue. Check this out.
https://playground.babylonjs.com/#NQXR4F#7
It looks much better but for sure there is problem how forces are applied. It seems like the tip of the dice is like 100x heavier than the rest of the dice.

I would try to focus on fixing that center of the object. Shouldn’t that be (0,0,0) in local object space?

The physics debug wireframe thingy is also completely off for the d20, so unsure if I need to first do a certain operation on the meshcollider as well to “sync” it with the base mesh

:thinking: :man_shrugging: No idea… That center of gravity is my best guess. But I would try my luck with @Evgeni_Popov or @labris perhaps. Alternatively search through this forum for someone who dealt with physics and mention them in this thread perhaps or msg directly. Sorry couldn’t help more… :disappointed:

Hey all help is appreciated!

1 Like

Adding @Cedric as this seems to be a physics problem: the mesh looks ok to me, normals are ok. I tried to set flat: false when creating the shape to have smooth normals but it does not fix the problem.

Use a convex hull as it applies particularly well with the dice mesh. Then, center your vertex position around 0 so forces distribution will work better (and transform will be at the center of the mesh). And that’s it!

dice test | Babylon.js Playground

5 Likes

I’m speechless… :bowing_man:

1 Like

Super, thanks cedric :bowing_man:

2 Likes

@Kruptein Have you seen this playground demo?

Came across it trying to fix something in my project, It doesn’t help me but instantly thought of your thread. Demo uses Polyhedron/polyhedra.js from babylon extensions. Perhaps it has “dice” you can use. :wink:

Hey thanks for the recommendation, but I had already found that page yeah :stuck_out_tongue: sadly the shape I want isn’t in there :smiley: