3d-model

Exact captured content · path skills/3d-model/SKILL.md · sha256 26096dc6f6dc9e52… · revision 5e145f2b6ff669771212e4d3df4a097e40e607f4

Download the exact captured file

---
name: 3d-model
description: "Build and edit a hosted Blender 3D model of a property from floor plans, sections, elevations, renders or a description, step by step, with a preview render after each step and an interactive viewer for the user. Use for a 3D model, a dollhouse view, massing, 'build my house in 3D', or a camera fly-through of a planned home; real photos of a finished home are listing-video."
---

# 3D model

A hosted Blender scene the user owns: you build it with small Python edits, look at a render after each one, and show the user the model in a viewer. The model holds the true geometry and camera; AI images and video made from its renders add the photoreal look.

**The user provides:** floor plans (images, or a PDF plan set: uploading it returns each page as an image), sections and elevations with levels, the architect's renders for materials, or a description; what they want to see.
**They get:** a 3D model with numbered revisions, a viewer they can orbit, preview renders as assets, and on request photoreal stills or clips made from those renders.

## House rules

- **The plan is the truth.** Walls, openings, levels and room sizes come from the drawings, never from taste. Where a drawing is unclear, keep it simple and say what you assumed.
- **Look before you claim.** A successful operation only means the code ran. Render from the camera that matters, look at the image the reply attaches, fix the biggest visible defect, render again.
- **Small steps.** One coherent edit per commit, about five minutes per operation at most. Split a house by floor, then by room.
- **One operation at a time.** If a reply says an operation is still running, poll it with `get_3d_model({ id, operation_id, wait_seconds: 55 })`; never send another meanwhile.
- **Fewer, fuller calls.** Each call is a round trip the user waits for: edit and check in the same operation, and never redefine the preloaded helpers.
- **Show at the end of a round.** After the last edit of a round is verified: `show_3d_model({ id })`, once.
- **Free to build.** Operations and preview renders cost nothing. GPU tours (`render_3d_video`) cost credits for the GPU time they take, and AI images and video from a render cost their usual credits: estimate and ask first, as in the other skills.
- **Disclose.** Stills and videos made from the model are "3D visualization", and photoreal ones "AI visualization from the plans", labelled as in `continuous-tour`. A video from a plan is made only through `continuous-tour` (Blender video as `@Video1`).

## The loop

1. `create_3d_model({ name })` once per property, or `get_3d_model()` to find an existing one. Revision 0 is an empty scene.
2. **Inspect** with `run_3d_python({ id, operation_id, commit: false, code })`: read names, dimensions, bounds; render a preview. Nothing is saved.
3. **Edit and check in one call**: `run_3d_python({ ..., commit: true, revision: <the one you inspected>, summary })` whose code ends with `result = views(["plan", "iso_ne", "iso_sw", "CAM_main"])`. The commit saves the edit and the reply attaches every published image as one sheet, in publish order, so you see the plan cut and the angles at once. Compare the plan cut with the sheet (`references/reading-plans.md`); if something is off, the next commit fixes it (the reply's `revision_after` is the revision to write it against). A reply of `revision_conflict` means someone else moved the model on: inspect again, write the edit against the new revision, use a new `operation_id`.
4. **Details**: for a closer look, publish one render on its own in a `commit: false` operation; `load_image` opens any earlier render or the plan at full size.
5. **Places**: once a floor's rooms exist, add one camera per room the user will want to visit, named `VIEW_<n>_<Place>` (`VIEW_1_Living_room`, `VIEW_2_Kitchen`, `VIEW_3_Master_bedroom`). Put it at eye level (1.6 m above that floor), in a corner or doorway, looking into the room, with an 18–24 mm lens, and commit them all in one operation ending with `views(["VIEW_1_Living_room", "VIEW_2_Kitchen", ...])`. The viewer turns them into buttons, in that order, that fly the user to each room.
6. **Show**: `show_3d_model({ id })`.

```python
place("VIEW_2_Kitchen", (5.8, 1.0, 1.6), (8.5, 3.5, 0.9))  # preloaded: adds or moves the camera
```

`operation_id` is an idempotency key: descriptive and new for each logical step (`walls-ground-01`, `openings-ground-01`, `preview-top-02`). Reuse it only to retry the identical request after a lost reply.

## Writing the code

```python
scene = bpy.context.scene
# Look things up by name: each operation starts fresh from the head revision.
wall = bpy.data.objects.get("ENV_wall_north")
# Publish a preview with Workbench: about 2 s a frame on the session's CPU.
scene.render.engine = "BLENDER_WORKBENCH"
shading = scene.display.shading
shading.light, shading.color_type = "STUDIO", "MATERIAL"   # reads material.diffuse_color
scene.render.resolution_x, scene.render.resolution_y = 960, 540
t = artifacts.file(name="eye.png", media_type="image/png")
scene.render.filepath = str(t.path)
scene.render.image_settings.media_type = "IMAGE"
scene.render.image_settings.file_format = "PNG"
bpy.ops.render.render(write_still=True)
t.publish()
result = {"walls": len([o for o in bpy.data.objects if o.name.startswith("ENV_wall")])}
```

- Blender 5.2, headless, metres, Z up. `Mesh.use_auto_smooth` is gone: use `shade_smooth()`.
- **Renders run on the CPU (no GPU):** Workbench about 2 s a frame, EEVEE 40–80 s at 960×540, Cycles slower still. Use Workbench for every check and for clips. Allow at most one EEVEE still per operation, at 640×360 with `scene.eevee.taa_render_samples = 4`, for a "how it looks" moment. A commit with four EEVEE previews runs past the 5-minute limit on a full house.
- Workbench colours come from `material.diffuse_color`, not the Principled Base Color: set both (the helper in `house-modelling.md` does). For plan checks use `shading.light = "FLAT"` and shadows off.
- **Interiors need a ceiling to read**, but a ceiling hides the inside in the viewer. Render interiors in a `commit: false` operation: add a temporary `CEIL_` slab there, render, and it's discarded with the rest of the inspection.
- Name every object by role: `ENV_` (walls, floors, roof), `OPEN_` (window and door frames), `FURN_`, `CAM_`, `LGT_`, `SITE_` (ground, walls, trees). Keep each floor in a collection (`GF`, `FF`, `ROOF`, `SITE`): the viewer shows one toggle per collection, so the user can lift the roof or hide the first floor.
- Lights: Sun, Spot or Point only; the GLB the viewer loads drops Area lights. A working rig: one sun, a modest world colour.
- **Preloaded in every operation** (don't define them): `material(name, rgb, rough=0.8)`, `collection(name)`, `box(name, x0, y0, x1, y1, z0, z1, mat, coll)`, `cut(wall, x0, y0, x1, y1, z0, z1)` and `place(name, eye, look_at, lens=22)`; `references/house-modelling.md` says what each does.
- `result` is a short summary (names, counts, dimensions), at most 64 KiB. Print for debugging; the tail comes back as `output`.
- At most 8 published files per operation: PNG, JPEG or MP4. No network fetches and no file paths outside the operation.
- `views(names, size=(960, 540), cut=1.4)` renders standard Workbench views and publishes each as `view-<name>.png`:
  - `"plan"` is a plan cut at `cut` metres above 0 (pass the floor level + 1.4 for an upper floor). Everything above is left out; what the cut slices gets a solid face: walls dark, `OPEN_` blue, `FURN_` tan. It renders at 50 px per metre with the model's corner 1 m in from the left and bottom edges.
  - `"iso_ne"`, `"iso_nw"`, `"iso_se"`, `"iso_sw"` show the whole model from the +X+Y, -X+Y, +X-Y, -X-Y corner. Hide `ROOF` first (`hide_render`) for a dollhouse look.
  - Any other name renders that camera.
  - It returns the model's bounds, leaves the scene as it was, and counts toward the 8 files.

## Plans to model

Read `references/reading-plans.md` before reading a plan set and `references/house-modelling.md` before building. In short:

1. List the sheets: which is the ground floor, first floor, roof, sections, elevations, renders. Read the scale (usually 1:50) and the units (cm on Israeli and most European plans).
2. Write down, before any code, the footprint, the wall lines with thickness, each opening with width, sill and head heights (from the elevations), the floor levels, the stair, voids and the roof (pitch, ridge, eaves).
3. Build the shell floor by floor: walls with openings cut, floor slabs, the stair, then the roof. After each floor, run the plan check in `reading-plans.md` (a plan cut at 1.4 m, overlaid on the sheet at the same scale) and fix anything off by more than 5 cm.
4. Materials from the renders (plaster colour, roof tiles, window frames, shutters, floors); simple furniture blocks for scale where the user wants it.

## Fly-throughs and photoreal

Read `references/tour-camera.md`. Keyframe `CAM_tour_<n>` cameras, check a storyboard of stills, commit, then `render_3d_video({ id })` renders them on GPUs and shows the user the tour with buttons to use it in a video project. For photoreal output, a clip goes to `generate_video` on `video/seedance-2.5` with `extras.omni_reference_task_type: "edit"` and the restyled first frame in `image_urls` (or a video project shot with `inputs.video_ref_mode: "edit"`). The render returns each clip's first frame, so restyle those directly, all clips at once. Estimate and get a yes first.

## When something goes wrong

| What happened | What to do |
|---|---|
| `revision_conflict` | Nothing ran. Inspect the revision it names, rewrite the edit against what is there, send it with that revision |
| `busy` | Nothing ran. Poll the running operation with `wait_seconds: 55`, then send yours again (its `operation_id` is still free) |
| `timed_out` | Nothing was saved: split the work, and render with Workbench |
| An operation still running | The reply says for how long and Blender's latest line; poll with `wait_seconds: 55` |
| Which revision was what | `get_3d_model({ id })` lists every revision with its summary; `show_3d_model({ id, revision })` shows any of them |
| A Python error | Read the traceback in the reply, fix the code, new `operation_id` |
| The viewer shows nothing | The model has no committed revision, or the last commit exported an empty scene: inspect |
| The model disagrees with the plan | Fix it before anything else; never paper over geometry with an AI image |