Properly take initial sleeping state set by the user when creating a rigid-body
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::dynamics::{
|
||||
ImpulseJointSet, MultibodyJointSet, RigidBodyActivation, RigidBodyColliders, RigidBodyHandle,
|
||||
RigidBodyIds, RigidBodySet, RigidBodyType, RigidBodyVelocity,
|
||||
ImpulseJointSet, MultibodyJointSet, RigidBodyActivation, RigidBodyChanges, RigidBodyColliders,
|
||||
RigidBodyHandle, RigidBodyIds, RigidBodySet, RigidBodyType, RigidBodyVelocity,
|
||||
};
|
||||
use crate::geometry::{ColliderSet, NarrowPhase};
|
||||
use crate::math::Real;
|
||||
@@ -96,12 +96,18 @@ impl IslandManager {
|
||||
// attempting to wake-up a rigid-body that has already been deleted.
|
||||
if bodies.get(handle).map(|rb| rb.body_type()) == Some(RigidBodyType::Dynamic) {
|
||||
let rb = bodies.index_mut_internal(handle);
|
||||
rb.activation.wake_up(strong);
|
||||
|
||||
if rb.is_enabled() && self.active_dynamic_set.get(rb.ids.active_set_id) != Some(&handle)
|
||||
{
|
||||
rb.ids.active_set_id = self.active_dynamic_set.len();
|
||||
self.active_dynamic_set.push(handle);
|
||||
// Check that the user didn’t change the sleeping state explicitly, in which
|
||||
// case we don’t overwrite it.
|
||||
if !rb.changes.contains(RigidBodyChanges::SLEEP) {
|
||||
rb.activation.wake_up(strong);
|
||||
|
||||
if rb.is_enabled()
|
||||
&& self.active_dynamic_set.get(rb.ids.active_set_id) != Some(&handle)
|
||||
{
|
||||
rb.ids.active_set_id = self.active_dynamic_set.len();
|
||||
self.active_dynamic_set.push(handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ impl RigidBody {
|
||||
}
|
||||
|
||||
/// Sets the type of this rigid-body.
|
||||
pub fn set_body_type(&mut self, status: RigidBodyType) {
|
||||
pub fn set_body_type(&mut self, status: RigidBodyType, wake_up: bool) {
|
||||
if status != self.body_type {
|
||||
self.changes.insert(RigidBodyChanges::TYPE);
|
||||
self.body_type = status;
|
||||
@@ -143,6 +143,10 @@ impl RigidBody {
|
||||
if status == RigidBodyType::Fixed {
|
||||
self.vels = RigidBodyVelocity::zero();
|
||||
}
|
||||
|
||||
if self.is_dynamic() && wake_up {
|
||||
self.wake_up(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user