Prompt specification
Build or customize the Three.js 3D scene "Apartment game night expansion" 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: Apartment game night expansion
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/apartment-game-night-expansion-x0207
Scene Description Prompt:
Animate stylized nesting tables spreading around apartment seating before board-game pieces and cups appear. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (apartment-game-night-expansion-x0207):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nesting Tables — Apartment Scene</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e2d8;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
color: #263b38;
background: rgba(255, 252, 246, 0.82);
border: 1px solid rgba(38, 59, 56, 0.12);
box-shadow: 0 14px 45px rgba(62, 47, 35, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 24px;
left: 24px;
max-width: 330px;
padding: 18px 20px 17px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #b36043;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 34px);
line-height: 1.03;
letter-spacing: -0.045em;
}
#description {
margin: 9px 0 0;
color: rgba(38, 59, 56, 0.68);
font-size: 13px;
line-height: 1.5;
}
#phase {
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 12px 15px;
border-radius: 999px;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.02em;
pointer-events: none;
}
#phase-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #d7835f;
box-shadow: 0 0 0 5px rgba(215, 131, 95, 0.13);
}
#bottom {
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 16px;
width: min(620px, calc(100vw - 32px));
padding: 11px 12px 11px 17px;
border-radius: 18px;
transform: translateX(-50%);
}
#hint {
flex: 1;
min-width: 0;
color: rgba(38, 59, 56, 0.63);
font-size: 12px;
white-space: nowrap;
}
#progress-track {
position: absolute;
right: 14px;
bottom: 5px;
left: 17px;
height: 2px;
overflow: hidden;
border-radius: 10px;
background: rgba(38, 59, 56, 0.09);
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #d7835f, #e0ae59, #4f8c82);
}
button {
position: relative;
z-index: 2;
padding: 10px 14px;
border: 0;
border-radius: 11px;
color: #fffaf1;
background: #294d47;
box-shadow: 0 5px 13px rgba(41, 77, 71, 0.18);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 160ms ease,
background 160ms ease;
}
button:hover {
background: #1f403b;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
@media (max-width: 640px) {
#intro {
top: 14px;
left: 14px;
max-width: calc(100vw - 28px);
padding: 14px 16px;
}
#description {
display: none;
}
#phase {
top: auto;
right: auto;
bottom: 85px;
left: 14px;
}
#bottom {
bottom: 14px;
}
#hint {
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section id="intro" class="panel">
<div class="eyebrow">Apartment vignette</div>
<h1>Nesting tables,<br />unfolded.</h1>
<p id="description">
Watch the tables spread around the seating before the game pieces and
conversation cups arrive.
</p>
</section>
<div id="phase" class="panel">
<span id="phase-dot"></span>
<span id="phase-text">01 · Nested together</span>
</div>
<div id="bottom" class="panel">
<span id="hint">Drag to orbit · Scroll or pinch to zoom</span>
<button id="replay" type="button">Replay</button>
<div id="progress-track"><div id="progress"></div></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 stage = document.querySelector("#stage");
const phaseText = document.querySelector("#phase-text");
const progress = document.querySelector("#progress");
const replayButton = document.querySelector("#replay");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e2d8);
scene.fog = new THREE.Fog(0xe9e2d8, 17, 34);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const palette = {
ink: 0x294d47,
cream: 0xf4ecdc,
wall: 0xe5ded1,
wood: 0x9d6a48,
walnut: 0x80543b,
coral: 0xd68160,
mustard: 0xe3b65d,
teal: 0x4f8c82,
navy: 0x344d63,
coffee: 0x4b2d20
};
function standardMaterial(color, roughness = 0.78, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const materials = {
floor: [
standardMaterial(0xc99970),
standardMaterial(0xd0a177),
standardMaterial(0xc49369)
],
wall: standardMaterial(palette.wall),
trim: standardMaterial(0xf4eee3),
sofa: standardMaterial(0x809b88),
sofaDark: standardMaterial(0x6d8876),
cushion: standardMaterial(0x9eb19f),
rust: standardMaterial(palette.coral),
mustard: standardMaterial(palette.mustard),
teal: standardMaterial(palette.teal),
navy: standardMaterial(palette.navy),
darkWood: standardMaterial(0x4a382c),
cream: standardMaterial(palette.cream),
black: standardMaterial(0x242a28)
};
function addMesh(
geometry,
material,
position = [0, 0, 0],
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedBox(
width,
height,
depth,
radius,
material,
position = [0, 0, 0],
parent = scene
) {
if (radius <= 0) {
return addMesh(
new THREE.BoxGeometry(width, height, depth),
material,
position,
parent
);
}
const r = Math.min(radius, width * 0.49, depth * 0.49);
const x = -width / 2;
const y = -depth / 2;
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + depth - r);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - r,
y + depth
);
shape.lineTo(x + r, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
const bevel = Math.min(0.035, height * 0.2);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: Math.max(0.012, height - bevel * 2),
bevelEnabled: true,
bevelSegments: 3,
bevelSize: bevel,
bevelThickness: bevel,
curveSegments: 7,
steps: 1
});
geometry.center();
geometry.rotateX(-Math.PI / 2);
return addMesh(geometry, material, position, parent);
}
function cylinder(
radiusTop,
radiusBottom,
height,
material,
position = [0, 0, 0],
parent = scene,
radialSegments = 16
) {
return addMesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
material,
position,
parent
);
}
function sphere(
radius,
material,
position = [0, 0, 0],
parent = scene,
widthSegments = 18
) {
return addMesh(
new THREE.SphereGeometry(radius, widthSegments, 12),
material,
position,
parent
);
}
// Lighting
scene.add(new THREE.HemisphereLight(0xfff8ec, 0x8a7668, 2.15));
const keyLight = new THREE.DirectionalLight(0xffefd6, 3.5);
keyLight.position.set(6, 10, -7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xdce8f0, 1.05);
fillLight.position.set(-7, 5, 3);
scene.add(fillLight);
// Background ground and apartment shell
const backgroundMaterial = standardMaterial(0xe9e2d8);
const backgroundGround = addMesh(
new THREE.PlaneGeometry(100, 100),
backgroundMaterial,
[0, -0.29, 0],
scene,
false
);
backgroundGround.rotation.x = -Math.PI / 2;
backgroundGround.receiveShadow = true;
roundedBox(
11.35,
0.24,
8.35,
0.22,
standardMaterial(0xb78359),
[0, -0.16, 0]
);
const plankCount = 11;
const plankWidth = 0.97;
const plankStart = -((plankCount - 1) * (plankWidth + 0.025)) / 2;
for (let i = 0; i < plankCount; i++) {
roundedBox(
plankWidth,
0.032,
8.03,
0.015,
materials.floor[i % materials.floor.length],
[plankStart + i * (plankWidth + 0.025), 0.005, 0]
);
}
roundedBox(
11.2,
4.25,
0.16,
0.04,
materials.wall,
[0, 2.08, 4.18]
);
roundedBox(
0.16,
4.25,
8.25,
0.04,
materials.wall,
[-5.55, 2.08, 0]
);
roundedBox(
11.05,
0.16,
0.12,
0.025,
materials.trim,
[0, 0.1, 4.04]
);
roundedBox(
0.12,
0.16,
8.05,
0.025,
materials.trim,
[-5.4, 0.1, 0]
);
// Rug
roundedBox(
6.55,
0.05,
3.95,
0.34,
standardMaterial(0xd9c6aa),
[0.15, 0.052, 0.48]
);
for (let i = 0; i < 9; i++) {
roundedBox(
0.018,
0.008,
3.55,
0.006,
standardMaterial(0xc5aa88),
[-2.55 + i * 0.68, 0.081, 0.48]
);
}
// Sofa
const sofa = new THREE.Group();
sofa.position.set(0.15, 0, 2.55);
scene.add(sofa);
for (const x of [-2.45, 2.45]) {
for (const z of [-0.55, 0.55]) {
cylinder(
0.075,
0.095,
0.28,
materials.darkWood,
[x, 0.21, z],
sofa
);
}
}
roundedBox(5.85, 0.48, 1.68, 0.2, materials.sofaDark, [0, 0.57, 0], sofa);
roundedBox(5.68, 1.38, 0.38, 0.16, materials.sofa, [0, 1.48, 0.66], sofa);
for (const x of [-2.83, 2.83]) {
roundedBox(
0.42,
1.08,
1.72,
0.18,
materials.sofa,
[x, 1.03, -0.01],
sofa
);
}
for (const x of [-1.78, 0, 1.78]) {
roundedBox(
1.68,
0.28,
1.3,
0.14,
materials.cushion,
[x, 0.92, -0.16],
sofa
);
}
const pillowLeft = roundedBox(
0.76,
0.76,
0.22,
0.17,
materials.mustard,
[-2.05, 1.43, 0.28],
sofa
);
pillowLeft.rotation.z = -0.17;
pillowLeft.rotation.x = -0.1;
const pillowRight = roundedBox(
0.78,
0.72,
0.23,
0.17,
materials.rust,
[2.03, 1.4, 0.28],
sofa
);
pillowRight.rotation.z = 0.15;
pillowRight.rotation.x = -0.08;
// Armchair
const chair = new THREE.Group();
chair.position.set(-4.05, 0, 0.18);
chair.rotation.y = Math.PI / 2;
scene.add(chair);
for (const x of [-0.62, 0.62]) {
for (const z of [-0.5, 0.5]) {
cylinder(
0.06,
0.08,
0.46,
materials.darkWood,
[x, 0.28, z],
chair
);
}
}
roundedBox(1.65, 0.3, 1.5, 0.15, materials.rust, [0, 0.63, 0], chair);
roundedBox(1.7, 1.25, 0.3, 0.15, materials.rust, [0, 1.3, 0.57], chair);
for (const x of [-0.78, 0.78]) {
roundedBox(
0.24,
0.68,
1.4,
0.1,
materials.rust,
[x, 0.94, 0],
chair
);
}
roundedBox(
1.34,
0.18,
1.14,
0.14,
materials.cream,
[0, 0.82, -0.03],
chair
);
// Wall art
function createArtwork(x, colorA, colorB) {
roundedBox(
1.35,
1.55,
0.11,
0.035,
materials.darkWood,
[x, 2.93, 4.03]
);
roundedBox(
1.17,
1.37,
0.035,
0.02,
standardMaterial(0xf0e6d3),
[x, 2.93, 3.955]
);
const artMaterialA = new THREE.MeshStandardMaterial({
color: colorA,
roughness: 0.9,
side: THREE.DoubleSide
});
const artMaterialB = new THREE.MeshStandardMaterial({
color: colorB,
roughness: 0.9,
side: THREE.DoubleSide
});
const shapeA = addMesh(
new THREE.CircleGeometry(0.34, 32),
artMaterialA,
[x - 0.22, 3.08, 3.928]
);
shapeA.rotation.y = Math.PI;
const shapeB = addMesh(
new THREE.CircleGeometry(0.2, 32),
artMaterialB,
[x + 0.28, 2.76, 3.922]
);
shapeB.rotation.y = Math.PI;
roundedBox(
0.15,
0.72,
0.018,
0.01,
artMaterialB,
[x + 0.24, 3.12, 3.92]
);
}
createArtwork(-1.28, palette.coral, palette.teal);
createArtwork(1.32, palette.mustard, palette.navy);
// Shelf and books
roundedBox(
2.05,
0.11,
0.38,
0.025,
materials.darkWood,
[3.67, 2.43, 3.83]
);
const bookColors = [palette.teal, palette.coral, palette.mustard, palette.navy];
for (let i = 0; i < 6; i++) {
const book = roundedBox(
0.11 + (i % 2) * 0.025,
0.48 + (i % 3) * 0.06,
0.25,
0.018,
standardMaterial(bookColors[i % bookColors.length]),
[2.94 + i * 0.17, 2.73, 3.82]
);
book.rotation.z = i === 5 ? -0.12 : 0;
}
// Floor lamp
const lamp = new THREE.Group();
lamp.position.set(-4.55, 0, 3.05);
scene.add(lamp);
cylinder(0.32, 0.38, 0.12, materials.darkWood, [0, 0.1, 0], lamp);
cylinder(0.035, 0.045, 2.45, materials.darkWood, [0, 1.32, 0], lamp);
const lampShade = addMesh(
new THREE.CylinderGeometry(0.3, 0.48, 0.62, 28, 1, true),
standardMaterial(0xe6bd68),
[0, 2.62, 0],
lamp
);
lampShade.castShadow = false;
const lampLight = new THREE.PointLight(0xffc678, 18, 5, 2);
lampLight.position.set(-4.55, 2.48, 3.05);
scene.add(lampLight);
// Plant
const plant = new THREE.Group();
plant.position.set(4.58, 0, 2.95);
scene.add(plant);
cylinder(
0.36,
0.27,
0.56,
standardMaterial(0xb86f50),
[0, 0.31, 0],
plant,
20
);
cylinder(
0.34,
0.34,
0.035,
standardMaterial(0x493d2f),
[0, 0.59, 0],
plant,
20
);
const leafMaterial = standardMaterial(0x557b55);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const radius = 0.25 + (i % 3) * 0.07;
const leaf = sphere(
0.27,
leafMaterial,
[
Math.cos(angle) * radius,
0.94 + (i % 3) * 0.19,
Math.sin(angle) * radius
],
plant
);
leaf.scale.set(0.55, 1.55, 0.25);
leaf.rotation.z = Math.cos(angle) * 0.55;
leaf.rotation.x = Math.sin(angle) * 0.55;
}
// Nesting tables
function createTable(width, depth, height, topMaterial, legMaterial) {
const group = new THREE.Group();
roundedBox(
width,
0.17,
depth,
0.13,
topMaterial,
[0, height - 0.085, 0],
group
);
roundedBox(
width - 0.18,
0.08,
depth - 0.18,
0.07,
legMaterial,
[0, height - 0.2, 0],
group
);
const legHeight = height - 0.24;
for (const x of [-width / 2 + 0.24, width / 2 - 0.24]) {
for (const z of [-depth / 2 + 0.2, depth / 2 - 0.2]) {
cylinder(
0.055,
0.075,
legHeight,
legMaterial,
[x, legHeight / 2 + 0.03, z],
group,
10
);
}
}
roundedBox(
width - 0.58,
0.055,
0.075,
0.02,
legMaterial,
[0, 0.28, -depth / 2 + 0.2],
group
);
roundedBox(
width - 0.58,
0.055,
0.075,
0.02,
legMaterial,
[0, 0.28, depth / 2 - 0.2],
group
);
scene.add(group);
return group;
}
const mainTable = createTable(
3.35,
1.7,
0.88,
materials.darkWood,
materials.teal
);
const coralTable = createTable(
1.58,
1.2,
0.73,
materials.rust,
materials.cream
);
const yellowTable = createTable(
1.3,
1.02,
0.59,
materials.mustard,
materials.navy
);
const tableAnimations = [
{
group: mainTable,
from: new THREE.Vector3(0.22, 0, 0.2),
to: new THREE.Vector3(0.35, 0, 0.12),
rotationFrom: 0,
rotationTo: -0.045,
start: 1.25,
duration: 2.35
},
{
group: coralTable,
from: new THREE.Vector3(0.22, 0, 0.2),
to: new THREE.Vector3(2.82, 0, 1.02),
rotationFrom: 0,
rotationTo: 0.18,
start: 1.72,
duration: 2.3
},
{
group: yellowTable,
from: new THREE.Vector3(0.22, 0, 0.2),
to: new THREE.Vector3(-2.32, 0, 1.2),
rotationFrom: 0,
rotationTo: -0.24,
start: 2.08,
duration: 2.25
}
];
// Board game
const boardRoot = new THREE.Group();
boardRoot.position.set(-0.28, 0.92, 0);
mainTable.add(boardRoot);
roundedBox(
1.38,
0.07,
1.38,
0.11,
materials.darkWood,
[0, 0, 0],
boardRoot
);
const lightTile = standardMaterial(0xe7d8bc);
const darkTile = standardMaterial(0x66877b);
for (let row = 0; row < 5; row++) {
for (let column = 0; column < 5; column++) {
roundedBox(
0.235,
0.022,
0.235,
0.028,
(row + column) % 2 === 0 ? lightTile : darkTile,
[(column - 2) * 0.252, 0.046, (row - 2) * 0.252],
boardRoot
);
}
}
function createPawn(color, style = 0) {
const group = new THREE.Group();
const pawnMaterial = standardMaterial(color, 0.55);
cylinder(
0.078,
0.09,
0.045,
pawnMaterial,
[0, 0.022, 0],
group,
14
);
if (style === 0) {
cylinder(
0.035,
0.055,
0.15,
pawnMaterial,
[0, 0.11, 0],
group,
12
);
sphere(0.063, pawnMaterial, [0, 0.215, 0], group);
} else {
cylinder(
0.058,
0.075,
0.11,
pawnMaterial,
[0, 0.095, 0],
group,
10
);
const top = sphere(
0.07,
pawnMaterial,
[0, 0.18, 0],
group
);
top.scale.set(1, 0.82, 1);
}
return group;
}
const gamePieces = [];
const pieceDefinitions = [
[-0.42, -0.35, palette.coral, 0],
[-0.05, -0.35, palette.navy, 1],
[0.39, -0.19, palette.mustard, 0],
[-0.32, 0.08, palette.teal, 1],
[0.09, 0.13, palette.coral, 0],
[0.4, 0.38, palette.navy, 1]
];
pieceDefinitions.forEach((definition, index) => {
const piece = createPawn(definition[2], definition[3]);
piece.position.set(definition[0], 0.066, definition[1]);
piece.userData.baseY = piece.position.y;
piece.userData.start = 5.25 + index * 0.16;
piece.scale.setScalar(0.001);
boardRoot.add(piece);
gamePieces.push(piece);
});
// Cups
function createCup(color, parent, position) {
const group = new THREE.Group();
group.position.copy(position);
parent.add(group);
const ceramic = standardMaterial(color, 0.36);
const coffee = standardMaterial(palette.coffee, 0.38);
cylinder(
0.235,
0.21,
0.025,
materials.cream,
[0, 0.012, 0],
group,
24
);
cylinder(
0.14,
0.12,
0.32,
ceramic,
[0, 0.18, 0],
group,
24
);
cylinder(
0.117,
0.117,
0.012,
coffee,
[0, 0.339, 0],
group,
24
);
addMesh(
new THREE.TorusGeometry(0.095, 0.025, 10, 24),
ceramic,
[0.145, 0.19, 0],
group
);
const steamMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0,
depthWrite: false
});
const steamCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0, 0.37, 0),
new THREE.Vector3(0.04, 0.49, 0),
new THREE.Vector3(-0.035, 0.62, 0),
new THREE.Vector3(0.025, 0.76, 0)
]);
const steam = addMesh(
new THREE.TubeGeometry(steamCurve, 18, 0.008, 5, false),
steamMaterial,
[0, 0, 0],
group,
false
);
steam.castShadow = false;
group.userData.baseY = position.y;
group.userData.steamMaterial = steamMaterial;
group.scale.setScalar(0.001);
return group;
}
const cups = [
createCup(
0xf4e5cb,
mainTable,
new THREE.Vector3(1.2, 0.88, 0.05)
),
createCup(
palette.teal,
coralTable,
new THREE.Vector3(0.13, 0.73, 0.02)
),
createCup(
palette.coral,
yellowTable,
new THREE.Vector3(-0.12, 0.59, 0.02)
)
];
cups.forEach((cup, index) => {
cup.userData.start = 6.55 + index * 0.27;
});
// Timeline helpers
const clamp01 = (value) => Math.min(1, Math.max(0, value));
const easeInOutCubic = (value) =>
value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
const easeOutCubic = (value) => 1 - Math.pow(1 - value, 3);
const easeOutBack = (value) => {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(value - 1, 3) + c1 * Math.pow(value - 1, 2);
};
let timelineStart = performance.now();
function updateTables(time) {
tableAnimations.forEach((animation) => {
const progressValue = clamp01(
(time - animation.start) / animation.duration
);
const eased = easeInOutCubic(progressValue);
animation.group.position.lerpVectors(
animation.from,
animation.to,
eased
);
animation.group.position.y =
Math.sin(progressValue * Math.PI) * 0.14;
animation.group.rotation.y = THREE.MathUtils.lerp(
animation.rotationFrom,
animation.rotationTo,
eased
) + Math.sin(progressValue * Math.PI) * 0.1;
});
}
function updateBoardAndCups(time) {
const boardProgress = clamp01((time - 4.78) / 0.58);
const boardScale = Math.max(
0.001,
0.72 + 0.28 * easeOutBack(boardProgress)
);
boardRoot.scale.setScalar(boardScale);
gamePieces.forEach((piece) => {
const p = clamp01((time - piece.userData.start) / 0.46);
const eased = easeOutBack(p);
piece.scale.setScalar(Math.max(0.001, eased));
piece.position.y =
piece.userData.baseY + (1 - easeOutCubic(p)) * -0.12;
});
cups.forEach((cup, index) => {
const p = clamp01((time - cup.userData.start) / 0.52);
const eased = easeOutBack(p);
cup.scale.setScalar(Math.max(0.001, eased));
cup.position.y = cup.userData.baseY + (1 - easeOutCubic(p)) * -0.1;
const steamProgress = clamp01(
(time - (cup.userData.start + 0.28)) / 0.45
);
cup.userData.steamMaterial.opacity =
steamProgress * (0.28 + Math.sin(time * 2.2 + index) * 0.07);
});
}
function updatePhase(time) {
let label;
let dotColor;
if (time < 1.25) {
label = "01 · Nested together";
dotColor = "#d7835f";
} else if (time < 4.75) {
label = "02 · Spreading around the room";
dotColor = "#e0ae59";
} else if (time < 6.45) {
label = "03 · Board-game pieces appear";
dotColor = "#4f8c82";
} else {
label = "04 · Cups and conversation";
dotColor = "#344d63";
}
if (phaseText.textContent !== label) {
phaseText.textContent = label;
document.querySelector("#phase-dot").style.background = dotColor;
document.querySelector("#phase-dot").style.boxShadow =
`0 0 0 5px ${dotColor}22`;
}
progress.style.width = `${Math.min(100, (time / 8.6) * 100)}%`;
}
// Direct orbit camera controls
const cameraState = {
theta: 2.48,
phi: 1.04,
radius: 12.9,
target: new THREE.Vector3(0, 1.02, 0.55)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
const pointers = new Map();
let previousPointer = null;
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
previousPointer = {
x: event.clientX,
y: event.clientY
};
if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && previousPointer) {
const deltaX = event.clientX - previousPointer.x;
const deltaY = event.clientY - previousPointer.y;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + deltaY * 0.005,
0.48,
1.36
);
previousPointer = {
x: event.clientX,
y: event.clientY
};
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius *
(previousPinchDistance / Math.max(distance, 1)),
8.2,
17.5
);
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPointer = null;
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8.2,
17.5
);
},
{ passive: false }
);
replayButton.addEventListener("click", () => {
timelineStart = performance.now();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// Render loop
function animate(now) {
requestAnimationFrame(animate);
const time = (now - timelineStart) / 1000;
updateTables(time);
updateBoardAndCups(time);
updatePhase(time);
updateCamera();
renderer.render(scene, camera);
}
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```