IK, VMD motion and camera playback, synced audio #4

Merged
dev merged 4 commits from devin/1795846281-vmd-ik into main 2026-11-28 09:11:09 -05:00
Owner

First step toward an MMD alternative: IK and .vmd motion playback.

  • IK data: PMX IK target/iterations/limit/links (with limits converted to right-handed axes via mmdLimitsToRightHanded) and PMD IK chains (knees get MMD's usual one-way limit) are now kept in Bone::ikLinks etc.; validateIk drops broken chains.
  • IK solver: Poser::solveIk is CCD as in MMD, run when the IK bone is reached in evaluation order (IK targets/links are now evaluation dependencies). Single-axis limited links (knees) solve as a signed angle about that axis; other limited links clamp Euler XYZ. Global and per-bone IK switches (setIkEnabled, ikBoneEnabled).
  • Motion: src/model/Motion.* — loadVmd (bone, morph and IK on/off keys; camera/light/shadow skipped for now), BezierCurve easing, and MotionPlayer, which binds tracks by name (15-byte truncated names match as prefixes) and writes Poser::motionPoses() / morph weights at a frame. User bone poses act as offsets on top of the motion.
  • UI: Motion window (play/pause, rewind, loop, unload, frame slider, matched track counts); File > Open accepts .vmd; View > Solve IK. Playback advances from an update callback, so it also runs with the UI hidden.
  • CLI: --motion FILE, --frame N, --play. tools/make_test_vmd.py writes tests/data/column.vmd and a --demo motion.
  • Tests: IK reach and limit clamping on the column fixture, VMD parsing, interpolation, IK switch keys and frame clamping.

Verified on Linux (Miku PMD) and the Mac (Karin PMX, 58-60 FPS while playing): lowering センター bends the knees with feet planted, and moving 左足IK/右足IK lifts each leg.

Camera and audio (added after testing with the Hi-Fi Raver dance):

  • loadVmd reads camera keys; evaluateCamera interpolates target/rotation/distance/fov with MMD's 6 Bezier curves, treats 1-frame gaps as cuts, and builds the eye as pitch, roll, yaw around the target (same convention as three.js and saba). The app drives the trackball manipulator and FOV from it; Motion window has a Follow toggle. Camera-only .vmd files are detected automatically.
  • src/audio/AudioPlayer wraps miniaudio 0.11.21 (fetched by CMake, single-file, no system deps): .wav/.mp3/.flac, play/pause/seek/volume. While the song plays, the timeline follows the audio clock so motion can't drift. Without an output device it loads silently and the timeline runs on the frame clock.
  • CLI: --camera FILE, --audio FILE. Tests cover camera evaluation/cuts and audio length/seek (tests/data/tone.wav).

Written by Devin

First step toward an MMD alternative: IK and `.vmd` motion playback. - **IK data:** PMX IK target/iterations/limit/links (with limits converted to right-handed axes via `mmdLimitsToRightHanded`) and PMD IK chains (knees get MMD's usual one-way limit) are now kept in `Bone::ikLinks` etc.; `validateIk` drops broken chains. - **IK solver:** `Poser::solveIk` is CCD as in MMD, run when the IK bone is reached in evaluation order (IK targets/links are now evaluation dependencies). Single-axis limited links (knees) solve as a signed angle about that axis; other limited links clamp Euler XYZ. Global and per-bone IK switches (`setIkEnabled`, `ikBoneEnabled`). - **Motion:** `src/model/Motion.*` — `loadVmd` (bone, morph and IK on/off keys; camera/light/shadow skipped for now), `BezierCurve` easing, and `MotionPlayer`, which binds tracks by name (15-byte truncated names match as prefixes) and writes `Poser::motionPoses()` / morph weights at a frame. User bone poses act as offsets on top of the motion. - **UI:** Motion window (play/pause, rewind, loop, unload, frame slider, matched track counts); File > Open accepts `.vmd`; View > Solve IK. Playback advances from an update callback, so it also runs with the UI hidden. - **CLI:** `--motion FILE`, `--frame N`, `--play`. `tools/make_test_vmd.py` writes `tests/data/column.vmd` and a `--demo` motion. - **Tests:** IK reach and limit clamping on the column fixture, VMD parsing, interpolation, IK switch keys and frame clamping. Verified on Linux (Miku PMD) and the Mac (Karin PMX, 58-60 FPS while playing): lowering センター bends the knees with feet planted, and moving 左足IK/右足IK lifts each leg. **Camera and audio** (added after testing with the Hi-Fi Raver dance): - `loadVmd` reads camera keys; `evaluateCamera` interpolates target/rotation/distance/fov with MMD's 6 Bezier curves, treats 1-frame gaps as cuts, and builds the eye as pitch, roll, yaw around the target (same convention as three.js and saba). The app drives the trackball manipulator and FOV from it; Motion window has a **Follow** toggle. Camera-only `.vmd` files are detected automatically. - `src/audio/AudioPlayer` wraps [miniaudio](https://miniaud.io) 0.11.21 (fetched by CMake, single-file, no system deps): `.wav/.mp3/.flac`, play/pause/seek/volume. While the song plays, the timeline follows the audio clock so motion can't drift. Without an output device it loads silently and the timeline runs on the frame clock. - CLI: `--camera FILE`, `--audio FILE`. Tests cover camera evaluation/cuts and audio length/seek (`tests/data/tone.wav`). [Written by Devin](https://app.devin.ai/sessions/edc92906d52f4fb09179a164d60f5f27)
dev added 1 commit 2026-11-28 01:16:19 -05:00
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
dev added 1 commit 2026-11-28 01:26:46 -05:00
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
dev added 1 commit 2026-11-28 01:27:29 -05:00
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
dev added 1 commit 2026-11-28 01:28:01 -05:00
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
dev changed title from IK solving and VMD motion playback to IK, VMD motion and camera playback, synced audio 2026-11-28 01:31:07 -05:00
dev merged commit 0658940348 into main 2026-11-28 09:11:09 -05:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dev/3d-model-renderer#4