# Blender and MysteryForge

The classic mystery adventures built every room as a 3D model and rendered each view to a still picture. That is why every view of a room agreed, why a drawer could open in place, and why a close-up matched the wide shot. MysteryForge works the same way with [Blender](https://www.blender.org): model the room once, render its pictures, and let the model say where the hotspots are. *Where There's a Will…*, the first full game made with MysteryForge, is rendered this way from end to end, rooms and cast.

This page is the practical path for any `.blend`. The [3D rooms guide](https://mysteryforge.vivalainsurreccion.com/docs/3d-rooms/) is the deep end: the room kit, lighting, MakeHuman characters, idle and talk loops, and everything learned rendering a whole game.

## What Blender gives a MysteryForge game

| Render | Becomes | Size |
|---|---|---|
| A room from its camera | a scene's `background` | 1920 × 1080 (the game's design size) |
| The same room with something changed (a drawer open, the letter gone) | an **overlay** shown by a condition | a patch: just the part that changed |
| A close-up of part of the room | a **view** with its own picture | the region × the zoom, up to 4096 on the long side |
| A 360° view from the middle of the room | a **panorama** scene | 2:1, 4096 × 2048 for a full circle |
| A character with a transparent background | an **actor pose** (idle, walk, talk, gestures) | the same canvas for every pose |
| A character's head and shoulders | a **portrait** (and a living portrait's loops) | 512 × 512, or a taller waist-up frame |
| An object on a transparent background | an **item icon** | 256 × 256 |

## The helper script

`integrations/blender/mf_blender.py` (in the MysteryForge download) runs inside Blender 4.x or 5.x with no add-ons. It renders from the scene camera and writes two files: the picture, and a report of every hotspot **projected from the model** into the fractions of the picture MysteryForge uses.

```bash
blender -b study.blend -P integrations/blender/mf_blender.py -- --room study --out ~/renders/study
```

On macOS `blender` is `/Applications/Blender.app/Contents/MacOS/Blender`.

| Option | Does |
|---|---|
| `--room ID` | names the output (`<ID>.png`, `<ID>.hotspots.json`) |
| `--out DIR` | where to write them |
| `--preview` | half size, 24 samples: for checking layout and light quickly |
| `--width`, `--height` | default 1920 × 1080 (4096 × 2048 with `--panorama`) |
| `--samples N`, `--engine` | override the file's own render settings |
| `--camera NAME` | another camera than the scene's |
| `--patch OBJ,OBJ` | render only the box those objects cover, and report the overlay rectangle (a state) |
| `--figure` | transparent background, for a character pose or an item |
| `--panorama` | a 360° equirectangular render (Cycles), hotspots projected onto the sheet |
| `--no-render` | only project the hotspots (seconds, no picture) |

### Mark the hotspots in the model

Any object can be a hotspot. Either:

- give it a **custom property** `mf_hotspot` whose value is the hotspot id (Object Properties → Custom Properties → New; set the name to `mf_hotspot`, the type to String, the value to e.g. `writing_desk`). Add `mf_label` for the name players see ("The writing desk"); without it the object's name is used. Or
- put it in a collection named **`mf_hotspots`**; its id is made from the object's name.

A hotspot can be a real object (the desk, the clock) or an invisible helper (an empty box drawn around a doorway, hidden from render). Each becomes a rectangle around everything of it in front of the camera, using the evaluated mesh, so modifiers count. The rectangle does not know what is in front of it: an object hidden behind a wall still gets its rectangle, so tag only what the player can see.

The report (`study.hotspots.json`):

```json
{
  "room": "study",
  "image": "study.png",
  "size": [1920, 1080],
  "kind": "room",
  "hotspots": [
    { "id": "writing_desk", "label": "The writing desk", "shape": { "type": "rect", "rect": [0.1733, 0.3224, 0.6534, 0.4791] } }
  ]
}
```

Each `shape` is exactly what a MysteryForge hotspot takes.

## Putting a render into the game

1. **The picture.** Deliver rooms as WebP: a 1920 × 1080 room is about a tenth of the PNG's size and looks the same (`cwebp -q 85 study.png -o study.webp`). Put it at `game/assets/backgrounds/study.webp`, then point the scene at it: Studio **Scenes → (room) → Background**, or, replacing a placeholder, **Assets → Replace…** (which rewrites every reference). Run `./mysteryforge import <game>`.
2. **The hotspots.** With an agent, hand it the report: it adds each one with `add_hotspot` (or moves an existing one with `update_hotspot`) and then checks with `screenshot_scene` and `show_hotspots: true`. By hand, the Studio's **Draw** tool on the new picture is quick, and the numbers in the report are there when you want them exact (the hotspot inspector shows x, y, w, h).
3. **Check it.** `validate_project` (or the Studio's **Validate**): a hotspot entirely under a later one, an exit too small to find, or a picture of the wrong shape is reported.

## States: render the change, not the room

A drawer that opens, a painting that swings aside, a letter that is taken: render the room again with the change, but only the part that changed.

```bash
blender -b study.blend -P integrations/blender/mf_blender.py -- --room study_drawer_open --out ~/renders/study --patch Drawer,Letter
```

`--patch` crops the render to the box those objects cover (plus a margin) and reports `patch_rect`, snapped to whole pixels so the crop and the rectangle agree exactly. The report includes the overlay to add:

```json
"overlay": { "id": "study_drawer_open", "image": "game/assets/backgrounds/study_drawer_open.png", "rect": [0.4214, 0.5602, 0.149, 0.1546] }
```

Give the overlay a `visible_if` (the variable set when the drawer is opened) and it appears exactly over the room's picture. Change the objects in the `.blend` (or keyframe them and set the frame) before rendering the patch; render the patch in the same light as the room. A patch must cover everything that differs, shadows included: when the change throws a shadow outside the objects, name a helper object that covers the shadow too.

## Close-ups

A close-up (the clock face, the desk drawer) is a scene **view**: a second camera, rendered with `--camera`, at the size of the part of the room it shows times its zoom. `make handoff` (or the MCP `export_handoff`) lists every close-up with its delivery size, and draws a **layout guide** per room and close-up at that size: every hotspot where it will be clicked and the parts of the screen the interface covers. Put a guide on a plane in front of the camera (or use it as a camera background image) to frame the render to the game.

## 360° rooms

```bash
blender -b hall.blend -P integrations/blender/mf_blender.py -- --room hall --out ~/renders/hall --panorama
```

Stand the camera in the middle of the room at eye height and **keep it level** (rotation X = 90°, Y = 0): the middle of the sheet is the camera's forward direction, and the player turns from there. Hotspots are projected onto the 2:1 sheet the way the engine reads a panorama; one that straddles the seam behind the camera is reported in `skipped` (split it into two objects, one each side). In the game, the scene gets a `panorama` block instead of a `background`. Decide on 360° rooms at the start of a game: re-rendering a finished flat game as panoramas is a big job.

## Characters

Render people with `--figure` (a transparent background). The rules that keep a figure believable in a room:

- **Light and camera from the room.** A figure rendered in a different light looks pasted on. Render the person inside the room's `.blend` with the room hidden from the camera but still casting light and shadow (Blender's holdout or a shadow catcher), from the room's own camera.
- **One canvas for every pose.** Never trim a pose to its content: each pose must keep the same canvas, or the figure jumps when it changes pose. The engine anchors a figure by its feet (`actor.feet`, default bottom-centre).
- **Walk to the right.** Render a walk cycle walking right; the engine mirrors it for the other way.
- **Loops are sheets.** Render an idle or talk loop as frames (start and end on the same neutral pose), then pack them into one sheet, for example `ffmpeg -i frame_%04d.png -vf tile=8x2 idle.png`, and set `"sheet": {"image": ..., "columns": 8, "rows": 2}` with its `fps`. If you will import the sheet VRAM-compressed for the web, make both sides multiples of 4 (WebGL draws others black).
- **Mouths.** A `talk` pose with frames from closed to widest lip-syncs to any recording by loudness; a living portrait's mouth sheet can name its rows by mouth shape (`visemes`) for lip-sync from a mouth track. See the format spec's "Actors" and "Living portraits".

The [3D rooms guide](https://mysteryforge.vivalainsurreccion.com/docs/3d-rooms/) shows all of this on real characters (MakeHuman bodies built with MPFB, period clothes, hair, idle and talk loops rendered in their rooms).

## For agents

An agent can run Blender itself (it is a command line), read the report and bind everything with MysteryForge's tools. The steps and the exact tool calls are in [art-integrations.md](https://mysteryforge.vivalainsurreccion.com/agents/art-integrations/).
