SoA world: joints, force/torque write lanes, capsules and boxes, parent/limb lanes
ABI 2. One body descriptor replaces add_sphere/add_static_box (kinds: sphere, capsule, box, static box). Revolute, spherical and weld joints created from a world anchor and axis, with joint state lanes (angle, frame A orientation, relative rotation, relative angular velocity). Per-body force and torque write lanes, applied before the step then cleared; non-finite values refuse the step. Parent and limb index lanes. Tests run serially: concurrent b3CreateWorld aborts the host. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7d9f1b57a1
commit
8bb0d0b1de
5 changed files with 908 additions and 137 deletions
|
|
@ -12,27 +12,45 @@ separate native object (`ymir_box3d_soa.c`, ABI 1) so the Aetheria session's con
|
|||
|
||||
## Contract
|
||||
|
||||
- Native: `ymir_box3d_soa_create(capacity, gravity) / add_sphere / add_static_box / step / get_view / destroy`.
|
||||
Capacity is fixed at creation, so lane pointers never move.
|
||||
- Lanes (`ymir_box3d_soa_view`): `stable_id`, `kind`, position xyz, rotation quaternion xyzw, linear
|
||||
velocity xyz, angular velocity xyz. One contiguous array per component, indexed by body.
|
||||
- Lane contents change only inside `step`. Between steps a caller may read any lane in place.
|
||||
- Managed (`src/Ymir.Box3D/Box3DSoaWorld.cs`, internal): `Box3DSoaView` exposes each lane as a
|
||||
`ReadOnlySpan<T>` over native memory. Spans are invalid after `Dispose`. `Count` is as of when the
|
||||
view was taken, so take it after the last add.
|
||||
- Native (ABI 2): `ymir_box3d_soa_create(capacity, joint_capacity, gravity) / add_body / add_joint / step /
|
||||
get_view / destroy`. `add_body` takes one descriptor (sphere, capsule, box, static box; position,
|
||||
rotation, velocity, size, density, friction, restitution, parent, limb). Capacities are fixed at creation,
|
||||
so lane pointers never move.
|
||||
- Body lanes (`ymir_box3d_soa_view`): `stable_id`, `kind`, `parent` and `limb` (set at creation, not read by
|
||||
Box3D: the limb tree for the consumer), position xyz, rotation quaternion xyzw, linear and angular
|
||||
velocity xyz. One contiguous array per component, indexed by body.
|
||||
- Write lanes: per-body world `force` (at the centre of mass) and `torque`, xyz, mutable through the view.
|
||||
`step` applies them to the dynamic bodies and clears them, so a lane holds one step's intent. A
|
||||
non-finite value refuses the whole step before any body is touched.
|
||||
- Joints: `add_joint` takes two body indices (B is the child), a world anchor and axis, and a kind
|
||||
(revolute, spherical, weld). The joint frame has its z axis on the axis (the hinge axis); the creation
|
||||
pose is the joint's zero. Optional limits: revolute angle, spherical swing cone and twist. Joint lanes:
|
||||
`joint_kind`, `joint_body_a/b`, `joint_angle` (Box3D's revolute angle or spherical twist), `joint_frame`
|
||||
(world orientation of frame A, quaternion), `joint_rotation` (frame B relative to frame A, quaternion,
|
||||
w >= 0) and `joint_angular_velocity` (B minus A, in frame A). A consumer can compute a joint torque from
|
||||
these and write it as equal and opposite torques on the two body lanes.
|
||||
- State lanes change only inside `step`. Between steps a caller may read any state lane in place.
|
||||
- Managed (`src/Ymir.Box3D/Box3DSoaWorld.cs`, internal): `Box3DSoaView` exposes each lane as a span over
|
||||
native memory (`ReadOnlySpan` for state, `Span` for write lanes). Spans are invalid after `Dispose`.
|
||||
`Count` and `JointCount` are as of when the view was taken, so take it after the last add.
|
||||
- Determinism: one Box3D worker, bodies stepped in insertion order, same inputs give identical lane
|
||||
bytes on the same build. It is not claimed across platforms or CPUs.
|
||||
- Concurrency: creating Box3D worlds from several threads at once aborts the process (seen in tests);
|
||||
create worlds one at a time.
|
||||
|
||||
## Tests
|
||||
|
||||
`tests/Ymir.Box3D.Soa.Tests`: gravity and rest read through one held view, address stability across
|
||||
steps, two runs byte-equal at six checkpoints (25 spheres colliding on a slab), a one-ulp input
|
||||
difference diverging (so the equality check can fail), argument refusal, dispose.
|
||||
`tests/Ymir.Box3D.Soa.Tests`, run serially: gravity and rest read through one held view, address stability
|
||||
across steps, two runs byte-equal at six checkpoints (25 spheres colliding on a slab), a one-ulp input
|
||||
difference diverging, argument refusal, dispose; and for joints: hinge angle and the relative-rotation
|
||||
lanes agreeing, an off-axis hinge, a limit and a weld, a spherical joint leaving the swing plane, force and
|
||||
torque lanes (exact acceleration, cleared after the step, static bodies ignoring them, NaN refusing the
|
||||
step), capsule and box rest heights with parent and limb lanes, refusals, and bit-identical repeat runs of
|
||||
a torque-driven jointed body.
|
||||
|
||||
## Needed next for Lodur
|
||||
## Not done
|
||||
|
||||
Recorded as a mind follow-up; summary: joints (Box3D has revolute, spherical, weld, motor), a body
|
||||
layout beyond spheres and static boxes (capsules, boxes, compound, per-shape density), a torque/force
|
||||
write path (per-body lane written before the step, as the planar session's `apply_torque`), joint
|
||||
state lanes, contact facts for the SoA world, and a public surface in `Ymir.Core` rather than an
|
||||
internal wrapper.
|
||||
Contact facts for the SoA world (Begin/Hit/End), body removal with a stable ordering rule, compound bodies
|
||||
and per-shape material, joint motors and springs (Lodur drives joints from torque lanes instead), and a
|
||||
public typed surface in `Ymir.Core` (the wrapper is internal, visible to the test assembly). Windows build
|
||||
and Unity consumption are unrun; cross-platform bit-identity is unclaimed.
|
||||
|
|
|
|||
Loading…
Reference in a new issue