Skip to content

Add per-shape collision filtering to the 3D physics system #7400

@aaronfranke

Description

@aaronfranke

Describe the project you are working on

I am working on GLTF support in Godot.

Describe the problem or limitation you are having in your project

The Khronos group had a meeting about physics the day I am writing this proposal, and decided that GLTF collision filtering should be per-shape. The opinion of the Khronos group is that per-shape filtering is important, should be in the base GLTF physics extension spec, and the spec should require implementations to support this.

Godot currently only has per-body filtering, so if a GLTF file has a body with multiple shapes and each has per-shape filtering, it's not possible to import that file and have it behave the same. Technically you could import the data as multiple bodies, but that would likely break other things.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The enhancement is to add the collision filtering properties (layers and masks) to the CollisionShape3D node. This would allow us to have per-shape filtering, which allows us to import the Khronos group's proposed GLTF physics filtering.

Note that aside from GLTF compatibility, per-shape filtering may also be useful for Godot users in general. Many other engines have per-shape filtering, including Jolt, so adding this to Godot's physics nodes would help with using the full capabilities of third-party physics engines in Godot. During the Khronos group meeting they mentioned that most engines they've worked with had this feature and Godot is the odd one out here.

The same may wish to be done in 2D as well for feature parity - but for the moment, I am primarily interested in 3D.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Add new properties to CollisionShape3D: collision_mask and collision_layer. These would work similarly to the properties on CollisionObject3D.

We also want to be careful not break compatibility by keeping this feature optional and to keep the per-body filtering working. How would the shape-based filtering interact with the body-based filtering? I see a few options. We could make the default be 0, and if non-zero it will override the body's filtering for that shape. Or maybe we could make the default be 2^32 - 1 and use it as a bitmask to compare against the body.

If this enhancement will not be used often, can it be worked around with a few lines of script?

It can't be worked around in script - at least, not without multiple bodies, which would likely break other things.

Is there a reason why this should be core and not an add-on in the asset library?

This is a core part of the physics system.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions