RFC-0040: Soft bodies (mass-spring grids)
Status: Normative. The language gains soft bodies: an nx × ny grid of dynamic particles connected by spring constraints, solved by the same deterministic, mass-weighted position relaxation as joints (RFC-0039). Soft bodies act on the EIR component surface (transform positions, velocity, rigid_body mass) and reuse only existing opcodes, so they compose with gravity/integrate and remain byte-identical across the interpreter and JIT.
Declaration
world {
soft cloth {
nx = 8; ny = 8
spacing = 0.25
origin = (0, 4, 0)
mass = 0.2
shape = sphere; size = 0.08
}
}
systems {
gravity { gravity_y = -9.81; dt = 0.016 }
integrate { dt = 0.016 }
soft { body = cloth; stiffness = 1.0; damping = 0.5; iterations = 6 }
}
Fields (all optional except a sensible default): nx (default 8), ny (default 8), spacing (1.0), origin (0,0,0), mass (1.0), and the presentation shape/size applied to every particle.
Rules
- Particles. A
softdeclaration createsnx × ny × nzactive dynamic entities (nzdefaults to 1, a sheet), ids contiguous and immediately after the declared entities, channels, and pools (matchingbuild_scene); particlek = (kz·ny + ky)·nx + kxis named<body>#<k>and starts atorigin + (i·spacing, j·spacing, k·spacing)withmassand a zero velocity. - Constraints. The grid generates:
- structural edges one cell along each axis (
spacing); - shear edges on both diagonals of each coordinate plane (
spacing·√2); - bend edges two cells along each axis (
2·spacing). Withnz = 1the edges involving the z axis vanish, leaving the 2D sheet. Each is a distance constraint|p_a − p_b| = rest.
- structural edges one cell along each axis (
- Lowering. A
softsystem lowers one function per particle. The particle owning a constraint's lower index applies it; per iteration it applies every such constraint as a position-relaxation pass (the RFC-0039 distance math, mass-weighted byis_dynamic ? 1/mass : 0), then the next particle's function applies its own.iterations(default 4) repeats the per-particle sweep;stiffnessand optionaldamping(along-axis relative velocity) parameterize the springs. - Determinism. The sweep order is fixed (particle id, then constraint order, then iterations); every read/write is an existing opcode, so results are reproducible and identical on both backends. No new opcode, ABI, schema, protocol, snapshot, or transaction contract is introduced.
- Presentation. Particles render as their
shape; the structural and shear edges are emitted asPresentationFrame.bonds, so the viewer draws the mesh. - Scope. This is a lattice of point masses with distance springs:
nz = 1models cloth/membrane sheets,nz > 1a soft gel cube. Volume/pressure constraints and self-collision are out of scope;softcomplementsjoint/pooland does not replace a full FEM solver.
Implementation is staged: Stage 1 adds the soft declaration, particle layout, and the soft system (structural/shear/bend, position relaxation). Stage 2 adds render bonds and the example/docs. Stage 3 re-baselines conformance and the example programs.