Skip to content

Commit 0c63c64

Browse files
committed
Update function
1 parent 134f433 commit 0c63c64

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

src/pipeline/physics_pipeline.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,100 @@ impl PhysicsPipeline {
668668

669669
self.counters.step_completed();
670670
}
671+
672+
673+
/// Update without physics simulation.
674+
pub fn update(
675+
&mut self,
676+
gravity: &Vector<Real>,
677+
integration_parameters: &IntegrationParameters,
678+
islands: &mut IslandManager,
679+
broad_phase: &mut BroadPhaseBvh,
680+
narrow_phase: &mut NarrowPhase,
681+
bodies: &mut RigidBodySet,
682+
colliders: &mut ColliderSet,
683+
impulse_joints: &mut ImpulseJointSet,
684+
multibody_joints: &mut MultibodyJointSet,
685+
ccd_solver: &mut CCDSolver,
686+
hooks: &dyn PhysicsHooks,
687+
events: &dyn EventHandler,
688+
) {
689+
self.counters.reset();
690+
self.counters.step_started();
691+
692+
// Apply modifications.
693+
let mut modified_colliders = colliders.take_modified();
694+
let mut removed_colliders = colliders.take_removed();
695+
696+
super::user_changes::handle_user_changes_to_colliders(
697+
bodies,
698+
colliders,
699+
&modified_colliders[..],
700+
);
701+
702+
let mut modified_bodies = bodies.take_modified();
703+
super::user_changes::handle_user_changes_to_rigid_bodies(
704+
Some(islands),
705+
bodies,
706+
colliders,
707+
impulse_joints,
708+
multibody_joints,
709+
&modified_bodies,
710+
&mut modified_colliders,
711+
);
712+
713+
// Disabled colliders are treated as if they were removed.
714+
// NOTE: this must be called here, after handle_user_changes_to_rigid_bodies to take into
715+
// account colliders disabled because of their parent rigid-body.
716+
removed_colliders.extend(
717+
modified_colliders
718+
.iter()
719+
.copied()
720+
.filter(|h| colliders.get(*h).map(|c| !c.is_enabled()).unwrap_or(false)),
721+
);
722+
self.counters.stages.user_changes.pause();
723+
724+
self.detect_collisions(
725+
integration_parameters,
726+
islands,
727+
broad_phase,
728+
narrow_phase,
729+
bodies,
730+
colliders,
731+
impulse_joints,
732+
multibody_joints,
733+
&modified_colliders,
734+
&removed_colliders,
735+
hooks,
736+
events,
737+
true,
738+
);
739+
740+
self.counters.stages.user_changes.resume();
741+
self.clear_modified_colliders(colliders, &mut modified_colliders);
742+
self.clear_modified_bodies(bodies, &mut modified_bodies);
743+
removed_colliders.clear();
744+
self.counters.stages.user_changes.pause();
745+
746+
// Finally, make sure we update the world mass-properties of the rigid-bodies
747+
// that moved. Otherwise, users may end up applying forces with respect to an
748+
// outdated center of mass.
749+
// TODO: avoid updating the world mass properties twice (here, and
750+
// at the beginning of the next timestep) for bodies that were
751+
// not modified by the user in the mean time.
752+
self.counters.stages.update_time.resume();
753+
for handle in islands.active_bodies() {
754+
let rb = bodies.index_mut_internal(*handle);
755+
rb.mprops
756+
.update_world_mass_properties(rb.body_type, &rb.pos.position);
757+
}
758+
self.counters.stages.update_time.pause();
759+
760+
// Re-insert the modified vector we extracted for the borrow-checker.
761+
colliders.set_modified(modified_colliders);
762+
763+
self.counters.step_completed();
764+
}
671765
}
672766

673767
#[cfg(test)]

0 commit comments

Comments
 (0)