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

Support default layers and density for ColliderConstructorHierarchy #386

Merged
merged 8 commits into from
Jun 29, 2024

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Jun 25, 2024

Objective

When loading a (glTF) scene and generating colliders for it, it can be useful to be able to add all entities in that scene to some collision layer. However, ColliderConstructorHierarchy (previously AsyncSceneCollider, see #378) doesn't currently allow specifying default collision layer or density configurations despite allowing configurations for individual entities.

Solution

Add default_layers and default_density properties for ColliderConstructorHierarchy. The layers and density properties of ColliderConstructorHierarchyData are now Options, and if they are None, the default values are used.

I also moved the collider constructor types and tests to their own module, and updated some docs to remove mesh-specific wording.

For reviewing purposes, the first commit (8cbe48c) should be easier to read, the other commit just moves code to the constructor module.


Migration Guide

If the default constructor for a ColliderConstructorHierarchy is None, meshes no longer default to triangle mesh colliders being generated even if they have a density or layers configured. The constructor must be specified either individually or through the default constructor.

@Jondolf Jondolf added the C-Enhancement New feature or request label Jun 25, 2024
@Jondolf Jondolf force-pushed the more-default-config-for-hierarchies branch 2 times, most recently from 1c49621 to 9ee6f30 Compare June 25, 2024 21:00
@Jondolf Jondolf force-pushed the more-default-config-for-hierarchies branch from 9ee6f30 to 8cbe48c Compare June 25, 2024 21:03
src/plugins/collision/collider/constructor.rs Outdated Show resolved Hide resolved
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]
#[cfg_attr(all(feature = "3d", feature = "collider-from-mesh"), reflect(Default))]
pub struct ColliderConstructorHierarchyConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird how everything but the constructor is optional. With this PR, wouldn't it make sense to want to override only the layers and leave the default constructor? I'd suggest making the constructor an Option as well.

This will also remove the special-cased Default and the need for ColliderConstructorHierarchyConfig::from_constructor

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. I made the constructor an Option and reworked the related logic a bit

Copy link
Contributor

@janhohenheim janhohenheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature looks good to me now :) Could you duplicate the collider_constructor_hierarchy_inserts_computed_colliders_on_scene test and adapt it to test the new behavior?

@Jondolf Jondolf merged commit 03627c4 into main Jun 29, 2024
4 checks passed
@Jondolf Jondolf deleted the more-default-config-for-hierarchies branch June 29, 2024 23:40
@Jondolf Jondolf added the C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt label Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Breaking-Change This change removes or changes behavior or APIs, requiring users to adapt C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants