Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help getting underlying mesh data of rigid body #382

Open
frankieali opened this issue Nov 4, 2021 · 2 comments
Open

Need help getting underlying mesh data of rigid body #382

frankieali opened this issue Nov 4, 2021 · 2 comments

Comments

@frankieali
Copy link

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.

@mikecoker
Copy link

mikecoker commented Nov 22, 2021

"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.

@suddenly4
Copy link

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

  1. There is an option to hang a ray on each face, which will check the point with whom it collided. The length of the ray can be adjusted. The ray allows you to get both the object with whom it intersected, the normal, the face. https://jsfiddle.net/suddenly4/xp9kc056/1/

  2. There is an option to get the point of contact of two objects using
    new Ammo.ConcreteContactResultCallback()
    You can also get the normal, the position of the point

  3. There is an option to hang a ghost object on each face and query it through a callback about whether it is in contact with the plane

  4. There is an option to measure the angle of the cube itself, like an internal gyroscope of its local / world angle in relation to the coordinate grid. Thus, get the face geometrically - You don't even need physics for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants