Skip to main content

bevy_rapier2d/geometry/shape_views/
compound.rs

1use super::ColliderView;
2use crate::math::{Rot, Vect};
3use rapier::parry::shape::Compound;
4
5/// Read-only access to the properties of a compound shape.
6#[derive(Copy, Clone)]
7pub struct CompoundView<'a> {
8    /// The raw shape from Rapier.
9    pub raw: &'a Compound,
10}
11
12impl CompoundView<'_> {
13    /// The shapes of this compound shape.
14    #[inline]
15    pub fn shapes(&self) -> impl ExactSizeIterator<Item = (Vect, Rot, ColliderView<'_>)> {
16        self.raw.shapes().iter().map(|(pos, shape)| {
17            #[cfg(feature = "dim2")]
18            let rot = pos.rotation.angle();
19            #[cfg(feature = "dim3")]
20            let rot = pos.rotation;
21            (pos.translation, rot, shape.as_typed_shape().into())
22        })
23    }
24}