Prompt specification
Build or customize the Three.js 3D scene "Bedside comfort arrangement" 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: Bedside comfort arrangement
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bedside-comfort-arrangement-x0071
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Compose a bedside table with tissue box, water glass, book, and dim lamp; a seated character reaches for one tissue without knocking neighboring objects.
Working Three.js Starter (bedside-comfort-arrangement-x0071):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Quiet Reach — A Bedside Scene</title>
<style>
:root {
color-scheme: dark;
--ink: #f5efe6;
--muted: rgba(245, 239, 230, 0.66);
--accent: #f0bc76;
--mint: #9be1d1;
--panel: rgba(20, 25, 31, 0.72);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #15191e;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body { color: var(--ink); }
#app, #scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene.dragging { cursor: grabbing; }
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 55% 48%, transparent 42%, rgba(5, 8, 11, 0.34) 100%),
linear-gradient(180deg, rgba(5, 8, 11, 0.18), transparent 28%, transparent 70%, rgba(5, 8, 11, 0.26));
}
.story {
position: fixed;
top: clamp(22px, 4vw, 48px);
left: clamp(22px, 4vw, 52px);
width: min(350px, calc(100vw - 44px));
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.35);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
color: var(--accent);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 1px;
background: currentColor;
opacity: 0.8;
}
h1 {
margin: 0;
font-size: clamp(36px, 5vw, 66px);
font-weight: 520;
letter-spacing: -0.055em;
line-height: 0.96;
}
.story p {
max-width: 310px;
margin: 17px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.safety {
position: fixed;
top: clamp(22px, 4vw, 48px);
right: clamp(22px, 4vw, 48px);
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 999px;
background: var(--panel);
color: rgba(255, 255, 255, 0.78);
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(14px);
font-size: 11px;
letter-spacing: 0.03em;
pointer-events: none;
}
.safety-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 0 4px rgba(155, 225, 209, 0.12), 0 0 14px rgba(155, 225, 209, 0.5);
}
.controls {
position: fixed;
left: 50%;
bottom: clamp(24px, 5vw, 52px);
transform: translateX(-50%);
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
width: min(92vw, 520px);
}
.status {
min-height: 18px;
color: rgba(255, 255, 255, 0.72);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
text-align: center;
}
#reachButton {
appearance: none;
border: 0;
border-radius: 999px;
padding: 14px 20px 14px 16px;
display: inline-flex;
align-items: center;
gap: 11px;
color: #2b211a;
background: linear-gradient(145deg, #f7d19d, #eeb775);
box-shadow:
0 12px 32px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.62);
font: inherit;
font-size: 13px;
font-weight: 720;
cursor: pointer;
transition: transform 180ms ease, filter 180ms ease, opacity 180ms ease;
}
#reachButton:hover:not(:disabled) {
transform: translateY(-2px);
filter: brightness(1.06);
}
#reachButton:active:not(:disabled) { transform: translateY(0); }
#reachButton:disabled {
cursor: default;
opacity: 0.72;
}
#reachButton svg {
width: 18px;
height: 18px;
flex: 0 0 auto;
}
.hint {
color: rgba(255, 255, 255, 0.42);
font-size: 10px;
letter-spacing: 0.05em;
text-align: center;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #15191e;
color: rgba(255, 255, 255, 0.65);
font-size: 12px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 350ms ease, visibility 350ms ease;
z-index: 20;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
@media (max-width: 640px) {
.story p { display: none; }
.safety { top: auto; bottom: 138px; right: 18px; }
.story { top: 20px; left: 20px; }
h1 { font-size: 42px; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="A stylized bedside table with a seated character reaching carefully for a tissue"></canvas>
<div id="vignette"></div>
<header class="story">
<div class="eyebrow">Bedside · 02:14 AM</div>
<h1>Quiet<br />reach.</h1>
<p>
One tissue, a soft arc, and not a single object disturbed.
Watch the hand rise above the crowded tabletop before it descends.
</p>
</header>
<div class="safety" aria-live="polite">
<span class="safety-dot"></span>
<span id="safetyText">Clearance maintained</span>
</div>
<div class="controls">
<div class="status" id="status" aria-live="polite">Ready to reach</div>
<button id="reachButton" type="button">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M7.2 11.4V7.8a1.45 1.45 0 0 1 2.9 0v2.7-4.2a1.45 1.45 0 0 1 2.9 0v4.2-2.8a1.45 1.45 0 0 1 2.9 0v3.6-1.7a1.45 1.45 0 0 1 2.9 0v4.7c0 4.1-2.4 6.7-6.3 6.7h-.5c-2.2 0-3.6-.8-5-2.4l-3.3-3.9a1.45 1.45 0 0 1 2.2-1.9l1.3 1.1Z"
stroke="currentColor" stroke-width="1.55" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span id="buttonLabel">Reach for a tissue</span>
</button>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
</div>
<div id="loading">Preparing the bedside…</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const reachButton = document.querySelector("#reachButton");
const buttonLabel = document.querySelector("#buttonLabel");
const status = document.querySelector("#status");
const safetyText = document.querySelector("#safetyText");
const loading = document.querySelector("#loading");
const v = (x = 0, y = 0, z = 0) => new THREE.Vector3(x, y, z);
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
const smooth = t => {
t = clamp(t, 0, 1);
return t * t * (3 - 2 * t);
};
// Renderer and scene --------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x171c22);
scene.fog = new THREE.Fog(0x171c22, 10, 22);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
50
);
const cameraTarget = v(0, 1.18, 0);
const cameraState = {
theta: 0.17,
phi: 1.22,
radius: 6.15
};
const cameraHome = { ...cameraState };
function updateCamera() {
const { theta, phi, radius } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Lighting ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xc5d7ef, 0x3d2922, 1.65));
const key = new THREE.DirectionalLight(0xffe3bd, 2.4);
key.position.set(-3.5, 6.5, 4.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 18;
key.shadow.bias = -0.0005;
scene.add(key);
const coolFill = new THREE.DirectionalLight(0x86a9d5, 0.72);
coolFill.position.set(5, 3, -4);
scene.add(coolFill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
...options
});
const mats = {
wall: material(0x29313a),
floor: material(0x26292d),
rug: material(0x41454a),
wood: material(0x8e5a42),
woodDark: material(0x573a32),
drawer: material(0xa06a4c),
brass: material(0xc69755, { metalness: 0.68, roughness: 0.32 }),
tissueBox: material(0xd89e86),
tissueLid: material(0xe8b6a0),
tissue: material(0xfffaf0, {
roughness: 0.95,
side: THREE.DoubleSide
}),
slot: material(0x5a3f3b),
cream: material(0xeee2cd),
pages: material(0xf1e6cc),
teal: material(0x4d8b8d),
blue: material(0x5d86a6),
sweater: material(0xd8a75e),
pants: material(0x536b80),
skin: material(0xdca989, { roughness: 0.86 }),
hair: material(0x3d2c29),
shoe: material(0x302b2b),
blanket: material(0x607d7c),
mattress: material(0xc5b8a8),
frame: material(0x5a4034)
};
// Geometry helpers ---------------------------------------------------
function roundedBox(width, height, depth, radius, mat, parent = scene) {
const bevel = Math.min(radius * 0.24, height * 0.11, depth * 0.11);
const sw = Math.max(0.01, width - bevel * 2);
const sh = Math.max(0.01, height - bevel * 2);
const sd = Math.max(0.01, depth - bevel * 2);
const r = Math.max(0.005, radius - bevel);
const s = new THREE.Shape();
const x = -sw / 2;
const y = -sh / 2;
s.moveTo(x + r, y);
s.lineTo(x + sw - r, y);
s.quadraticCurveTo(x + sw, y, x + sw, y + r);
s.lineTo(x + sw, y + sh - r);
s.quadraticCurveTo(x + sw, y + sh, x + sw - r, y + sh);
s.lineTo(x + r, y + sh);
s.quadraticCurveTo(x, y + sh, x, y + sh - r);
s.lineTo(x, y + r);
s.quadraticCurveTo(x, y, x + r, y);
const geometry = new THREE.ExtrudeGeometry(s, {
depth: sd,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: bevel,
bevelThickness: bevel,
curveSegments: 8
});
geometry.center();
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, height, mat, parent = scene, segments = 24) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, height, segments),
mat
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const up = v(0, 1, 0);
function setSegment(mesh, a, b) {
const direction = b.clone().sub(a);
const length = Math.max(0.0001, direction.length());
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(up, direction.normalize());
mesh.scale.set(1, length, 1);
}
function segmentBetween(a, b, rt, rb, mat, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, 1, 14),
mat
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
setSegment(mesh, a, b);
return mesh;
}
function sphere(radius, mat, parent = scene, segments = 20) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, Math.max(10, segments / 2)),
mat
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Room ---------------------------------------------------------------
const floor = new THREE.Mesh(new THREE.PlaneGeometry(30, 30), mats.floor);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const wall = new THREE.Mesh(new THREE.PlaneGeometry(16, 9), mats.wall);
wall.position.set(0, 4, -3.15);
wall.receiveShadow = true;
scene.add(wall);
const baseboard = roundedBox(15, 0.18, 0.12, 0.03, mats.woodDark);
baseboard.position.set(0, 0.09, -3.06);
const rug = cylinder(2.65, 2.65, 0.035, mats.rug, scene, 64);
rug.position.set(0, 0.018, 0.15);
rug.receiveShadow = true;
// Partial bed at left, establishing the bedside setting.
const mattress = roundedBox(2.25, 0.55, 2.8, 0.17, mats.mattress);
mattress.position.set(-3.0, 0.56, -0.18);
const blanket = roundedBox(2.28, 0.12, 1.65, 0.12, mats.blanket);
blanket.position.set(-3.0, 0.87, 0.3);
const pillow = roundedBox(1.25, 0.22, 0.55, 0.16, mats.cream);
pillow.position.set(-3.03, 0.96, -1.12);
pillow.rotation.y = 0.06;
// Small abstract wall print.
const artFrame = roundedBox(1.02, 1.13, 0.08, 0.06, mats.frame);
artFrame.position.set(-0.65, 2.85, -3.06);
const artCanvas = roundedBox(0.88, 0.99, 0.025, 0.03, material(0xd7c6ac));
artCanvas.position.set(-0.65, 2.85, -3.005);
const sun = new THREE.Mesh(
new THREE.CircleGeometry(0.18, 32),
material(0xd8875d)
);
sun.position.set(-0.51, 3.01, -2.984);
scene.add(sun);
const horizon = roundedBox(0.61, 0.2, 0.018, 0.04, material(0x6e8b83));
horizon.position.set(-0.73, 2.65, -2.982);
// Bedside table ------------------------------------------------------
const tableTop = roundedBox(3.6, 0.22, 1.8, 0.09, mats.wood);
tableTop.position.set(0, 1.2, 0);
const drawer = roundedBox(1.42, 0.28, 0.09, 0.055, mats.drawer);
drawer.position.set(0, 1.015, 0.855);
const knob = sphere(0.065, mats.brass);
knob.position.set(0, 1.015, 0.925);
knob.scale.z = 0.7;
const legPositions = [
[-1.48, -0.64], [1.48, -0.64],
[-1.48, 0.64], [1.48, 0.64]
];
for (const [x, z] of legPositions) {
const leg = roundedBox(0.15, 1.1, 0.15, 0.035, mats.woodDark);
leg.position.set(x, 0.55, z);
}
// Tissue box ---------------------------------------------------------
const tissueBoxGroup = new THREE.Group();
tissueBoxGroup.position.set(-0.28, 1.31, 0.02);
scene.add(tissueBoxGroup);
const tissueBody = roundedBox(
0.82, 0.4, 0.56, 0.075, mats.tissueBox, tissueBoxGroup
);
tissueBody.position.y = 0.2;
const tissueLid = roundedBox(
0.79, 0.055, 0.53, 0.06, mats.tissueLid, tissueBoxGroup
);
tissueLid.position.y = 0.405;
const slot = new THREE.Mesh(
new THREE.CircleGeometry(1, 32),
mats.slot
);
slot.rotation.x = -Math.PI / 2;
slot.scale.set(0.21, 0.064, 1);
slot.position.set(0, 0.435, 0.015);
tissueBoxGroup.add(slot);
const tissueLabel = roundedBox(
0.33, 0.12, 0.012, 0.035, mats.cream, tissueBoxGroup
);
tissueLabel.position.set(0, 0.22, 0.286);
const labelDot = sphere(0.026, mats.tissueBox, tissueBoxGroup, 14);
labelDot.position.set(-0.075, 0.22, 0.296);
labelDot.scale.z = 0.35;
const labelDot2 = sphere(0.026, mats.tissueBox, tissueBoxGroup, 14);
labelDot2.position.set(0.075, 0.22, 0.296);
labelDot2.scale.z = 0.35;
// A single soft, irregular tissue.
const tissueShape = new THREE.Shape();
tissueShape.moveTo(-0.145, 0);
tissueShape.lineTo(0.145, 0);
tissueShape.lineTo(0.15, 0.26);
tissueShape.bezierCurveTo(0.13, 0.33, 0.09, 0.29, 0.075, 0.37);
tissueShape.bezierCurveTo(0.04, 0.43, 0.015, 0.32, -0.015, 0.4);
tissueShape.bezierCurveTo(-0.055, 0.45, -0.07, 0.31, -0.11, 0.36);
tissueShape.bezierCurveTo(-0.14, 0.38, -0.15, 0.29, -0.145, 0.26);
tissueShape.lineTo(-0.145, 0);
const tissueMesh = new THREE.Mesh(
new THREE.ShapeGeometry(tissueShape, 12),
mats.tissue
);
tissueMesh.castShadow = true;
const tissue = new THREE.Group();
tissue.add(tissueMesh);
tissue.position.set(-0.28, 1.735, 0.02);
scene.add(tissue);
// Water glass --------------------------------------------------------
const glassGroup = new THREE.Group();
glassGroup.position.set(-1.16, 1.31, 0.4);
scene.add(glassGroup);
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc7e0e3,
roughness: 0.08,
metalness: 0,
transparent: true,
opacity: 0.36,
transmission: 0.18,
thickness: 0.08,
side: THREE.DoubleSide,
depthWrite: false
});
const glass = cylinder(0.19, 0.16, 0.58, glassMaterial, glassGroup, 32);
glass.position.y = 0.29;
glass.castShadow = false;
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x6fa7b7,
roughness: 0.08,
transparent: true,
opacity: 0.58,
transmission: 0.12,
depthWrite: false
});
const water = cylinder(0.151, 0.145, 0.31, waterMaterial, glassGroup, 32);
water.position.y = 0.155;
water.castShadow = false;
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.014, 8, 32),
glassMaterial
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 0.58;
glassGroup.add(rim);
const glassHighlight = roundedBox(
0.018, 0.26, 0.012, 0.007,
new THREE.MeshBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0.5 }),
glassGroup
);
glassHighlight.position.set(-0.09, 0.34, 0.164);
// Book ---------------------------------------------------------------
const book = new THREE.Group();
book.position.set(0.63, 1.31, 0.37);
book.rotation.y = -0.17;
scene.add(book);
const lowerCover = roundedBox(0.76, 0.04, 0.49, 0.035, mats.blue, book);
lowerCover.position.y = 0.02;
const bookPages = roundedBox(0.7, 0.12, 0.43, 0.018, mats.pages, book);
bookPages.position.y = 0.095;
const upperCover = roundedBox(0.76, 0.04, 0.49, 0.035, mats.teal, book);
upperCover.position.y = 0.17;
const bookTitle = roundedBox(
0.29, 0.018, 0.11, 0.009,
material(0xe4d5ad),
book
);
bookTitle.position.set(0.04, 0.194, 0.03);
const bookmark = roundedBox(0.045, 0.012, 0.29, 0.006, mats.sweater, book);
bookmark.position.set(0.24, 0.196, 0.1);
// Lamp ---------------------------------------------------------------
const lamp = new THREE.Group();
lamp.position.set(1.17, 1.31, -0.43);
scene.add(lamp);
const lampBase = cylinder(0.25, 0.29, 0.09, mats.brass, lamp, 32);
lampBase.position.y = 0.045;
const lampStem = cylinder(0.038, 0.052, 0.92, mats.brass, lamp, 20);
lampStem.position.y = 0.55;
const lampCollar = cylinder(0.09, 0.09, 0.08, mats.brass, lamp, 20);
lampCollar.position.y = 0.98;
const shadeMaterial = material(0xe1ae62, {
roughness: 0.7,
side: THREE.DoubleSide,
emissive: 0x7a3d13,
emissiveIntensity: 0.2
});
const shade = cylinder(0.24, 0.47, 0.48, shadeMaterial, lamp, 36);
shade.position.y = 1.19;
shade.castShadow = false;
const bulb = sphere(0.12, material(0xffd596, {
emissive: 0xffb54f,
emissiveIntensity: 2.2
}), lamp);
bulb.position.y = 1.07;
bulb.castShadow = false;
const lampLight = new THREE.PointLight(0xffb867, 16, 4.5, 2);
lampLight.position.set(1.17, 2.32, -0.43);
lampLight.castShadow = true;
lampLight.shadow.mapSize.set(1024, 1024);
lampLight.shadow.bias = -0.002;
scene.add(lampLight);
// Character ----------------------------------------------------------
const character = new THREE.Group();
character.position.set(0.72, 0, -1.45);
scene.add(character);
// Chair behind the seated character.
const chairSeat = roundedBox(0.82, 0.14, 0.78, 0.09, mats.woodDark, character);
chairSeat.position.set(0, 0.72, -0.05);
const chairBack = roundedBox(0.8, 0.82, 0.12, 0.09, mats.woodDark, character);
chairBack.position.set(0, 1.22, -0.48);
for (const x of [-0.32, 0.32]) {
for (const z of [-0.31, 0.22]) {
const chairLeg = roundedBox(0.075, 0.72, 0.075, 0.018, mats.woodDark, character);
chairLeg.position.set(x, 0.36, z);
}
}
const torsoGroup = new THREE.Group();
character.add(torsoGroup);
const torso = new THREE.Mesh(
new THREE.CapsuleGeometry(0.32, 0.42, 6, 14),
mats.sweater
);
torso.position.set(0, 1.29, 0);
torso.scale.z = 0.77;
torso.castShadow = true;
torso.receiveShadow = true;
torsoGroup.add(torso);
const hips = sphere(0.3, mats.pants, character);
hips.position.set(0, 0.89, 0);
hips.scale.set(1.05, 0.75, 0.86);
// Seated legs.
for (const x of [-0.17, 0.17]) {
segmentBetween(
v(x, 0.88, 0.03),
v(x, 0.78, 0.58),
0.16, 0.13, mats.pants, character
);
segmentBetween(
v(x, 0.78, 0.58),
v(x, 0.21, 0.65),
0.13, 0.105, mats.pants, character
);
const shoe = roundedBox(0.25, 0.16, 0.42, 0.07, mats.shoe, character);
shoe.position.set(x, 0.16, 0.79);
shoe.rotation.x = -0.06;
}
// Head and face, facing generally toward the table.
const head = new THREE.Group();
head.position.set(0, 1.96, 0.01);
head.rotation.y = -0.29;
character.add(head);
const face = sphere(0.335, mats.skin, head, 28);
face.scale.set(0.96, 1.08, 0.94);
const hair = new THREE.Mesh(
new THREE.SphereGeometry(0.35, 28, 16, 0, Math.PI * 2, 0, 1.5),
mats.hair
);
hair.position.y = 0.035;
hair.scale.set(1.02, 1.04, 1.02);
hair.castShadow = true;
head.add(hair);
for (const x of [-0.105, 0.105]) {
const eye = sphere(0.023, material(0x2c2424), head, 12);
eye.position.set(x, 0.025, 0.303);
eye.scale.set(0.8, 1.25, 0.45);
}
const nose = sphere(0.036, mats.skin, head, 12);
nose.position.set(0, -0.045, 0.33);
nose.scale.set(0.75, 0.75, 0.85);
for (const x of [-0.335, 0.335]) {
const ear = sphere(0.06, mats.skin, head, 14);
ear.position.set(x, -0.015, 0);
ear.scale.set(0.55, 1, 0.8);
}
// Resting right arm.
segmentBetween(
v(0.23, 1.67, 0.05),
v(0.39, 1.29, 0.25),
0.125, 0.105, mats.sweater, character
);
segmentBetween(
v(0.39, 1.29, 0.25),
v(0.28, 1.03, 0.43),
0.082, 0.067, mats.skin, character
);
const restingHand = sphere(0.09, mats.skin, character);
restingHand.position.set(0.28, 1.03, 0.43);
// Animated left arm.
const animatedShoulder = v(-0.23, 1.68, 0.06);
const upperArm = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.105, 1, 16),
mats.sweater
);
upperArm.castShadow = true;
upperArm.receiveShadow = true;
character.add(upperArm);
const forearm = new THREE.Mesh(
new THREE.CylinderGeometry(0.083, 0.066, 1, 16),
mats.skin
);
forearm.castShadow = true;
forearm.receiveShadow = true;
character.add(forearm);
const shoulderCap = sphere(0.135, mats.sweater, character);
shoulderCap.position.copy(animatedShoulder);
const elbowJoint = sphere(0.085, mats.skin, character);
const hand = new THREE.Group();
character.add(hand);
const palm = sphere(0.095, mats.skin, hand, 18);
palm.scale.set(0.9, 0.82, 1);
for (const x of [-0.045, 0.045]) {
const finger = sphere(0.029, mats.skin, hand, 12);
finger.position.set(x, -0.025, -0.035);
finger.scale.set(0.8, 1.25, 0.9);
}
const thumb = sphere(0.034, mats.skin, hand, 12);
thumb.position.set(-0.075, -0.015, 0.015);
thumb.scale.set(0.9, 1.2, 0.9);
// Two-bone inverse kinematics gives the arm a natural bent shape.
const upperLength = 0.88;
const lowerLength = 0.86;
function solveArm(target) {
const direction = target.clone().sub(animatedShoulder);
let distance = direction.length();
const maxReach = upperLength + lowerLength - 0.002;
if (distance > maxReach) {
direction.multiplyScalar(maxReach / distance);
distance = maxReach;
}
if (distance < 0.001) distance = 0.001;
const along =
(upperLength * upperLength - lowerLength * lowerLength + distance * distance) /
(2 * distance);
const height = Math.sqrt(Math.max(0, upperLength * upperLength - along * along));
const dir = direction.clone().normalize();
const desiredBend = v(0.65, -1, 0.25);
const bend = desiredBend.addScaledVector(dir, -desiredBend.dot(dir));
if (bend.lengthSq() < 0.001) {
bend.set(1, 0, 0).addScaledVector(dir, -dir.x);
}
if (bend.lengthSq() < 0.001) bend.set(0, 0, 1);
bend.normalize();
const elbow = animatedShoulder
.clone()
.addScaledVector(dir, along)
.addScaledVector(bend, height);
setSegment(upperArm, animatedShoulder, elbow);
setSegment(forearm, elbow, target);
elbowJoint.position.copy(elbow);
hand.position.copy(target);
return elbow;
}
// Motion path. Every transition rises above neighboring objects.
const restHand = v(-0.36, 1.03, 0.12);
const motionFrames = [
{ t: 0.00, p: restHand.clone() },
{ t: 0.80, p: restHand.clone() },
{ t: 1.50, p: v(-0.38, 1.88, 0.15) },
{ t: 2.40, p: v(-0.52, 2.28, 0.47) },
{ t: 3.20, p: v(-0.86, 2.34, 0.92) },
{ t: 3.80, p: v(-1.00, 2.05, 1.23) },
{ t: 4.25, p: v(-1.00, 1.78, 1.47) },
{ t: 5.00, p: v(-0.97, 2.08, 1.43) },
{ t: 5.80, p: v(-0.78, 2.24, 1.03) },
{ t: 6.70, p: v(-0.53, 1.88, 0.51) },
{ t: 7.55, p: restHand.clone() },
{ t: 8.30, p: restHand.clone() }
];
function sampleMotion(time) {
if (time <= motionFrames[0].t) return motionFrames[0].p.clone();
const last = motionFrames[motionFrames.length - 1];
if (time >= last.t) return last.p.clone();
for (let i = 0; i < motionFrames.length - 1; i++) {
const a = motionFrames[i];
const b = motionFrames[i + 1];
if (time >= a.t && time <= b.t) {
const u = smooth((time - a.t) / (b.t - a.t));
return a.p.clone().lerp(b.p, u);
}
}
return restHand.clone();
}
// A faint dashed line reveals the clearance arc during the action.
const routePoints = motionFrames.slice(0, 7).map(frame =>
frame.p.clone().add(character.position)
);
const routeGeometry = new THREE.BufferGeometry().setFromPoints(routePoints);
const routeMaterial = new THREE.LineDashedMaterial({
color: 0x9be1d1,
transparent: true,
opacity: 0,
dashSize: 0.075,
gapSize: 0.06,
depthWrite: false
});
const routeLine = new THREE.Line(routeGeometry, routeMaterial);
routeLine.computeLineDistances();
routeLine.visible = false;
scene.add(routeLine);
const slotPosition = v(-0.28, 1.735, 0.02);
let animationStart = 0;
let animationActive = false;
let tissueHeld = false;
const duration = 8.3;
function setStatus(text, safeText = "Clearance maintained") {
status.textContent = text;
safetyText.textContent = safeText;
}
function beginReach() {
if (animationActive) return;
animationActive = true;
tissueHeld = false;
tissue.position.copy(slotPosition);
tissue.rotation.set(0, 0, 0);
animationStart = performance.now();
reachButton.disabled = true;
buttonLabel.textContent = "Reaching carefully…";
routeLine.visible = true;
setStatus("Lifting above the tabletop");
}
reachButton.addEventListener("click", beginReach);
document.addEventListener("keydown", event => {
if (event.code === "Space" && !event.repeat) {
event.preventDefault();
beginReach();
}
});
// Clicking the tissue box also starts the action.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
canvas.addEventListener("pointerdown", event => {
pointerDown = { x: event.clientX, y: event.clientY };
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointerup", event => {
canvas.classList.remove("dragging");
if (
pointerDown &&
Math.hypot(event.clientX - pointerDown.x, event.clientY - pointerDown.y) < 5
) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
if (raycaster.intersectObject(tissueBody, true).length) beginReach();
}
pointerDown = null;
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
canvas.classList.remove("dragging");
});
// Direct camera controls, implemented without examples or addons.
let orbiting = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointermove", event => {
if (!orbiting) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.68, 1.46);
updateCamera();
});
// The pointerdown listener above is also used for picking, so orbit
// starts only after a small movement threshold.
let orbitCandidate = false;
canvas.addEventListener("pointerdown", event => {
orbitCandidate = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
canvas.addEventListener("pointermove", event => {
if (!orbitCandidate || !pointerDown) return;
if (Math.hypot(event.clientX - pointerDown.x, event.clientY - pointerDown.y) > 3) {
orbiting = true;
}
});
canvas.addEventListener("pointerup", () => {
orbiting = false;
orbitCandidate = false;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * (1 + event.deltaY * 0.001),
4.3,
9.2
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => {
cameraState.theta = cameraHome.theta;
cameraState.phi = cameraHome.phi;
cameraState.radius = cameraHome.radius;
updateCamera();
});
document.addEventListener("keydown", event => {
if (event.key === "ArrowLeft") cameraState.theta -= 0.08;
if (event.key === "ArrowRight") cameraState.theta += 0.08;
if (event.key === "ArrowUp") cameraState.phi = clamp(cameraState.phi - 0.06, 0.68, 1.46);
if (event.key === "ArrowDown") cameraState.phi = clamp(cameraState.phi + 0.06, 0.68, 1.46);
if (event.key === "+" || event.key === "=") cameraState.radius = clamp(cameraState.radius - 0.3, 4.3, 9.2);
if (event.key === "-") cameraState.radius = clamp(cameraState.radius + 0.3, 4.3, 9.2);
updateCamera();
});
function updateTissue(time, handWorld) {
if (!animationActive && !tissueHeld) {
tissue.position.copy(slotPosition);
tissue.rotation.set(0, 0, 0);
return;
}
const heldPosition = handWorld.clone().add(v(0, -0.045, 0));
if (animationActive && time < 4.25) {
tissue.position.copy(slotPosition);
tissue.rotation.z = Math.sin(time * 2.1) * 0.012;
} else if (animationActive && time < 4.75) {
const u = smooth((time - 4.25) / 0.5);
tissue.position.copy(slotPosition).lerp(heldPosition, u);
tissue.rotation.z = lerp(0, -0.16, u);
} else {
tissue.position.copy(heldPosition);
tissue.rotation.z = -0.16;
tissue.rotation.x = Math.sin(time * 3.2) * 0.018;
}
}
const clock = new THREE.Clock();
function animate(now) {
const elapsed = clock.getElapsedTime();
let motionTime = 0;
if (animationActive) {
motionTime = (now - animationStart) / 1000;
if (motionTime < 1.5) {
setStatus("Lifting clear of the tabletop");
} else if (motionTime < 4.25) {
setStatus("Traveling above neighboring objects");
} else if (motionTime < 5.0) {
setStatus("Grasping exactly one tissue");
} else {
setStatus("Returning along the clear route");
}
routeMaterial.opacity = 0.24;
if (motionTime >= duration) {
animationActive = false;
tissueHeld = true;
reachButton.disabled = false;
buttonLabel.textContent = "Reach again";
setStatus("One tissue lifted · nothing disturbed", "All neighboring objects stayed still");
}
}
const handLocal = animationActive
? sampleMotion(motionTime)
: restHand.clone();
solveArm(handLocal);
const handWorld = handLocal.clone().add(character.position);
updateTissue(motionTime, handWorld);
const reachingAmount = animationActive
? smooth(motionTime / 1.5) * (1 - smooth((motionTime - 5.1) / 2.0))
: 0;
torsoGroup.rotation.x = 0.045 * reachingAmount;
head.rotation.y = -0.29 - 0.08 * reachingAmount;
head.rotation.x = -0.025 * reachingAmount;
if (!animationActive) {
routeMaterial.opacity = Math.max(0, routeMaterial.opacity - 0.025);
if (routeMaterial.opacity === 0) routeLine.visible = false;
}
// Gentle breathing and a nearly imperceptible lamp flicker.
torso.scale.y = 1 + Math.sin(elapsed * 1.65) * 0.004;
lampLight.intensity = 16 + Math.sin(elapsed * 7.3) * 0.22 + Math.sin(elapsed * 13.1) * 0.08;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
requestAnimationFrame(() => loading.classList.add("hidden"));
</script>
</body>
</html>
```