cloth: GPU XPBD cloth on the ordinary geometry compute chain.
Python entry point: vork.cloth.attach(scene, node, *, pins, collider, ...).
attach edits scene in place, returns None and updates the node geometry reference.
Call before write_scene, on native triangle buffers in world metres. Pins are
vertex indices; collider names a native mesh, including animated skin or morphs.
Controls: vork help cloth --all.

<!-- all -->
# Cloth simulation

attach(scene, node, *, pins=(), collider=None, dt=None, iterations=64,
       density=.2, stretch_modulus=50000, bending_rigidity=.002, damping=.8,
       collision_margin=.004, acceleration=None)

The helper appends ordinary compute programs and state to scene.simulation and
rewires POSITION/NORMAL/TANGENT, preserving surface materials, UVs and other
attributes. Each object receives automatic private state, reset, checkpoints
and canonical predecessor inputs. Existing passes keep their order. Optional
Slang includes share generated typed accessors: cloth/solver.slang,
cloth/body.slang, cloth/self.slang. No renderer cloth primitive or extra clock.

Units: density kg/m², stretch modulus N/m, bending rigidity N·m, damping 1/s,
margin metres. Mass uses triangle area; stretch/dihedral compliance uses dual
edge widths. XPBD accumulates multipliers within each tick, with compliance/dt².
Check convergence for the chosen mesh.

Omitted dt inherits scene.simulation.dt, otherwise 1/240 seconds. All patches
share that exact clock. iterations is positive and even. Pins follow canonical
predecessor positions, so native morphs/skin can animate attachments.
acceleration is a Slang body with i, p, v and time, returning float3 in m/s²
INCLUDING gravity. Default: float3(0,-9.81,0).
This prescribes acceleration, not calibrated aerodynamic pressure.

Use consistently oriented fixed native triangles, 3..1024 vertices per patch,
no unused vertices, degenerate triangles or nonmanifold edges. Bake transforms
into rest vertices and keep each cloth node at an identity root; animate pins
through skin/morphs instead of root TRS. Instances, imported geometry,
subdivision and computed colliders need a baked native proxy. A collider may
have 1..4096 triangles and authored NORMAL (split triangle vertices for face
normals); the general Geometry input samples it at canonical tick
left endpoints. No continuous collision detection: motion per tick must be small
relative to contact distances; reduce dt to resolve fast motion.

collision_margin is a positive finite distance in world metres, default .004.
Body contact uses that margin; self-contact separation is 6*collision_margin
(three margins per surface). Vertex/triangle and edge/edge pairs whose closest
rest-pose distance is below that separation are excluded from self-contact.
Edges and altitudes may be shorter than the separation. Rest exclusions persist
through deformation, including initially overlapping layers. Increasing margin
increases separation and exclusions; use smaller dt for fast motion.

Surface contact uses point/face and edge/edge constraints and Coulomb friction .6.
Contact planes refresh up to eight times per tick. Limit: 512 combined
body/self-contact slots per vertex.
Overflow rejects output with the cloth node name, capacity and a lower bound on
required slots. A reported overflow invalidates the installed scene and requires
reinstalling it before rendering again; resetting simulation state alone does not
clear the publication failure. Dense folds,
initial intersections and large margins can exhaust capacity; reduce the margin
or initial intersections, or reduce dt for fast motion and extreme folding.

Publication reconstructs area-weighted normals and UV0 tangents/handedness;
without UV0 it supplies a finite geometric frame. Duplicated seam vertices are
independent unless connected by triangles. State stays on GPU; no runtime
position readback. Cost grows with contacts and iterations; contact-heavy cloth has no interactive
performance guarantee.
