Prompt specification
Build or customize the Three.js 3D scene "Recursive containment story display" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Recursive containment story display
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/recursive-containment-story-display-x0360
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts nesting dolls. Create a toy house containing a room model, cabinet, and nesting figure; selectable cutaways reveal containment at several scales without changing the identity of enclosed objects. Low-poly.
Working Three.js Starter (recursive-containment-story-display-x0360):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Nested Room — Three.js Cutaway Study</title>
<style>
:root {
--paper: #f1ede4;
--ink: #302d29;
--muted: #746e64;
--accent: #6674aa;
--line: rgba(48, 45, 41, 0.14);
--panel: rgba(250, 248, 242, 0.9);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
outline: none;
}
button {
font: inherit;
}
.masthead {
position: fixed;
z-index: 5;
top: 26px;
left: 28px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.masthead h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(29px, 3.2vw, 48px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 0.98;
}
.masthead p {
max-width: 310px;
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.panel {
position: fixed;
z-index: 6;
top: 22px;
right: 22px;
width: 314px;
max-height: calc(100vh - 44px);
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(61, 53, 42, 0.12);
backdrop-filter: blur(14px);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.panel-heading .eyebrow {
margin: 0;
}
.live-chip {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.live-chip::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 15%, transparent);
content: "";
}
.cut-list {
position: relative;
display: grid;
gap: 5px;
}
.cut-list::before {
position: absolute;
top: 22px;
bottom: 22px;
left: 16px;
width: 1px;
background: var(--line);
content: "";
}
.cut-step {
position: relative;
display: grid;
grid-template-columns: 33px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
padding: 9px 10px 9px 0;
border: 1px solid transparent;
border-radius: 12px;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.cut-step:hover {
background: rgba(255, 255, 255, 0.58);
transform: translateX(-2px);
}
.cut-step.active {
border-color: color-mix(in srgb, var(--accent) 30%, transparent);
background: color-mix(in srgb, var(--accent) 9%, rgba(255, 255, 255, 0.58));
}
.cut-step .node {
z-index: 1;
display: grid;
width: 33px;
height: 33px;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: #f8f5ee;
color: var(--muted);
font-size: 10px;
font-weight: 800;
}
.cut-step.active .node {
border-color: var(--accent);
background: var(--accent);
color: white;
}
.cut-step b {
display: block;
font-size: 12px;
font-weight: 750;
letter-spacing: -0.01em;
}
.cut-step small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.cut-step .arrow {
color: var(--muted);
font-size: 15px;
opacity: 0;
transform: translateX(-4px);
transition: 160ms ease;
}
.cut-step.active .arrow {
opacity: 1;
transform: none;
}
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.action {
padding: 10px 8px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
cursor: pointer;
transition: 150ms ease;
}
.action:hover {
border-color: var(--accent);
color: var(--accent);
transform: translateY(-1px);
}
.identity-note {
margin: 13px 0 0;
padding-top: 13px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.identity-path {
margin-top: 7px;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 700;
line-height: 1.65;
letter-spacing: 0.03em;
}
.inspector {
position: fixed;
z-index: 5;
left: 28px;
bottom: 26px;
width: min(390px, calc(100vw - 56px));
padding: 16px 18px;
border-left: 3px solid var(--accent);
border-radius: 0 14px 14px 0;
background: rgba(250, 248, 242, 0.88);
box-shadow: 0 12px 38px rgba(61, 53, 42, 0.09);
backdrop-filter: blur(12px);
pointer-events: none;
}
.inspector .eyebrow {
margin-bottom: 5px;
}
.inspector h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
letter-spacing: -0.025em;
}
.inspector p {
margin: 7px 0 10px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.boundary {
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.025em;
}
.hint {
position: fixed;
z-index: 4;
right: 358px;
bottom: 27px;
color: rgba(48, 45, 41, 0.62);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
pointer-events: none;
}
.scene-cue {
position: fixed;
z-index: 7;
display: flex;
align-items: center;
gap: 10px;
min-width: 174px;
padding: 9px 13px 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 999px;
background: rgba(43, 41, 37, 0.88);
color: white;
box-shadow: 0 8px 25px rgba(32, 29, 25, 0.2);
transform: translate(-50%, -100%);
cursor: pointer;
backdrop-filter: blur(8px);
transition:
left 80ms linear,
top 80ms linear,
background 150ms ease;
}
.scene-cue:hover {
background: var(--accent);
}
.scene-cue .cue-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.12);
}
.scene-cue:hover .cue-dot {
background: white;
}
.scene-cue b {
display: block;
font-size: 9px;
letter-spacing: 0.095em;
}
.scene-cue small {
display: block;
margin-top: 2px;
color: rgba(255, 255, 255, 0.63);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 8px;
}
[hidden] {
display: none !important;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
transition: opacity 350ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
.loader-card {
text-align: center;
}
.loader-ring {
width: 42px;
height: 42px;
margin: 0 auto 15px;
border: 2px solid rgba(48, 45, 41, 0.12);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
#loading b {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
}
#loading small {
display: block;
margin-top: 6px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 760px) {
.masthead {
top: 16px;
left: 16px;
}
.masthead h1 {
font-size: 31px;
}
.masthead p {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 42vh;
padding: 13px;
border-radius: 15px;
}
.cut-list {
grid-template-columns: repeat(5, 1fr);
gap: 4px;
}
.cut-list::before {
display: none;
}
.cut-step {
display: flex;
min-width: 0;
flex-direction: column;
gap: 5px;
padding: 7px 3px;
text-align: center;
}
.cut-step:hover {
transform: none;
}
.cut-step .node {
width: 27px;
height: 27px;
font-size: 8px;
}
.cut-step b {
overflow: hidden;
max-width: 100%;
font-size: 9px;
text-overflow: ellipsis;
}
.cut-step small,
.cut-step .arrow,
.identity-note {
display: none;
}
.panel-actions {
margin-top: 8px;
}
.inspector {
right: 12px;
bottom: calc(42vh + 22px);
left: 12px;
width: auto;
padding: 11px 13px;
}
.inspector h2 {
font-size: 19px;
}
.inspector p {
display: none;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">
<div class="loader-card">
<div class="loader-ring"></div>
<b>The Nested Room</b>
<small>Assembling low-poly scene</small>
</div>
</div>
<header class="masthead">
<p class="eyebrow">Low-poly containment study / 04 boundaries</p>
<h1>The Nested Room</h1>
<p>
A toy house contains a room, the room contains a cabinet, and the cabinet
contains a family of nesting figures.
</p>
</header>
<aside class="panel" aria-label="Cutaway controls">
<div class="panel-heading">
<p class="eyebrow">Cutaway stack</p>
<span class="live-chip">Live scene graph</span>
</div>
<div class="cut-list">
<button class="cut-step" data-depth="0" aria-pressed="false">
<span class="node">00</span>
<span>
<b>Exterior</b>
<small>House sealed</small>
</span>
<span class="arrow">›</span>
</button>
<button class="cut-step" data-depth="1" aria-pressed="false">
<span class="node">01</span>
<span>
<b>House</b>
<small>Facade cutaway</small>
</span>
<span class="arrow">›</span>
</button>
<button class="cut-step" data-depth="2" aria-pressed="false">
<span class="node">02</span>
<span>
<b>Room</b>
<small>Room cutaway</small>
</span>
<span class="arrow">›</span>
</button>
<button class="cut-step" data-depth="3" aria-pressed="false">
<span class="node">03</span>
<span>
<b>Cabinet</b>
<small>Hinged cutaway</small>
</span>
<span class="arrow">›</span>
</button>
<button class="cut-step" data-depth="4" aria-pressed="false">
<span class="node">04</span>
<span>
<b>Figure</b>
<small>Nesting cutaway</small>
</span>
<span class="arrow">›</span>
</button>
</div>
<div class="panel-actions">
<button class="action" id="revealAll">Reveal all</button>
<button class="action" id="resetView">Reset view</button>
</div>
<p class="identity-note">
Every enclosure is opened in place. The contained meshes are never
replaced or re-parented.
<div class="identity-path">
HOUSE-01 › ROOM-01 › CAB-01 › NEST-01<br>
NEST-01A › NEST-01B › NEST-01C
</div>
</p>
</aside>
<section class="inspector" id="inspector" aria-live="polite">
<p class="eyebrow" id="stageKicker">Boundary 03 / cabinet</p>
<h2 id="stageTitle">Cabinet cut open</h2>
<p id="stageText"></p>
<div class="boundary" id="boundary"></div>
</section>
<button class="scene-cue" id="sceneCue" aria-label="Open the next containment boundary">
<span class="cue-dot"></span>
<span>
<b id="cueTitle">Open figure</b>
<small id="cueIdentity">NEST-01</small>
</span>
</button>
<div class="hint">Drag to orbit · wheel to zoom · shift-drag to pan · click a shell</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, camera, lighting
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf1ede4);
scene.fog = new THREE.Fog(0xf1ede4, 12, 24);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute("aria-label", "Interactive nesting doll cutaway scene");
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8ec, 0x8f786a, 2.1);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff5df, 3.15);
key.position.set(5.5, 8.5, 6.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 1;
key.shadow.camera.far = 22;
key.shadow.bias = -0.00025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xc7dcff, 1.2);
fill.position.set(-5, 4, 4);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffc7ad, 1.1);
rim.position.set(1, 5, -6);
scene.add(rim);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(12, 64),
new THREE.MeshStandardMaterial({
color: 0xe9e1d4,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.095;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
const M = {
house: material(0xe58f79),
houseSide: material(0xd97867),
roof: material(0xa9414b),
roofTrim: material(0x7f303b),
cream: material(0xf7ead5),
blue: material(0x547b91),
darkBlue: material(0x324e63),
room: material(0x85c7ba),
roomSide: material(0x63aa9e),
roomFloor: material(0xd3b68f),
cabinet: material(0x6775aa),
cabinetSide: material(0x4d5988),
cabinetInside: material(0x353e64),
wood: material(0xa87555),
rug: material(0xe7b85d),
sofa: material(0xe9a66e),
pillow: material(0xf5d9b4),
leaf: material(0x609c71),
pot: material(0xc67b60),
outerDoll: material(0xd85d50, { side: THREE.DoubleSide }),
outerApron: material(0xf3d8ae),
mediumDoll: material(0xe5a43f, { side: THREE.DoubleSide }),
mediumApron: material(0x8ab49d),
innerDoll: material(0x6fae9d, { side: THREE.DoubleSide }),
innerApron: material(0xf1e6cb),
face: material(0x272526),
cheek: material(0xef9c82)
};
function box(parent, size, position, mat, rotation = null) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, top, bottom, height, position, mat, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(top, bottom, height, segments),
mat
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(parent, radius, position, mat, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, 4),
mat
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const pickTargets = [];
function tagMeshes(group, stage) {
group.traverse((object) => {
if (object.isMesh) {
object.userData.cutawayStage = stage;
pickTargets.push(object);
}
});
}
// ------------------------------------------------------------
// HOUSE-01
//
// Actual scene graph:
// HOUSE-01
// └─ ROOM-01
// └─ CAB-01
// └─ NEST-01
// └─ NEST-01A
// └─ NEST-01B
// └─ NEST-01C
//
// Cutaways only transform shell pieces. Containment never changes.
// ------------------------------------------------------------
const house = new THREE.Group();
house.name = "HOUSE-01";
house.userData.identity = "HOUSE-01";
scene.add(house);
const houseShell = new THREE.Group();
houseShell.name = "HOUSE-01-SHELL";
house.add(houseShell);
box(houseShell, [5.15, 0.18, 3.58], [0, 0, 0], M.cream);
box(houseShell, [4.58, 2.5, 0.14], [0, 1.37, -1.68], M.house);
box(houseShell, [0.14, 2.5, 3.35], [-2.29, 1.37, 0], M.houseSide);
const houseFront = new THREE.Group();
houseFront.name = "HOUSE-01-FRONT";
houseShell.add(houseFront);
box(houseFront, [4.58, 2.5, 0.14], [0, 1.37, 1.68], M.house);
const gableShape = new THREE.Shape();
gableShape.moveTo(-2.29, 0);
gableShape.lineTo(2.29, 0);
gableShape.lineTo(0, 0.92);
gableShape.closePath();
const gableGeometry = new THREE.ExtrudeGeometry(gableShape, {
depth: 0.1,
bevelEnabled: false,
steps: 1
});
const gableMaterial = material(0xe58f79, { side: THREE.DoubleSide });
const frontGable = new THREE.Mesh(gableGeometry, gableMaterial);
frontGable.position.set(0, 2.62, 1.68);
frontGable.castShadow = true;
houseFront.add(frontGable);
const backGable = new THREE.Mesh(gableGeometry, gableMaterial);
backGable.position.set(0, 2.62, -1.78);
backGable.castShadow = true;
houseShell.add(backGable);
// Front door and windows.
box(houseFront, [0.8, 1.4, 0.07], [0.48, 0.8, 1.79], M.blue);
box(houseFront, [0.58, 0.58, 0.03], [0.48, 1.02, 1.84], M.darkBlue);
sphere(houseFront, 0.045, [0.76, 0.75, 1.86], M.cream, 6);
box(houseFront, [1.0, 0.11, 0.38], [0.48, 0.08, 1.94], M.cream);
for (const x of [-1.25, 1.55]) {
box(houseFront, [0.78, 0.7, 0.035], [x, 1.53, 1.78], M.darkBlue);
box(houseFront, [0.88, 0.08, 0.08], [x, 1.18, 1.82], M.cream);
box(houseFront, [0.88, 0.08, 0.08], [x, 1.88, 1.82], M.cream);
box(houseFront, [0.08, 0.78, 0.08], [x - 0.4, 1.53, 1.82], M.cream);
box(houseFront, [0.08, 0.78, 0.08], [x + 0.4, 1.53, 1.82], M.cream);
box(houseFront, [0.06, 0.72, 0.08], [x, 1.53, 1.82], M.cream);
}
const houseRight = new THREE.Group();
houseRight.name = "HOUSE-01-RIGHT";
houseRight.position.x = 2.29;
houseShell.add(houseRight);
box(houseRight, [0.14, 2.5, 3.35], [0, 1.37, 0], M.houseSide);
box(houseRight, [0.035, 0.72, 0.78], [0.09, 1.52, -0.28], M.darkBlue);
box(houseRight, [0.08, 0.82, 0.08], [0.11, 1.52, -0.28], M.cream);
box(houseRight, [0.08, 0.08, 0.88], [0.11, 1.52, -0.28], M.cream);
// Two separately pivoted roof slopes.
const roofLeftPivot = new THREE.Group();
roofLeftPivot.position.set(0, 3.54, 0);
houseShell.add(roofLeftPivot);
box(
roofLeftPivot,
[2.83, 0.16, 3.86],
[-1.34, -0.43, 0],
M.roof,
[0, 0, 0.322]
);
const roofRightPivot = new THREE.Group();
roofRightPivot.position.set(0, 3.54, 0);
houseShell.add(roofRightPivot);
box(
roofRightPivot,
[2.83, 0.16, 3.86],
[1.34, -0.43, 0],
M.roof,
[0, 0, -0.322]
);
box(houseShell, [0.16, 0.12, 3.95], [0, 3.59, 0], M.roofTrim);
tagMeshes(houseShell, 1);
// ------------------------------------------------------------
// ROOM-01
// ------------------------------------------------------------
const room = new THREE.Group();
room.name = "ROOM-01";
room.userData.identity = "ROOM-01";
room.position.set(0, 0.1, 0.02);
house.add(room);
const roomShell = new THREE.Group();
roomShell.name = "ROOM-01-SHELL";
room.add(roomShell);
box(roomShell, [3.46, 0.12, 2.2], [0, 0, 0], M.roomFloor);
box(roomShell, [3.36, 2, 0.12], [0, 1.02, -1.04], M.room);
box(roomShell, [0.12, 2, 2.08], [-1.68, 1.02, 0], M.roomSide);
const roomFront = new THREE.Group();
roomFront.name = "ROOM-01-FRONT";
roomFront.position.z = 1.04;
roomShell.add(roomFront);
box(roomFront, [3.36, 2, 0.12], [0, 1.02, 0], M.room);
box(roomFront, [1.3, 0.78, 0.035], [-0.42, 1.25, 0.08], M.darkBlue);
box(roomFront, [1.4, 0.08, 0.08], [-0.42, 0.82, 0.11], M.cream);
box(roomFront, [1.4, 0.08, 0.08], [-0.42, 1.68, 0.11], M.cream);
box(roomFront, [0.08, 0.94, 0.08], [-1.07, 1.25, 0.11], M.cream);
box(roomFront, [0.08, 0.94, 0.08], [0.23, 1.25, 0.11], M.cream);
box(roomFront, [0.88, 1.3, 0.05], [0.98, 0.73, 0.08], M.cream);
const roomRight = new THREE.Group();
roomRight.name = "ROOM-01-RIGHT";
roomRight.position.x = 1.68;
roomShell.add(roomRight);
box(roomRight, [0.12, 2, 2.08], [0, 1.02, 0], M.roomSide);
tagMeshes(roomShell, 2);
// Room furnishings.
const roomContents = new THREE.Group();
roomContents.name = "ROOM-01-CONTENTS";
room.add(roomContents);
const rug = new THREE.Mesh(
new THREE.CircleGeometry(0.86, 8),
M.rug
);
rug.rotation.x = -Math.PI / 2;
rug.position.set(-0.83, 0.075, 0.43);
rug.receiveShadow = true;
roomContents.add(rug);
const sofa = new THREE.Group();
sofa.position.set(-1.02, 0.08, 0.25);
roomContents.add(sofa);
box(sofa, [0.92, 0.2, 0.5], [0, 0.22, 0], M.sofa);
box(sofa, [0.92, 0.5, 0.13], [0, 0.48, -0.19], M.sofa);
box(sofa, [0.13, 0.34, 0.5], [-0.43, 0.36, 0], M.sofa);
box(sofa, [0.13, 0.34, 0.5], [0.43, 0.36, 0], M.sofa);
box(sofa, [0.27, 0.25, 0.12], [-0.2, 0.58, -0.08], M.pillow, [0, 0, 0.12]);
cylinder(roomContents, 0.27, 0.27, 0.08, [-0.78, 0.23, 0.78], M.cream, 8);
cylinder(roomContents, 0.08, 0.1, 0.2, [-0.78, 0.1, 0.78], M.wood, 6);
const plant = new THREE.Group();
plant.position.set(1.34, 0.08, -0.62);
roomContents.add(plant);
cylinder(plant, 0.15, 0.12, 0.23, [0, 0.12, 0], M.pot, 6);
cylinder(plant, 0.025, 0.04, 0.62, [0, 0.5, 0], M.leaf, 5);
const leafA = cylinder(
plant, 0.02, 0.12, 0.42, [-0.1, 0.47, 0], M.leaf, 5
);
leafA.rotation.z = -0.65;
const leafB = cylinder(
plant, 0.02, 0.12, 0.42, [0.1, 0.5, 0], M.leaf, 5
);
leafB.rotation.z = 0.65;
// Framed pictures on the room's rear wall.
box(roomContents, [0.48, 0.58, 0.04], [-0.93, 1.47, -0.96], M.cream);
box(roomContents, [0.35, 0.43, 0.025], [-0.93, 1.47, -0.925], M.blue);
box(roomContents, [0.38, 0.48, 0.04], [0.9, 1.52, -0.96], M.cream);
box(roomContents, [0.27, 0.35, 0.025], [0.9, 1.52, -0.925], M.rug);
// ------------------------------------------------------------
// CAB-01
// ------------------------------------------------------------
const cabinet = new THREE.Group();
cabinet.name = "CAB-01";
cabinet.userData.identity = "CAB-01";
cabinet.position.set(0.53, 0.08, -0.12);
room.add(cabinet);
const cabinetShell = new THREE.Group();
cabinetShell.name = "CAB-01-SHELL";
cabinet.add(cabinetShell);
box(cabinetShell, [1.16, 0.12, 0.7], [0, 0.18, 0], M.cabinet);
box(cabinetShell, [1.16, 0.12, 0.7], [0, 1.47, 0], M.cabinet);
box(cabinetShell, [0.11, 1.25, 0.68], [-0.525, 0.82, 0], M.cabinetSide);
box(cabinetShell, [0.11, 1.25, 0.68], [0.525, 0.82, 0], M.cabinetSide);
box(cabinetShell, [1.05, 1.2, 0.08], [0, 0.82, -0.32], M.cabinetInside);
for (const x of [-0.47, 0.47]) {
for (const z of [-0.25, 0.25]) {
box(cabinetShell, [0.11, 0.17, 0.11], [x, 0.04, z], M.wood);
}
}
const cabinetDoor = new THREE.Group();
cabinetDoor.name = "CAB-01-DOOR";
cabinetDoor.position.set(-0.56, 0, 0.37);
cabinetShell.add(cabinetDoor);
box(cabinetDoor, [1.1, 1.23, 0.08], [0.55, 0.82, 0], M.cabinet);
box(cabinetDoor, [0.82, 0.94, 0.035], [0.55, 0.82, 0.06], M.cabinetSide);
sphere(cabinetDoor, 0.045, [0.98, 0.82, 0.1], M.cream, 6);
tagMeshes(cabinetShell, 3);
// ------------------------------------------------------------
// Nesting figure
//
// Each shell is split into front and back halves. The front half
// rotates around the same group, leaving the inner doll in place.
// ------------------------------------------------------------
function halfCylinder(parent, top, bottom, height, y, mat, front) {
const geometry = new THREE.CylinderGeometry(
top,
bottom,
height,
8,
1,
true,
front ? 0 : Math.PI,
Math.PI
);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.y = y;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function halfHead(parent, radius, y, mat, front) {
const geometry = new THREE.SphereGeometry(
radius,
8,
4,
front ? 0 : Math.PI,
Math.PI
);
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.y = y;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createDollShell(bodyMat, apronMat, withFace) {
const group = new THREE.Group();
const back = new THREE.Group();
const front = new THREE.Group();
group.add(back, front);
halfCylinder(back, 0.29, 0.36, 0.48, 0.25, bodyMat, false);
halfCylinder(front, 0.29, 0.36, 0.48, 0.25, bodyMat, true);
halfCylinder(back, 0.25, 0.29, 0.46, 0.72, bodyMat, false);
halfCylinder(front, 0.25, 0.29, 0.46, 0.72, bodyMat, true);
halfHead(back, 0.24, 1.15, bodyMat, false);
halfHead(front, 0.24, 1.15, bodyMat, true);
box(front, [0.31, 0.37, 0.028], [0, 0.42, 0.315], apronMat);
if (withFace) {
sphere(front, 0.024, [-0.074, 1.17, 0.225], M.face, 6);
sphere(front, 0.024, [0.074, 1.17, 0.225], M.face, 6);
sphere(front, 0.018, [-0.1, 1.1, 0.222], M.cheek, 6);
sphere(front, 0.018, [0.1, 1.1, 0.222], M.cheek, 6);
}
return { group, front, back };
}
const nesting = new THREE.Group();
nesting.name = "NEST-01";
nesting.userData.identity = "NEST-01";
nesting.position.set(0, 0.18, 0.02);
cabinet.add(nesting);
const outerDoll = new THREE.Group();
outerDoll.name = "NEST-01A";
outerDoll.userData.identity = "NEST-01A";
outerDoll.scale.setScalar(0.92);
nesting.add(outerDoll);
const outerShell = createDollShell(M.outerDoll, M.outerApron, true);
outerDoll.add(outerShell.group);
const mediumDoll = new THREE.Group();
mediumDoll.name = "NEST-01B";
mediumDoll.userData.identity = "NEST-01B";
mediumDoll.position.y = 0.035;
mediumDoll.scale.setScalar(0.68);
outerDoll.add(mediumDoll);
const mediumShell = createDollShell(M.mediumDoll, M.mediumApron, true);
mediumDoll.add(mediumShell.group);
const innerDoll = new THREE.Group();
innerDoll.name = "NEST-01C";
innerDoll.userData.identity = "NEST-01C";
innerDoll.position.y = 0.025;
innerDoll.scale.setScalar(0.66);
mediumDoll.add(innerDoll);
const innerShell = createDollShell(M.innerDoll, M.innerApron, true);
innerDoll.add(innerShell.group);
tagMeshes(outerDoll, 4);
// ------------------------------------------------------------
// Camera controls implemented directly, without add-ons
// ------------------------------------------------------------
const orbit = {
theta: 0.58,
phi: 1.17,
radius: 8.7,
goalTheta: 0.58,
goalPhi: 1.17,
goalRadius: 8.7
};
const cameraTarget = new THREE.Vector3(0, 1.45, 0);
const pointerState = new Map();
let gestureMode = "rotate";
let gestureMoved = false;
let pinchDistance = 0;
function updateCamera(dt) {
const damping = 1 - Math.exp(-9 * dt);
orbit.theta = THREE.MathUtils.lerp(orbit.theta, orbit.goalTheta, damping);
orbit.phi = THREE.MathUtils.lerp(orbit.phi, orbit.goalPhi, damping);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
orbit.goalRadius,
damping
);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function panCamera(dx, dy) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
const amount = orbit.radius * 0.00115;
cameraTarget.addScaledVector(right, -dx * amount);
cameraTarget.addScaledVector(up, dy * amount);
}
function pointerPairDistance() {
const points = [...pointerState.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
const raycaster = new THREE.Raycaster();
const normalizedPointer = new THREE.Vector2();
function isPickable(object) {
let current = object;
let scaleProduct = 1;
while (current) {
if (!current.visible) return false;
scaleProduct *=
Math.abs(current.scale.x) *
Math.abs(current.scale.y) *
Math.abs(current.scale.z);
current = current.parent;
}
return scaleProduct > 0.025;
}
function pickScene(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
normalizedPointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
normalizedPointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(normalizedPointer, camera);
const intersections = raycaster.intersectObjects(pickTargets, false);
const hit = intersections.find((entry) => isPickable(entry.object));
if (hit) {
const stage = hit.object.userData.cutawayStage;
if (Number.isInteger(stage)) {
setDepth(Math.max(currentDepth, stage));
}
}
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerState.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointerState.size === 1) {
gestureMode =
event.button === 2 || event.shiftKey ? "pan" : "rotate";
gestureMoved = false;
} else {
gestureMoved = true;
pinchDistance = pointerPairDistance();
}
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointerState.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) gestureMoved = true;
if (pointerState.size === 1) {
if (gestureMode === "pan") {
panCamera(dx, dy);
} else {
orbit.goalTheta -= dx * 0.006;
orbit.goalPhi = THREE.MathUtils.clamp(
orbit.goalPhi + dy * 0.005,
0.56,
1.44
);
}
} else if (pointerState.size === 2) {
const distance = pointerPairDistance();
if (pinchDistance > 0 && distance > 0) {
orbit.goalRadius = THREE.MathUtils.clamp(
orbit.goalRadius * (pinchDistance / distance),
4.4,
13
);
}
pinchDistance = distance;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const shouldPick =
pointerState.size === 1 &&
!gestureMoved &&
event.button !== 2;
pointerState.delete(event.pointerId);
if (pointerState.size < 2) pinchDistance = 0;
if (pointerState.size === 0) {
renderer.domElement.style.cursor = "grab";
}
if (shouldPick) pickScene(event.clientX, event.clientY);
});
renderer.domElement.addEventListener("pointercancel", (event) => {
pointerState.delete(event.pointerId);
gestureMoved = true;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.goalRadius = THREE.MathUtils.clamp(
orbit.goalRadius * Math.exp(event.deltaY * 0.001),
4.4,
13
);
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
// ------------------------------------------------------------
// UI and cutaway state
// ------------------------------------------------------------
const stages = [
{
kicker: "Boundary 00 / exterior",
title: "House sealed",
text:
"HOUSE-01 contains a complete room model. Select the facade or use the next boundary to open the first shell.",
boundary: "HOUSE-01 ▸ ROOM-01",
accent: "#b85c50",
cue: "Open house",
identity: "HOUSE-01"
},
{
kicker: "Boundary 01 / house",
title: "House cut open",
text:
"The facade retracts and the near roof slope pivots away. The same ROOM-01 instance is exposed inside HOUSE-01.",
boundary: "HOUSE-01 ▸ ROOM-01",
accent: "#d77661",
cue: "Open room",
identity: "ROOM-01"
},
{
kicker: "Boundary 02 / room",
title: "Room cut open",
text:
"The room's front and right walls fold away. CAB-01 remains on the original room floor and keeps its identity.",
boundary: "ROOM-01 ▸ CAB-01",
accent: "#4a9e91",
cue: "Open cabinet",
identity: "CAB-01"
},
{
kicker: "Boundary 03 / cabinet",
title: "Cabinet cut open",
text:
"The hinged door rotates out of the way, revealing NEST-01A. No mesh is replaced or re-parented.",
boundary: "CAB-01 ▸ NEST-01A ▸ NEST-01B ▸ NEST-01C",
accent: "#6674aa",
cue: "Open figure",
identity: "NEST-01"
},
{
kicker: "Boundary 04 / nesting figure",
title: "Containment revealed",
text:
"Three doll shells pivot apart in place. NEST-01B remains inside NEST-01A, and NEST-01C remains inside NEST-01B.",
boundary: "NEST-01A ▸ NEST-01B ▸ NEST-01C",
accent: "#cf9134",
cue: "",
identity: ""
}
];
const depthButtons = [...document.querySelectorAll(".cut-step")];
const stageKicker = document.getElementById("stageKicker");
const stageTitle = document.getElementById("stageTitle");
const stageText = document.getElementById("stageText");
const boundary = document.getElementById("boundary");
const sceneCue = document.getElementById("sceneCue");
const cueTitle = document.getElementById("cueTitle");
const cueIdentity = document.getElementById("cueIdentity");
let currentDepth = 3;
const cuts = {
house: 0,
room: 0,
cabinet: 0,
figure: 0
};
function setDepth(depth) {
currentDepth = THREE.MathUtils.clamp(depth, 0, 4);
const stage = stages[currentDepth];
document.documentElement.style.setProperty("--accent", stage.accent);
depthButtons.forEach((button) => {
const active = Number(button.dataset.depth) === currentDepth;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
stageKicker.textContent = stage.kicker;
stageTitle.textContent = stage.title;
stageText.textContent = stage.text;
boundary.textContent = stage.boundary;
sceneCue.hidden = currentDepth === 4;
cueTitle.textContent = stage.cue;
cueIdentity.textContent = stage.identity;
selectionHelper.material.color.set(stage.accent);
}
depthButtons.forEach((button) => {
button.addEventListener("click", () => {
setDepth(Number(button.dataset.depth));
});
});
document.getElementById("revealAll").addEventListener("click", () => {
setDepth(4);
});
document.getElementById("resetView").addEventListener("click", () => {
orbit.goalTheta = 0.58;
orbit.goalPhi = 1.17;
orbit.goalRadius = 8.7;
cameraTarget.set(0, 1.45, 0);
});
sceneCue.addEventListener("click", () => {
setDepth(Math.min(4, currentDepth + 1));
});
// Selection outline.
const highlightObjects = [
house,
room,
cabinetShell,
outerDoll,
outerDoll
];
const selectionHelper = new THREE.BoxHelper(
highlightObjects[currentDepth],
stages[currentDepth].accent
);
selectionHelper.material.transparent = true;
selectionHelper.material.opacity = 0.43;
selectionHelper.material.depthTest = false;
selectionHelper.renderOrder = 20;
scene.add(selectionHelper);
setDepth(currentDepth);
// Floating cue anchors.
const houseCueAnchor = new THREE.Object3D();
houseCueAnchor.position.set(0, 3.82, 0);
house.add(houseCueAnchor);
const roomCueAnchor = new THREE.Object3D();
roomCueAnchor.position.set(-0.45, 2.24, 0.08);
room.add(roomCueAnchor);
const cabinetCueAnchor = new THREE.Object3D();
cabinetCueAnchor.position.set(0, 1.67, 0);
cabinet.add(cabinetCueAnchor);
const dollCueAnchor = new THREE.Object3D();
dollCueAnchor.position.set(0, 1.57, 0);
outerDoll.add(dollCueAnchor);
const cueAnchors = [
houseCueAnchor,
roomCueAnchor,
cabinetCueAnchor,
dollCueAnchor
];
const projected = new THREE.Vector3();
function updateSceneCue() {
if (currentDepth === 4) return;
const anchor = cueAnchors[currentDepth];
anchor.getWorldPosition(projected);
projected.project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
sceneCue.style.left = `${x}px`;
sceneCue.style.top = `${y - 12}px`;
sceneCue.style.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function damp(current, target, lambda, dt) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * dt)
);
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
cuts.house = damp(cuts.house, currentDepth >= 1 ? 1 : 0, 6.5, dt);
cuts.room = damp(cuts.room, currentDepth >= 2 ? 1 : 0, 6.5, dt);
cuts.cabinet = damp(
cuts.cabinet,
currentDepth >= 3 ? 1 : 0,
6.5,
dt
);
cuts.figure = damp(
cuts.figure,
currentDepth >= 4 ? 1 : 0,
6.5,
dt
);
// House facade collapses toward its floor line.
houseFront.scale.y = Math.max(0.001, 1 - cuts.house);
houseFront.position.y = -0.06 * cuts.house;
// Near wall retracts sideways.
houseRight.scale.x = Math.max(0.001, 1 - cuts.house);
houseRight.position.x = 2.29 + 0.15 * cuts.house;
// Roof slope pivots around the ridge.
roofRightPivot.rotation.z = cuts.house * 1.04;
// Room shell retracts independently.
roomFront.scale.z = Math.max(0.001, 1 - cuts.room);
roomFront.position.z = 1.04 + 0.12 * cuts.room;
roomRight.scale.x = Math.max(0.001, 1 - cuts.room);
roomRight.position.x = 1.68 + 0.12 * cuts.room;
// Cabinet door and doll shells hinge in place.
cabinetDoor.rotation.y = -1.88 * cuts.cabinet;
outerShell.front.rotation.y = -1.56 * cuts.figure;
mediumShell.front.rotation.y = -1.47 * cuts.figure;
innerShell.front.rotation.y = -1.36 * cuts.figure;
updateCamera(dt);
scene.updateMatrixWorld(true);
selectionHelper.setFromObject(highlightObjects[currentDepth]);
updateSceneCue();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.render(scene, camera);
const loading = document.getElementById("loading");
requestAnimationFrame(() => {
loading.classList.add("done");
setTimeout(() => loading.remove(), 400);
});
animate();
</script>
</body>
</html>
```