Skip to main content

bevy_rapier3d/geometry/shape_views/
compound.rs

1use super::ColliderView;
2use crate::math::{Real, Rot, Vect};
3use rapier::parry::shape::{Compound, CompoundFlags};
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
12macro_rules! impl_ref_methods(
13    ($View: ident) => {
14        impl<'a> $View<'a> {
15            /// The shapes of this compound shape.
16            #[inline]
17            pub fn shapes(&self) -> impl ExactSizeIterator<Item = (Vect, Rot, ColliderView<'_>)> {
18                self.raw.shapes().iter().map(|(pos, shape)| {
19                    #[cfg(feature = "dim2")]
20                    let rot = pos.rotation.angle();
21                    #[cfg(feature = "dim3")]
22                    let rot = pos.rotation;
23                    (pos.translation, rot, shape.as_typed_shape().into())
24                })
25            }
26
27            /// The flags controlling the optional data associated to this compound shape.
28            pub fn flags(&self) -> CompoundFlags {
29                self.raw.flags()
30            }
31        }
32    }
33);
34
35impl_ref_methods!(CompoundView);
36
37/// Read-write access to the properties of a compound shape.
38///
39/// The parts of the compound shape are shared and cannot be modified through this view.
40pub struct CompoundViewMut<'a> {
41    /// The raw shape from Rapier.
42    pub raw: &'a mut Compound,
43}
44
45impl_ref_methods!(CompoundViewMut);
46
47impl CompoundViewMut<'_> {
48    /// Sets the flags of this compound shape, computing or discarding its optional
49    /// associated data.
50    ///
51    /// `weld_tolerance` is the distance (in ULPs) under which two corners of different parts
52    /// are considered equal when detecting internal edges; `None` selects parry's default.
53    pub fn set_flags(&mut self, flags: CompoundFlags, weld_tolerance: Option<Real>) {
54        self.raw.set_flags(flags, weld_tolerance)
55    }
56}