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

MassProperties for 3D triangle mesh #16

Closed
willcrichton opened this issue Sep 24, 2020 · 6 comments
Closed

MassProperties for 3D triangle mesh #16

willcrichton opened this issue Sep 24, 2020 · 6 comments
Labels
3D The issue is specifically about the 3D version of Rapier. C-Enhancement New feature or request good first issue Good for newcomers

Comments

@willcrichton
Copy link

willcrichton commented Sep 24, 2020

I'd like to have a 3D physics simulation using dynamic triangle meshes. I think (not sure?) that the main missing component in rapier is that MassProperties has not been implemented for Trimesh, shown here: https://github.com/dimforge/rapier/blob/master/src/geometry/collider.rs#L202

I'd be happy to take a stab at implementing this feature, but I don't understand the engine design or the involved math well enough (e.g. what is principal inertia, how to compute it, so on). If anyone has a good reference, I can take a look.

@sebcrozet
Copy link
Member

Hi! Sorry for the late answer.

Yes, the main missing component is the MassProperties computation. Implementing this will allow meshes to be dynamic.
However, it should be kept in mind that most game physics engines don't allow dynamic triangle-meshes because they can quickly suffer from some collision-detection problems causing the to be stuck (mostly because triangles-meshes are generally considered to not have any interior).

I don't have any references to give you on this. What we need here is to be able to compute the triangle mesh's volume and angular inertia tensor.

Once you have these:

  • The TriMesh mass is equal to the volume multiplied by the collider's density.
  • The TriMesh principal inertia is obtained by the Eigendecomposition of the angular inertia tensor like this.

@sebcrozet sebcrozet added 3D The issue is specifically about the 3D version of Rapier. C-Enhancement New feature or request good first issue Good for newcomers labels Oct 10, 2020
@willcrichton
Copy link
Author

No worries, thanks for the details @sebcrozet. My ultimate goal is to turn an arbitrary glTF into a dynamic collider, and I figured implementing a collider for trimesh was the correct path. Can you explain a little more on how game engines don't allow dynamic triangle-meshes? How do they simulate collisions on arbitrary 3D models (eg Source engine)? Is there some way of translating models into a group of non-triangular primitive shapes that you link together?

@sebcrozet
Copy link
Member

For arbitrary non-deformable 3D models, game physics engines generally require the model to be represented as a set of convex polyhedrons. So the solution is generally to compute a (often approximate) convex decomposition of the mesh with an algorithm like V-HACD, and use these convex parts as the collider shapes. ncollide has an implementation of HACD (which is a bit older than V-HACD) but it is not extremely robust.

Now even if we had a working V-HACD implementation, you could not achieve your goal with the current version of Rapier because it does not support arbitrary 3D convex polyhedron yet. Though my current works on capsule shapes will make it much easier to support 3D convex polyhedron too.

So I guess two things are possibles (and both are things we would like to support at some point):

  • Find a way to compute the mass properties of triangle meshes.
  • Implement an algorithm like V-HACD, and wait for Rapier to support arbitrary 3D convex polyhedron shapes (should land in one or two months).

@willcrichton
Copy link
Author

Ok, that makes sense. I would be happy to try my hand at a V-HACD implementation. I'll try to keep an eye on the changelog, but if you can ping this thread once support for 3D convex polyhedron lands on master, then I will get started then.

ryo33 pushed a commit to ryo33/rapier that referenced this issue Nov 15, 2020
@zicklag
Copy link

zicklag commented Jun 23, 2021

This is can be closed now that there is V-HACD in parry2d and rapier right?

@sebcrozet
Copy link
Member

Computing mass-properties of a 3D triangle mesh has been added to Rapier 0.12 (non-alpha version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3D The issue is specifically about the 3D version of Rapier. C-Enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants