Add methods to read the mass or volume of a collider.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
- Remove the deprecated methods `RigidBodyBuilder::mass`, `::principal_angular_inertia`, `::principal_inertia`.
|
||||
- Remove the methods `RigidBodyBuilder::additional_principal_angular_inertia`. Use
|
||||
`RigidBodyBuilder::additional_mass_properties` instead.
|
||||
- The `Collider::density` method now always returns a `Real` (instead of an `Option<Real>`).
|
||||
|
||||
### Added
|
||||
- Add `RigidBody::recompute_mass_properties_from_colliders` to force the immediate computation
|
||||
@@ -20,6 +21,7 @@
|
||||
computed based on this mass and on its shape.
|
||||
- Add `ColliderBuilder::mass` to set the mass of the collider instead of its density. Its angular
|
||||
inertia tensor will be automatically computed based on this mass and its shape.
|
||||
- Add `Collider::mass` and `Collider::volume` to retrieve the mass or volume of a collider.
|
||||
|
||||
## v0.13.0 (31 May 2022)
|
||||
### Fixed
|
||||
|
||||
@@ -4,8 +4,7 @@ use crate::dynamics::{
|
||||
RigidBodyIds, RigidBodyMassProps, RigidBodyPosition, RigidBodyType, RigidBodyVelocity,
|
||||
};
|
||||
use crate::geometry::{
|
||||
Collider, ColliderHandle, ColliderMassProps, ColliderParent, ColliderPosition, ColliderSet,
|
||||
ColliderShape,
|
||||
ColliderHandle, ColliderMassProps, ColliderParent, ColliderPosition, ColliderSet, ColliderShape,
|
||||
};
|
||||
use crate::math::{AngVector, Isometry, Point, Real, Rotation, Vector};
|
||||
use crate::utils::WCross;
|
||||
@@ -484,7 +483,7 @@ impl RigidBody {
|
||||
}
|
||||
|
||||
/// Removes a collider from this rigid-body.
|
||||
pub(crate) fn remove_collider_internal(&mut self, handle: ColliderHandle, coll: &Collider) {
|
||||
pub(crate) fn remove_collider_internal(&mut self, handle: ColliderHandle) {
|
||||
if let Some(i) = self.colliders.0.iter().position(|e| *e == handle) {
|
||||
self.changes.set(RigidBodyChanges::COLLIDERS, true);
|
||||
self.colliders.0.swap_remove(i);
|
||||
|
||||
@@ -237,12 +237,32 @@ impl Collider {
|
||||
&self.material
|
||||
}
|
||||
|
||||
/// The density of this collider, if set.
|
||||
pub fn density(&self) -> Option<Real> {
|
||||
/// The volume (or surface in 2D) of this collider.
|
||||
pub fn volume(&self) -> Real {
|
||||
self.shape.mass_properties(1.0).mass()
|
||||
}
|
||||
|
||||
/// The density of this collider.
|
||||
pub fn density(&self) -> Real {
|
||||
match &self.mprops {
|
||||
ColliderMassProps::Density(density) => Some(*density),
|
||||
ColliderMassProps::Mass(_) => None,
|
||||
ColliderMassProps::MassProperties(_) => None,
|
||||
ColliderMassProps::Density(density) => *density,
|
||||
ColliderMassProps::Mass(mass) => {
|
||||
let inv_volume = self.shape.mass_properties(1.0).inv_mass;
|
||||
mass * inv_volume
|
||||
}
|
||||
ColliderMassProps::MassProperties(mprops) => {
|
||||
let inv_volume = self.shape.mass_properties(1.0).inv_mass;
|
||||
mprops.mass() * inv_volume
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The mass of this collider.
|
||||
pub fn mass(&self) -> Real {
|
||||
match &self.mprops {
|
||||
ColliderMassProps::Density(density) => self.shape.mass_properties(*density).mass(),
|
||||
ColliderMassProps::Mass(mass) => *mass,
|
||||
ColliderMassProps::MassProperties(mprops) => mprops.mass(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ impl ColliderSet {
|
||||
|
||||
if let Some(parent_handle) = curr_parent {
|
||||
if let Some(rb) = bodies.get_mut(parent_handle) {
|
||||
rb.remove_collider_internal(handle, &*collider);
|
||||
rb.remove_collider_internal(handle);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ impl ColliderSet {
|
||||
if let Some(parent_rb) =
|
||||
bodies.get_mut_internal_with_modification_tracking(parent.handle)
|
||||
{
|
||||
parent_rb.remove_collider_internal(handle, &collider);
|
||||
parent_rb.remove_collider_internal(handle);
|
||||
|
||||
if wake_up {
|
||||
islands.wake_up(bodies, parent.handle, true);
|
||||
|
||||
@@ -338,7 +338,7 @@ impl PhysxWorld {
|
||||
let densities: Vec<_> = rb
|
||||
.colliders()
|
||||
.iter()
|
||||
.map(|h| colliders[*h].density().unwrap_or(0.0))
|
||||
.map(|h| colliders[*h].density())
|
||||
.collect();
|
||||
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user