Skip to main content

soft_body_events

The tears applied during a step, whether they were generated by the simulation itself or requested with SoftBody::tear_edge, are reported the same way as the collision events: by giving an event handler (EventHandler::handle_soft_body_tear_event) to the step. Each event (a SoftBodyTearEvent) identifies the soft-body that tore and gives the pieces it was split into, so the rendering of the scene can be updated accordingly:

// Tears applied during a step are reported through the event handler.
let (collision_send, _collision_recv) = std::sync::mpsc::channel();
let (contact_force_send, _contact_force_recv) = std::sync::mpsc::channel();
let (soft_body_tear_send, soft_body_tear_recv) = std::sync::mpsc::channel();
let event_handler =
ChannelEventCollector::new(collision_send, contact_force_send, soft_body_tear_send);
world.step_with_events(&(), &event_handler);
while let Ok(tear_event) = soft_body_tear_recv.try_recv() {
println!("Soft body {:?} tore", tear_event.soft_body);
}