Prompt specification
Build or customize the Three.js 3D scene "Small home birthday gathering" 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: Small home birthday gathering
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-home-birthday-gathering-x3847
Scene Description Prompt:
A stylized birthday gathering at home, progressing from decorating and cake preparation to guests arriving and celebrating. Three.js from cdnjs, one HTML file.
Working Three.js Starter (small-home-birthday-gathering-x3847):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>A Small Celebration</title>
<style>
:root {
color-scheme: dark;
--cream: #fff5df;
--muted: rgba(255, 245, 223, 0.68);
--glass: rgba(35, 25, 48, 0.72);
--line: rgba(255, 255, 255, 0.13);
--accent: #ffb86b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #211a2c;
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body {
color: var(--cream);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 48%, rgba(16, 11, 25, 0.32) 100%),
linear-gradient(to bottom, rgba(21, 15, 31, 0.12), transparent 30%);
z-index: 2;
}
.header {
position: fixed;
top: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 46px);
z-index: 5;
max-width: min(430px, calc(100vw - 40px));
pointer-events: none;
text-shadow: 0 2px 22px rgba(20, 12, 28, 0.52);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
border-radius: 4px;
background: currentColor;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 5vw, 58px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.phase-copy {
min-height: 48px;
max-width: 370px;
margin-top: 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.phase-number {
position: fixed;
top: clamp(22px, 4vw, 44px);
right: clamp(20px, 4vw, 46px);
z-index: 5;
display: grid;
width: 52px;
height: 52px;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: rgba(35, 25, 48, 0.42);
backdrop-filter: blur(14px);
color: var(--accent);
font-family: Georgia, serif;
font-size: 20px;
pointer-events: none;
}
.controls {
position: fixed;
right: clamp(16px, 3vw, 34px);
bottom: clamp(16px, 3vw, 28px);
left: clamp(16px, 3vw, 34px);
z-index: 6;
padding: 15px 18px 13px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--glass);
box-shadow: 0 18px 60px rgba(12, 8, 20, 0.28);
backdrop-filter: blur(18px) saturate(125%);
}
.control-row {
display: flex;
align-items: center;
gap: 15px;
}
.play {
flex: 0 0 auto;
display: grid;
width: 42px;
height: 42px;
place-items: center;
border: 0;
border-radius: 50%;
background: var(--cream);
color: #34243f;
font-size: 16px;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease;
}
.play:hover {
transform: scale(1.06);
background: #fff;
}
.timeline-wrap {
flex: 1;
min-width: 0;
}
.timeline-meta {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
display: block;
width: 100%;
height: 4px;
margin: 0;
border-radius: 10px;
appearance: none;
background:
linear-gradient(
to right,
var(--accent) 0%,
var(--accent) var(--progress, 0%),
rgba(255, 255, 255, 0.15) var(--progress, 0%),
rgba(255, 255, 255, 0.15) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 3px solid #fff5df;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 2px 9px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #fff5df;
border-radius: 50%;
background: var(--accent);
}
.chapters {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
margin-top: 12px;
}
.chapter {
position: relative;
padding: 7px 4px 0;
border: 0;
background: transparent;
color: rgba(255, 245, 223, 0.46);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
text-align: left;
cursor: pointer;
transition: color 180ms ease;
}
.chapter::before {
content: "";
position: absolute;
top: -13px;
left: 0;
width: 100%;
height: 2px;
background: transparent;
}
.chapter.active {
color: var(--cream);
}
.chapter.active::before {
background: var(--accent);
}
.hint {
margin-top: 11px;
color: rgba(255, 245, 223, 0.38);
font-size: 10px;
text-align: center;
}
@media (max-width: 620px) {
.header {
top: 20px;
left: 20px;
}
.phase-copy {
max-width: 280px;
font-size: 12px;
}
.phase-number {
top: 18px;
right: 18px;
width: 42px;
height: 42px;
font-size: 17px;
}
.controls {
padding: 13px 14px 11px;
}
.chapter {
font-size: 9px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">A tiny birthday story</div>
<h1>A Small<br />Celebration</h1>
<p id="phaseCopy" class="phase-copy"></p>
</header>
<div id="phaseNumber" class="phase-number">01</div>
<section class="controls" aria-label="Animation controls">
<div class="control-row">
<button id="playButton" class="play" aria-label="Pause animation">Ⅱ</button>
<div class="timeline-wrap">
<div class="timeline-meta">
<span id="timelineLabel">Decorating</span>
<span id="timeLabel">00:00 / 00:24</span>
</div>
<input
id="timeline"
type="range"
min="0"
max="24"
step="0.01"
value="0"
aria-label="Celebration timeline"
/>
</div>
</div>
<nav class="chapters" aria-label="Timeline chapters">
<button class="chapter active" data-time="0">01 · Decorating</button>
<button class="chapter" data-time="5">02 · Cake</button>
<button class="chapter" data-time="10">03 · Arrivals</button>
<button class="chapter" data-time="14">04 · Celebrate</button>
</nav>
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Space to pause</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x282036);
scene.fog = new THREE.Fog(0x282036, 18, 34);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"A stylized birthday celebration inside a small home"
);
document.body.prepend(renderer.domElement);
const DURATION = 24;
const ui = {
play: document.querySelector("#playButton"),
timeline: document.querySelector("#timeline"),
timelineLabel: document.querySelector("#timelineLabel"),
timeLabel: document.querySelector("#timeLabel"),
phaseCopy: document.querySelector("#phaseCopy"),
phaseNumber: document.querySelector("#phaseNumber"),
chapters: [...document.querySelectorAll(".chapter")]
};
let timeline = 0;
let playing = true;
let previousTime = performance.now();
const phaseData = [
{
name: "Decorating",
copy: "Balloons rise, bunting unfolds, and the last touches turn an ordinary room into a party.",
start: 0
},
{
name: "Cake preparation",
copy: "A little mixing, a careful layer, and seven candles ready for the guest of honor.",
start: 5
},
{
name: "The guests arrive",
copy: "The door opens. Friends drift into the warm room and find their places.",
start: 10
},
{
name: "Celebration",
copy: "Candles glow, confetti flies, and everyone dances into the evening.",
start: 14
}
];
function smoothstep(a, b, value) {
const x = THREE.MathUtils.clamp((value - a) / (b - a), 0, 1);
return x * x * (3 - 2 * x);
}
function easeInOut(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function randomGenerator(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = randomGenerator(74219);
function material(color, roughness = 0.78, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const palette = {
wall: material(0xf0d9c3),
wallTrim: material(0x8e5962),
floor: material(0xb98264),
rug: material(0x735b82),
rugInset: material(0xa987aa),
wood: material(0x9b6646),
darkWood: material(0x5a3c39),
cream: material(0xfff1d9),
pink: material(0xe78999),
coral: material(0xe87568),
mint: material(0x78b9aa),
blue: material(0x6989bd),
yellow: material(0xf2bc61),
plum: material(0x6d486b),
skin: material(0xd99b76),
skinDark: material(0x9c6047),
hair: material(0x35252d),
white: material(0xffffff),
metal: material(0xd4c7b6, 0.32, 0.25)
};
function addMesh(
geometry,
mat,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(
w,
h,
d,
mat,
x = 0,
y = 0,
z = 0,
parent = scene
) {
return addMesh(new THREE.BoxGeometry(w, h, d), mat, x, y, z, parent);
}
function cylinder(
rTop,
rBottom,
h,
mat,
x = 0,
y = 0,
z = 0,
segments = 24,
parent = scene
) {
return addMesh(
new THREE.CylinderGeometry(rTop, rBottom, h, segments),
mat,
x,
y,
z,
parent
);
}
function sphere(
radius,
mat,
x = 0,
y = 0,
z = 0,
parent = scene
) {
return addMesh(
new THREE.SphereGeometry(radius, 20, 14),
mat,
x,
y,
z,
parent
);
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xffe7c6, 0x554369, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffddb1, 3.2);
keyLight.position.set(5, 9, 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 = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const coolFill = new THREE.DirectionalLight(0xa9bfff, 1.1);
coolFill.position.set(-5, 5, 1);
scene.add(coolFill);
const partyLight = new THREE.PointLight(0xff9c74, 0, 8, 2);
partyLight.position.set(-0.2, 3.4, 0.3);
scene.add(partyLight);
// -------------------------------------------------------------------------
// Room shell
// -------------------------------------------------------------------------
box(11.2, 0.28, 8.2, palette.floor, 0, -0.16, 0);
// Back wall, with a real opening for the front door.
box(8.6, 5, 0.2, palette.wall, -1.2, 2.5, -4);
box(0.8, 5, 0.2, palette.wall, 5.1, 2.5, -4);
box(1.6, 1.8, 0.2, palette.wall, 3.9, 4.1, -4);
box(0.2, 5, 8, palette.wall, -5.6, 2.5, 0);
box(0.1, 0.18, 8.1, palette.wallTrim, -5.47, 0.15, 0);
box(8.65, 0.18, 0.1, palette.wallTrim, -1.2, 0.15, -3.87);
box(0.9, 0.18, 0.1, palette.wallTrim, 5.05, 0.15, -3.87);
// Rug.
const rug = cylinder(4.35, 4.35, 0.035, palette.rug, -0.1, 0.015, 0.25, 64);
rug.scale.set(1.3, 1, 0.72);
const rugInset = cylinder(3.65, 3.65, 0.042, palette.rugInset, -0.1, 0.023, 0.25, 64);
rugInset.scale.set(1.3, 1, 0.72);
// Window on the left wall.
const windowMat = new THREE.MeshStandardMaterial({
color: 0x9cc7d2,
emissive: 0x547a91,
emissiveIntensity: 0.48,
roughness: 0.5
});
box(0.06, 2.05, 2.5, windowMat, -5.47, 2.75, -0.85);
box(0.12, 2.25, 0.12, palette.cream, -5.39, 2.75, -0.85);
box(0.12, 0.12, 2.65, palette.cream, -5.39, 2.75, -0.85);
box(0.18, 2.35, 0.16, palette.cream, -5.35, 2.75, -2.17);
box(0.18, 2.35, 0.16, palette.cream, -5.35, 2.75, 0.47);
// Door with hinge pivot.
const doorPivot = new THREE.Group();
doorPivot.position.set(3.12, 0, -3.88);
scene.add(doorPivot);
box(1.5, 3.2, 0.13, palette.darkWood, 0.75, 1.6, 0, doorPivot);
box(1.13, 1.18, 0.05, palette.wood, 0.75, 2.08, 0.085, doorPivot);
box(1.13, 0.82, 0.05, palette.wood, 0.75, 0.78, 0.085, doorPivot);
sphere(0.075, palette.metal, 1.32, 1.48, 0.15, doorPivot);
// -------------------------------------------------------------------------
// Kitchen
// -------------------------------------------------------------------------
const kitchen = new THREE.Group();
scene.add(kitchen);
box(3.55, 1.12, 1.1, palette.mint, -3.25, 0.61, -3.2, kitchen);
box(3.72, 0.16, 1.25, palette.cream, -3.25, 1.24, -3.16, kitchen);
// Cabinet doors.
for (let i = 0; i < 3; i++) {
const x = -4.35 + i * 1.1;
box(0.98, 0.84, 0.04, material(0x6ca89d), x, 0.67, -2.62, kitchen);
sphere(0.035, palette.metal, x, 0.88, -2.57, kitchen);
}
box(2.8, 0.88, 0.65, palette.cream, -3.0, 3.25, -3.53, kitchen);
box(1.32, 0.78, 0.05, material(0xe4c9ad), -3.65, 3.25, -3.18, kitchen);
box(1.32, 0.78, 0.05, material(0xe4c9ad), -2.35, 3.25, -3.18, kitchen);
sphere(0.035, palette.metal, -3.27, 3.22, -3.13, kitchen);
sphere(0.035, palette.metal, -2.73, 3.22, -3.13, kitchen);
// Refrigerator.
box(0.92, 2.55, 0.95, palette.cream, -4.78, 1.3, -2.95, kitchen);
box(0.045, 0.85, 0.78, material(0xe7d7c8), -4.3, 1.75, -2.95, kitchen);
box(0.06, 1.38, 0.78, material(0xe7d7c8), -4.3, 0.72, -2.95, kitchen);
box(0.09, 0.42, 0.07, palette.metal, -4.25, 1.95, -2.51, kitchen);
box(0.09, 0.42, 0.07, palette.metal, -4.25, 1.0, -2.51, kitchen);
// Counter ingredients.
const flour = new THREE.Group();
flour.position.set(-4.02, 1.33, -3.04);
kitchen.add(flour);
const flourBag = box(0.48, 0.62, 0.32, palette.cream, 0, 0.31, 0, flour);
flourBag.rotation.z = -0.04;
box(0.29, 0.16, 0.34, material(0xd8b98f), 0, 0.68, 0, flour);
const eggMat = material(0xf3dfbd);
sphere(0.12, eggMat, -3.57, 1.4, -3.05, kitchen);
sphere(0.115, eggMat, -3.31, 1.39, -3.13, kitchen);
sphere(0.12, eggMat, -3.7, 1.39, -2.83, kitchen);
const bowl = new THREE.Group();
bowl.position.set(-2.93, 1.32, -3.05);
kitchen.add(bowl);
const bowlMaterial = material(0xd77878);
bowlMaterial.side = THREE.DoubleSide;
cylinder(0.39, 0.25, 0.26, bowlMaterial, 0, 0.13, 0, 28, bowl);
cylinder(0.33, 0.33, 0.015, material(0x9b5257), 0, 0.18, 0, 28, bowl);
const whisk = new THREE.Group();
whisk.position.set(-2.95, 1.67, -3.03);
whisk.rotation.z = -0.28;
kitchen.add(whisk);
cylinder(0.035, 0.045, 0.45, palette.wood, 0, 0.2, 0, 12, whisk);
for (let i = 0; i < 3; i++) {
const loop = addMesh(
new THREE.TorusGeometry(0.12, 0.015, 7, 20, Math.PI),
palette.metal,
0,
-0.05,
0,
whisk
);
loop.rotation.y = (i * Math.PI) / 3;
}
// -------------------------------------------------------------------------
// Dining and living furniture
// -------------------------------------------------------------------------
const tableX = -0.15;
const tableZ = 0.28;
box(3.15, 0.18, 1.82, palette.wood, tableX, 1.25, tableZ);
box(3.23, 0.08, 1.9, palette.cream, tableX, 1.18, tableZ);
for (const x of [-1.27, 0.97]) {
for (const z of [-0.36, 0.9]) {
box(0.16, 1.14, 0.16, palette.darkWood, x, 0.57, z);
}
}
// Plates and cups.
for (const x of [-1.0, 0.72]) {
cylinder(0.27, 0.3, 0.035, palette.white, x, 1.37, 0.77);
cylinder(0.12, 0.1, 0.25, palette.mint, x + 0.38, 1.48, 0.72);
}
// Sofa.
const sofa = new THREE.Group();
sofa.position.set(3.55, 0, 0.65);
sofa.rotation.y = -0.12;
scene.add(sofa);
box(2.45, 0.48, 1.08, palette.plum, 0, 0.46, 0, sofa);
box(2.45, 0.92, 0.32, palette.plum, 0, 1.02, -0.42, sofa);
box(0.32, 0.82, 1.08, palette.plum, -1.08, 0.87, 0, sofa);
box(0.32, 0.82, 1.08, palette.plum, 1.08, 0.87, 0, sofa);
box(0.8, 0.16, 0.76, material(0x936d91), -0.48, 0.78, 0.05, sofa);
box(0.8, 0.16, 0.76, material(0x936d91), 0.48, 0.78, 0.05, sofa);
// Side table and plant.
cylinder(0.52, 0.52, 0.1, palette.wood, 4.65, 0.82, -1.35);
cylinder(0.07, 0.07, 0.78, palette.darkWood, 4.65, 0.4, -1.35);
cylinder(0.3, 0.23, 0.44, palette.coral, 4.65, 1.09, -1.35);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const leaf = sphere(
0.23,
material(0x5d8b66),
4.65 + Math.cos(angle) * 0.2,
1.55 + Math.sin(i * 1.7) * 0.08,
-1.35 + Math.sin(angle) * 0.2
);
leaf.scale.set(0.65, 1.45, 0.5);
leaf.rotation.z = Math.cos(angle) * 0.45;
}
// -------------------------------------------------------------------------
// Bunting and balloons
// -------------------------------------------------------------------------
const bunting = new THREE.Group();
scene.add(bunting);
const buntingPoints = [];
for (let i = 0; i <= 16; i++) {
const x = -4.95 + (i / 16) * 9.9;
const y = 4.47 - 0.42 * (1 - Math.pow(x / 5, 2));
buntingPoints.push(new THREE.Vector3(x, y, -3.78));
}
const stringCurve = new THREE.CatmullRomCurve3(buntingPoints);
addMesh(
new THREE.TubeGeometry(stringCurve, 80, 0.018, 6, false),
palette.darkWood,
0,
0,
0,
bunting
);
const flagMaterials = [
palette.pink,
palette.yellow,
palette.mint,
palette.blue,
palette.coral
];
const flags = [];
for (let i = 0; i < 14; i++) {
const x = -4.7 + i * 0.72;
const y = 4.47 - 0.42 * (1 - Math.pow(x / 5, 2));
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[-0.29, 0, 0, 0.29, 0, 0, 0, -0.56, 0],
3
)
);
geometry.computeVertexNormals();
const flagMat = flagMaterials[i % flagMaterials.length].clone();
flagMat.side = THREE.DoubleSide;
const flag = addMesh(
geometry,
flagMat,
x,
y,
-3.75,
bunting
);
flag.userData.delay = i * 0.18;
flags.push(flag);
}
const balloonGroups = [];
function createBalloon(x, y, z, color, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
const balloonMat = material(color, 0.42);
const body = sphere(0.48, balloonMat, 0, 0, 0, group);
body.scale.set(0.82, 1.12, 0.82);
const knot = cylinder(
0,
0.09,
0.15,
balloonMat,
0,
-0.56,
0,
10,
group
);
const stringGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -0.62, 0),
new THREE.Vector3(0.08, -1.05, 0.04),
new THREE.Vector3(-0.03, -1.55, 0)
]);
const line = new THREE.Line(
stringGeometry,
new THREE.LineBasicMaterial({ color: 0xf2dfc6, transparent: true, opacity: 0.75 })
);
group.add(line);
group.userData.baseY = y;
group.userData.phase = random() * Math.PI * 2;
group.userData.delay = random() * 1.2;
balloonGroups.push(group);
return group;
}
createBalloon(-4.55, 3.28, -2.9, 0xe87478, 1.05);
createBalloon(-4.0, 3.55, -3.02, 0xf1bc62, 0.88);
createBalloon(-4.8, 2.92, -3.0, 0x759dca, 0.78);
createBalloon(4.55, 3.2, -3.02, 0x79b7a7, 0.95);
createBalloon(4.98, 2.88, -3.05, 0xe98a79, 0.78);
createBalloon(4.2, 3.57, -3.02, 0x8f76ad, 0.8);
// -------------------------------------------------------------------------
// Cake
// -------------------------------------------------------------------------
const cake = new THREE.Group();
cake.position.set(tableX, 0, tableZ);
scene.add(cake);
cylinder(0.91, 0.98, 0.08, palette.white, 0, 1.39, 0, 40, cake);
const cakeBase = 1.43;
const bottomLayer = cylinder(0.78, 0.78, 1, palette.pink, 0, cakeBase, 0, 40, cake);
const middleLayer = cylinder(0.69, 0.69, 1, palette.cream, 0, cakeBase, 0, 40, cake);
const topLayer = cylinder(0.61, 0.61, 1, palette.coral, 0, cakeBase, 0, 40, cake);
const frosting = cylinder(0.64, 0.64, 1, material(0xffdfac), 0, cakeBase, 0, 40, cake);
[bottomLayer, middleLayer, topLayer, frosting].forEach((layer) => {
layer.scale.y = 0.001;
});
const candleGroup = new THREE.Group();
cake.add(candleGroup);
const flames = [];
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const x = Math.cos(angle) * 0.43;
const z = Math.sin(angle) * 0.43;
const candle = cylinder(
0.055,
0.06,
0.34,
i % 2 ? palette.blue : palette.pink,
x,
2.02,
z,
12,
candleGroup
);
const flameMaterial = new THREE.MeshStandardMaterial({
color: 0xffd36b,
emissive: 0xff7a1a,
emissiveIntensity: 3,
roughness: 0.4
});
const flame = sphere(0.075, flameMaterial, x, 2.24, z, candleGroup);
flame.scale.y = 1.55;
flames.push(flame);
}
const cakeLight = new THREE.PointLight(0xffa23c, 0, 4.2, 2);
cakeLight.position.set(tableX, 2.35, tableZ);
scene.add(cakeLight);
// -------------------------------------------------------------------------
// Stylized people
// -------------------------------------------------------------------------
function makePerson({
shirt = palette.coral,
skin = palette.skin,
hair = palette.hair,
scale = 1
} = {}) {
const group = new THREE.Group();
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.25, 0.32, 0.72, shirt, 0, 1.04, 0, 14, group);
sphere(0.275, skin, 0, 1.7, 0, group);
const hairMesh = sphere(0.285, hair, 0, 1.87, -0.025, group);
hairMesh.scale.set(1.04, 0.56, 1.02);
sphere(0.028, palette.white, -0.09, 1.72, 0.252, group);
sphere(0.028, palette.white, 0.09, 1.72, 0.252, group);
sphere(0.016, palette.hair, -0.09, 1.72, 0.274, group);
sphere(0.016, palette.hair, 0.09, 1.72, 0.274, group);
const mouth = addMesh(
new THREE.TorusGeometry(0.055, 0.012, 6, 14, Math.PI),
palette.hair,
0,
1.59,
0.262,
group
);
mouth.rotation.z = Math.PI;
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.33, 1.31, 0);
rightArm.position.set(0.33, 1.31, 0);
group.add(leftArm, rightArm);
cylinder(0.075, 0.085, 0.5, shirt, 0, -0.23, 0, 12, leftArm);
cylinder(0.075, 0.085, 0.5, shirt, 0, -0.23, 0, 12, rightArm);
sphere(0.09, skin, 0, -0.52, 0, leftArm);
sphere(0.09, skin, 0, -0.52, 0, rightArm);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.13, 0.67, 0);
rightLeg.position.set(0.13, 0.67, 0);
group.add(leftLeg, rightLeg);
cylinder(0.09, 0.105, 0.56, palette.darkWood, 0, -0.27, 0, 12, leftLeg);
cylinder(0.09, 0.105, 0.56, palette.darkWood, 0, -0.27, 0, 12, rightLeg);
const leftShoe = sphere(0.13, palette.hair, 0, -0.58, 0.065, leftLeg);
const rightShoe = sphere(0.13, palette.hair, 0, -0.58, 0.065, rightLeg);
leftShoe.scale.set(0.9, 0.55, 1.35);
rightShoe.scale.set(0.9, 0.55, 1.35);
return {
group,
leftArm,
rightArm,
leftLeg,
rightLeg,
head: group.children.find((child) => child.geometry?.type === "SphereGeometry")
};
}
const host = makePerson({
shirt: palette.pink,
skin: palette.skin,
hair: material(0x6a3a2b)
});
const guests = [
makePerson({
shirt: palette.mint,
skin: palette.skinDark,
hair: palette.hair,
scale: 0.98
}),
makePerson({
shirt: palette.blue,
skin: palette.skin,
hair: material(0x342a2a),
scale: 1.04
}),
makePerson({
shirt: palette.yellow,
skin: palette.skinDark,
hair: material(0x251c20),
scale: 0.94
})
];
const guestTargets = [
new THREE.Vector3(-1.35, 0, 1.26),
new THREE.Vector3(1.15, 0, 1.28),
new THREE.Vector3(0.05, 0, -1.08)
];
const guestStarts = [10.05, 10.7, 11.35];
const guestDurations = [2.45, 2.45, 2.45];
// -------------------------------------------------------------------------
// Confetti
// -------------------------------------------------------------------------
const confetti = [];
const confettiMaterials = [
palette.pink,
palette.yellow,
palette.mint,
palette.blue,
palette.cream
];
for (let i = 0; i < 150; i++) {
const mesh = box(
0.055,
0.018,
0.13,
confettiMaterials[i % confettiMaterials.length],
0,
0,
0
);
mesh.visible = false;
confetti.push({
mesh,
originX: tableX + (random() - 0.5) * 2.8,
originZ: tableZ + (random() - 0.5) * 1.7,
velocityX: (random() - 0.5) * 2.9,
velocityY: 1.1 + random() * 2.1,
velocityZ: (random() - 0.5) * 2.7,
offset: random() * 3.7,
duration: 3.2 + random() * 1.2,
rotationX: random() * Math.PI,
rotationY: random() * Math.PI
});
}
// -------------------------------------------------------------------------
// Camera rig and direct controls
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(-1.1, 2.0, -0.6),
yaw: 0.4,
pitch: 0.44,
distance: 12.5,
userYaw: 0,
userPitch: 0,
zoom: 0
};
let dragging = false;
let dragX = 0;
let dragY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
cameraState.userYaw -= dx * 0.006;
cameraState.userPitch = THREE.MathUtils.clamp(
cameraState.userPitch - dy * 0.0035,
-0.42,
0.45
);
dragX = event.clientX;
dragY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.releasePointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("dblclick", () => {
cameraState.userYaw = 0;
cameraState.userPitch = 0;
cameraState.zoom = 0;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom + event.deltaY * 0.006,
-3.2,
5.5
);
},
{ passive: false }
);
function updateCamera(delta) {
let desiredTarget;
let desiredYaw;
let desiredPitch;
let desiredDistance;
if (timeline < 5) {
desiredTarget = new THREE.Vector3(-1.25, 2.0, -0.65);
desiredYaw = 0.38;
desiredPitch = 0.43;
desiredDistance = 12.6;
} else if (timeline < 10) {
desiredTarget = new THREE.Vector3(-2.65, 1.75, -1.55);
desiredYaw = 0.16;
desiredPitch = 0.4;
desiredDistance = 9.6;
} else if (timeline < 14) {
desiredTarget = new THREE.Vector3(1.2, 1.55, -1.0);
desiredYaw = 0.57;
desiredPitch = 0.46;
desiredDistance = 12.1;
} else {
desiredTarget = new THREE.Vector3(-0.15, 1.55, 0.18);
desiredYaw = 0.48;
desiredPitch = 0.49;
desiredDistance = 11.9;
}
const alpha = 1 - Math.exp(-delta * 2.1);
cameraState.target.lerp(desiredTarget, alpha);
cameraState.yaw = THREE.MathUtils.lerp(cameraState.yaw, desiredYaw, alpha);
cameraState.pitch = THREE.MathUtils.lerp(cameraState.pitch, desiredPitch, alpha);
cameraState.distance = THREE.MathUtils.lerp(
cameraState.distance,
desiredDistance,
alpha
);
const yaw = cameraState.yaw + cameraState.userYaw;
const pitch = THREE.MathUtils.clamp(
cameraState.pitch + cameraState.userPitch,
0.16,
0.92
);
const distance = Math.max(6.2, cameraState.distance + cameraState.zoom);
camera.position.set(
cameraState.target.x + Math.sin(yaw) * Math.cos(pitch) * distance,
cameraState.target.y + Math.sin(pitch) * distance,
cameraState.target.z + Math.cos(yaw) * Math.cos(pitch) * distance
);
camera.lookAt(cameraState.target);
}
// -------------------------------------------------------------------------
// Timeline animation
// -------------------------------------------------------------------------
function updateDecorations(t) {
flags.forEach((flag, index) => {
const p = smoothstep(0.15 + flag.userData.delay, 1.25 + flag.userData.delay, t);
flag.scale.y = Math.max(0.001, p);
flag.rotation.z = (1 - p) * 0.28 * (index % 2 ? 1 : -1);
});
balloonGroups.forEach((balloon) => {
const reveal = smoothstep(0.25 + balloon.userData.delay, 2 + balloon.userData.delay, t);
balloon.scale.setScalar(reveal * (1 + Math.sin(t * 1.1 + balloon.userData.phase) * 0.025));
balloon.position.y =
balloon.userData.baseY + Math.sin(t * 1.35 + balloon.userData.phase) * 0.12;
balloon.rotation.z = Math.sin(t * 0.9 + balloon.userData.phase) * 0.05;
});
const open =
smoothstep(9.45, 10.0, t) * (1 - smoothstep(13.6, 14.25, t));
doorPivot.rotation.y = -1.38 * open;
}
function updateCake(t) {
const bottomP = smoothstep(5.25, 6.35, t);
const middleP = smoothstep(6.15, 7.15, t);
const topP = smoothstep(6.95, 7.9, t);
const frostingP = smoothstep(7.75, 8.65, t);
const candleP = smoothstep(8.55, 9.4, t);
bottomLayer.scale.y = Math.max(0.001, bottomP * 0.3);
bottomLayer.position.y = cakeBase + (bottomLayer.scale.y * 0.3) / 2;
middleLayer.scale.y = Math.max(0.001, middleP * 0.25);
middleLayer.position.y = cakeBase + 0.3 + (middleLayer.scale.y * 0.25) / 2;
topLayer.scale.y = Math.max(0.001, topP * 0.21);
topLayer.position.y = cakeBase + 0.55 + (topLayer.scale.y * 0.21) / 2;
frosting.scale.y = Math.max(0.001, frostingP * 0.1);
frosting.position.y = cakeBase + 0.76 + (frosting.scale.y * 0.1) / 2;
candleGroup.visible = candleP > 0.001;
candleGroup.scale.setScalar(Math.max(0.001, candleP));
flames.forEach((flame, index) => {
const flicker = 0.88 + Math.sin(t * 15 + index * 1.8) * 0.13;
flame.scale.y = 1.5 * flicker;
flame.material.emissiveIntensity = 2.6 + flicker;
});
cakeLight.intensity = candleP * (1.6 + Math.sin(t * 10) * 0.35);
}
function setCelebrationPose(person, t, strength = 1) {
const bounce = Math.abs(Math.sin(t * 4.2)) * 0.045 * strength;
person.group.position.y = bounce;
person.leftArm.rotation.z = -1.25 * strength;
person.rightArm.rotation.z = 1.25 * strength;
person.leftArm.rotation.x = -0.22 + Math.sin(t * 5.1) * 0.12;
person.rightArm.rotation.x = -0.22 - Math.sin(t * 5.1) * 0.12;
person.group.rotation.z = Math.sin(t * 2.1) * 0.018 * strength;
}
function updateHost(t) {
host.group.position.y = 0;
host.group.rotation.z = 0;
host.leftArm.rotation.set(0, 0, 0);
host.rightArm.rotation.set(0, 0, 0);
host.leftLeg.rotation.set(0, 0, 0);
host.rightLeg.rotation.set(0, 0, 0);
if (t < 5) {
const p = t / 5;
host.group.position.set(-4.1 + p * 0.55, 0, -1.45);
host.group.rotation.y = -0.25;
host.rightArm.rotation.x = -1.65 + Math.sin(t * 3.2) * 0.18;
host.rightArm.rotation.z = 0.24;
host.leftArm.rotation.x = -0.35;
host.leftLeg.rotation.x = Math.sin(t * 2.2) * 0.06;
host.rightLeg.rotation.x = -Math.sin(t * 2.2) * 0.06;
} else if (t < 10) {
const stir = Math.sin(t * 7.5);
host.group.position.set(-3.0, 0, -1.85);
host.group.rotation.y = Math.PI;
host.leftArm.rotation.x = -0.98 + stir * 0.14;
host.rightArm.rotation.x = -0.98 - stir * 0.14;
host.leftArm.rotation.z = -0.18;
host.rightArm.rotation.z = 0.18;
whisk.position.y = 1.67 + stir * 0.025;
whisk.rotation.z = -0.28 + stir * 0.07;
} else if (t < 13.25) {
const p = easeInOut((t - 10) / 3.25);
host.group.position.set(
THREE.MathUtils.lerp(-3.0, -2.45, p),
0,
THREE.MathUtils.lerp(-1.85, 1.12, p)
);
host.group.rotation.y = Math.PI * (1 - p) + 0.25 * p;
host.leftLeg.rotation.x = Math.sin(t * 7) * 0.45 * (1 - p);
host.rightLeg.rotation.x = -Math.sin(t * 7) * 0.45 * (1 - p);
host.leftArm.rotation.x = -0.25;
host.rightArm.rotation.x = 0.25;
} else {
const amount = smoothstep(13.25, 14.0, t);
host.group.position.set(-2.45, 0, 1.12);
host.group.rotation.y = 0.25;
setCelebrationPose(host, t, amount);
}
}
function quadraticBezier(a, b, c, t) {
const oneMinus = 1 - t;
return new THREE.Vector3()
.addScaledVector(a, oneMinus * oneMinus)
.addScaledVector(b, 2 * oneMinus * t)
.addScaledVector(c, t * t);
}
function updateGuests(t) {
guests.forEach((guest, index) => {
const start = guestStarts[index];
const duration = guestDurations[index];
const raw = THREE.MathUtils.clamp((t - start) / duration, 0, 1);
const visible = t >= start - 0.05;
guest.group.visible = visible;
if (!visible) return;
const p = easeInOut(raw);
const startPoint = new THREE.Vector3(3.92, 0, -4.85);
const controlPoint = new THREE.Vector3(3.3 + index * 0.12, 0, -2.4);
const target = guestTargets[index];
const position = quadraticBezier(startPoint, controlPoint, target, p);
guest.group.position.copy(position);
if (raw < 0.98) {
const lookAhead = quadraticBezier(
startPoint,
controlPoint,
target,
Math.min(1, raw + 0.03)
);
const direction = lookAhead.sub(position);
guest.group.rotation.y = Math.atan2(direction.x, direction.z);
const stride = Math.sin(t * 8 + index);
guest.leftLeg.rotation.x = stride * 0.58;
guest.rightLeg.rotation.x = -stride * 0.58;
guest.leftArm.rotation.x = -stride * 0.38;
guest.rightArm.rotation.x = stride * 0.38;
guest.leftArm.rotation.z = 0;
guest.rightArm.rotation.z = 0;
guest.group.position.y = Math.abs(Math.sin(t * 8 + index)) * 0.025;
guest.group.rotation.z = 0;
} else {
guest.group.position.copy(target);
guest.group.rotation.y = Math.atan2(-target.x, -target.z);
const celebration = smoothstep(13.7 + index * 0.1, 14.4 + index * 0.1, t);
setCelebrationPose(guest, t + index * 0.35, celebration);
}
});
}
function updateConfetti(t) {
const celebrationTime = Math.max(0, t - 14);
confetti.forEach((piece) => {
if (celebrationTime <= 0) {
piece.mesh.visible = false;
return;
}
piece.mesh.visible = true;
const u = ((celebrationTime + piece.offset) % piece.duration) / piece.duration;
piece.mesh.position.set(
piece.originX + piece.velocityX * u,
5.2 + piece.velocityY * u - 5.1 * u * u,
piece.originZ + piece.velocityZ * u
);
piece.mesh.rotation.set(
piece.rotationX + u * 8,
piece.rotationY + u * 11,
u * 6
);
});
}
function updateAtmosphere(t) {
const celebration = smoothstep(14, 15, t);
const pulse = 0.5 + 0.5 * Math.sin(t * 3.1);
partyLight.intensity = celebration * (2 + pulse * 1.4);
hemisphere.intensity = 2.15 + celebration * 0.18;
keyLight.intensity = 3.2 + celebration * 0.25;
}
// -------------------------------------------------------------------------
// UI and playback
// -------------------------------------------------------------------------
function getPhaseIndex(t) {
if (t >= 14) return 3;
if (t >= 10) return 2;
if (t >= 5) return 1;
return 0;
}
let currentPhase = -1;
function updateUI() {
const phaseIndex = getPhaseIndex(timeline);
const phase = phaseData[phaseIndex];
if (phaseIndex !== currentPhase) {
currentPhase = phaseIndex;
ui.phaseCopy.textContent = phase.copy;
ui.phaseNumber.textContent = String(phaseIndex + 1).padStart(2, "0");
ui.timelineLabel.textContent = phase.name;
ui.chapters.forEach((chapter, index) => {
chapter.classList.toggle("active", index === phaseIndex);
});
}
const seconds = Math.floor(timeline);
ui.timeLabel.textContent = `00:${String(seconds).padStart(2, "0")} / 00:24`;
ui.timeline.value = timeline;
ui.timeline.style.setProperty("--progress", `${(timeline / DURATION) * 100}%`);
}
ui.play.addEventListener("click", () => {
if (timeline >= DURATION) timeline = 0;
playing = !playing;
ui.play.textContent = playing ? "Ⅱ" : "▶";
ui.play.setAttribute("aria-label", playing ? "Pause animation" : "Play animation");
});
ui.timeline.addEventListener("input", (event) => {
timeline = Number(event.target.value);
playing = false;
ui.play.textContent = "▶";
ui.play.setAttribute("aria-label", "Play animation");
});
ui.chapters.forEach((chapter) => {
chapter.addEventListener("click", () => {
timeline = Number(chapter.dataset.time);
playing = true;
ui.play.textContent = "Ⅱ";
ui.play.setAttribute("aria-label", "Pause animation");
});
});
addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
ui.play.click();
} else if (event.code === "ArrowRight") {
timeline = Math.min(DURATION, timeline + 0.5);
playing = false;
ui.play.textContent = "▶";
} else if (event.code === "ArrowLeft") {
timeline = Math.max(0, timeline - 0.5);
playing = false;
ui.play.textContent = "▶";
}
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
timeline += delta;
if (timeline >= DURATION) {
timeline = DURATION;
playing = false;
ui.play.textContent = "↻";
ui.play.setAttribute("aria-label", "Replay animation");
}
}
updateDecorations(timeline);
updateCake(timeline);
updateHost(timeline);
updateGuests(timeline);
updateConfetti(timeline);
updateAtmosphere(timeline);
updateCamera(delta);
updateUI();
renderer.render(scene, camera);
}
updateUI();
requestAnimationFrame(animate);
</script>
</body>
</html>
```