Skip to content

Commit 28d0ba9

Browse files
authored
feat: add support for soft-bodies (#1010)
* feat(soft-body): add real-time soft bodies with deformable surface colliders, debug rendering and testbed support * feat(soft-body): add the 2D and 3D demos and integration tests * feat(soft-body): add the FEM solver behind the `fem` feature, with demos, tests and a bench * feat(soft-body): add clusters: SoftFrame proxies, per-cluster shape matching, material sugar and impulse joints on clusters * feat(testbed): add soft joints demos, mouse dragging of dynamic objects and a Debug tab, fix the camera view axis * feat(soft-body): bind collision meshes to clusters with `ColliderSet::insert_deformable`, wire meshes, CCD targets and mesh rendering * feat(soft-body): tangle prevention and detection: recovery settings, velocity margin, edge speculation, crossing detection * feat(soft-body): tangle recovery: stand-down, expel-only gate and crossing repulsion on crossed pairs * feat(soft-body): intersection-volume constraints for crossed soft and rigid pairs, self-overlaps and the skin-volume contact model * feat(soft-body): self-repulsion guided by the fold's volume normal * feat(soft-body): FEM augmented mass for every constraint, volume elements, a parallel response stage and column responses * feat(soft-body): tear by force with a smoothed load, per-element resistance, interior strength and damage propagation * feat(soft-body): plastic flow of the edge rest lengths with yield, creep, cap and direction * feat(soft-body): tear events and pieces, blade cuts, point and radial impulses, tear-load coloring and 2D demos * feat(testbed): show the measured frame time and the recent step peak in the performance tab * feat(soft-body): predictive vertex contacts against convex rigid shapes * feat(soft-body): measure-preserving particle splits for cracks and cuts, pieces as soft bodies, min-piece setting, rest contact gaps * feat(soft-body): never split a pinned particle; the testbed draws and grabs the torn-off pieces * feat(soft-body): stress-based plasticity with rest shapes following the flow, dihedral creases, reset and per-body PGS iterations * feat(testbed): soft-body stress scenes, cloth on a Keva tower, translucent bins and lighting tweaks * fix(soft-body): two-sided contacts for open 2D surfaces and per-endpoint interior segment contacts * fix(testbed): time frames from the renderer's return so vsync waits are left out of the timings * chore: switch to parry and glamx git dependencies * chore: switch back to the published version of glamx * feat(typescript): expose soft bodies in the JS bindings and testbeds * feat(python): expose soft bodies in the Python bindings and testbed * docs(website): soft-body examples for the Rust and JS snippets, and the changed pipeline signatures * chore: switch to parry 0.31 * feat: improve handling of the ORIENTED flag and oriented/shell soft-bodies * chore: CI fixes * chore: small demo tweaks * chore: more CI fixes
1 parent d90dd95 commit 28d0ba9

411 files changed

Lines changed: 62681 additions & 935 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/rapier-ci-build.yml‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,34 @@ jobs:
310310
workspaces: website/docs-examples
311311
- name: Tests injection + code snippets
312312
run: cd website/docs-examples && cargo test
313-
# Checks the JavaScript documentation snippets build (against the published @dimforge/rapier).
313+
# Checks the JavaScript documentation snippets build against the in-tree bindings, so a
314+
# snippet may use an API before it is released on npm. The snippet package depends on
315+
# `typescript/builds/rapier{2,3}d/pkg` through a `file:` path, which this job builds first
316+
# (the same two steps a local checkout runs).
314317
website-javascript-snippets:
315318
runs-on: ubuntu-latest
316319
strategy:
317320
matrix:
318321
dimension: [2d, 3d]
319-
defaults:
320-
run:
321-
working-directory: ./website/docs-examples/${{ matrix.dimension }}/javascript
322322
steps:
323323
- uses: actions/checkout@v4
324+
- uses: Swatinem/rust-cache@v2
325+
with:
326+
workspaces: typescript
327+
- name: Generate the binding crates
328+
working-directory: ./typescript
329+
run: |
330+
npm ci
331+
cargo run -p prepare_builds -- -d dim${{ matrix.dimension == '2d' && '2' || '3' }} -f non-deterministic
332+
- name: Build the in-tree bindings
333+
working-directory: ./typescript/builds/rapier${{ matrix.dimension }}
334+
run: |
335+
npm i
336+
npm run build:wasm
337+
npm run build:ts
324338
- name: Install dependencies
339+
working-directory: ./website/docs-examples/${{ matrix.dimension }}/javascript
325340
run: npm ci
326341
- name: Builds javascript snippets.
342+
working-directory: ./website/docs-examples/${{ matrix.dimension }}/javascript
327343
run: npm run build

‎.typos.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ ignore-hidden = false
1616
[default]
1717
extend-ignore-re = [
1818
"\\bPolygon::PN\\b",
19+
# Index notation in the strain-constraint docs: `m_ba`, `ε_ba` (the b,a entry).
20+
"_ba\\b",
1921
]
2022

2123
# Case sensitive, matches entire word.

‎Cargo.toml‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ needless_lifetimes = "allow"
6666
[workspace.dependencies]
6767
# Core math
6868
nalgebra = { version = "0.35", default-features = false, features = ["macros"] }
69-
glamx = { version = "0.3", default-features = false }
69+
glamx = { version = "0.3.1", default-features = false }
7070
simba = { version = "0.10.2", default-features = false }
7171
num-traits = { version = "0.2", default-features = false }
7272
approx = { version = "0.5", default-features = false }
7373

7474
# Parry (each crate picks its own variant)
75-
parry2d = { version = "0.30.2", default-features = false, features = ["required-features"] }
76-
parry3d = { version = "0.30.2", default-features = false, features = ["required-features"] }
77-
parry2d-f64 = { version = "0.30.2", default-features = false, features = ["required-features"] }
78-
parry3d-f64 = { version = "0.30.2", default-features = false, features = ["required-features"] }
75+
parry2d = { version = "0.31.1", default-features = false, features = ["required-features"] }
76+
parry3d = { version = "0.31.1", default-features = false, features = ["required-features"] }
77+
parry2d-f64 = { version = "0.31.1", default-features = false, features = ["required-features"] }
78+
parry3d-f64 = { version = "0.31.1", default-features = false, features = ["required-features"] }
7979

8080
# Utilities
8181
arrayvec = { version = "0.7", default-features = false }
@@ -159,10 +159,11 @@ tempfile = "3"
159159

160160
#kiss3d = { git = "https://github.com/sebcrozet/kiss3d", branch = "render-2d" }
161161
#nalgebra = { git = "https://github.com/dimforge/nalgebra", branch = "dev" }
162-
#parry2d = { git = "https://github.com/dimforge/parry", branch = "master" }
163-
#parry3d = { git = "https://github.com/dimforge/parry", branch = "master" }
164-
#parry2d-f64 = { git = "https://github.com/dimforge/parry", branch = "master" }
165-
#parry3d-f64 = { git = "https://github.com/dimforge/parry", branch = "master" }
162+
#glamx = { git = "https://github.com/dimforge/glamx", branch = "fix-lerp2" }
163+
#parry2d = { git = "https://github.com/dimforge/parry", branch = "soft-bodies" }
164+
#parry3d = { git = "https://github.com/dimforge/parry", branch = "soft-bodies" }
165+
#parry2d-f64 = { git = "https://github.com/dimforge/parry", branch = "soft-bodies" }
166+
#parry3d-f64 = { git = "https://github.com/dimforge/parry", branch = "soft-bodies" }
166167

167168
# See https://github.com/EmbarkStudios/puffin/pull/234
168169
puffin_egui = { git = "https://github.com/tedsteen/puffin.git", rev = "11771ebe00fd257aedbb545df3339ad597b1cc34" }

‎crates/rapier2d-f64/Cargo.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ alloc = [
4040
std = [
4141
"alloc",
4242
"parry2d-f64/std",
43+
# Needed by `SoftBodyBuilder::volumetric`, for the Delaunay refinement. Kept out of
44+
# `alloc`: spade's `robust` dependency does not build without the standard library.
45+
"parry2d-f64/spade",
4346
"nalgebra/std",
4447
"simba/std",
4548
"num-traits/std",
4649
"approx/std",
4750
"thiserror/std",
4851
"serde?/std",
4952
]
53+
# Adds an alternative FEM solver for soft bodies, selected per body with
54+
# `SoftBodyBuilder::solver(SoftBodySolver::Fem)`. Instead of resolving elasticity
55+
# as sequential impulse rows, the FEM path assembles the element forces and
56+
# tangent stiffness of a strain-energy density and takes one implicit Euler step
57+
# per substep, solving `(M + h D + h^2 K) dv = b` over the whole body. Off by
58+
# default: it adds per-body solver state and is still experimental.
59+
fem = []
5060
parallel = ["dep:rayon", "std", "parry2d-f64/parallel"]
5161
# Drops the `Sync` requirement from callbacks (`PhysicsHooks`, `EventHandler`).
5262
# As a side effect, this also removes the dedicated threadpool API from the physics world

‎crates/rapier2d/Cargo.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ alloc = [
4040
std = [
4141
"alloc",
4242
"parry2d/std",
43+
# Needed by `SoftBodyBuilder::volumetric`, for the Delaunay refinement. Kept out of
44+
# `alloc`: spade's `robust` dependency does not build without the standard library.
45+
"parry2d/spade",
4346
"nalgebra/std",
4447
"simba/std",
4548
"num-traits/std",
@@ -48,6 +51,13 @@ std = [
4851
"wide/std",
4952
"serde?/std",
5053
]
54+
# Adds an alternative FEM solver for soft bodies, selected per body with
55+
# `SoftBodyBuilder::solver(SoftBodySolver::Fem)`. Instead of resolving elasticity
56+
# as sequential impulse rows, the FEM path assembles the element forces and
57+
# tangent stiffness of a strain-energy density and takes one implicit Euler step
58+
# per substep, solving `(M + h D + h^2 K) dv = b` over the whole body. Off by
59+
# default: it adds per-body solver state and is still experimental.
60+
fem = []
5161
parallel = ["dep:rayon", "std", "parry2d/parallel"]
5262
# Drops the `Sync` requirement from callbacks (`PhysicsHooks`, `EventHandler`).
5363
# As a side effect, this also removes the dedicated threadpool API from the physics world

‎crates/rapier2d/tests/ccd_default_vs_fixed.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct Harness {
1010
colliders: ColliderSet,
1111
impulse_joints: ImpulseJointSet,
1212
multibody_joints: MultibodyJointSet,
13+
soft_bodies: SoftBodySet,
1314
pipeline: PhysicsPipeline,
1415
bf: BroadPhaseBvh,
1516
nf: NarrowPhase,
@@ -26,6 +27,7 @@ impl Harness {
2627
colliders: ColliderSet::new(),
2728
impulse_joints: ImpulseJointSet::new(),
2829
multibody_joints: MultibodyJointSet::new(),
30+
soft_bodies: SoftBodySet::new(),
2931
pipeline: PhysicsPipeline::new(),
3032
bf: BroadPhaseBvh::new(),
3133
nf: NarrowPhase::new(),
@@ -48,6 +50,7 @@ impl Harness {
4850
&mut self.colliders,
4951
&mut self.impulse_joints,
5052
&mut self.multibody_joints,
53+
&mut self.soft_bodies,
5154
&mut self.ccd,
5255
&(),
5356
&(),

‎crates/rapier2d/tests/ccd_oriented_wall.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn fires_through(wall: ColliderBuilder, speed: f32) -> f32 {
88
let mut colliders = ColliderSet::new();
99
let mut impulse_joints = ImpulseJointSet::new();
1010
let mut multibody_joints = MultibodyJointSet::new();
11+
let mut soft_bodies = SoftBodySet::new();
1112
let mut pipeline = PhysicsPipeline::new();
1213
let mut bf = BroadPhaseBvh::new();
1314
let mut nf = NarrowPhase::new();
@@ -37,6 +38,7 @@ fn fires_through(wall: ColliderBuilder, speed: f32) -> f32 {
3738
&mut colliders,
3839
&mut impulse_joints,
3940
&mut multibody_joints,
41+
&mut soft_bodies,
4042
&mut ccd,
4143
&(),
4244
&(),

‎crates/rapier2d/tests/ccd_semantics.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ impl EventHandler for EventCollector {
3333
_total_force_magnitude: Real,
3434
) {
3535
}
36+
37+
fn handle_soft_body_tear_event(&self, _soft_bodies: &SoftBodySet, _event: &SoftBodyTearEvent) {}
3638
}
3739

3840
struct Harness {
3941
bodies: RigidBodySet,
4042
colliders: ColliderSet,
4143
impulse_joints: ImpulseJointSet,
4244
multibody_joints: MultibodyJointSet,
45+
soft_bodies: SoftBodySet,
4346
pipeline: PhysicsPipeline,
4447
bf: BroadPhaseBvh,
4548
nf: NarrowPhase,
@@ -57,6 +60,7 @@ impl Harness {
5760
colliders: ColliderSet::new(),
5861
impulse_joints: ImpulseJointSet::new(),
5962
multibody_joints: MultibodyJointSet::new(),
63+
soft_bodies: SoftBodySet::new(),
6064
pipeline: PhysicsPipeline::new(),
6165
bf: BroadPhaseBvh::new(),
6266
nf: NarrowPhase::new(),
@@ -80,6 +84,7 @@ impl Harness {
8084
&mut self.colliders,
8185
&mut self.impulse_joints,
8286
&mut self.multibody_joints,
87+
&mut self.soft_bodies,
8388
&mut self.ccd,
8489
&(),
8590
&self.events,

‎crates/rapier2d/tests/issue_629_large_ground_stability.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct Harness {
1111
colliders: ColliderSet,
1212
impulse_joints: ImpulseJointSet,
1313
multibody_joints: MultibodyJointSet,
14+
soft_bodies: SoftBodySet,
1415
pipeline: PhysicsPipeline,
1516
bf: BroadPhaseBvh,
1617
nf: NarrowPhase,
@@ -27,6 +28,7 @@ impl Harness {
2728
colliders: ColliderSet::new(),
2829
impulse_joints: ImpulseJointSet::new(),
2930
multibody_joints: MultibodyJointSet::new(),
31+
soft_bodies: SoftBodySet::new(),
3032
pipeline: PhysicsPipeline::new(),
3133
bf: BroadPhaseBvh::new(),
3234
nf: NarrowPhase::new(),
@@ -48,6 +50,7 @@ impl Harness {
4850
&mut self.colliders,
4951
&mut self.impulse_joints,
5052
&mut self.multibody_joints,
53+
&mut self.soft_bodies,
5154
&mut self.ccd,
5255
&(),
5356
&(),

‎crates/rapier2d/tests/issue_643_polyline_corner_stuck.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct Harness {
1212
colliders: ColliderSet,
1313
impulse_joints: ImpulseJointSet,
1414
multibody_joints: MultibodyJointSet,
15+
soft_bodies: SoftBodySet,
1516
pipeline: PhysicsPipeline,
1617
bf: BroadPhaseBvh,
1718
nf: NarrowPhase,
@@ -28,6 +29,7 @@ impl Harness {
2829
colliders: ColliderSet::new(),
2930
impulse_joints: ImpulseJointSet::new(),
3031
multibody_joints: MultibodyJointSet::new(),
32+
soft_bodies: SoftBodySet::new(),
3133
pipeline: PhysicsPipeline::new(),
3234
bf: BroadPhaseBvh::new(),
3335
nf: NarrowPhase::new(),
@@ -49,6 +51,7 @@ impl Harness {
4951
&mut self.colliders,
5052
&mut self.impulse_joints,
5153
&mut self.multibody_joints,
54+
&mut self.soft_bodies,
5255
&mut self.ccd,
5356
&(),
5457
&(),

0 commit comments

Comments
 (0)