kripken / ammo.js

Direct port of the Bullet physics engine to JavaScript using Emscripten

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need help getting underlying mesh data of rigid body

frankieali opened this issue · comments

commented

Since there's no forum for Ammo.js I'm posting a help question here.

I'm creating yet another dice roller app using many different shaped dice. After a die has stopped rolling, meaning its Linear Velocity and Angular Velocity have dropped below a certain threshold, I'm trying to calculate which face is up. I've attempted to do this with raycasting, but it does not work on the backfaces of my convexHulls. I don't want to rely on assuming the dice are laying flat either, because sometimes they are tilted when they finish.

I've seen a few tutorials for six sided dice, but I have use cases for D&D game dice which makes things more complicated.

What I think I need is the underlying geometry of the convexHull (or collisionShape). Then I could calculate which face has the greatest "Y" value. I have no idea how to do this.

Alternatively, I've looked into setting a vector for each face of a die, then calculating the dot value based on the rigidBody transform, but I was not able to get this working well.

Please help me find a simple way to calculate the top most face of a collider. This is not just for six sided dice, and sometimes the dice are tilted or stacked up when they finish.

"Alternatively, I've looked into setting a vector for each face of a die, then calculating the dot value based on the rigidBody transform, but I was not able to get this working well."

Why are you relying on the physics sim info for this? Use face normals from the mesh data and calculate which face is the "most up" based on the dot with the up vector.