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

Invalid mass error when using a ConcavePolygonShape3D as the collision for a Area3D in Jolt Physics #101917

Open
ydeltastar opened this issue Jan 22, 2025 · 5 comments · May be fixed by #102029
Open

Comments

@ydeltastar
Copy link
Contributor

ydeltastar commented Jan 22, 2025

Tested versions

  • 4.4.beta

System information

Windows 11 (build 22621) - Vulkan (Forward+)

Issue description

Jolt Physics gives an error when I use a ConcavePolygonShape3D generated from a mesh as the collision shape for an Area3D.

ERROR: modules\jolt_physics\jolt_globals.cpp:79 - Jolt Physics assertion 'inMassProperties.mMass > 0.0f' failed with message 'Invalid mass.
Some shapes like MeshShape or TriangleShape cannot calculate mass automatically, in this case you need to provide it by setting BodyCreationSettings::mOverrideMassProperties and mMassPropertiesOverride.' at 'thirdparty\jolt_physics\Jolt\Physics\Body\MotionProperties.cpp:31'

The error doesn't make much sense since mass is not relevant for Area3D and it doesn't happen when using the shape with static or rigidbody nodes.

Steps to reproduce

  • Open "boulder.tscn" in the MRP.

Minimal reproduction project (MRP)

jolt-error.zip

@AThousandShips
Copy link
Member

CC @mihe

@mihe
Copy link
Contributor

mihe commented Jan 22, 2025

When using Jolt Physics you won't be able to use ConcavePolygonShape3D with Area3D at the moment.

I honestly can't remember if this was a deliberate deviation on my part (and I just forgot about it) or if I just assumed that this didn't work in Godot Physics either, given the warning in the documentation of Area3D about using concave shapes with it:

Warning: Using a ConcavePolygonShape3D inside a CollisionShape3D child of this node (created e.g. by using the Create Trimesh Collision Sibling option in the Mesh menu that appears when selecting a MeshInstance3D node) may give unexpected results, since this collision shape is hollow. If this is not desired, it has to be split into multiple ConvexPolygonShape3Ds or primitive shapes like BoxShape3D, or in some cases it may be replaceable by a CollisionPolygon3D.

As hinted at there you can end up with some strange results with this setup, as you'll only ever register overlaps if the other shape happens to intersect with one of the triangles, and only if it's a "shallow" enough intersection to not be a backface hit. I'm sure there are probably other odd artefacts with this setup as well.

What you might want instead is (as mentioned above) to use either a single or multiple ConvexPolygonShape3D, both of which you can generate from a MeshInstance3D from the viewport toolbar.

Either way, using any concave shape won't work with how I've implemented Area3D in the Jolt integration, as it's done using a kinematic body under the hood, which only supports convex shapes (i.e. solid shapes).

@mihe mihe added this to the 4.4 milestone Jan 22, 2025
@mihe mihe moved this from Unassessed to Not Critical in 4.x Release Blockers Jan 22, 2025
@ydeltastar
Copy link
Contributor Author

Oh right, concave shapes are a common limitation in physics engines but the error message got me confused. It could be changed to clarify that the shape type is not supported.

@mihe
Copy link
Contributor

mihe commented Jan 22, 2025

the error message got me confused. It could be changed to clarify that the shape type is not supported.

Yes, definitely. The current error was not intentional. I'll see about adding something more useful instead, if only just as a hold-over.

@mihe mihe self-assigned this Jan 23, 2025
@mihe
Copy link
Contributor

mihe commented Jan 25, 2025

It seems I need to correct myself here.

When taking a closer look at using ConcavePolygonShape3D for Area3D, with the way things are now, it seems it already "works", much to my surprise, in terms of it being able to detect things like overlaps with other (convex) bodies. So all that needed to be done here was provide Area3D with some default mass properties, just to prevent the assertion mentioned in the issue description here, and that was that.

With that said, the thing about overlaps being janky still applies. You still ideally shouldn't use a ConcavePolygonShape3D for an Area3D, and the warning in the documentation still applies, but at least we're at some kind of parity with Godot Physics already.

You'll also be met with a lot of errors (in dev_build=yes) saying "Unsupported shape pair" if you end up having your ConcavePolygonShape3D Area3D overlap with another ConcavePolygonShape3D of any kind, whether it be another Area3D or a StaticBody3D. This is something you'll see with Godot Physics as well though, but there it's a warning instead, and only emitted once during the lifetime of the application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Not Critical
Development

Successfully merging a pull request may close this issue.

3 participants