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
impl CompoundShape
Sourcepub const MAX_PARTS: usize = 32
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.
Sourcepub const DEFAULT_DENSITY: f64 = 1000.0
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.
Sourcepub fn new(parts: impl Into<Arc<[CompoundPart]>>) -> Result<Self, CompoundError>
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.
Sourcepub fn from_aabbs(parts: &[Aabb]) -> Result<Self, CompoundError>
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.
Sourcepub fn parts(&self) -> &[CompoundPart]
pub fn parts(&self) -> &[CompoundPart]
The parts, in the order given.
Sourcepub fn volume(&self) -> f64
pub fn volume(&self) -> f64
The parts’ volumes summed, overlaps counted once for each part they are in.
Sourcepub fn mass_properties(&self, density: f64) -> MassProperties
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.
Sourcepub fn dynamic_body(&self, density: f64) -> CompoundBody
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.
Sourcepub fn world_bounds(&self, offset: DVec3, transform: &Transform) -> Aabb
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.