Skip to main content

CompoundShape

Struct CompoundShape 

Source
pub struct CompoundShape { /* private fields */ }
Expand description

Boxes fixed in one rigid body’s frame, validated once: the collision shape ColliderComponent::Compound carries.

The parts are shared behind an Arc, so cloning a shape — which crate::PhysicsSystem::set_collider does to keep its component — copies a pointer. Every part is finite, has no negative half-extent and a unit rotation; there is at least one part, at most CompoundShape::MAX_PARTS, and some volume among them.

Implementations§

Source§

impl CompoundShape

Source

pub const MAX_PARTS: usize = 32

The most parts a shape may have.

Each part is a broadphase proxy and each touching pair of parts a manifold of up to crate::contact::manifold::MAX_POINTS points, so this is what bounds the proxies a compound body costs and, with the other body’s parts, the points a pair of bodies can put in the solver. It leaves room above what an item boxed one part per mesh primitive has: the model of EW’s break-action shotgun has thirteen primitives.

Source

pub const DEFAULT_DENSITY: f64 = 1000.0

A density for a body whose mass nobody authored: water’s, in kg/m³. It sets a scale, not a measurement: boxes overstate a model’s volume by their empty corners and by their overlaps, so a game that knows an item’s real mass weighs it with MassProperties::of_collider, which shares that mass among the parts. The centre of mass and the inertia’s shape, which are what make it tumble, are the same either way.

Source

pub fn new(parts: impl Into<Arc<[CompoundPart]>>) -> Result<Self, CompoundError>

A shape of parts, each in the shape’s frame. Part indices in a crate::ContactReport are indices into parts.

A rotation within glam’s unit tolerance is kept normalised.

§Errors

Naming the first offending part where there is one: CompoundError::NoParts, CompoundError::TooManyParts, CompoundError::NonFinitePart for a NaN or infinity anywhere in a part, CompoundError::InvertedPart for a negative half-extent, CompoundError::NonUnitRotation, CompoundError::NoVolume when every part is flat, which leaves nothing for a density to weigh, and CompoundError::UnweighableMass when the parts weighed at unit density give an inertia tensor RigidBody::with_inertia would refuse: one overflowed or underflowed out of an f64’s range.

Source

pub fn from_aabbs(parts: &[Aabb]) -> Result<Self, CompoundError>

A shape of axis-aligned boxes in the body’s frame — what AabbCompound takes, and what EW’s ItemMotion keeps.

§Errors

AabbCompound::new’s refusals of a part, then new’s of the whole.

Source

pub fn parts(&self) -> &[CompoundPart]

The parts, in the order given.

Source

pub fn volume(&self) -> f64

The parts’ volumes summed, overlaps counted once for each part they are in.

Source

pub fn mass_properties(&self, density: f64) -> MassProperties

The shape’s mass properties as a solid of density, in its own frame: each part weighed alone and the parts summed — see the module docs for why an overlap counts twice.

§Panics

Panics if density is not positive and finite.

Source

pub fn dynamic_body(&self, density: f64) -> CompoundBody

A dynamic body of density with this shape: its mass and inertia from mass_properties, and a collider offset by the centre of mass so the body’s origin is that centre, as RigidBody requires.

§Panics

Panics if density is not positive and finite, or so large that the inertia it weighs leaves an f64’s range.

Source

pub fn world_bounds(&self, offset: DVec3, transform: &Transform) -> Aabb

The world bounds of every part, with the shape offset from a body at transform, as ColliderComponent::Compound places it.

Trait Implementations§

Source§

impl Clone for CompoundShape

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompoundShape

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CompoundShape

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CompoundShape

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.