Skip to content

Make SpatialQuery more generic across colliders#975

Draft
NiseVoid wants to merge 5 commits into
avianphysics:mainfrom
NiseVoid:updated_generic_spatial
Draft

Make SpatialQuery more generic across colliders#975
NiseVoid wants to merge 5 commits into
avianphysics:mainfrom
NiseVoid:updated_generic_spatial

Conversation

@NiseVoid
Copy link
Copy Markdown
Contributor

Objective

SpatialQuery cannot be used with non-parry collider types.

Solution

Add a trait to let types use SpatialQuery, and add a generic param in a few places

Testing

  • Run various examples that use SpatialQuery to ensure nothing broke
  • Make sure things still compile without default features

Next steps

  • Make ShapeCast and RayCast components work with the new approach
  • Look into simplify some of the methods by applying translation/rotation/scaling externally
  • Add an example for a custom QueryCollider impl
  • Look into allowing QueryCollider without AnyCollider
  • Use some better Rust magic to clean up the trait madness in this PR

@Jondolf Jondolf added C-Feature A new feature, making something new possible A-Spatial-Query Relates to spatial queries, such as ray casting, shape casting, and intersection tests M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide labels Apr 18, 2026
Copy link
Copy Markdown
Member

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

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

Thanks! This largely looks like the right shape for this sort of thing. I did my first pass on this, initial thoughts are mainly that some of the APIs and trait bounds may need some more thought to figure out if we can make them a bit nicer somehow

Comment thread src/spatial_query/system_param.rs Outdated
Comment on lines +139 to +161
/// A trait to indicate the [`Entity`] usage of a [`BoundedCollider`] `Context`. See [`NoEntity`] and [`NeedsEntity`].
pub trait EntityUsage {
/// The type the [`Entity`] is stored in ([`()`] vs [`Entity`])
type Entity: Clone + Copy;
/// Convert an [`Entity`] to the stored type
fn to_field(e: Entity) -> Self::Entity;
}

/// A type indicating an entity is required for a [`BoundedCollider`]'s `Context`
pub struct NeedsEntity;
impl EntityUsage for NeedsEntity {
type Entity = Entity;
fn to_field(e: Entity) -> Self::Entity {
e
}
}

/// A type indicating no entity is used for a [`BoundedCollider`]'s `Context`
pub struct NoEntity;
impl EntityUsage for NoEntity {
type Entity = ();
fn to_field(_: Entity) {}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels quite nasty, but I can see why something like this may be needed for AabbContext 🤔 I'll have to think if there's a better way to handle this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Spatial-Query Relates to spatial queries, such as ray casting, shape casting, and intersection tests C-Feature A new feature, making something new possible M-Migration-Guide A breaking change to Avian's public API that needs to be noted in a migration guide

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants