Skip to content

physics: draw a world in a scene graph between its last two states (P6a) - #648

Merged
transfix merged 2 commits into
masterfrom
feat/physics-scene-binding
Oct 17, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/physics-scene-binding

Conversation

@transfix

Copy link
Copy Markdown
Owner

Why

The first piece of P6a, the scene binding: how a cvc::physics world shows up in the scene graph. The world steps in fixed quanta and the display runs at its own rate, so drawing each body at its newest state judders whenever the two rates beat. Nothing in the tree interpolates poses today; the nav demos draw the latest snapshot.

Change

  • world::states(ids) reads several bodies and the tick under one lock, so a batch never mixes two steps. An unknown or removed id reads as empty instead of throwing.
  • cvc::physics::pose_tracker (core, std-only header) keeps the last two states of the bodies it tracks.
    • follow(clock) steps the world in two parts when several steps are due, so the two samples are the last two ticks. It replaces world::follow; don't call both.
    • alpha(clock, clock_alpha) converts the clock's fraction of a quantum into the world's fraction of a step, for a world that steps once every several quanta.
    • sample_all / sample_one lerp the position and blend the rotation along the shorter arc. A body without a previous sample exactly one step back is drawn at its newest state: just tracked, after a gap, after a restore, or after snap() for a teleport.
    • Removed bodies drop out at the next capture. Thread-safe: one thread steps, others sample, and a sample never sees half a capture.
  • cvc::gl::physics_scene_binding (cvcGL) owns a tracker and writes the scene.
    • bind(id, node, body_from_visual) sets the node's local transform through setPoseMatrix every present(). That call is already thread-safe: latest wins, applied on the owner thread.
    • bind_group(ids, sink) hands a merged-mesh swarm its poses once per frame, in group order.
    • Nodes are held weakly. Destroyed nodes and removed bodies unbind, and the node keeps its last pose.
  • Docs: PHYSICS_API.md covers the one-writer-per-actor rule: dynamic bodies are drawn from physics, while kinematic actors are drawn by their own source, which also calls move_kinematic. It also covers using world_binding's pull()/push() around the scene binding's follow, and the clock-quantum mismatch: cvc::app's clock defaults to 1/120 s and a world to 0.01 s, which throws. The roadmap gets a P6a row.

Verified (Windows, MSVC Release)

  • physics_pose_tracker_test: 10/10 pass, including a Jolt box falling between its last two states and a 2000-frame sampler-vs-stepper tearing check.
  • cvcgl_physics_scene_binding (headless): 6/6 pass. A bound node's transform equals the interpolated pose bit for bit; an off-thread present() is posted and applied at processEvents(); group order; removed bodies and destroyed nodes unbind; a slower world's alpha; a Jolt crate lands at its half height.
  • physics_world_test 30/30 and system_macro_headers_test 3/3 still pass.

Next in P6a

  • The city bundle loader moves into the library, so the scene and the world build static geometry from one source.
  • Ariadne physics: / body: specs.
  • A demo.

world::states(ids) reads several bodies and the tick under one lock; an
unknown or removed id reads as empty.

cvc::physics::pose_tracker keeps the last two states of the bodies it
tracks and interpolates between them at the clock's fraction of a step
(position lerp, rotation along the shorter arc). follow(clock) steps the
world in two parts when several steps are due, so the samples are the
last two ticks; alpha() converts the clock's alpha for a world that steps
every several quanta; snap() handles teleports; removed bodies drop out.

cvc::gl::physics_scene_binding (cvcGL) poses bound nodes through
setPoseMatrix every present(), with an optional visual offset, and hands
merged-mesh groups their poses through a sink. Nodes are held weakly;
destroyed nodes and removed bodies unbind. One writer per actor: dynamic
bodies are drawn from physics, kinematic actors by their own source.
On a fast runner the stepping loop finished 2000 frames before the
viewer thread was first scheduled, so SamplersNeverSeeHalfACapture saw
no samples. Start once the viewer has sampled, and step until both
sides have done real work (2000 frames and 200 samples), capped.
@transfix
transfix merged commit 2989213 into master Oct 17, 2026
15 checks passed
@transfix
transfix deleted the feat/physics-scene-binding branch October 17, 2026 17:23
transfix added a commit that referenced this pull request Nov 27, 2026
… recipes

The job installed wamr and binaryen from cvcpkg.org, which has wamr only at
cvc.3 (with WAMR's own WASI, which takes a guest's WASI imports from the
host) and no binaryen until cy-pca/cvcpkg#648 is published, so it failed at
its install step. It now checks out that PR's recipes at a pinned commit and
builds both with cvcpkg build, then installs python312 from the catalog.
Once #648 is published the step goes back to cvcpkg install.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant