Is there a way to make Convex Collision Generation more accurate?

Godot Version

4.6

I was prototyping a 3D physics sandbox, in which shapes can be combined to make one complex mesh, as well as be cut out to create holes or dips in the mesh. After realizing that concave colliders don’t work with rigidbodies, I tried convex decomposition. While this did get me closer to the result I want, I cant seem to fine tune the decomposition in a way that gives completely accurate collision to the mesh’s visuals

The decomposition code currently looks like this, is there something I’m missing to get more precise decomposition?

image

How are you creating the mesh holes? Are you using CSG nodes or another method? Thanks!

They are CSG shapes generated using an existing standard mesh (the one that gets a hole cut into it), and the standard mesh you’re about to place down (the mesh that does the cutting). The CSG shapes are then combined and then turned into a single, standard mesh on the fly. The resulting mesh is what is used to base the decomposition to make the collision.

If i need to provide more info or clarification then lemme know!

1 Like

How?

Also, tagging @normalized into this who might have an answer for you.

Convex hulls are always approximations.

Best to make a tool script that exposes all of the MeshConvexDecompositionSettings properties and rebuilds the collider on your typical mesh as you drag the sliders. That way you’ll see in what way the parameters are relevant for your use case.

2 Likes

Made said script and have been toying around with it, however I can’t seem to find any combination of settings that get it to generate a more accurate shape. I split it off into a standalone project so you can check out the code if you want, or see if you can find the right combo of settings.

Why do you need those things as rigid bodies? Letting the player construct arbitrary concave rigid bodies in probably not a good idea in any case.

1 Like

The prototype is a physics sandbox similar to LittleBigPlanet, so they need to be rigid bodies so they can abide by physics and such. If they are static bodies then they lose out on what this prototype is all about, since then its just a sandbox and not a physics sandbox

Yeah but do you think it is a wise design (and technical) choice to allow the player to build any random concave rigid body on any complexity? It will end up in a complete mess sooner or later.

That is fair, I figured I would have some sort of limit for if a shape gets too complex (probably checking face count if its too large a number, as that same method is used to delete a shape if it has no faces).

How would you suggest I go about this kind of design though? I’m open to hearing other implementations and such, honestly this is a type of project I’m entirely new to.

You haven’t shared the concept of your game, so I can’t suggest anything specific. What type of interaction is supposed to happen with those objects after they’ve been created? It it grid/block based? What aspects of rigid body physics are really needed? Etc…

My apologies, here’s a gameplay video from a bit ago for context https://youtu.be/lcnffMrJNvQ?si=kksdL_teAioyVcq2 .You stamp shapes, cut into shapes, or stamp shapes on top of other shapes to combine them, all to make whatever shape you feel like. Those shapes can then be interacted with by the player, or other shapes, or attached with joints to make things like pendulums. Shapes don’t occupy a grid but instead are free to be placed wherever, as of the current version.

The rigid body bit is needed just so shapes can abide by gravity and collide with other shapes, as well as be connected with joints, as seen with the sections in the footage where the player swings from shapes (1:42 in the video for example).

I’d limit the movable rigid bodies to an assortment of pre-defined convex (and simple concave) forms and keep everything else a static body. Maybe color code the distinction.