Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## Unreleased

### Fixed

- Snapshots of soft–rigid contacts: `RigidPairContacts::soft` (the soft–rigid vertex contacts that warm-start the
next update) is now serialized, so a world restored from a snapshot taken during a soft–rigid contact continues
without cold-starting that contact in the reported cloth-and-ball case (#1038). **Snapshot format change:** snapshots written by
earlier versions cannot be loaded by this version and vice versa, including worlds without soft bodies (one extra
byte per rigid contact pair).

## v0.36.1 (4 October 2026)

### Added
Expand Down
2 changes: 1 addition & 1 deletion crates/rapier2d/tests/snapshot_portability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rapier2d::prelude::*;
/// Snapshot size in bytes, and its FNV-1a digest. Both, because the size alone localizes a
/// failure: a differing size means a container's *encoding* changed, an equal size with a
/// differing digest means the values did.
const GOLDEN: (usize, u64) = (90_574, 0x3019_f8f0_67c5_e643);
const GOLDEN: (usize, u64) = (90_707, 0xce54_129e_4f61_529f);

const STEPS: usize = 60;

Expand Down
2 changes: 1 addition & 1 deletion crates/rapier3d/tests/snapshot_portability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rapier3d::prelude::*;
/// Snapshot size in bytes, and its FNV-1a digest. Both, because the size alone localizes a
/// failure: a differing size means a container's *encoding* changed, an equal size with a
/// differing digest means the values did.
const GOLDEN: (usize, u64) = (488_334, 0x3f5e_ac53_ad07_5243);
const GOLDEN: (usize, u64) = (489_223, 0xc096_63ba_4908_50cb);

const STEPS: usize = 60;

Expand Down
59 changes: 59 additions & 0 deletions crates/rapier3d/tests/snapshot_roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,62 @@ fn replacing_the_pipeline_changes_nothing() {
assert_same(step, &record(&a), &record(&b), "fresh pipeline");
}
}

/// A pinned cloth with a heavy ball landing on it (issue #1038). The soft–rigid pair's vertex
/// contacts warm-start the next update, so a snapshot taken during the impact must carry them:
/// with them skipped, the restored world cold-starts the contact and diverges on its first
/// step. 48 steps is the first step of the impact.
#[test]
fn soft_rigid_cloth_and_ball() {
let mut world = PhysicsWorld::new();
world.integration_parameters.dt = 1.0 / 64.0;
world.insert(
RigidBodyBuilder::fixed().translation(Vector::new(0.0, -0.1, 0.0)),
ColliderBuilder::cuboid(30.0, 0.1, 30.0),
);
let n = 24;
let border = (0..n * n)
.filter(|k| *k < n || *k >= n * (n - 1) || k % n == 0 || k % n == n - 1)
.map(|k| k as u32)
.collect();
let mut material = SoftBodyMaterial::uniform(SpringCoefficients::new(100.0, 1.0));
material.bend_softness = SpringCoefficients::new(3.0, 1.0);
let mut cloth = SoftBodyBuilder::cloth(
Vector::new(-1.15, 3.0, -1.15),
Vector::new(0.1, 0.0, 0.0),
Vector::new(0.0, 0.0, 0.1),
n,
n,
);
cloth.pinned = border;
cloth.material = material;
cloth.particle_mass = 0.02;
cloth.masses.clear();
cloth.particle_radius = 0.05;
cloth.collider_template = Some(ColliderBuilder::ball(0.05).density(0.0).friction(0.8));
cloth.particle_settings.can_sleep = false;
world.insert_soft_body(cloth);
let (_, ball_collider) = world.insert(
RigidBodyBuilder::dynamic()
.translation(Vector::new(0.0, 6.0, 0.0))
.can_sleep(false),
ColliderBuilder::ball(0.6).density(30.0),
);
check_roundtrip(
"soft-rigid cloth and ball",
world,
48,
4,
false,
move |world, step, _| {
if step == 48 {
assert!(
world
.contact_pairs_with(ball_collider)
.any(|pair| pair.has_any_active_contact()),
"the ball must actively contact the cloth at the snapshot boundary"
);
}
},
);
}
5 changes: 3 additions & 2 deletions src/geometry/contact_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ pub struct RigidPairContacts {
/// world-frozen solver anchors) where the uninterrupted run would have recycled.
pub(crate) recycle_state: Option<ContactRecycleState>,
/// The soft contacts of a soft-rigid pair beside its manifolds (the predictive vertex
/// contacts and the volume patch, see `SoftRigidContacts`), rebuilt by every update; `None`
/// contacts and the volume patch, see `SoftRigidContacts`). Rebuilt by each update, but
/// previous vertex impulses are reused to warm-start the next contact update. These contacts
/// must be serialized for deterministic continuation after restoring a snapshot; `None`
/// for every other pair.
#[cfg_attr(feature = "serde-serialize", serde(skip))]
pub(crate) soft: Option<Box<SoftRigidContacts>>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub struct SoftVolumePatch {
/// The volume patch of a closed soft surface intruded by a rigid collider (see
/// `SoftOverlapConstraint`): the bins (own side only), the surface vertices' depths in the patch
/// (`NEG_INFINITY` outside, patch-constraint policies only), and the rigid side's CoM and rotation.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub struct SoftRigidPatch {
pub bins: Vec<VolumeBin>,
Expand All @@ -217,6 +218,7 @@ pub struct SoftRigidPatch {
/// A predictive contact between a surface vertex of a soft-rigid pair and the convex rigid
/// collider: the support of the vertex itself, which an element's manifold does not give when
/// the rigid shape wraps the element (a single closest point per element).
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug)]
pub(crate) struct SoftRigidVertexContact {
/// The vertex of the soft mesh.
Expand All @@ -237,6 +239,7 @@ pub(crate) struct SoftRigidVertexContact {
}

/// The soft contacts of a soft-rigid pair beside its manifolds, rebuilt by every update.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Clone, Default, Debug)]
pub(crate) struct SoftRigidContacts {
/// The predictive vertex contacts, sorted by vertex.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ pub(super) struct VolumeSide<'a> {
/// One volume constraint of a pair (see `SoftOverlapConstraint`): the whole patch, or a cell of
/// the multi-volume grid (Allard et al. 2010, section 5), as particle entries (particle,
/// gradient) per side.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
pub struct VolumeBin {
/// The own side's entries: (particle, volume gradient).
Expand Down
Loading