Skip to main content

soft_body_events

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

The collector keeps the events of every step it is given to, until it is emptied with r3EventCollector_Clear. The tear events are counted by r3EventCollector_TearEventCount, and r3EventCollector_TearEvent returns an owned copy of one of them, to be freed with r3FreeSoftBodyTearEvent. This is the same R3SoftBodyTearEvent as the one returned by r3SoftBody_Tear and r3CutSoftBody, so all the accessors described in the previous section apply to it as well:

// Tears applied during a step are reported through the event collector.
R2EventCollector *events = r2NewEventCollector();
r2Step(world, NULL, events);
size_t num_tear_events = r2EventCollector_TearEventCount(events);
for (size_t i = 0; i < num_tear_events; i++) {
// An owned copy of the event.
R2SoftBodyTearEvent *tear_event = r2EventCollector_TearEvent(events, i);
R2SoftBodyHandle torn = r2SoftBodyTearEvent_SoftBody(tear_event);
printf("Soft body %u tore\n", torn.index);
r2FreeSoftBodyTearEvent(tear_event);
}
// The collector keeps its events until it is cleared.
r2EventCollector_Clear(events);