Open in Blender: basic scene and the Playblast operator (#160) #171

Merged
crowmaki merged 2 commits from issue-160-open-in-blender into main 2026-10-10 23:22:01 +00:00
Owner

Closes #160. Part of #139.

What it does

  • Open in Blender (Shot panel, previz section): writes scene.json and the shipped bootstrap.py into the Shot's previz folder previz/<shot id>/ in the media folder, then starts Blender. The folder is named by Shot id, so relabelling a Shot never breaks the link. The first run builds the scene and saves scene.blend. Later runs reopen that file, and the app never overwrites it.
  • Rebuild Blender scene: renames the saved file to scene-set-aside-N.blend in the same folder, then builds the scene again.
  • Scene spec (previz_scene.rs, studio-core, per ADR-0003): a pure read of the Shot. It holds:
    • the effective aspect ratio at the draft size (the same render_size that Takes use)
    • 24 fps and the Shot's frame count
    • the subjects in Setup order, with colours from the fixed 8-colour PREVIZ_PALETTE
    • the output path playblast.mp4
  • Bootstrap (crates/studio-core/blender/bootstrap.py): builds a ground plane, a camera, and one flat-coloured figure per subject, named after its Character, in a line-up in front of the camera. Both the build and the reopen register Playblast for AI Studio, which you can run from the N-panel AI Studio tab or the Render menu. It sets the output path, size, frame range and fps, and H.264 MP4 output. It switches the viewport to solid/flat/object-colour shading with no overlays and camera background images hidden. Then it runs a viewport render of the animation and restores the viewport afterwards. Colours are converted to linear and shown with the Standard view transform, so the pixels match the palette hex exactly.
  • Blender executable: an app setting (blender.json) on a new Blender page in App settings. The lookup order is AI_STUDIO_BLENDER, then the user's pick, then detection: the newest Blender Foundation\Blender X.Y and Steam on Windows, /Applications on macOS, and PATH. When nothing is found, the error explains how to fix it.
  • Storage: leaves previz/ out of orphan files, so Purge can't delete a working scene.blend.

Checks

  • Integration tests in tests/previz.rs cover:
    • ratio and frame count
    • subjects in order with stable palette colours, which move when the subjects are reordered
    • the folder named by Shot id, which survives a split and relabel
    • non-complex Shots refused
    • the first open building the scene and reopening leaving the .blend untouched
    • rebuild keeping each old file
    • no orphan files
    • a video rendered to the spec importing as current
  • Unit tests in blender.rs cover detection order and the error messages.
  • cargo test --workspace --all-features, bun test and bun run check all pass.
  • Hand check with Blender 5.2: the bootstrap built and saved the scene. The operator wrote a 73-frame 1824×768 H.264 MP4 with exact palette colours, flat shading and no overlays. Reopening left scene.blend byte-identical, and running the script twice in one session works. In the running app, Open in Blender detected 5.2 and built the scene. Rebuild left scene-set-aside-1.blend beside the new file. A missing pick shows the error.
  • Not checked: Blender 3.x/4.x, which are untested here; the script only uses APIs from 3.2 and later. Not yet done: importing a real Blender playblast through the app UI. The spec-to-current path is covered by the test above.

Notes / follow-ups

  • Set-aside .blend files and the folders of deleted Shots are invisible to Storage until #167 lists previz working files.
  • Nothing stops a second Blender instance on the same folder, for example after Rebuild while the old one is still open. Whichever instance saves last wins.
  • A Shot with more than 8 subjects reuses palette colours.

Screenshots

previz.png

settings.png

Closes #160. Part of #139. ## What it does - **Open in Blender** (Shot panel, previz section): writes `scene.json` and the shipped `bootstrap.py` into the Shot's previz folder `previz/<shot id>/` in the media folder, then starts Blender. The folder is named by Shot id, so relabelling a Shot never breaks the link. The first run builds the scene and saves `scene.blend`. Later runs reopen that file, and the app never overwrites it. - **Rebuild Blender scene**: renames the saved file to `scene-set-aside-N.blend` in the same folder, then builds the scene again. - **Scene spec** (`previz_scene.rs`, studio-core, per ADR-0003): a pure read of the Shot. It holds: - the effective aspect ratio at the draft size (the same `render_size` that Takes use) - 24 fps and the Shot's frame count - the subjects in Setup order, with colours from the fixed 8-colour `PREVIZ_PALETTE` - the output path `playblast.mp4` - **Bootstrap** (`crates/studio-core/blender/bootstrap.py`): builds a ground plane, a camera, and one flat-coloured figure per subject, named after its Character, in a line-up in front of the camera. Both the build and the reopen register **Playblast for AI Studio**, which you can run from the N-panel *AI Studio* tab or the Render menu. It sets the output path, size, frame range and fps, and H.264 MP4 output. It switches the viewport to solid/flat/object-colour shading with no overlays and camera background images hidden. Then it runs a viewport render of the animation and restores the viewport afterwards. Colours are converted to linear and shown with the Standard view transform, so the pixels match the palette hex exactly. - **Blender executable**: an app setting (`blender.json`) on a new *Blender* page in App settings. The lookup order is `AI_STUDIO_BLENDER`, then the user's pick, then detection: the newest `Blender Foundation\Blender X.Y` and Steam on Windows, `/Applications` on macOS, and `PATH`. When nothing is found, the error explains how to fix it. - **Storage**: leaves `previz/` out of orphan files, so Purge can't delete a working `scene.blend`. ## Checks - Integration tests in `tests/previz.rs` cover: - ratio and frame count - subjects in order with stable palette colours, which move when the subjects are reordered - the folder named by Shot id, which survives a split and relabel - non-complex Shots refused - the first open building the scene and reopening leaving the `.blend` untouched - rebuild keeping each old file - no orphan files - a video rendered to the spec importing as `current` - Unit tests in `blender.rs` cover detection order and the error messages. - `cargo test --workspace --all-features`, `bun test` and `bun run check` all pass. - **Hand check with Blender 5.2**: the bootstrap built and saved the scene. The operator wrote a 73-frame 1824×768 H.264 MP4 with exact palette colours, flat shading and no overlays. Reopening left `scene.blend` byte-identical, and running the script twice in one session works. In the running app, Open in Blender detected 5.2 and built the scene. Rebuild left `scene-set-aside-1.blend` beside the new file. A missing pick shows the error. - Not checked: Blender 3.x/4.x, which are untested here; the script only uses APIs from 3.2 and later. Not yet done: importing a real Blender playblast through the app UI. The spec-to-`current` path is covered by the test above. ## Notes / follow-ups - Set-aside `.blend` files and the folders of deleted Shots are invisible to Storage until #167 lists previz working files. - Nothing stops a second Blender instance on the same folder, for example after Rebuild while the old one is still open. Whichever instance saves last wins. - A Shot with more than 8 subjects reuses palette colours. ## Screenshots ![previz.png](https://git.crowmaki.me/attachments/55d493e5-cdeb-48b5-b561-abe8c9307dd4) ![settings.png](https://git.crowmaki.me/attachments/6ca52c66-4ae7-48f3-9b34-fb5eaf860073)
"Open in Blender" on a complex Shot writes a scene spec and the shipped
bootstrap script into the Shot's previz folder (previz/<shot id> in the
media folder, so relabelling never breaks the link), then starts
Blender on them. The spec is a pure studio-core read of the Shot: its
effective aspect ratio at the draft size, H3's 24 fps and the Shot's
frame count, its subjects in order with colours from a fixed palette,
and the output path. The bootstrap builds the scene the first time
(ground, camera, one flat-coloured figure per subject) and saves it;
after that the app opens the saved file, which it never overwrites.
Both register "Playblast for AI Studio", a flat, overlay-free viewport
render to H.264 MP4. "Rebuild Blender scene" sets the saved file aside
in the folder first.

The Blender executable is an app setting with detection of the usual
install locations, following the ffmpeg locator, and a message saying
what to do when none is found. Storage leaves the previz folders out of
its orphan files.

Co-Authored-By: Claude <noreply@anthropic.com>
Name the AI_STUDIO_BLENDER override when it points nowhere, and show
the gone-pick error in App settings only when the pick is gone. Rename
the DTO after BlenderLocation. The bootstrap stamps its version on the
scene it builds, leaves a reopened file's viewport shading alone, and
keeps one Render menu entry however often it runs.

Co-Authored-By: Claude <noreply@anthropic.com>
crowmaki deleted branch issue-160-open-in-blender 2026-10-10 23:22:02 +00:00
Sign in to join this conversation.
No description provided.