CommunityImagegithub.com

threejs-photoreal-interior

A comprehensive skill to procedurally generate a photorealistic interior scene with three.js, from scratch—no model files, textures, or HDRI needed. It covers the entire pipeline: layout, shell, main objects, materials, props, baked GI, post-processing, verification, and cinematic output.

What is threejs-photoreal-interior?

This skill orchestrates multiple sub-skills into a complete workflow for creating a photorealistic interior scene entirely with code, inspired by the room-at-dawn project. It provides a ready-to-run project template that builds a bedroom with procedural geometry, materials, lighting, and post-effects—all running in the browser without any external 3D models or texture files. The skill integrates components like procedural cloth, vegetation, textures, baked global illumination (GI), real-time post-processing, and deterministic recording for cinematic output. Key integration rules ensure deterministic behavior, proper GI patching with albedo, sunlight vs. baked light division, and structural wall closure to prevent light leaks. Users can bootstrap a new project with a single command, and the template includes a full scene with room, windows, wood floor, walls, table, chair, towel, bookshelf, cup, kettle, and on-site baking. The skill is designed for AI agents and developers who want to generate high-quality 3D interiors programmatically, supporting platforms like Claude Code, Cursor, and Codex. It emphasizes real-world metrics: ~1.07 million triangles, ~7s load time, 13 MB GI cache, and 30-minute bake time on an RTX 4090, with a 4K HDR10 video output capability.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ammosu/claude-threejs-photoreal/tree/HEAD/skills/threejs-photoreal-interior

Installed? Explore more Image skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Photorealistic Interior Scene (Master Guide)

This skill chains the following sub-skills into a complete workflow and provides a directly executable project template. The method is based on room-at-dawn (MIT): an early morning bedroom, entirely procedurally generated, running in a browser. The original project's scale is approximately:

  • 1.07 million triangles, loading in about 7 seconds (RTX 4090).
  • The baked GI file gi.bin is about 13 MB, baking once takes about 30 minutes.
  • The output video is 4K HDR10.

Which Skill for Each Step

StepSkillDeliverable
03d-spec-promptWrite the idea into verifiable specs: mood, time, scale, hero objects, camera
1 Dimensions & shellThis skill's template/src/layout.js, parts/room.jsReal-world dimensions (meters), windows, wall thickness, shell
2 Hero objectsthreejs-procedural-cloth (blankets, curtains), threejs-procedural-vegetation (trees outside window), threejs-procedural-pothos (indoor plants)Focal point objects
2b Sky & outsidethreejs-sky-backdrop (sky presets, clouds, grass outside, houses, distant tree walls, only build what's visible)Same sky for both baking and rendering
3 Materialsthreejs-procedural-texturesWalls, floors, wood, fabric, wear & tear, book covers
4 Propsthreejs-lived-in-propsCloth draped over chair back, cups, kettle, socks, wires, crumpled paper
5 Lightingthreejs-baked-giSky & sun bounce light baked to vertices, saved as gi.bin; direct sunlight uses real-time light
6 Visualsthreejs-realtime-postAO, bloom, separate exposure for outside and interior, color grading
7 Verification, recordingwebgl-deterministic-recordingScreenshot regression, frame-by-frame rendering, cinematic output (depth of field, motion blur, HDR10)

Starting a New Project

bash <skill folder>/scripts/new-project.sh ~/git_project/my-room
cd ~/git_project/my-room && python3 -m http.server 5430 --bind 127.0.0.1
# http://127.0.0.1:5430/            Pre-baked bake/gi.bin included
# http://127.0.0.1:5430/?bake=128   Re-bake after changing the scene, press "Download gi.bin", save to bake/

(<skill folder> is the Base directory shown when loading this skill; when installed as a plugin, it's under ~/.claude/plugins/cache/)

  • This script copies the template and copies each sub-skill's libraries to src/lib/ (gi, post, props, textures, cloth, vegetation, pothos, sky, film). The project becomes standalone.
  • No bundler or npm required. three and three-mesh-bvh are loaded from jsdelivr.
  • URL parameters:
    • ?cam= : Camera (room, desk, window, corner, view = standing by window looking out).
    • ?t= : Fixed time (leaves, clouds don't move, for screenshots).
    • ?view=gi : View only lighting.
    • ?only=furniture : Build only a specific part.
    • ?exp= : Exposure.
  • The page exposes window.__ready, window.__stats, window.__camera for direct connection to webgl-deterministic-recording tools.
  • Controls: Drag to orbit; WASD / arrow keys to move (Shift to walk slowly, collides with walls and furniture); click on the screen to switch to mouse look with eye height at 1.6 m (Esc to exit). Orbit camera and point of interest are constrained within the room; zooming out or panning won't clip through walls.

Template structure:

FileContent
src/layout.jsThe only place for dimensions, sun, sky (with SKIES presets), outside configuration (OUTSIDE), color grading, camera, and furniture collision bounds (BLOCKERS)
src/materials.jslit() (GI patch, preserves original shader patch, records albedo), solid(), tbox(), tplane(), metres()
src/scene.jsBuilds each part by order; order is fixed
src/parts/room.jsFloor, ceiling, four walls, window openings and sills, black outer shell, wall cores
src/parts/outside.jsOutside the window: sky sphere, grass, gravel path, hedges, house, distant tree wall, main tree & mid-distance trees (only what's visible, threejs-sky-backdrop + threejs-procedural-vegetation). All gi = false, don't block baking light
src/parts/furniture.jsTable, chair, towel draped over chair back (PBD), cup, kettle, books on table, books on shelf
src/main.jsCreate scene → Bake / load file or flat lighting → Sun → Reflections → Post-processing → Camera (orbit + walk, constrained to room)

Cross-Skill Rules (Must Follow)

  1. Units are meters, coordinates are fixed. X along the window wall, Z into the room (window wall at z = 0, z < 0 is outside), Y up. All dimensions are written only in layout.js.
  2. Deterministic. Random numbers always use RNG(seed). If the order, name, or vertex count of a part changes, the bake for that mesh becomes invalid; applyBake reports stale meshes.
  3. Light exists on vertices, so subdivide. Surfaces with objects on top: subdivide to 1.5–2 cm. Large areas: 4–8 cm. Use tbox/tplane.
  4. All lit materials must go through lit(). giPatch directly replaces onBeforeCompile; lit() chains the original patch behind it, including wall variation (wallPatch), cloth backlighting, and wind. Textured materials must provide albedo (the avg of the texture) for correct bounce light colors.
  5. Division of sun: Direct sunlight uses DirectionalLight (intensity equals bake settings sun.irr). Bounce light is baked into the file. Do not add any ambient or hemisphere light.
  6. Walls must have a solid wall core with shadowSide set to FrontSide. Without it, the sun leaks a row of bright points at wall bases and corners (real issue encountered; see references/integration.md).
  7. Exposure targets the interior. Interior is about 1/20 of exterior: exposure ≈ 4.5, outside window use ext ≈ 0.3 to dim.
  8. Capture reflections after baking. captureEnv must run after applyBake/runBake, with the probe placed in the center of the room.
  9. When distant exteriors are visible, the camera far plane must be larger than the farthest object. The template uses 400 m (tree wall at 100 m, grass extends to 260 m). With far only 100, the clipped distant area exposes a white horizon fog band that moves with the camera (real issue encountered).
  10. The sun's shadow camera must cover the tree canopy outside the window so tree shadows fall inside: the template places the sun 30 m away, near 12, far 40.

Benchmarks (Template, RTX 4090, Chrome headless, 1280×800)

  • Scene creation 1.2 seconds, with towel simulation about 0.65 seconds; 107k triangles; page to first frame about 1.6 seconds.
  • On-site bake at 128 spp: 61,407 sample points, 26 workers, 6 seconds, gi.bin 743 KB. On reload, applied 39 meshes, 0 stale meshes.
  • preview.jpg: Room, desk side, window, lighting only. preview-bake.jpg: Left is flat lighting, right is after baking.

Further Reading

  • references/workflow.md: Each step's method, decisions to make, deliverables, and checkpoints.
  • references/integration.md: Interfaces between skills, gotchas, encountered issues.
  • references/checklist.md: Acceptance checklist and reference ranges for numbers.

Individual skills in this repo

This repo contains 3 individual skills — each has its own dedicated page.

threejs-procedural-cloth

用程式「設計」出照片級的靜態布料(不做物理模擬):沒鋪好的棉被、毯子、桌巾、垂下床緣或桌緣的布、翻起一角的被子、布上放東西,以及掛在桿子上的窗簾(吊環夾出的折、往下鬆開與散開、綁起下擺、車線與雙層縫邊、亞麻平織)。方法是平面高度場(團塊+有方向的長折+削峰+逐條畫上的皺褶)→ 包到支撐物上 → 高的折往一側倒 → 翻角 → 依 3D 曲面攤平 UV → 細皺紋 normal map+凹處變暗,含可重用程式庫、分階段範例、驗證數據,以及搬到 Godot/Unreal 的做法。當使用者說「程式生成布料」「棉被/床單/毯子/桌巾建模」「布料皺褶」「布垂下床邊」「被子翻一角」「布料不要用模擬」「cloth without simulation」「procedural cloth」「布上的花紋被拉長」「布料看起來像塑膠/像山」「窗簾建模」「程式生成窗簾」「窗簾皺褶」「curtain」「布簾」時使用。

threejs-procedural-textures

在 three.js 用程式即時生成照片級材質貼圖(不用任何圖檔):可無縫重複的雜訊、以公釐為單位的高度場轉 normal map、粗糙度與 AO 打包、Canvas2D 轉貼圖、平均反照率(給光照烘焙用)、接縫檢查。內含現成的材質:滾筒漆木屑壁紙加上大尺度的灰泥與漆色變化、烤漆橘皮紋、手摸過的粗糙度、積灰、橡木地板(交錯接縫、每片紋理不同、節疤、四邊微倒角)、通用木紋、對拼橡木貼皮、平織、鬆餅格、毛巾布、羅紋、針織、毛氈、棉繩、使用痕跡(灰塵、油脂、指紋、碎屑、棉絮、頭髮、杯印、細刮痕,同時畫進顏色與粗糙度)、斑點釉、粉體塗裝刮傷、書封圖集與對應 UV 的書本幾何、書頁邊、地形圖海報、照片、假文字。當使用者說「程式生成貼圖」「procedural texture」「不用圖檔的材質」「normal map 怎麼產生」「木地板/木紋貼圖」「牆面看起來太假」「布料材質」「針織/毛巾布 normal map」「使用痕跡」「刮痕/指紋/灰塵」「粗糙度貼圖」「書封/書背」「假文字」「貼圖有接縫」「Canvas 畫貼圖」時使用。

threejs-sky-backdrop

在 three.js 用程式做天空與窗外遠景,不需要 HDRI 或圖檔。天空的同一份參數同時用在三個地方:烘焙光照用的解析式天空、看得到的天空球(雲層、高空薄雲、地平線霧帶、太陽),以及不烘焙時用的太陽光、半球光與環境貼圖。內含四種預設(清晨、白天、陰天、黃昏)和一個量測工具,確認看到的天空和照亮場景的天空亮度一致。遠景部分包括:只建從室內窗戶看得到的東西(窗洞可見性與 LOD)、隨距離變淡的大氣霧化、遠處逐漸變粗的草地網格、碎石小路、樹籬、鄰居房子(陶瓦屋頂、窗戶、煙囪、天窗)、封住地平線的遠方樹牆,並可以搭配 threejs-procedural-vegetation 種樹。當使用者說「天空」「sky shader」「雲」「程式生成天空」「不用 HDRI」「窗外景色」「遠景」「背景房子」「地平線」「大氣透視」「霧化」「窗外的樹」「天空和光照對不上」「清晨/黃昏/陰天的天空」「只建看得到的東西」時使用。

Related Skills