Prompt specification
Build or customize the Three.js 3D scene "Surprise-party timing puzzle" 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: Surprise-party timing puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/surprise-party-timing-puzzle-x3848
Scene Description Prompt:
Schedule voxel party helpers so prerequisite tasks, decorations, and table preparation finish before the guest arrives. One HTML scene; Three.js from cdnjs.
Working Three.js Starter (surprise-party-timing-puzzle-x3848):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Party Crew — Voxel Party Planner</title>
<style>
:root {
--ink: #242432;
--muted: #777583;
--paper: #fbfaf6;
--panel: #f6f4ee;
--line: #e5e1d8;
--purple: #705cf5;
--purple-dark: #5643d6;
--green: #2fa477;
--orange: #f29a51;
--red: #e15d5d;
--shadow: 0 18px 50px rgba(45, 39, 71, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
background: var(--paper);
}
button,
select {
font: inherit;
}
button {
cursor: pointer;
}
#app {
height: 100%;
display: grid;
grid-template-rows: 74px minmax(0, 1fr);
}
header {
position: relative;
z-index: 20;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 26px;
background: rgba(255, 255, 255, 0.94);
border-bottom: 1px solid var(--line);
box-shadow: 0 4px 20px rgba(41, 35, 65, 0.04);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 245px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
}
.brand-mark i {
position: absolute;
width: 17px;
height: 17px;
border-radius: 4px;
box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.08);
}
.brand-mark i:nth-child(1) {
left: 1px;
top: 2px;
background: #ff766b;
}
.brand-mark i:nth-child(2) {
right: 1px;
top: 2px;
background: #f6bd45;
}
.brand-mark i:nth-child(3) {
left: 10px;
bottom: 1px;
background: #705cf5;
}
.brand-copy strong {
display: block;
font-size: 15px;
letter-spacing: 0.13em;
}
.brand-copy span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 12px;
}
.event-info {
display: flex;
align-items: center;
gap: 13px;
color: #5f5c69;
font-size: 13px;
}
.event-info b {
color: var(--ink);
}
.event-dot {
width: 4px;
height: 4px;
border-radius: 50%;
background: #b7b2c0;
}
.header-status {
display: flex;
align-items: center;
gap: 9px;
min-width: 220px;
justify-content: flex-end;
padding: 10px 14px;
color: #237a5e;
background: #eaf8f1;
border: 1px solid #cfeddf;
border-radius: 12px;
font-size: 12px;
font-weight: 750;
}
.header-status.warning {
color: #9a5a24;
background: #fff3e6;
border-color: #f3dcc3;
}
.header-status.danger {
color: #a44444;
background: #fff0f0;
border-color: #f1cece;
}
.status-light {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 0 4px rgba(47, 164, 119, 0.12);
}
main {
min-height: 0;
display: grid;
grid-template-columns: 385px minmax(0, 1fr);
}
aside {
position: relative;
z-index: 10;
min-height: 0;
display: flex;
flex-direction: column;
padding: 22px 20px 18px;
background: var(--panel);
border-right: 1px solid var(--line);
overflow: hidden;
}
.plan-heading {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 15px;
margin-bottom: 16px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--purple);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.1;
letter-spacing: -0.04em;
}
.arrival-pill {
flex: 0 0 auto;
padding: 8px 10px;
background: #fff;
border: 1px solid var(--line);
border-radius: 10px;
text-align: right;
}
.arrival-pill span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.arrival-pill strong {
display: block;
margin-top: 2px;
font-size: 12px;
}
.plan-summary {
margin-bottom: 16px;
padding: 14px;
background: #fff;
border: 1px solid var(--line);
border-radius: 15px;
box-shadow: 0 7px 24px rgba(45, 39, 71, 0.04);
}
.summary-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font-size: 11px;
font-weight: 750;
}
.summary-top span:last-child {
color: var(--muted);
font-weight: 650;
}
.progress-track {
height: 7px;
overflow: hidden;
background: #ece9e1;
border-radius: 8px;
}
.progress-fill {
width: 100%;
height: 100%;
background: linear-gradient(90deg, var(--purple), #a78ef9);
border-radius: inherit;
transition: width 180ms ease;
}
.helper-roster {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
margin-bottom: 18px;
}
.helper-card {
min-width: 0;
padding: 10px 9px;
background: #fff;
border: 1px solid var(--line);
border-radius: 13px;
}
.helper-head {
display: flex;
align-items: center;
gap: 7px;
margin-bottom: 7px;
}
.helper-avatar {
position: relative;
flex: 0 0 auto;
width: 25px;
height: 25px;
border-radius: 6px;
background: var(--helper);
box-shadow: inset -4px -4px 0 rgba(0, 0, 0, 0.09);
}
.helper-avatar::before {
content: "";
position: absolute;
left: 5px;
right: 5px;
top: 5px;
height: 6px;
border-radius: 2px 2px 0 0;
background: #f5c7a5;
}
.helper-avatar::after {
content: "";
position: absolute;
left: 7px;
top: 7px;
width: 3px;
height: 3px;
background: #342f3d;
box-shadow: 7px 0 0 #342f3d;
}
.helper-name {
min-width: 0;
font-size: 11px;
font-weight: 850;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.helper-next {
min-height: 23px;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 9px;
}
.section-title h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.02em;
}
.section-title span {
color: var(--muted);
font-size: 10px;
}
.task-list {
min-height: 0;
flex: 1;
overflow-y: auto;
padding: 1px 3px 8px 1px;
scrollbar-width: thin;
scrollbar-color: #d6d1c7 transparent;
}
.task-card {
position: relative;
margin-bottom: 8px;
padding: 11px 11px 10px 13px;
background: #fff;
border: 1px solid var(--line);
border-radius: 13px;
transition: border-color 160ms ease, transform 160ms ease;
}
.task-card::before {
content: "";
position: absolute;
left: 0;
top: 12px;
bottom: 12px;
width: 3px;
border-radius: 0 3px 3px 0;
background: var(--task-color);
}
.task-card.running {
border-color: color-mix(in srgb, var(--task-color) 58%, white);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--task-color) 12%, transparent);
}
.task-card.done {
background: #fbfefc;
}
.task-main {
display: grid;
grid-template-columns: 26px minmax(0, 1fr) auto;
align-items: center;
gap: 9px;
}
.task-icon {
width: 25px;
height: 25px;
display: grid;
place-items: center;
color: var(--task-color);
background: color-mix(in srgb, var(--task-color) 12%, white);
border-radius: 8px;
font-size: 11px;
font-weight: 900;
}
.task-copy {
min-width: 0;
}
.task-copy strong {
display: block;
overflow: hidden;
font-size: 11.5px;
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
}
.task-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.task-meta {
display: flex;
align-items: center;
gap: 7px;
}
.duration {
color: #696573;
font-size: 9px;
white-space: nowrap;
}
.task-select {
position: relative;
}
.task-select select {
width: 61px;
padding: 5px 19px 5px 6px;
color: var(--ink);
background: #f6f4ef;
border: 1px solid #e4e0d7;
border-radius: 7px;
font-size: 9px;
font-weight: 800;
outline: none;
appearance: none;
}
.task-select::after {
content: "▾";
position: absolute;
right: 6px;
top: 3px;
pointer-events: none;
color: #8b8790;
font-size: 9px;
}
.task-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-top: 8px;
padding-left: 35px;
}
.dependency {
color: #8c8793;
font-size: 8.5px;
}
.task-status {
flex: 0 0 auto;
padding: 3px 7px;
color: #77727e;
background: #f2f0eb;
border-radius: 10px;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.task-card.running .task-status {
color: #5d49d5;
background: #eeeaff;
}
.task-card.done .task-status {
color: #287e61;
background: #e5f6ee;
}
.actions {
display: grid;
grid-template-columns: 1fr 1.25fr;
gap: 9px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.action-button {
min-height: 42px;
padding: 0 13px;
border-radius: 11px;
font-size: 11px;
font-weight: 850;
transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.action-button:hover {
transform: translateY(-1px);
}
.action-button.secondary {
color: #4f4b59;
background: #fff;
border: 1px solid #dedad2;
}
.action-button.primary {
color: #fff;
background: var(--purple);
border: 1px solid var(--purple);
box-shadow: 0 8px 18px rgba(112, 92, 245, 0.25);
}
.action-button.primary:hover {
background: var(--purple-dark);
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #e9e5dc;
}
#canvas-wrap,
#scene-labels {
position: absolute;
inset: 0;
}
#canvas-wrap canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#canvas-wrap canvas:active {
cursor: grabbing;
}
#scene-labels {
pointer-events: none;
overflow: hidden;
}
.scene-tag {
position: absolute;
left: 0;
top: 0;
display: flex;
align-items: center;
gap: 5px;
padding: 4px 7px;
color: #514d59;
background: rgba(255, 255, 255, 0.87);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 7px;
box-shadow: 0 4px 12px rgba(42, 36, 62, 0.08);
font-size: 7px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(5px);
}
.scene-tag i {
width: 6px;
height: 6px;
border-radius: 2px;
background: var(--tag);
}
.scene-tools {
position: absolute;
z-index: 5;
top: 17px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.scene-title {
padding: 10px 13px;
background: rgba(255, 255, 255, 0.82);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 12px;
box-shadow: 0 8px 24px rgba(42, 36, 62, 0.07);
backdrop-filter: blur(8px);
}
.scene-title span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.scene-title strong {
display: block;
margin-top: 2px;
font-size: 12px;
}
.camera-help {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 11px;
color: #65616d;
background: rgba(255, 255, 255, 0.76);
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 10px;
font-size: 9px;
pointer-events: auto;
backdrop-filter: blur(8px);
}
.camera-help button {
padding: 4px 7px;
color: #514d5b;
background: #fff;
border: 1px solid #dfdbd2;
border-radius: 6px;
font-size: 9px;
font-weight: 800;
}
.timeline-panel {
position: absolute;
z-index: 7;
left: 18px;
right: 18px;
bottom: 17px;
padding: 13px 15px 12px;
background: rgba(255, 255, 255, 0.9);
border: 1px solid rgba(255, 255, 255, 0.95);
border-radius: 15px;
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.timeline-title {
display: flex;
align-items: center;
gap: 9px;
}
.timeline-title strong {
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.clock-pill {
padding: 4px 8px;
color: var(--purple-dark);
background: #eeeaff;
border-radius: 7px;
font-size: 9px;
font-weight: 900;
}
.timeline-note {
color: var(--muted);
font-size: 8.5px;
}
.timeline-grid {
display: grid;
grid-template-columns: 58px minmax(0, 1fr);
gap: 6px 8px;
align-items: center;
}
.lane-label {
display: flex;
align-items: center;
gap: 6px;
font-size: 9px;
font-weight: 850;
}
.lane-label i {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--helper);
}
.lane {
position: relative;
height: 20px;
background-image: linear-gradient(to right, #e9e6df 1px, transparent 1px);
background-size: 20% 100%;
border-radius: 5px;
}
.timeline-bar {
position: absolute;
top: 3px;
height: 14px;
min-width: 8px;
padding: 0 5px;
overflow: hidden;
color: #fff;
background: var(--bar);
border-radius: 4px;
font-size: 7px;
font-weight: 850;
line-height: 14px;
text-overflow: ellipsis;
white-space: nowrap;
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.08);
}
.arrival-line {
position: absolute;
z-index: 4;
top: -4px;
bottom: -4px;
left: 100%;
width: 1px;
background: #e15d5d;
}
.arrival-line::before {
content: "GUEST";
position: absolute;
top: -13px;
left: 50%;
padding: 1px 4px;
color: #fff;
background: #e15d5d;
border-radius: 3px;
font-size: 6px;
font-weight: 900;
transform: translateX(-50%);
}
.time-axis {
grid-column: 2;
display: flex;
justify-content: space-between;
padding-top: 2px;
color: #98939f;
font-size: 7px;
}
#now-line {
position: absolute;
z-index: 5;
top: -6px;
bottom: -4px;
width: 2px;
background: var(--purple);
pointer-events: none;
transition: left 100ms linear;
}
#now-line::before {
content: "";
position: absolute;
top: -3px;
left: 50%;
width: 7px;
height: 7px;
background: var(--purple);
border: 2px solid #fff;
border-radius: 50%;
transform: translateX(-50%);
box-shadow: 0 2px 7px rgba(73, 57, 190, 0.28);
}
#toast {
position: fixed;
z-index: 50;
left: 50%;
bottom: 27px;
padding: 11px 15px;
color: #fff;
background: rgba(36, 36, 50, 0.93);
border-radius: 10px;
box-shadow: 0 12px 30px rgba(20, 18, 30, 0.2);
font-size: 11px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 10px);
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 1000px) {
main {
grid-template-columns: 340px minmax(0, 1fr);
}
aside {
padding-left: 15px;
padding-right: 15px;
}
.event-info {
display: none;
}
.helper-card {
padding: 8px 6px;
}
.helper-head {
gap: 5px;
}
.helper-avatar {
width: 21px;
height: 21px;
}
}
@media (max-width: 760px) {
html,
body {
height: auto;
overflow: auto;
}
#app {
min-height: 100%;
grid-template-rows: 68px auto;
}
header {
padding: 0 15px;
}
.brand {
min-width: 0;
}
.header-status {
min-width: 0;
padding: 9px;
}
.header-status span:last-child {
display: none;
}
main {
display: flex;
flex-direction: column;
}
aside {
max-height: none;
overflow: visible;
}
.task-list {
max-height: 420px;
}
#stage {
min-height: 680px;
}
.camera-help {
display: none;
}
.timeline-note {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i></div>
<div class="brand-copy">
<strong>PARTY CREW</strong>
<span>Voxel planning studio</span>
</div>
</div>
<div class="event-info">
<span><b>Saturday, June 22</b></span>
<i class="event-dot"></i>
<span>Garden room</span>
<i class="event-dot"></i>
<span>6 tasks · 3 helpers</span>
</div>
<div class="header-status" id="header-status">
<i class="status-light"></i>
<span id="header-status-text">Everything is guest-ready</span>
</div>
</header>
<main>
<aside>
<div class="plan-heading">
<div>
<p class="eyebrow">Prep plan</p>
<h1>Ready for a guest!</h1>
</div>
<div class="arrival-pill">
<span>Guest arrives</span>
<strong>5:00 PM</strong>
</div>
</div>
<div class="plan-summary">
<div class="summary-top">
<span id="summary-label">6 of 6 tasks complete</span>
<span id="summary-detail">Ready 15 min early</span>
</div>
<div class="progress-track"><div class="progress-fill" id="progress-fill"></div></div>
</div>
<div class="helper-roster" id="helper-roster"></div>
<div class="section-title">
<h2>Preparation checklist</h2>
<span>Assign a helper</span>
</div>
<div class="task-list" id="task-list"></div>
<div class="actions">
<button class="action-button secondary" id="auto-button">Auto-schedule</button>
<button class="action-button primary" id="play-button">▶ Run rehearsal</button>
</div>
</aside>
<section id="stage" aria-label="Interactive 3D party preparation scene">
<div id="canvas-wrap"></div>
<div id="scene-labels"></div>
<div class="scene-tools">
<div class="scene-title">
<span>Live room preview</span>
<strong>The garden party room</strong>
</div>
<div class="camera-help">
Drag to orbit · Scroll to zoom
<button id="reset-camera" type="button">Reset view</button>
</div>
</div>
<div class="timeline-panel">
<div class="timeline-head">
<div class="timeline-title">
<strong>Team timeline</strong>
<span class="clock-pill" id="clock-pill">5:00 PM</span>
</div>
<div class="timeline-note">Tasks begin at 4:00 PM · All work respects prerequisite order</div>
</div>
<div class="timeline-grid" id="timeline-grid">
<div class="arrival-line"></div>
<div id="now-line"></div>
</div>
</div>
</section>
</main>
</div>
<div id="toast"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const TASKS = [
{
id: "supplies",
title: "Check party supplies",
short: "Supplies",
duration: 10,
deps: [],
color: "#4f8df7",
station: [-4.45, 0, 1.55]
},
{
id: "punch",
title: "Mix the punch",
short: "Punch",
duration: 15,
deps: ["supplies"],
color: "#ff766b",
station: [-4.25, 0, -1.55]
},
{
id: "lights",
title: "Test string lights",
short: "Lights",
duration: 8,
deps: [],
color: "#f6bd45",
station: [2.75, 0, -2.75]
},
{
id: "decorations",
title: "Hang decorations",
short: "Decor",
duration: 12,
deps: ["lights"],
color: "#9b72e8",
station: [3.45, 0, -0.75]
},
{
id: "napkins",
title: "Fold colorful napkins",
short: "Napkins",
duration: 12,
deps: [],
color: "#45b6a4",
station: [-1.2, 0, 2.15]
},
{
id: "table",
title: "Set the party table",
short: "Set table",
duration: 18,
deps: ["punch", "decorations", "napkins"],
color: "#ff9f58",
station: [0.65, 0, 0.45]
}
];
const HELPERS = {
Pip: { name: "Pip", color: "#4f8df7", standby: [-3.35, 0, 2.85] },
Ada: { name: "Ada", color: "#ef7065", standby: [-0.2, 0, 3.0] },
Max: { name: "Max", color: "#efb83f", standby: [4.15, 0, 2.8] }
};
const state = {
assignments: {
supplies: "Pip",
punch: "Ada",
lights: "Max",
decorations: "Pip",
napkins: "Ada",
table: "Max"
},
schedule: {},
currentTime: 60,
playing: false,
speed: 2.5
};
const taskMap = Object.fromEntries(TASKS.map(task => [task.id, task]));
const taskList = document.getElementById("task-list");
const helperRoster = document.getElementById("helper-roster");
const timelineGrid = document.getElementById("timeline-grid");
const nowLine = document.getElementById("now-line");
const clockPill = document.getElementById("clock-pill");
const progressFill = document.getElementById("progress-fill");
const summaryLabel = document.getElementById("summary-label");
const summaryDetail = document.getElementById("summary-detail");
const headerStatus = document.getElementById("header-status");
const headerStatusText = document.getElementById("header-status-text");
const playButton = document.getElementById("play-button");
const autoButton = document.getElementById("auto-button");
const toast = document.getElementById("toast");
function formatTime(minutes) {
const total = 16 * 60 + Math.max(0, minutes);
const hour = Math.floor(total / 60);
const minute = Math.floor(total % 60);
const suffix = hour >= 12 ? "PM" : "AM";
const displayHour = hour > 12 ? hour - 12 : hour;
return `${displayHour}:${String(minute).padStart(2, "0")} ${suffix}`;
}
function buildSchedule() {
const result = {};
const availability = { Pip: 0, Ada: 0, Max: 0 };
const remaining = new Set(TASKS.map(task => task.id));
while (remaining.size) {
let progressed = false;
for (const task of TASKS) {
if (!remaining.has(task.id)) continue;
if (!task.deps.every(dep => result[dep])) continue;
const helper = state.assignments[task.id];
const dependencyEnd = task.deps.length
? Math.max(...task.deps.map(dep => result[dep].end))
: 0;
const start = Math.max(dependencyEnd, availability[helper]);
const end = start + task.duration;
result[task.id] = { start, end, helper };
availability[helper] = end;
remaining.delete(task.id);
progressed = true;
break;
}
if (!progressed) break;
}
state.schedule = result;
}
function renderHelpers() {
helperRoster.innerHTML = Object.values(HELPERS).map(helper => `
<div class="helper-card">
<div class="helper-head">
<span class="helper-avatar" style="--helper:${helper.color}"></span>
<span class="helper-name">${helper.name}</span>
</div>
<div class="helper-next" data-helper-next="${helper.name}">All done</div>
</div>
`).join("");
}
function renderTasks() {
taskList.innerHTML = TASKS.map((task, index) => {
const dependencyText = task.deps.length
? `After ${task.deps.map(dep => taskMap[dep].short).join(" + ")}`
: "Ready to start";
return `
<article class="task-card" data-task="${task.id}" style="--task-color:${task.color}">
<div class="task-main">
<div class="task-icon">${String(index + 1).padStart(2, "0")}</div>
<div class="task-copy">
<strong>${task.title}</strong>
<span>${dependencyText}</span>
</div>
<div class="task-meta">
<span class="duration">${task.duration} min</span>
<label class="task-select">
<select data-assign="${task.id}" aria-label="Assign ${task.title}">
${Object.values(HELPERS).map(helper => `
<option value="${helper.name}" ${state.assignments[task.id] === helper.name ? "selected" : ""}>
${helper.name}
</option>
`).join("")}
</select>
</label>
</div>
</div>
<div class="task-bottom">
<span class="dependency" data-task-time>—</span>
<span class="task-status" data-task-status>Queued</span>
</div>
</article>
`;
}).join("");
taskList.querySelectorAll("[data-assign]").forEach(select => {
select.addEventListener("change", event => {
const taskId = event.target.dataset.assign;
state.assignments[taskId] = event.target.value;
buildSchedule();
state.currentTime = 0;
state.playing = false;
renderTimeline();
updateUI();
showToast(`${taskMap[taskId].title} reassigned to ${event.target.value}.`);
});
});
}
function renderTimeline() {
timelineGrid.querySelectorAll(".timeline-lane, .lane, .time-axis").forEach(element => element.remove());
Object.values(HELPERS).forEach(helper => {
const label = document.createElement("div");
label.className = "timeline-lane";
label.innerHTML = `<div class="lane-label" style="--helper:${helper.color}"><i></i>${helper.name}</div>`;
const lane = document.createElement("div");
lane.className = "lane";
TASKS.filter(task => state.schedule[task.id]?.helper === helper.name).forEach(task => {
const slot = state.schedule[task.id];
const bar = document.createElement("div");
bar.className = "timeline-bar";
bar.style.left = `${(slot.start / 60) * 100}%`;
bar.style.width = `${(task.duration / 60) * 100}%`;
bar.style.setProperty("--bar", helper.color);
bar.textContent = task.short;
bar.title = `${task.title}: ${formatTime(slot.start)}–${formatTime(slot.end)}`;
lane.appendChild(bar);
});
const arrival = document.createElement("div");
arrival.className = "arrival-line";
lane.appendChild(arrival);
timelineGrid.appendChild(label);
timelineGrid.appendChild(lane);
});
const axis = document.createElement("div");
axis.className = "time-axis";
axis.innerHTML = ["4:00", "4:12", "4:24", "4:36", "4:48", "5:00"]
.map(time => `<span>${time}</span>`)
.join("");
timelineGrid.appendChild(axis);
}
function updateUI() {
const time = state.currentTime;
const completed = TASKS.filter(task => time >= state.schedule[task.id].end);
const running = TASKS.find(task => {
const slot = state.schedule[task.id];
return time >= slot.start && time < slot.end;
});
progressFill.style.width = `${(completed.length / TASKS.length) * 100}%`;
summaryLabel.textContent = `${completed.length} of ${TASKS.length} tasks complete`;
clockPill.textContent = formatTime(time);
const finish = Math.max(...TASKS.map(task => state.schedule[task.id].end));
summaryDetail.textContent = time < 60
? `Finish at ${formatTime(finish)}`
: (completed.length === TASKS.length ? (`Ready ${60 - finish} min early`) : "Prep overdue");
TASKS.forEach(task => {
const card = taskList.querySelector(`[data-task="${task.id}"]`);
const slot = state.schedule[task.id];
const badge = card.querySelector("[data-task-status]");
const timeLabel = card.querySelector("[data-task-time]");
card.classList.toggle("done", time >= slot.end);
card.classList.toggle("running", time >= slot.start && time < slot.end);
badge.textContent = time >= slot.end ? "Done" : time >= slot.start ? "Working" : "Queued";
timeLabel.textContent = `${formatTime(slot.start)} – ${formatTime(slot.end)} · ${slot.helper}`;
});
Object.values(HELPERS).forEach(helper => {
const target = helperRoster.querySelector(`[data-helper-next="${helper.name}"]`);
const tasks = TASKS.filter(task => state.schedule[task.id].helper === helper.name)
.sort((a, b) => state.schedule[a.id].start - state.schedule[b.id].start);
const active = tasks.find(task => {
const slot = state.schedule[task.id];
return time >= slot.start && time < slot.end;
});
const next = tasks.find(task => state.schedule[task.id].start > time);
target.textContent = active
? `Now: ${active.short}`
: next
? `Next: ${next.short}`
: "All done";
});
headerStatus.classList.remove("warning", "danger");
if (time >= 60 && completed.length === TASKS.length) {
headerStatusText.textContent = "Guest arrived — everything is ready";
} else if (time >= 60) {
headerStatusText.textContent = "Guest arrived — prep is overdue";
headerStatus.classList.add("danger");
} else if (state.playing) {
headerStatusText.textContent = `Prep in progress · ${TASKS.length - completed.length} tasks left`;
headerStatus.classList.add("warning");
} else {
headerStatusText.textContent = `${completed.length} of ${TASKS.length} prep tasks complete`;
headerStatus.classList.add("warning");
}
playButton.textContent = state.playing
? "Ⅱ Pause rehearsal"
: time >= 60
? "▶ Run rehearsal"
: "▶ Resume plan";
nowLine.style.left = `${Math.min(100, (time / 60) * 100)}%`;
}
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2400);
}
renderHelpers();
renderTasks();
buildSchedule();
renderTimeline();
updateUI();
playButton.addEventListener("click", () => {
if (state.playing) {
state.playing = false;
} else {
if (state.currentTime >= 60) state.currentTime = 0;
state.playing = true;
}
updateUI();
});
autoButton.addEventListener("click", () => {
buildSchedule();
renderTimeline();
state.currentTime = 0;
state.playing = true;
updateUI();
const finish = Math.max(...TASKS.map(task => state.schedule[task.id].end));
showToast(finish <= 60
? `Schedule rebuilt — ready by ${formatTime(finish)}.`
: `Schedule rebuilt, but prep finishes at ${formatTime(finish)}.`);
});
// ---------- Three.js scene ----------
const stage = document.getElementById("stage");
const canvasWrap = document.getElementById("canvas-wrap");
const sceneLabels = document.getElementById("scene-labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e9e5dc");
scene.fog = new THREE.Fog("#e9e5dc", 23, 40);
const camera = new THREE.PerspectiveCamera(35, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
canvasWrap.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight("#fffaf0", "#8b8175", 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff4df", 3.1);
sun.position.set(7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rim = new THREE.DirectionalLight("#c9c2ff", 1.1);
rim.position.set(-8, 6, -8);
scene.add(rim);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.02
}));
}
return materialCache.get(color);
}
function box(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(...size);
const mesh = new THREE.Mesh(geometry, options.material || material(color));
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) mesh.rotation.set(...options.rotation);
if (options.name) mesh.name = options.name;
parent.add(mesh);
return mesh;
}
const room = new THREE.Group();
scene.add(room);
// Floor tiles
const floorColors = ["#d7d2bd", "#ddd8c5", "#d2cdb8"];
for (let x = -6; x <= 5; x++) {
for (let z = -4; z <= 3; z++) {
const color = floorColors[(x + z + 20) % floorColors.length];
box(room, [0.98, 0.28, 0.98], [x + 0.5, -0.16, z + 0.5], color);
}
}
// Back and left walls, with a chunky voxel trim
box(room, [12.4, 4.8, 0.25], [0, 2.25, -4.15], "#f0eadc");
box(room, [0.25, 4.8, 8.4], [-6.15, 2.25, 0], "#e8e0d2");
box(room, [12.2, 0.18, 0.32], [0, 0.28, -4.02], "#c9bca7");
box(room, [0.32, 0.18, 8.2], [-6.02, 0.28, 0], "#c9bca7");
box(room, [12.2, 0.15, 0.3], [0, 4.42, -4.02], "#d8c7ad");
box(room, [0.3, 0.15, 8.2], [-6.02, 4.42, 0], "#d8c7ad");
// Back-wall decorative panels
for (let x = -5; x <= 5; x += 2) {
box(room, [1.35, 1.8, 0.08], [x, 2.55, -3.99], x % 4 === 0 ? "#e6d8c4" : "#eee6d7");
}
// Window on the back wall
box(room, [2.55, 2.0, 0.12], [-2.7, 2.65, -3.94], "#7b9ca2", { castShadow: false });
box(room, [2.25, 1.7, 0.08], [-2.7, 2.65, -3.86], "#a9d3d4", { castShadow: false });
box(room, [0.11, 1.8, 0.12], [-2.7, 2.65, -3.78], "#f7f0e5");
box(room, [2.3, 0.11, 0.12], [-2.7, 2.65, -3.77], "#f7f0e5");
// Main party table
const tableGroup = new THREE.Group();
scene.add(tableGroup);
box(tableGroup, [3.35, 0.24, 1.75], [0, 1.08, 0], "#a66f42");
for (const x of [-1.35, 1.35]) {
for (const z of [-0.58, 0.58]) {
box(tableGroup, [0.2, 1.1, 0.2], [x, 0.52, z], "#70452e");
}
}
box(tableGroup, [2.8, 0.15, 0.15], [0, 0.42, 0], "#70452e");
// Cloth and runner appear when napkins are complete
const tableCloth = new THREE.Group();
scene.add(tableCloth);
box(tableCloth, [3.5, 0.07, 1.9], [0, 1.23, 0], "#fff7e8");
box(tableCloth, [0.62, 0.035, 1.94], [0, 1.275, 0], "#ef7065");
// Tableware appears after the table task
const tableware = new THREE.Group();
scene.add(tableware);
const plateColors = ["#ffffff", "#fff6e7", "#ffffff", "#fff6e7"];
[-1.05, -0.35, 0.35, 1.05].forEach((x, index) => {
box(tableware, [0.48, 0.06, 0.48], [x, 1.3, 0.06], plateColors[index]);
box(tableware, [0.25, 0.08, 0.25], [x, 1.35, 0.06], index % 2 ? "#f6bd45" : "#9b72e8");
box(tableware, [0.18, 0.42, 0.18], [x + 0.28, 1.48, -0.5], "#6fc4c0");
});
box(tableware, [0.7, 0.65, 0.7], [0, 1.55, -0.45], "#ffffff");
box(tableware, [0.82, 0.12, 0.82], [0, 1.91, -0.45], "#ff766b");
// Supply station
const suppliesGroup = new THREE.Group();
scene.add(suppliesGroup);
box(suppliesGroup, [1.8, 0.18, 1.15], [-4.45, 0.8, 1.55], "#9b7653");
for (const x of [-5.12, -3.78]) {
for (const z of [1.15, 1.95]) {
box(suppliesGroup, [0.16, 0.82, 0.16], [x, 0.39, z], "#684d37");
}
}
box(suppliesGroup, [0.85, 0.55, 0.75], [-4.7, 1.18, 1.55], "#d6a867");
box(suppliesGroup, [0.65, 0.4, 0.55], [-4.05, 1.12, 1.62], "#e7d8bd");
box(suppliesGroup, [0.85, 0.09, 0.12], [-4.7, 1.5, 1.55], "#6e5037");
// Punch station
const punchGroup = new THREE.Group();
scene.add(punchGroup);
box(punchGroup, [1.85, 0.18, 1.1], [-4.25, 0.83, -1.55], "#b78355");
for (const x of [-4.95, -3.55]) {
for (const z of [-1.9, -1.2]) {
box(punchGroup, [0.16, 0.85, 0.16], [x, 0.4, z], "#704b32");
}
}
box(punchGroup, [0.95, 0.4, 0.75], [-4.25, 1.12, -1.55], "#ff766b");
box(punchGroup, [1.08, 0.12, 0.86], [-4.25, 1.37, -1.55], "#ffd0c4");
box(punchGroup, [0.17, 0.5, 0.17], [-3.92, 1.56, -1.55], "#b68155");
box(punchGroup, [0.48, 0.1, 0.15], [-3.92, 1.8, -1.55], "#f6bd45");
// Lights station
const lightsGroup = new THREE.Group();
scene.add(lightsGroup);
box(lightsGroup, [1.6, 0.16, 1.05], [2.75, 0.84, -2.75], "#92704f");
for (const x of [2.15, 3.35]) {
for (const z of [-3.1, -2.4]) {
box(lightsGroup, [0.16, 0.85, 0.16], [x, 0.4, z], "#654a34");
}
}
box(lightsGroup, [0.72, 0.42, 0.72], [2.65, 1.13, -2.75], "#34323d");
box(lightsGroup, [0.9, 0.14, 0.14], [2.65, 1.4, -2.75], "#f6bd45");
// String lights on the wall
const stringLights = new THREE.Group();
scene.add(stringLights);
const bulbColors = ["#ffd36a", "#ff8f80", "#a98af1", "#69d5c2"];
for (let i = 0; i < 9; i++) {
const x = -0.6 + i * 0.72;
const y = 3.72 - Math.sin(i / 8 * Math.PI) * 0.24;
box(stringLights, [0.07, 0.07, 0.08], [x, y + 0.12, -3.82], "#48434c", { castShadow: false });
box(stringLights, [0.18, 0.22, 0.16], [x, y - 0.03, -3.76], bulbColors[i % bulbColors.length], {
material: new THREE.MeshStandardMaterial({
color: bulbColors[i % bulbColors.length],
emissive: bulbColors[i % bulbColors.length],
emissiveIntensity: 0.35,
roughness: 0.65
})
});
}
// Decorations station and finished decorations
const decorStation = new THREE.Group();
scene.add(decorStation);
box(decorStation, [1.45, 0.17, 1.0], [3.45, 0.85, -0.75], "#9e7956");
for (const x of [2.93, 3.97]) {
for (const z of [-1.08, -0.42]) {
box(decorStation, [0.16, 0.85, 0.16], [x, 0.4, z], "#674a34");
}
}
box(decorStation, [0.8, 0.52, 0.75], [3.43, 1.2, -0.75], "#f2c457");
const decorations = new THREE.Group();
scene.add(decorations);
const decorColors = ["#ff766b", "#f6bd45", "#9b72e8", "#45b6a4", "#ff9f58"];
for (let i = 0; i < 10; i++) {
const x = -0.2 + i * 0.52;
const y = 3.4 - Math.sin(i / 9 * Math.PI) * 0.35;
box(decorations, [0.4, 0.4, 0.13], [x, y, -3.77], decorColors[i % decorColors.length]);
box(decorations, [0.12, 0.12, 0.08], [x, y + 0.28, -3.69], "#fff4dc");
}
// Napkin station
const napkinGroup = new THREE.Group();
scene.add(napkinGroup);
box(napkinGroup, [1.65, 0.17, 1.0], [-1.2, 0.82, 2.15], "#9b7653");
for (const x of [-1.82, -0.58]) {
for (const z of [1.82, 2.48]) {
box(napkinGroup, [0.16, 0.82, 0.16], [x, 0.39, z], "#684d37");
}
}
box(napkinGroup, [0.62, 0.2, 0.58], [-1.47, 1.0, 2.15], "#45b6a4");
box(napkinGroup, [0.62, 0.2, 0.58], [-0.92, 1.0, 2.15], "#9b72e8");
box(napkinGroup, [0.62, 0.2, 0.58], [-1.2, 1.2, 2.15], "#f6bd45");
// Small side table and cake
box(scene, [1.15, 0.16, 1.0], [4.35, 0.9, -2.45], "#9b7653");
box(scene, [0.9, 0.85, 0.9], [4.35, 0.43, -2.45], "#b8885b");
const cake = new THREE.Group();
cake.position.set(4.35, 0, -2.45);
scene.add(cake);
box(cake, [0.75, 0.55, 0.75], [0, 1.23, 0], "#fff0cf");
box(cake, [0.82, 0.1, 0.82], [0, 1.53, 0], "#ff9f58");
box(cake, [0.12, 0.28, 0.12], [0, 1.72, 0], "#ff766b");
// Plants in blocky pots
function addPlant(x, z, scale = 1) {
const plant = new THREE.Group();
plant.position.set(x, 0, z);
plant.scale.setScalar(scale);
scene.add(plant);
box(plant, [0.72, 0.68, 0.72], [0, 0.33, 0], "#b97855");
box(plant, [0.82, 0.12, 0.82], [0, 0.7, 0], "#d3936a");
box(plant, [0.14, 1.05, 0.14], [0, 1.18, 0], "#526e4d");
box(plant, [0.78, 0.55, 0.55], [0.05, 1.58, 0], "#6f9465");
box(plant, [0.55, 0.72, 0.62], [-0.28, 1.35, 0.08], "#5f8559");
box(plant, [0.55, 0.62, 0.55], [0.34, 1.52, -0.02], "#7ca26b");
}
addPlant(-5.25, -3.2, 0.9);
addPlant(5.15, -3.1, 0.82);
addPlant(-5.25, 3.0, 0.76);
// Entrance mat and doorway
box(scene, [1.55, 0.04, 0.8], [4.35, 0.02, 3.15], "#ef7065");
box(scene, [0.18, 3.0, 0.18], [3.52, 1.5, 3.7], "#d8c7ad");
box(scene, [0.18, 3.0, 0.18], [5.18, 1.5, 3.7], "#d8c7ad");
box(scene, [1.85, 0.18, 0.18], [4.35, 3.0, 3.7], "#d8c7ad");
// Voxel characters
function textSprite(text, color = "#ffffff") {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 64;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(36,36,50,0.88)";
context.fillRect(2, 2, 252, 60);
context.fillStyle = color;
context.font = "800 28px system-ui";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 33);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({ map: texture, depthTest: false, transparent: true });
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.35, 0.34, 1);
sprite.renderOrder = 20;
return sprite;
}
function createPerson(color, name, skin = "#f1c49f") {
const group = new THREE.Group();
box(group, [0.34, 0.43, 0.38], [-0.19, 0.28, 0], "#343443");
box(group, [0.34, 0.43, 0.38], [0.19, 0.28, 0], "#343443");
box(group, [0.66, 0.65, 0.4], [0, 0.77, 0], color);
box(group, [0.48, 0.49, 0.46], [0, 1.31, 0], skin);
box(group, [0.52, 0.18, 0.48], [0, 1.56, -0.01], "#3d3542");
const leftArm = new THREE.Group();
leftArm.position.set(-0.44, 0.99, 0);
group.add(leftArm);
box(leftArm, [0.2, 0.56, 0.22], [0, -0.22, 0], color);
box(leftArm, [0.2, 0.17, 0.22], [0, -0.53, 0], skin);
const rightArm = new THREE.Group();
rightArm.position.set(0.44, 0.99, 0);
group.add(rightArm);
box(rightArm, [0.2, 0.56, 0.22], [0, -0.22, 0], color);
box(rightArm, [0.2, 0.17, 0.22], [0, -0.53, 0], skin);
box(group, [0.07, 0.08, 0.03], [-0.11, 1.34, 0.24], "#302b35");
box(group, [0.07, 0.08, 0.03], [0.11, 1.34, 0.24], "#302b35");
box(group, [0.12, 0.035, 0.03], [0, 1.21, 0.245], "#8f5c56");
const label = textSprite(name.toUpperCase(), color);
label.position.y = 2.02;
group.add(label);
group.scale.setScalar(0.92);
group.userData = { leftArm, rightArm, color };
return group;
}
const helperMeshes = {};
Object.values(HELPERS).forEach(helper => {
const mesh = createPerson(helper.color, helper.name);
mesh.position.set(...helper.standby);
scene.add(mesh);
helperMeshes[helper.name] = mesh;
});
const guest = createPerson("#d96fb4", "Guest", "#dba47d");
guest.position.set(4.35, 0, 3.15);
guest.scale.setScalar(0.9);
scene.add(guest);
// Confetti for the arrival moment
const confetti = new THREE.Group();
scene.add(confetti);
let seed = 91;
function random() {
seed = (seed * 9301 + 49297) % 233280;
return seed / 233280;
}
const confettiPieces = [];
const confettiColors = ["#ff766b", "#f6bd45", "#9b72e8", "#45b6a4", "#4f8df7"];
for (let i = 0; i < 42; i++) {
const piece = box(
confetti,
[0.08, 0.08, 0.16],
[(random() - 0.5) * 9, 2 + random() * 4, (random() - 0.5) * 6],
confettiColors[i % confettiColors.length],
{ receiveShadow: false }
);
piece.userData = {
speed: 0.55 + random() * 0.75,
drift: (random() - 0.5) * 0.7,
phase: random() * Math.PI * 2
};
confettiPieces.push(piece);
}
// HTML labels projected from world positions
const projectedLabels = TASKS.map(task => {
const element = document.createElement("div");
element.className = "scene-tag";
element.style.setProperty("--tag", task.color);
element.innerHTML = `<i></i>${task.short}`;
sceneLabels.appendChild(element);
return { task, element };
});
// Direct camera controls: orbit, pan and zoom.
const controls = {
theta: 0.72,
phi: 0.91,
radius: 17.2,
target: new THREE.Vector3(0, 0.72, -0.25)
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.theta = 0.72;
controls.phi = 0.91;
controls.radius = 17.2;
controls.target.set(0, 0.72, -0.25);
updateCamera();
}
document.getElementById("reset-camera").addEventListener("click", resetCamera);
let dragging = false;
let dragButton = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragButton = event.button;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (dragButton === 0) {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.48, 1.28);
} else {
const scale = controls.radius * 0.00115;
const rightX = Math.cos(controls.theta);
const rightZ = -Math.sin(controls.theta);
controls.target.x -= dx * scale * rightX;
controls.target.z -= dx * scale * rightZ;
controls.target.x += dy * scale * Math.sin(controls.theta);
controls.target.z += dy * scale * Math.cos(controls.theta);
}
updateCamera();
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
10.5,
24
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
updateCamera();
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
let previousStateKey = "";
function updateScene(delta, elapsed) {
const completedIds = new Set(
TASKS.filter(task => state.currentTime >= state.schedule[task.id].end)
.map(task => task.id)
);
tableCloth.visible = completedIds.has("napkins");
punchGroup.visible = completedIds.has("punch");
stringLights.visible = completedIds.has("lights");
decorations.visible = completedIds.has("decorations");
tableware.visible = completedIds.has("table");
guest.visible = state.currentTime >= 60;
confetti.visible = state.currentTime >= 60;
if (confetti.visible) {
confettiPieces.forEach((piece, index) => {
const data = piece.userData;
const cycle = (elapsed * data.speed + index * 0.37) % 6;
piece.position.y = 6.1 - cycle;
piece.position.x += Math.sin(elapsed * 1.2 + data.phase) * 0.008;
piece.rotation.x += delta * (1.4 + index % 3 * 0.25);
piece.rotation.z += delta * (0.8 + index % 4 * 0.18);
});
}
Object.values(HELPERS).forEach(helper => {
const mesh = helperMeshes[helper.name];
const activeTask = TASKS.find(task => {
const slot = state.schedule[task.id];
return slot.helper === helper.name &&
state.currentTime >= slot.start &&
state.currentTime < slot.end;
});
const target = activeTask ? activeTask.station : helper.standby;
const easing = 1 - Math.exp(-delta * 5.2);
mesh.position.x = THREE.MathUtils.lerp(mesh.position.x, target[0], easing);
mesh.position.z = THREE.MathUtils.lerp(mesh.position.z, target[2], easing);
mesh.position.y = THREE.MathUtils.lerp(
mesh.position.y,
activeTask ? Math.abs(Math.sin(elapsed * 5.5)) * 0.045 : 0,
easing
);
const swing = activeTask ? Math.sin(elapsed * 7.5) * 0.5 : 0;
mesh.userData.leftArm.rotation.x = swing;
mesh.userData.rightArm.rotation.x = -swing;
});
projectedLabels.forEach(({ task, element }) => {
projected.set(task.station[0], 1.8, task.station[2]);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "flex" : "none";
if (visible) {
element.style.left = `${(projected.x * 0.5 + 0.5) * stage.clientWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * stage.clientHeight}px`;
}
});
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (state.playing) {
state.currentTime += delta * state.speed;
if (state.currentTime >= 60) {
state.currentTime = 60;
state.playing = false;
showToast(TASKS.every(task => state.schedule[task.id].end <= 60)
? "The guest arrived and the party room was ready!"
: "The guest arrived before the party room was ready.");
}
}
const stateKey = `${Math.floor(state.currentTime * 3)}-${state.playing}`;
if (stateKey !== previousStateKey) {
previousStateKey = stateKey;
updateUI();
}
updateScene(delta, elapsed);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```