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

create_multiple_collision_shapes() does not do convex decomposition #67801

Closed
Tracked by #45333
ghost opened this issue Oct 23, 2022 · 14 comments · Fixed by #72152
Closed
Tracked by #45333

create_multiple_collision_shapes() does not do convex decomposition #67801

ghost opened this issue Oct 23, 2022 · 14 comments · Fixed by #72152

Comments

@ghost
Copy link

ghost commented Oct 23, 2022

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:

  1. Create a new 3D scene with Node3D as root.
  2. Add RigidBody3D as child of scene root
  3. Add MeshInstance3D as child of RigidBody3D
  4. Assign TorusMesh to the mesh of the MeshInstance3D
  5. Select the MeshInstance3D in the scene tree
  6. Click the Mesh icon next to the view icon in the editor
  7. Click Create Multiple Convex Collision Siblings
  8. Observe that only one convex collision shape is added as a child to the RigidBody3D

In code:

  1. Create a torus mesh as the mesh of a MeshInstance3D that is the child of a rigid body
  2. call create_multiple_convex_collisions() on the mesh instance
  3. reparent the collision shapes to be the siblings of the MeshInstance3D
  4. 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

ExampleOfBug.zip

@Calinou
Copy link
Member

Calinou commented Oct 23, 2022

4.0 dev( 4.1 beta, 4.2 beta, 4.3 beta)

There are no 4.1/4.2/4.3 betas yet 🙂 You meant 4.0.beta1, 4.0.beta2 and 4.0.beta3 instead.

@ghost
Copy link
Author

ghost commented Oct 23, 2022

That's what I meant

@smix8
Copy link
Contributor

smix8 commented Oct 23, 2022

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.

@ghost
Copy link
Author

ghost commented Oct 23, 2022

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.

@ghost
Copy link
Author

ghost commented Oct 23, 2022

and other rigid bodies should be then able to fall through the hole of the torus

@smix8
Copy link
Contributor

smix8 commented Oct 23, 2022

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.

@Calinou
Copy link
Member

Calinou commented Oct 23, 2022

The default option for the maximum number of convex hulls should probably be 10 or so, rather than 1.

@ghost
Copy link
Author

ghost commented Oct 24, 2022

Why not have the max number of convex hulls be a parameter in MeshInstance3D.create_multiple_convex_collisions() function

@smix8
Copy link
Contributor

smix8 commented Oct 25, 2022

It is not only the hull count, there are a lot of parameters, to much for a function, needs to be wrapped if exposed.

struct ConvexDecompositionSettings {
enum Mode : int {
CONVEX_DECOMPOSITION_MODE_VOXEL = 0,
CONVEX_DECOMPOSITION_MODE_TETRAHEDRON
};
/// Maximum concavity. [Range: 0.0 -> 1.0]
real_t max_concavity = 1.0;
/// Controls the bias toward clipping along symmetry planes. [Range: 0.0 -> 1.0]
real_t symmetry_planes_clipping_bias = 0.05;
/// Controls the bias toward clipping along revolution axes. [Range: 0.0 -> 1.0]
real_t revolution_axes_clipping_bias = 0.05;
real_t min_volume_per_convex_hull = 0.0001;
/// Maximum number of voxels generated during the voxelization stage.
uint32_t resolution = 10'000;
uint32_t max_num_vertices_per_convex_hull = 32;
/// Controls the granularity of the search for the "best" clipping plane.
/// [Range: 1 -> 16]
uint32_t plane_downsampling = 4;
/// Controls the precision of the convex-hull generation process during the
/// clipping plane selection stage.
/// [Range: 1 -> 16]
uint32_t convexhull_downsampling = 4;
/// enable/disable normalizing the mesh before applying the convex decomposition.
bool normalize_mesh = false;
Mode mode = CONVEX_DECOMPOSITION_MODE_VOXEL;
bool convexhull_approximation = true;
/// This is the maximum number of convex hulls to produce from the merge operation.
uint32_t max_convex_hulls = 1;
bool project_hull_vertices = true;

@ghost
Copy link
Author

ghost commented Nov 19, 2022

It would be really helpful if this was exposed

@bvigario
Copy link

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.

@ghost
Copy link
Author

ghost commented Jan 23, 2023

When will this be exposed?

@Calinou
Copy link
Member

Calinou commented Jan 25, 2023

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.

@henriquelalves
Copy link
Contributor

henriquelalves commented Mar 7, 2023

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.

convex_shapes_regression.zip

@YuriSizov YuriSizov added this to the 4.1 milestone Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants