Skip to content

Make Bounded3d dyn-compatible#23623

Draft
omeranson wants to merge 1 commit intobevyengine:mainfrom
omeranson:dyn-compatibility
Draft

Make Bounded3d dyn-compatible#23623
omeranson wants to merge 1 commit intobevyengine:mainfrom
omeranson:dyn-compatibility

Conversation

@omeranson
Copy link
Copy Markdown
Contributor

Objective

Make Bounded3d a dyn-compatible object. This is so that components can contain a dyn Bounded3d type member, and won't need a template.

I am suggesting this as a draft, because there is an alternative that may be preferable (shown below). There are also other such traits, e.g., Bounded2d that will need to go through the same process for the same result.

Solution

Refractor Bounded3d so that its methods accept Isometry3d, rather than an Into<Isometry3d>. This removes the single item limiting Bounded3d from being dyn-compatible.

Testing

  • Compiled bevy
  • Compiled and ran a small example.

Alternative

As an alternative, a new dyn-compatible trait can be created, with a blanket implementation for Bounded3d. This requires no code change from other implementations of Bounded3d to change their signature.

pub trait Bounded3dDyn {
    /// Get an axis-aligned bounding box for the shape translated and rotated by the given isometry.
    fn aabb_3d_dyn(&self, isometry: bevy_::Isometry3d) -> Aabb3d;
    /// Get a bounding sphere for the shape translated and rotated by the given isometry.
    fn bounding_sphere_dyn(&self, isometry: bevy_::Isometry3d) -> BoundingSphere;
}

impl<T: Bounded3d> Bounded3dDyn for T {
    /// Get an axis-aligned bounding box for the shape translated and rotated by the given isometry.
    fn aabb_3d_dyn(&self, isometry: Isometry3d) -> Aabb3d {
        self.aabb_3d(isometry)
    }
    /// Get a bounding sphere for the shape translated and rotated by the given isometry.
    fn bounding_sphere_dyn(&self, isometry: Isometry3d) -> BoundingSphere {
        self.bounding_sphere(isometry)
    }
}

Related: #19491

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Math Fundamental domain-agnostic mathematical operations S-Needs-Design This issue requires design work to think about how it would best be accomplished labels Apr 2, 2026
@omeranson omeranson force-pushed the dyn-compatibility branch from be83018 to f72b8f5 Compare April 3, 2026 10:45
@omeranson omeranson force-pushed the dyn-compatibility branch from f72b8f5 to bc8577e Compare April 3, 2026 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Math Fundamental domain-agnostic mathematical operations C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Design This issue requires design work to think about how it would best be accomplished

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants