rapier icon indicating copy to clipboard operation
rapier copied to clipboard

📐 Create Convex Decomposition From 2D Triangle Mesh?

Open zicklag opened this issue 4 years ago • 4 comments

I have a 2D triangle mesh that I want to do a convex decomposition on, but the convex_decomposition function only takes a triangle mesh in 3D mode, and it takes a polyline in 2D mode. Is there a way to either:

  1. Create a convex decomposition from a 2D triangle mesh, or
  2. Create a polyline from a 2D triangle mesh?

I'm not super geometry math savvy so I'm not sure if there is a simple algorithm to convert a 2D trimesh into a polyline or not.

zicklag avatar Jun 23 '21 19:06 zicklag

This is a feature I am going to be needing in my own project as well. Luckily I am dealing with very low polygon geometry. I'll probably write the decomposition code myself and share it. Perhaps this could fit somewhere in Rapier for ease of use?

manon-gfx avatar Sep 08 '21 12:09 manon-gfx

I found this algorithm that should be usable. The only issue is, is that it takes a polygon, instead of a triangle mesh. So we would need to first convert the mesh to a polygon, then split it into 1 or more convex polygons, and then somehow puzzle those into meshes.

So far I have been able to generate a list of outer edges, of a mesh, but it's not ordered like a polygon yet.

manon-gfx avatar Sep 09 '21 08:09 manon-gfx

Maybe a dumb question: If each 2D triangle is already convex (by definition of triangle), what decomposition is needed? I think you can feed your triangles to e.g. Collider::trimesh and it should just work. I'm using Collider::trimesh with hollow 2D shapes (so the whole object is hollow, but every single vertice is convex by themselves) and it seems to behave right.

tv42 avatar Nov 17 '22 20:11 tv42

That's actually quite a good question. 🤔

Triangle meshes are not recommended in 3D, because they aren't convex, but in 2D, you don't have the same problem.

It's been a while, but if I remember my use-case correctly, I was actually hoping rapier would simplify my mesh. Because my mesh was a naive repetitive mesh that had a bunch of internal vertices that it didn't really need.

Rapier's convex decomposition looked like it would choose a reasonably efficient mesh based on the exterior surfaces, so I was wondering if it could create a reasonable, simple collider for my more complicated mesh.

zicklag avatar Nov 17 '22 21:11 zicklag