create_multiple_collision_shapes() does not do convex decomposition
Godot version
4.0 dev( 4.1 beta, 4.2 beta, 4.3 beta)
System information
OS Version : MacOS Monterrey, Hardware : Mac OS Silicon
Issue description
When trying to automatically create multiple convex collision shapes from a concave MeshInstance3D, only one convex collision shape is created instead of multiple. This happens in the editor and when calling create_multiple_convex_collisions() in code on a MeshInstance3D.
Steps to reproduce
In editor:
- Create a new 3D scene with Node3D as root.
- Add RigidBody3D as child of scene root
- Add MeshInstance3D as child of RigidBody3D
- Assign TorusMesh to the mesh of the MeshInstance3D
- Select the MeshInstance3D in the scene tree
- Click the Mesh icon next to the view icon in the editor
- Click Create Multiple Convex Collision Siblings
- Observe that only one convex collision shape is added as a child to the RigidBody3D
In code:
- Create a torus mesh as the mesh of a MeshInstance3D that is the child of a rigid body
- call create_multiple_convex_collisions() on the mesh instance
- reparent the collision shapes to be the siblings of the MeshInstance3D
- put a rigid body with a collision shape that fits in the hole of the torus, and notice that it does not fall through, because the only one convex collision shape is being created for the entire mesh even though it is concave.
Minimal reproduction project
4.0 dev( 4.1 beta, 4.2 beta, 4.3 beta)
There are no 4.1/4.2/4.3 betas yet :slightly_smiling_face: You meant 4.0.beta1, 4.0.beta2 and 4.0.beta3 instead.
That's what I meant
You are asking to create a convex hull shape for a single torus triangle mesh while keeping the torus hole which is impossible.
~~The "Create Multiple Convex Collision Siblings" function will give you multiple collision shapes if you have a mesh resource with triangles arranged in a way that it requires multiple convex hulls. A single torus triangle mesh requires a single hull so you only get one collision shape.~~ Actually the Godot 4 defaults limit the convex hull count to 1 so it would not even work for meshes with disconnected triangles in the same mesh resource.
~~The real~~ One bug here is that the other "Create Single Convex Collision Sibling" Editor option tries to build a convex hull shape for a torus with a hole and fails half the shape creation while the other convex menu options do what is correct, close the hole to be convex.
No, "Create Multiple Convex Collisions" is supposed to create multiple convex collision shapes that approximately do what a trimesh collision shape would do, using convex decomposition using v-hacd. This bug isn't just happening with toruses but any concave mesh. The hole should not be closed to make the torus's collision shape be convex, it should have multiple collision shapes generated using v-hacd convex decomposition, whose union approximates what a trimesh collision shape does.
and other rigid bodies should be then able to fall through the hole of the torus
is supposed to
I agree for VHACD in general but VHACD has a wide range of bake parameters and those are set very low for both Editor Menu option as well as MeshInstance3D.create_multiple_convex_collisions(). So low in fact they have max_convex_hulls=1 set and this was done in 2021 (before it was set to infinite hulls) so it seemed like a deliberate choice but don't ask me why, not my area.
Still even with this limits lifted in a custom build the torus has problems, might be the TriMesh creation or geometry parsing or something else I don't know but maybe someone else can use some of this info to fix it.
The default option for the maximum number of convex hulls should probably be 10 or so, rather than 1.
Why not have the max number of convex hulls be a parameter in MeshInstance3D.create_multiple_convex_collisions() function
It is not only the hull count, there are a lot of parameters, to much for a function, needs to be wrapped if exposed. https://github.com/godotengine/godot/blob/32997a5b9de14bd08f75f1f5d4c0a7b913338d2c/scene/resources/mesh.h#L178-L207
It would be really helpful if this was exposed
I think the ConvexDecompositionSettings could be exposed as a public property (serializable). Also, the user should be able to edit these settings in the editor: maybe displayed as a popup window when clicking on Mesh > Create Multiple Convex Collision Siblings.
This should be added to the Godot 4.0 Issues Roadmap (Physics) since it's a breaking bug.
When will this be exposed?
When will this be exposed?
Issues are resolved on a best-effort basis, so there's no ETA. A quick way to fix this would be to change the hardcoded hull count to something like 10 as I suggested, but this may introduce performance issues in certain situations.
I can confirm this is behavior creates a regression in Godot 4.0. A simple concave shape mesh creates multiple convex collision shapes in Godot 3.5 when I use "Create Multiple Convex Collision Siblings", but in Godot 4.0 the same concave shape mesh creates one single convex block.
I'm annexing a simple project with the shape in question. I haven't tested the PR yet, but it's weird that the default values for creating convex shapes in Godot 4.0 is worse than Godot 3.5; the behavior for a simple mesh like this should be the same.