Prompt specification
Build or customize the Three.js 3D scene "Shared reading and craft corner" 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: Shared reading and craft corner
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shared-reading-and-craft-corner-x0195
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring desk-lamp illumination. Compose a reading chair and craft desk with independent lights; selecting one activity changes its illumination while retaining visible circulation and the neighboring workstation. Stylized solid forms.
Working Three.js Starter (shared-reading-and-craft-corner-x0195):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Two-Mode Studio</title>
<style>
:root {
color-scheme: light;
--ink: #28312f;
--muted: #68716e;
--paper: rgba(249, 246, 239, 0.9);
--line: rgba(44, 55, 51, 0.14);
--reading: #d9774d;
--craft: #d49b39;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e4ded4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
max-width: min(390px, calc(100vw - 52px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #59615e;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
background: var(--craft);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 40px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
max-width: 340px;
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.view-button {
position: fixed;
z-index: 8;
top: 24px;
right: 24px;
display: grid;
width: 42px;
height: 42px;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: rgba(249, 246, 239, 0.78);
color: var(--ink);
cursor: pointer;
box-shadow: 0 8px 30px rgba(48, 53, 49, 0.08);
backdrop-filter: blur(12px);
transition:
transform 160ms ease,
background 160ms ease;
}
.view-button:hover {
transform: rotate(-12deg) scale(1.04);
background: rgba(255, 255, 255, 0.96);
}
.view-button svg {
width: 19px;
height: 19px;
}
.mode-panel {
position: fixed;
z-index: 7;
bottom: 24px;
left: 50%;
width: min(560px, calc(100vw - 32px));
padding: 9px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 21px;
background: var(--paper);
box-shadow:
0 20px 60px rgba(45, 50, 47, 0.16),
inset 0 1px 0 rgba(255, 255, 255, 0.75);
backdrop-filter: blur(18px);
}
.modes {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.mode {
position: relative;
display: grid;
grid-template-columns: 38px 1fr auto;
gap: 11px;
align-items: center;
min-height: 72px;
padding: 11px 13px;
overflow: hidden;
border: 1px solid transparent;
border-radius: 15px;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.mode:hover {
background: rgba(255, 255, 255, 0.54);
transform: translateY(-1px);
}
.mode.active {
border-color: rgba(73, 82, 77, 0.18);
background: rgba(255, 255, 255, 0.82);
box-shadow: 0 8px 24px rgba(52, 58, 54, 0.07);
}
.mode-icon {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border-radius: 12px;
background: rgba(40, 49, 47, 0.07);
color: var(--muted);
transition:
color 180ms ease,
background 180ms ease;
}
.mode.active[data-mode="reading"] .mode-icon {
background: rgba(217, 119, 77, 0.15);
color: var(--reading);
}
.mode.active[data-mode="craft"] .mode-icon {
background: rgba(212, 155, 57, 0.17);
color: #b37d19;
}
.mode-icon svg {
width: 22px;
height: 22px;
}
.mode-name {
display: block;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.01em;
}
.mode-note {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.mode-level {
width: 5px;
height: 40px;
overflow: hidden;
border-radius: 5px;
background: rgba(40, 49, 47, 0.08);
}
.mode-level i {
position: absolute;
right: 13px;
bottom: 13px;
width: 5px;
height: var(--level, 50%);
border-radius: 5px;
background: #8d9692;
transform-origin: bottom;
transition:
height 350ms ease,
background 180ms ease;
}
.mode.active[data-mode="reading"] .mode-level i {
background: var(--reading);
}
.mode.active[data-mode="craft"] .mode-level i {
background: var(--craft);
}
.status {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin: 7px 9px 2px;
padding: 9px 3px 2px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.status strong {
color: #4a5551;
font-weight: 750;
}
.status span:last-child {
flex: none;
color: #7f8985;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint {
position: fixed;
z-index: 5;
right: 24px;
bottom: 28px;
color: rgba(51, 61, 57, 0.58);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e4ded4;
color: #59615e;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.view-button {
top: 16px;
right: 16px;
}
.mode-panel {
bottom: 14px;
}
.mode {
grid-template-columns: 31px 1fr;
gap: 8px;
min-height: 61px;
padding: 9px;
}
.mode-icon {
width: 31px;
height: 31px;
border-radius: 10px;
}
.mode-level {
display: none;
}
.status span:last-child,
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="eyebrow">Studio 07 · Adaptive light</div>
<h1>Read. Make. Settle in.</h1>
<p class="subtitle">
Choose an activity to focus its lamp. The other station stays visible,
and the central aisle remains clear.
</p>
</header>
<button class="view-button" id="resetView" title="Reset camera view" aria-label="Reset camera view">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
<path d="M4.8 8.5A8 8 0 1 1 4 13" />
<path d="M4.8 4.5v4h4" />
</svg>
</button>
<section class="mode-panel" aria-label="Choose room activity">
<div class="modes">
<button class="mode" data-mode="reading" aria-pressed="false">
<span class="mode-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.65">
<path d="M5 11.5 8.5 5h7L19 11.5v7H5z" />
<path d="M8.5 5v6.5h7V5M5 18.5h14" />
</svg>
</span>
<span>
<span class="mode-name">Reading nook</span>
<span class="mode-note">Floor lamp</span>
</span>
<span class="mode-level"><i></i></span>
</button>
<button class="mode active" data-mode="craft" aria-pressed="true">
<span class="mode-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.65">
<path d="M4 17h16M6 17v3M18 17v3" />
<path d="M7 14h10M8 14l1-7h6l1 7M12 7V4" />
<path d="M10 4h4" />
</svg>
</span>
<span>
<span class="mode-name">Craft desk</span>
<span class="mode-note">Task lamp</span>
</span>
<span class="mode-level"><i></i></span>
</button>
</div>
<div class="status">
<span id="statusText"><strong>Craft focus</strong> · Reading nook remains visible</span>
<span>Circulation preserved</span>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Click a station</div>
<div id="loading">Building the studio</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneContainer = document.getElementById("scene");
const loading = document.getElementById("loading");
const statusText = document.getElementById("statusText");
const modeButtons = [...document.querySelectorAll(".mode")];
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive studio scene with a reading chair and illuminated craft desk"
);
sceneContainer.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe4ded4);
scene.fog = new THREE.Fog(0xe4ded4, 17, 28);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const orbit = {
radius: 14.2,
theta: 0.27,
phi: 1.16,
target: new THREE.Vector3(0, 1.08, -0.45)
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
applyCamera();
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
...options
});
}
const materials = {
floor: standard(0xd8d0c3),
aisle: standard(0xeee8dc),
wall: standard(0xeee9df),
wallTrim: standard(0xd6d0c5),
wood: standard(0xc9945f),
woodDark: standard(0x80583c),
woodLight: standard(0xe0bd86),
green: standard(0x667a6d),
darkGreen: standard(0x344743),
rust: standard(0xc76f50),
rustDark: standard(0x97503b),
cream: standard(0xeadbc4),
paper: standard(0xf7f0df),
teal: standard(0x3f7775),
blue: standard(0x6d8d95),
screen: standard(0x274a50, {
emissive: 0x3c777d,
emissiveIntensity: 0.55,
roughness: 0.45
}),
metal: standard(0x35413e, {
roughness: 0.38,
metalness: 0.5
}),
brass: standard(0xb9853f, {
roughness: 0.48,
metalness: 0.35
}),
terracotta: standard(0xb9674c),
plant: standard(0x52725a),
plantLight: standard(0x78966d),
black: standard(0x252c2b)
};
function mesh(geometry, material, position, parent = scene, cast = true) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.copy(position);
object.castShadow = cast;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(w, h, d, material, position, parent = scene, cast = true) {
return mesh(
new THREE.BoxGeometry(w, h, d),
material,
position,
parent,
cast
);
}
function roundedBox(w, h, d, radius, material, position, parent = scene) {
radius = Math.min(radius, w * 0.24, h * 0.24, d * 0.24);
const sw = w - radius * 2;
const sh = h - radius * 2;
const x = -sw / 2;
const y = -sh / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + sw - radius, y);
shape.quadraticCurveTo(x + sw, y, x + sw, y + radius);
shape.lineTo(x + sw, y + sh - radius);
shape.quadraticCurveTo(x + sw, y + sh, x + sw - radius, y + sh);
shape.lineTo(x + radius, y + sh);
shape.quadraticCurveTo(x, y + sh, x, y + sh - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: d - radius * 2,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: radius,
bevelThickness: radius,
curveSegments: 6,
steps: 1
});
geometry.translate(0, 0, -(d - radius * 2) / 2);
geometry.computeVertexNormals();
return mesh(geometry, material, position, parent);
}
function cylinderBetween(a, b, radius, material, parent = scene, radialSegments = 14) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
);
const object = mesh(geometry, material, null, parent);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
function makeTextPlane(
text,
width,
height,
options = {}
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
if (options.background) {
context.fillStyle = options.background;
context.beginPath();
context.roundRect(8, 8, 1008, 240, 34);
context.fill();
}
context.fillStyle = options.color || "#59615e";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = `${options.weight || 800} ${options.size || 62}px system-ui`;
context.letterSpacing = "8px";
context.fillText(text, 512, 130);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
}
// -------------------------------------------------------------------------
// Room shell and circulation
// -------------------------------------------------------------------------
box(14, 0.26, 10, materials.floor, new THREE.Vector3(0, -0.15, -0.2));
box(14, 4.7, 0.18, materials.wall, new THREE.Vector3(0, 2.3, -5.05));
box(0.18, 4.7, 5.65, materials.wall, new THREE.Vector3(-6.92, 2.3, -2.25));
box(14, 0.14, 0.08, materials.wallTrim, new THREE.Vector3(0, 0.13, -4.92));
box(0.08, 0.14, 5.55, materials.wallTrim, new THREE.Vector3(-6.78, 0.13, -2.25));
// Broad central circulation runner.
box(1.3, 0.024, 6.3, materials.aisle, new THREE.Vector3(0, -0.008, 0.35));
for (let i = 0; i < 9; i++) {
box(
0.055,
0.03,
0.28,
materials.woodLight,
new THREE.Vector3(0, 0.02, 3.08 - i * 0.68)
);
}
const aisleLabel = makeTextPlane("CLEAR AISLE", 2.05, 0.52, {
color: "rgba(74, 82, 76, .42)",
size: 60
});
aisleLabel.rotation.x = -Math.PI / 2;
aisleLabel.position.set(0, 0.025, 2.05);
scene.add(aisleLabel);
// Window on the rear wall.
box(2.25, 1.62, 0.06, materials.blue, new THREE.Vector3(-3.65, 2.8, -4.90));
box(2.48, 0.12, 0.16, materials.cream, new THREE.Vector3(-3.65, 3.66, -4.82));
box(2.48, 0.12, 0.16, materials.cream, new THREE.Vector3(-3.65, 1.94, -4.82));
box(0.12, 1.82, 0.16, materials.cream, new THREE.Vector3(-4.78, 2.8, -4.82));
box(0.12, 1.82, 0.16, materials.cream, new THREE.Vector3(-2.52, 2.8, -4.82));
box(0.09, 1.6, 0.16, materials.cream, new THREE.Vector3(-3.65, 2.8, -4.81));
// Small studio title.
const studioLabel = makeTextPlane("STUDIO / 07", 2.25, 0.52, {
background: "rgba(224, 218, 205, .78)",
color: "#59615e",
size: 52
});
studioLabel.position.set(0.1, 3.52, -4.91);
scene.add(studioLabel);
// Rear wall shelf and books.
box(2.3, 0.12, 0.42, materials.wood, new THREE.Vector3(0.25, 2.47, -4.66));
const bookColors = [materials.rust, materials.teal, materials.cream, materials.woodDark];
for (let i = 0; i < 7; i++) {
const book = box(
0.16 + (i % 2) * 0.04,
0.44 + (i % 3) * 0.07,
0.25,
bookColors[i % bookColors.length],
new THREE.Vector3(-0.58 + i * 0.23, 2.76, -4.66)
);
book.rotation.z = i === 5 ? -0.08 : 0;
}
// -------------------------------------------------------------------------
// Reading nook
// -------------------------------------------------------------------------
const readingGroup = new THREE.Group();
readingGroup.position.set(-3.7, 0, -1.25);
readingGroup.rotation.y = -0.08;
readingGroup.userData.activity = "reading";
scene.add(readingGroup);
const rug = mesh(
new THREE.CylinderGeometry(2.05, 2.05, 0.055, 64),
standard(0xc8b49d),
new THREE.Vector3(0, 0.015, 0.1),
readingGroup
);
rug.scale.set(1.18, 1, 0.78);
roundedBox(1.48, 0.34, 1.28, 0.15, materials.rust, new THREE.Vector3(0, 0.68, 0.03), readingGroup);
roundedBox(1.5, 1.18, 0.34, 0.15, materials.rustDark, new THREE.Vector3(0, 1.25, -0.57), readingGroup);
roundedBox(0.3, 0.7, 1.22, 0.13, materials.rust, new THREE.Vector3(-0.84, 0.98, 0.01), readingGroup);
roundedBox(0.3, 0.7, 1.22, 0.13, materials.rust, new THREE.Vector3(0.84, 0.98, 0.01), readingGroup);
for (const x of [-0.53, 0.53]) {
for (const z of [-0.43, 0.47]) {
cylinderBetween(
new THREE.Vector3(x * 1.1, 0.13, z * 1.05),
new THREE.Vector3(x, 0.53, z),
0.055,
materials.woodDark,
readingGroup
);
}
}
const readingCushion = roundedBox(
0.88,
0.11,
0.72,
0.08,
materials.cream,
new THREE.Vector3(0, 0.89, 0.08),
readingGroup
);
readingCushion.rotation.x = -0.07;
// Side table.
mesh(
new THREE.CylinderGeometry(0.46, 0.46, 0.09, 32),
materials.woodLight,
new THREE.Vector3(-1.36, 0.77, 0.42),
readingGroup
);
cylinderBetween(
new THREE.Vector3(-1.36, 0.1, 0.42),
new THREE.Vector3(-1.36, 0.73, 0.42),
0.055,
materials.metal,
readingGroup
);
mesh(
new THREE.CylinderGeometry(0.28, 0.32, 0.08, 28),
materials.metal,
new THREE.Vector3(-1.36, 0.04, 0.42),
readingGroup
);
// Open book.
const leftPage = roundedBox(
0.33,
0.045,
0.4,
0.025,
materials.paper,
new THREE.Vector3(-1.48, 0.84, 0.42),
readingGroup
);
leftPage.rotation.y = 0.08;
const rightPage = roundedBox(
0.33,
0.045,
0.4,
0.025,
materials.paper,
new THREE.Vector3(-1.2, 0.84, 0.42),
readingGroup
);
rightPage.rotation.y = -0.08;
// -------------------------------------------------------------------------
// Craft desk and neighboring workstation
// -------------------------------------------------------------------------
const craftGroup = new THREE.Group();
craftGroup.position.set(2.4, 0, -1.75);
craftGroup.userData.activity = "craft";
scene.add(craftGroup);
roundedBox(3.4, 0.16, 1.55, 0.12, materials.woodLight, new THREE.Vector3(0, 1.38, 0), craftGroup);
box(3.08, 0.25, 0.1, materials.wood, new THREE.Vector3(0, 1.12, -0.62), craftGroup);
for (const x of [-1.45, 1.45]) {
for (const z of [-0.58, 0.58]) {
roundedBox(
0.15,
1.28,
0.15,
0.035,
materials.darkGreen,
new THREE.Vector3(x, 0.65, z),
craftGroup
);
}
}
// Craft mat and paper.
box(1.42, 0.025, 0.88, materials.teal, new THREE.Vector3(-0.56, 1.475, 0.18), craftGroup);
const paper = box(
0.72,
0.012,
0.52,
materials.paper,
new THREE.Vector3(-0.55, 1.497, 0.18),
craftGroup
);
paper.rotation.y = -0.09;
// Scissors: simple torus handles and thin blades.
const scissors = new THREE.Group();
scissors.position.set(-0.77, 1.53, 0.25);
scissors.rotation.y = -0.25;
craftGroup.add(scissors);
const handleGeometry = new THREE.TorusGeometry(0.09, 0.022, 8, 20);
const handleA = mesh(handleGeometry, materials.rust, new THREE.Vector3(-0.09, 0, -0.07), scissors);
const handleB = mesh(handleGeometry, materials.rust, new THREE.Vector3(0.09, 0, -0.07), scissors);
handleA.rotation.x = Math.PI / 2;
handleB.rotation.x = Math.PI / 2;
const bladeA = box(0.025, 0.018, 0.32, materials.metal, new THREE.Vector3(-0.04, 0, 0.13), scissors);
const bladeB = box(0.025, 0.018, 0.32, materials.metal, new THREE.Vector3(0.04, 0, 0.13), scissors);
bladeA.rotation.y = -0.12;
bladeB.rotation.y = 0.12;
// Thread spools.
const spoolColors = [materials.rust, materials.cream, materials.blue];
for (let i = 0; i < 3; i++) {
const spool = mesh(
new THREE.CylinderGeometry(0.095, 0.095, 0.2, 18),
spoolColors[i],
new THREE.Vector3(-1.35 + i * 0.25, 1.58, -0.36),
craftGroup
);
spool.castShadow = true;
}
// Pencil cup.
mesh(
new THREE.CylinderGeometry(0.13, 0.11, 0.26, 18),
materials.woodDark,
new THREE.Vector3(1.38, 1.59, -0.34),
craftGroup
);
for (let i = 0; i < 4; i++) {
cylinderBetween(
new THREE.Vector3(1.34 + i * 0.025, 1.65, -0.35),
new THREE.Vector3(1.29 + i * 0.045, 1.95 - (i % 2) * 0.08, -0.33),
0.014,
i % 2 ? materials.brass : materials.rust,
craftGroup,
8
);
}
// Monitor: always-on visual anchor of the neighboring workstation.
roundedBox(1.16, 0.7, 0.11, 0.055, materials.darkGreen, new THREE.Vector3(0.83, 2.08, -0.56), craftGroup);
roundedBox(1.02, 0.55, 0.018, 0.025, materials.screen, new THREE.Vector3(0.83, 2.08, -0.495), craftGroup);
box(0.1, 0.42, 0.1, materials.metal, new THREE.Vector3(0.83, 1.7, -0.56), craftGroup);
box(0.48, 0.045, 0.28, materials.metal, new THREE.Vector3(0.83, 1.49, -0.56), craftGroup);
roundedBox(0.84, 0.035, 0.25, 0.025, materials.cream, new THREE.Vector3(0.76, 1.48, 0.04), craftGroup);
// Pegboard and hanging tools.
roundedBox(2.85, 1.55, 0.1, 0.06, materials.wood, new THREE.Vector3(0.2, 2.72, -3.18), craftGroup);
const holeMaterial = standard(0x765238);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 9; col++) {
const hole = mesh(
new THREE.CircleGeometry(0.022, 10),
holeMaterial,
new THREE.Vector3(-0.9 + col * 0.27, 2.2 + row * 0.26, -3.12),
craftGroup,
false
);
hole.rotation.y = 0;
}
}
for (let i = 0; i < 4; i++) {
cylinderBetween(
new THREE.Vector3(-0.75 + i * 0.42, 2.93, -3.04),
new THREE.Vector3(-0.75 + i * 0.42, 2.38 + (i % 2) * 0.16, -3.04),
0.026,
i % 2 ? materials.brass : materials.darkGreen,
craftGroup,
10
);
}
box(1.95, 0.1, 0.28, materials.woodDark, new THREE.Vector3(0.2, 2.1, -3.05), craftGroup);
// Desk chair.
roundedBox(0.82, 0.15, 0.72, 0.08, materials.green, new THREE.Vector3(0.05, 0.72, 1.15), craftGroup);
roundedBox(0.82, 0.68, 0.15, 0.08, materials.green, new THREE.Vector3(0.05, 1.12, 0.82), craftGroup);
cylinderBetween(
new THREE.Vector3(0.05, 0.72, 1.15),
new THREE.Vector3(0.05, 0.17, 1.15),
0.055,
materials.metal,
craftGroup
);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
cylinderBetween(
new THREE.Vector3(0.05, 0.13, 1.15),
new THREE.Vector3(
0.05 + Math.cos(angle) * 0.43,
0.08,
1.15 + Math.sin(angle) * 0.43
),
0.03,
materials.metal,
craftGroup,
8
);
}
// Plant beside the workstation.
mesh(
new THREE.CylinderGeometry(0.22, 0.17, 0.37, 18),
materials.terracotta,
new THREE.Vector3(2.05, 0.19, 0.18),
craftGroup
);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const end = new THREE.Vector3(
2.05 + Math.cos(angle) * 0.22,
0.68 + (i % 3) * 0.12,
0.18 + Math.sin(angle) * 0.2
);
cylinderBetween(
new THREE.Vector3(2.05, 0.32, 0.18),
end,
0.012,
materials.plant,
craftGroup,
7
);
const leaf = mesh(
new THREE.SphereGeometry(0.13, 12, 8),
i % 2 ? materials.plant : materials.plantLight,
end,
craftGroup
);
leaf.scale.set(0.7, 1.5, 0.45);
leaf.rotation.z = Math.cos(angle) * 0.5;
leaf.rotation.x = Math.sin(angle) * 0.5;
}
scene.updateMatrixWorld(true);
// -------------------------------------------------------------------------
// Fixed room lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff6e9, 0x738177, 1.45);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1dc, 2.25);
keyLight.position.set(-4, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
// This soft fill deliberately remains on in both modes so the neighboring
// workstation never disappears into darkness.
const workstationFill = new THREE.PointLight(0xbdd4d7, 28, 9, 1.4);
workstationFill.position.set(2.6, 3.8, 0.8);
scene.add(workstationFill);
// -------------------------------------------------------------------------
// Independent lamps
// -------------------------------------------------------------------------
function worldPoint(group, point) {
return group.localToWorld(point.clone());
}
function makeBeam(source, target, radius, color) {
const direction = new THREE.Vector3().subVectors(target, source);
const length = direction.length();
direction.normalize();
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending,
toneMapped: false
});
const beam = new THREE.Mesh(
new THREE.ConeGeometry(radius, length, 36, 1, true),
material
);
beam.position.copy(source).addScaledVector(direction, -length / 2);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
beam.renderOrder = 3;
scene.add(beam);
return beam;
}
function makeLampShade(source, target, material, topRadius, bottomRadius, length) {
const midpoint = source.clone().add(target).multiplyScalar(0.5);
const axis = source.clone().sub(target).normalize();
const shade = new THREE.Mesh(
new THREE.CylinderGeometry(
topRadius,
bottomRadius,
length,
28,
1,
true
),
material
);
shade.position.copy(midpoint);
shade.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
axis
);
shade.castShadow = false;
shade.receiveShadow = true;
scene.add(shade);
const direction = target.clone().sub(source).normalize();
const opening = source.clone().addScaledVector(direction, length * 0.49);
const glowMaterial = new THREE.MeshBasicMaterial({
color: 0xffc36a,
transparent: true,
opacity: 0.38,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending,
depthWrite: false,
toneMapped: false
});
const glow = new THREE.Mesh(
new THREE.CircleGeometry(bottomRadius * 0.86, 28),
glowMaterial
);
glow.position.copy(opening);
glow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction
);
glow.renderOrder = 4;
scene.add(glow);
return { shade, glow };
}
// Reading floor lamp.
const readingSource = worldPoint(
readingGroup,
new THREE.Vector3(-1.65, 2.72, -1.0)
);
const readingTarget = worldPoint(
readingGroup,
new THREE.Vector3(0.24, 0.82, 0.3)
);
const readingShadeMaterial = standard(0xf0c879, {
roughness: 0.55,
emissive: 0xffb454,
emissiveIntensity: 0.08
});
mesh(
new THREE.CylinderGeometry(0.31, 0.38, 0.09, 28),
materials.metal,
new THREE.Vector3(-1.65, 0.075, -1.0),
readingGroup
);
cylinderBetween(
new THREE.Vector3(-1.65, 0.1, -1.0),
new THREE.Vector3(-1.65, 2.22, -1.0),
0.035,
materials.brass,
readingGroup
);
cylinderBetween(
new THREE.Vector3(-1.65, 2.22, -1.0),
new THREE.Vector3(-1.65, 2.72, -1.0),
0.04,
materials.brass,
readingGroup
);
const readingShade = makeLampShade(
readingSource,
readingTarget,
readingShadeMaterial,
0.22,
0.43,
0.5
);
const readingSpot = new THREE.SpotLight(
0xffbd68,
9,
9,
Math.PI * 0.27,
0.72,
1.25
);
readingSpot.position.copy(readingSource);
readingSpot.castShadow = true;
readingSpot.shadow.mapSize.set(1024, 1024);
readingSpot.shadow.bias = -0.0004;
readingSpot.target.position.copy(readingTarget);
scene.add(readingSpot, readingSpot.target);
const readingPoint = new THREE.PointLight(0xffc078, 2, 4.5, 1.5);
readingPoint.position.copy(readingSource);
scene.add(readingPoint);
const readingBeam = makeBeam(
readingSource,
readingTarget,
1.12,
0xffb45f
);
const readingPool = new THREE.Mesh(
new THREE.CircleGeometry(1.12, 48),
new THREE.MeshBasicMaterial({
color: 0xffb765,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false
})
);
readingPool.rotation.x = -Math.PI / 2;
readingPool.position.set(0.18, 0.05, 0.22);
readingGroup.add(readingPool);
// Craft task lamp.
const craftSource = worldPoint(
craftGroup,
new THREE.Vector3(1.18, 2.67, 0.02)
);
const craftTarget = worldPoint(
craftGroup,
new THREE.Vector3(-0.3, 1.47, 0.38)
);
const craftShadeMaterial = standard(0xdba94d, {
roughness: 0.48,
emissive: 0xffae35,
emissiveIntensity: 1.2
});
mesh(
new THREE.CylinderGeometry(0.21, 0.25, 0.07, 28),
materials.metal,
new THREE.Vector3(1.35, 1.49, -0.18),
craftGroup
);
cylinderBetween(
new THREE.Vector3(1.35, 1.52, -0.18),
new THREE.Vector3(1.35, 2.15, -0.18),
0.032,
materials.brass,
craftGroup
);
cylinderBetween(
new THREE.Vector3(1.35, 2.15, -0.18),
new THREE.Vector3(1.18, 2.67, 0.02),
0.032,
materials.brass,
craftGroup
);
mesh(
new THREE.SphereGeometry(0.075, 16, 12),
materials.metal,
new THREE.Vector3(1.35, 2.15, -0.18),
craftGroup
);
const craftShade = makeLampShade(
craftSource,
craftTarget,
craftShadeMaterial,
0.15,
0.27,
0.43
);
const craftSpot = new THREE.SpotLight(
0xffce82,
170,
7,
Math.PI * 0.27,
0.7,
1.2
);
craftSpot.position.copy(craftSource);
craftSpot.castShadow = true;
craftSpot.shadow.mapSize.set(1024, 1024);
craftSpot.shadow.bias = -0.0004;
craftSpot.target.position.copy(craftTarget);
scene.add(craftSpot, craftSpot.target);
const craftPoint = new THREE.PointLight(0xffbd65, 30, 4, 1.4);
craftPoint.position.copy(craftSource);
scene.add(craftPoint);
const craftBeam = makeBeam(
craftSource,
craftTarget,
0.72,
0xffbd61
);
const craftPool = new THREE.Mesh(
new THREE.CircleGeometry(0.72, 48),
new THREE.MeshBasicMaterial({
color: 0xffc46e,
transparent: true,
opacity: 0,
depthWrite: false,
blending: THREE.AdditiveBlending,
toneMapped: false
})
);
craftPool.rotation.x = -Math.PI / 2;
craftPool.position.set(-0.3, 1.487, 0.38);
craftGroup.add(craftPool);
// -------------------------------------------------------------------------
// Activity rings
// -------------------------------------------------------------------------
function makeActivityRing(radius, group, x, z, color) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.022, 10, 80),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false,
toneMapped: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, 0.07, z);
ring.scale.y = 0.72;
group.add(ring);
return ring;
}
const readingRing = makeActivityRing(
1.68,
readingGroup,
0,
0.05,
0xd9774d
);
const craftRing = makeActivityRing(
2.05,
craftGroup,
0,
0,
0xd49b39
);
// -------------------------------------------------------------------------
// Activity switching
// -------------------------------------------------------------------------
const profiles = {
reading: {
readingSpot: 125,
readingPoint: 24,
readingBeam: 0.105,
readingPool: 0.12,
readingShade: 1.25,
readingGlow: 0.64,
readingRing: 0.68,
craftSpot: 10,
craftPoint: 2,
craftBeam: 0.012,
craftPool: 0.012,
craftShade: 0.06,
craftGlow: 0.08,
craftRing: 0.11
},
craft: {
readingSpot: 9,
readingPoint: 2,
readingBeam: 0.012,
readingPool: 0.012,
readingShade: 0.06,
readingGlow: 0.08,
readingRing: 0.11,
craftSpot: 170,
craftPoint: 30,
craftBeam: 0.13,
craftPool: 0.13,
craftShade: 1.4,
craftGlow: 0.72,
craftRing: 0.72
}
};
let activeMode = "craft";
let currentProfile = { ...profiles.craft };
function setMode(mode, immediate = false) {
activeMode = mode;
const profile = profiles[mode];
modeButtons.forEach((button) => {
const isActive = button.dataset.mode === mode;
button.classList.toggle("active", isActive);
button.setAttribute("aria-pressed", String(isActive));
button.style.setProperty(
"--level",
isActive ? "92%" : mode === "reading" ? "18%" : "12%"
);
});
if (mode === "reading") {
statusText.innerHTML =
"<strong>Reading focus</strong> · Craft workstation remains visible";
} else {
statusText.innerHTML =
"<strong>Craft focus</strong> · Reading nook remains visible";
}
if (immediate) currentProfile = { ...profile };
}
modeButtons.forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
setMode("craft", true);
// -------------------------------------------------------------------------
// Direct camera controls and object selection
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pickRoots = [readingGroup, craftGroup];
let pointerDown = false;
let pointerMoved = false;
let lastX = 0;
let lastY = 0;
let downX = 0;
let downY = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function activityAt(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickRoots, true);
if (!hits.length) return null;
let object = hits[0].object;
while (object) {
if (object.userData.activity) return object.userData.activity;
object = object.parent;
}
return null;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
lastX = downX = event.clientX;
lastY = downY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.hypot(event.clientX - downX, event.clientY - downY) > 5) {
pointerMoved = true;
}
orbit.theta = THREE.MathUtils.clamp(
orbit.theta - dx * 0.005,
-0.72,
0.72
);
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - dy * 0.0045,
0.72,
1.38
);
lastX = event.clientX;
lastY = event.clientY;
applyCamera();
} else {
const activity = activityAt(event);
renderer.domElement.style.cursor = activity ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved) {
const activity = activityAt(event);
if (activity) setMode(activity);
}
pointerDown = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
10.2,
18
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") orbit.theta -= 0.08;
else if (key === "ArrowRight") orbit.theta += 0.08;
else if (key === "ArrowUp") orbit.phi -= 0.06;
else if (key === "ArrowDown") orbit.phi += 0.06;
else if (key === "+" || key === "=") orbit.radius -= 0.5;
else if (key === "-") orbit.radius += 0.5;
else if (key === "1") setMode("reading");
else if (key === "2") setMode("craft");
else return;
orbit.theta = THREE.MathUtils.clamp(orbit.theta, -0.72, 0.72);
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.72, 1.38);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 10.2, 18);
applyCamera();
event.preventDefault();
});
function resetView() {
orbit.radius = 14.2;
orbit.theta = 0.27;
orbit.phi = 1.16;
applyCamera();
}
document.getElementById("resetView").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function damp(current, target, lambda, dt) {
return current + (target - current) * (1 - Math.exp(-lambda * dt));
}
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const profile = profiles[activeMode];
for (const key of Object.keys(currentProfile)) {
currentProfile[key] = damp(
currentProfile[key],
profile[key],
5.2,
dt
);
}
readingSpot.intensity = currentProfile.readingSpot;
readingPoint.intensity = currentProfile.readingPoint;
readingBeam.material.opacity = currentProfile.readingBeam;
readingPool.material.opacity = currentProfile.readingPool;
readingShadeMaterial.emissiveIntensity = currentProfile.readingShade;
readingShade.glow.material.opacity = currentProfile.readingGlow;
readingRing.material.opacity = currentProfile.readingRing;
craftSpot.intensity = currentProfile.craftSpot;
craftPoint.intensity = currentProfile.craftPoint;
craftBeam.material.opacity = currentProfile.craftBeam;
craftPool.material.opacity = currentProfile.craftPool;
craftShadeMaterial.emissiveIntensity = currentProfile.craftShade;
craftShade.glow.material.opacity = currentProfile.craftGlow;
craftRing.material.opacity = currentProfile.craftRing;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
animate();
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```