Prompt specification
Build or customize the Three.js 3D scene "Morning-order counterfactual game" 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: Morning-order counterfactual game
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/morning-order-counterfactual-game-x3880
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a low-poly morning-routine scheduling game. Use a small apartment cutaway with a kitchen, bedroom, bathroom, and front door, occupied by two original characters. Give the morning tasks fictional durations and visible dependencies: packing lunch follows preparing it, and leaving requires each character's bag and keys. Let users rearrange independent tasks on a short timeline, then replay the resulting movements through the rooms. Track belongings as physical objects rather than check marks alone. The final state should show who reached the door, what they carried, and which unmet dependency prevented an unfinished action. Tasks that can overlap should occupy separate timeline lanes, while a blocked task stays at its location with the missing prerequisite highlighted beside it.
Working Three.js Starter (morning-order-counterfactual-game-x3880):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Morning Routes — A Tiny Apartment Scheduler</title>
<style>
:root {
--ink: #24313a;
--muted: #69767d;
--paper: #fbf7ee;
--panel: #fffaf1;
--line: #d9cfbf;
--blue: #3f83a5;
--blue-dark: #2c607b;
--green: #4d9872;
--green-light: #dcefe4;
--orange: #d78a42;
--orange-light: #fff0d9;
--red: #c85d54;
--red-light: #fbe2de;
--shadow: 0 12px 35px rgba(45, 52, 55, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e1d3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button {
border: 1px solid var(--line);
background: var(--panel);
color: var(--ink);
border-radius: 9px;
padding: 9px 13px;
cursor: pointer;
font-weight: 700;
transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: #bdb09d;
}
button:active {
transform: translateY(0);
}
button.primary {
color: white;
background: var(--blue-dark);
border-color: var(--blue-dark);
}
button.primary:hover {
background: #244f65;
}
button.small {
padding: 6px 9px;
font-size: 0.78rem;
}
header {
height: 70px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
background: rgba(255, 250, 241, 0.94);
border-bottom: 1px solid var(--line);
box-shadow: 0 4px 20px rgba(40, 50, 54, 0.05);
position: relative;
z-index: 20;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-icon {
width: 38px;
height: 38px;
display: grid;
place-items: center;
border-radius: 12px;
background: var(--blue-dark);
color: white;
font-size: 1.25rem;
flex: none;
}
.brand h1 {
margin: 0;
font-size: 1.12rem;
letter-spacing: -0.02em;
}
.brand p {
margin: 2px 0 0;
color: var(--muted);
font-size: 0.79rem;
}
.header-actions {
display: flex;
align-items: center;
gap: 8px;
flex: none;
}
main {
height: calc(100vh - 70px);
display: grid;
grid-template-columns: minmax(0, 1fr) 430px;
overflow: hidden;
}
.stage {
position: relative;
min-width: 0;
overflow: hidden;
background: #e9e1d3;
}
#scene {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.stage-help {
position: absolute;
top: 15px;
left: 15px;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 10px;
background: rgba(255, 250, 241, 0.82);
backdrop-filter: blur(8px);
box-shadow: 0 6px 20px rgba(40, 50, 54, 0.08);
font-size: 0.75rem;
color: #4c5a61;
pointer-events: none;
}
.camera-controls {
position: absolute;
right: 15px;
top: 15px;
z-index: 4;
display: flex;
gap: 6px;
}
.clock-card {
position: absolute;
left: 15px;
bottom: 15px;
z-index: 4;
min-width: 198px;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 13px;
background: rgba(255, 250, 241, 0.9);
backdrop-filter: blur(10px);
box-shadow: var(--shadow);
}
.clock-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
}
.clock-row strong {
font-size: 1.35rem;
font-variant-numeric: tabular-nums;
}
.clock-row span {
color: var(--muted);
font-size: 0.72rem;
}
.scrub {
width: 100%;
margin: 9px 0 1px;
accent-color: var(--blue-dark);
}
.rail {
overflow-y: auto;
overflow-x: hidden;
padding: 17px;
background: var(--paper);
border-left: 1px solid var(--line);
scrollbar-width: thin;
scrollbar-color: #c8bdab transparent;
}
.panel {
margin-bottom: 14px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 5px 18px rgba(50, 57, 60, 0.055);
}
.panel h2 {
margin: 0 0 4px;
font-size: 0.98rem;
letter-spacing: -0.01em;
}
.panel-intro {
margin: 0 0 12px;
color: var(--muted);
font-size: 0.77rem;
line-height: 1.45;
}
.play-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
margin-bottom: 11px;
}
.play-row select {
min-width: 100px;
border: 1px solid var(--line);
border-radius: 9px;
padding: 8px;
color: var(--ink);
background: white;
}
.warning {
margin-top: 11px;
padding: 9px 10px;
border-radius: 9px;
background: var(--red-light);
color: #8c403b;
border: 1px solid #efc6c1;
font-size: 0.74rem;
line-height: 1.4;
}
.warning.good {
background: var(--green-light);
color: #346d51;
border-color: #c5e4d3;
}
.timeline-scroll {
overflow-x: auto;
overflow-y: hidden;
padding-bottom: 5px;
scrollbar-width: thin;
}
.timeline-inner {
position: relative;
width: 620px;
min-height: 164px;
}
#dependencySvg {
position: absolute;
inset: 0;
width: 620px;
height: 164px;
overflow: visible;
pointer-events: none;
z-index: 2;
}
.ruler {
position: relative;
height: 28px;
margin-left: 80px;
width: 520px;
border-bottom: 1px solid #cfc5b5;
}
.ruler span {
position: absolute;
top: 5px;
transform: translateX(-50%);
color: #7a817f;
font-size: 0.65rem;
font-variant-numeric: tabular-nums;
}
.lane {
height: 67px;
position: relative;
border-bottom: 1px solid #e6ded2;
}
.lane-name {
position: absolute;
left: 0;
top: 17px;
width: 70px;
display: flex;
align-items: center;
gap: 7px;
font-size: 0.78rem;
font-weight: 800;
}
.avatar-dot {
width: 25px;
height: 25px;
border-radius: 50%;
display: grid;
place-items: center;
color: white;
font-size: 0.65rem;
font-weight: 900;
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.13);
}
.pip-dot {
background: #d88355;
}
.nia-dot {
background: #518c9e;
}
.lane-track {
position: absolute;
left: 80px;
top: 13px;
width: 520px;
height: 40px;
border-radius: 7px;
background:
repeating-linear-gradient(
90deg,
rgba(99, 117, 123, 0.055) 0,
rgba(99, 117, 123, 0.055) 1px,
transparent 1px,
transparent calc(520px / 12)
),
#f2ece2;
overflow: visible;
}
.task-block {
position: absolute;
top: 0;
height: 40px;
min-width: 12px;
padding: 4px 5px;
border: 1px solid #8db6c7;
border-radius: 7px;
background: #dcecf3;
color: #28556b;
overflow: hidden;
cursor: grab;
user-select: none;
touch-action: none;
z-index: 4;
box-shadow: 0 2px 5px rgba(49, 68, 77, 0.1);
transition: background 100ms ease, border-color 100ms ease;
}
.task-block:active {
cursor: grabbing;
}
.task-block:hover {
filter: brightness(1.02);
}
.task-block .task-short {
display: block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-size: 0.66rem;
line-height: 1.05;
font-weight: 850;
}
.task-block .task-duration {
display: block;
margin-top: 2px;
font-size: 0.58rem;
opacity: 0.72;
white-space: nowrap;
}
.task-block.nia {
border-color: #79aeb0;
background: #dceeee;
color: #315f61;
}
.task-block.selected {
outline: 3px solid rgba(63, 131, 165, 0.28);
outline-offset: 2px;
}
.task-block.invalid {
border: 2px dashed var(--red);
background: var(--red-light);
color: #873d38;
}
.task-block.doing {
background: #b8dff0;
box-shadow: 0 0 0 3px rgba(63, 131, 165, 0.2);
}
.task-block.done {
border-color: #70a98a;
background: var(--green-light);
color: #32664d;
}
.task-block.blocked {
border: 2px solid var(--red);
background: var(--red-light);
color: #873d38;
animation: blockedPulse 1s infinite alternate;
}
@keyframes blockedPulse {
to {
box-shadow: 0 0 0 4px rgba(200, 93, 84, 0.18);
}
}
.time-cursor {
position: absolute;
top: 0;
bottom: 0;
width: 2px;
background: var(--orange);
z-index: 6;
pointer-events: none;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.65);
}
.time-cursor::before {
content: "";
position: absolute;
top: 0;
left: -4px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 7px solid var(--orange);
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
margin-top: 11px;
color: var(--muted);
font-size: 0.68rem;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.legend i {
width: 10px;
height: 10px;
border-radius: 3px;
background: #dcecf3;
border: 1px solid #8db6c7;
}
.legend .done-key {
background: var(--green-light);
border-color: #70a98a;
}
.legend .bad-key {
background: var(--red-light);
border-color: var(--red);
}
.task-detail {
margin-top: 12px;
padding: 11px;
border-radius: 10px;
background: #f4eee4;
border: 1px solid #e1d7c8;
}
.task-detail h3 {
margin: 0 0 4px;
font-size: 0.86rem;
}
.task-detail p {
margin: 3px 0;
color: #677278;
font-size: 0.72rem;
line-height: 1.42;
}
.dependency-chip {
display: inline-block;
margin: 4px 4px 0 0;
padding: 4px 7px;
border-radius: 999px;
color: #7b4d2b;
background: var(--orange-light);
border: 1px solid #ebcfac;
font-size: 0.65rem;
font-weight: 750;
}
.summary-list {
display: grid;
gap: 10px;
}
.summary-card {
padding: 11px;
border-radius: 10px;
border: 1px solid #ddd3c4;
background: #f8f2e8;
}
.summary-card.reached {
border-color: #bad9c7;
background: #edf7f0;
}
.summary-card.blocked {
border-color: #edc0ba;
background: #fff0ed;
}
.summary-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
}
.summary-head strong {
font-size: 0.84rem;
}
.status-pill {
padding: 4px 7px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.72);
border: 1px solid rgba(80, 90, 92, 0.12);
color: #5b666a;
font-size: 0.62rem;
font-weight: 850;
text-transform: uppercase;
letter-spacing: 0.04em;
}
.summary-card.reached .status-pill {
color: #337052;
background: #dcefe4;
}
.summary-card.blocked .status-pill {
color: #8b3e38;
background: #f8d9d5;
}
.summary-line {
margin: 4px 0;
color: #586468;
font-size: 0.72rem;
line-height: 1.4;
}
.carry-list {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 7px;
}
.carry-chip,
.missing-chip {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 4px 7px;
border-radius: 999px;
font-size: 0.65rem;
font-weight: 750;
}
.carry-chip {
color: #3f6951;
background: #dfefe4;
border: 1px solid #c4dfce;
}
.missing-chip {
color: #873d38;
background: #f8d9d5;
border: 1px solid #eabbb5;
}
.help-text {
color: var(--muted);
font-size: 0.71rem;
line-height: 1.5;
}
.help-text strong {
color: #435157;
}
#toast {
position: fixed;
left: 50%;
bottom: 24px;
transform: translate(-50%, 20px);
z-index: 100;
max-width: min(90vw, 430px);
padding: 10px 15px;
border-radius: 10px;
background: #29363e;
color: white;
box-shadow: var(--shadow);
opacity: 0;
pointer-events: none;
transition: opacity 160ms ease, transform 160ms ease;
font-size: 0.78rem;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 920px) {
html,
body {
overflow: auto;
}
header {
height: auto;
min-height: 70px;
padding: 10px 14px;
}
.brand p {
display: none;
}
main {
height: auto;
display: block;
overflow: visible;
}
.stage {
height: 62vh;
min-height: 440px;
}
.rail {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
}
@media (max-width: 560px) {
.header-actions .button-label {
display: none;
}
.stage-help {
max-width: calc(100% - 110px);
}
.clock-card {
min-width: 170px;
}
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="brand-icon" aria-hidden="true">☀</div>
<div>
<h1>Morning Routes</h1>
<p>A tiny apartment schedule for Pip and Nia</p>
</div>
</div>
<div class="header-actions">
<button id="resetButton" title="Restore the original schedule">
↺ <span class="button-label">Reset</span>
</button>
<button id="viewButton" title="Reset the apartment camera">⌂ <span class="button-label">View</span></button>
</div>
</header>
<main>
<section class="stage" id="stage">
<canvas id="scene" aria-label="Low-poly apartment morning routine"></canvas>
<div class="stage-help">Drag to orbit · Scroll to zoom · Play to replay</div>
<div class="camera-controls">
<button id="zoomIn" class="small" aria-label="Zoom in">+</button>
<button id="zoomOut" class="small" aria-label="Zoom out">−</button>
</div>
<div class="clock-card">
<div class="clock-row">
<strong id="timeNow">0:00</strong>
<span id="replayState">fictional time</span>
</div>
<input id="scrub" class="scrub" type="range" min="0" max="12" step="0.05" value="0"
aria-label="Scrub the morning timeline" />
</div>
</section>
<aside class="rail">
<section class="panel">
<h2>Build the morning</h2>
<p class="panel-intro">
Drag task blocks along their character lane. Different characters can work at the same
time, but one character cannot overlap two tasks.
</p>
<div class="play-row">
<button id="playButton" class="primary">▶ Replay morning</button>
<select id="speedSelect" aria-label="Replay speed">
<option value="2">2×</option>
<option value="3" selected>3×</option>
<option value="5">5×</option>
</select>
</div>
<div id="scheduleWarning" class="warning"></div>
<div class="timeline-scroll">
<div id="timelineInner" class="timeline-inner">
<svg id="dependencySvg" aria-hidden="true">
<defs>
<marker id="arrowHead" markerWidth="7" markerHeight="7" refX="6" refY="3.5"
orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L7,3.5 L0,7 Z" fill="#b47b46"></path>
</marker>
<marker id="badArrowHead" markerWidth="7" markerHeight="7" refX="6" refY="3.5"
orient="auto" markerUnits="strokeWidth">
<path d="M0,0 L7,3.5 L0,7 Z" fill="#c85d54"></path>
</marker>
</defs>
</svg>
<div id="ruler" class="ruler"></div>
<div id="pipLane" class="lane">
<div class="lane-name"><span class="avatar-dot pip-dot">P</span>Pip</div>
<div class="lane-track" id="pipTrack"></div>
</div>
<div id="niaLane" class="lane">
<div class="lane-name"><span class="avatar-dot nia-dot">N</span>Nia</div>
<div class="lane-track" id="niaTrack"></div>
</div>
<div id="timeCursor" class="time-cursor"></div>
</div>
</div>
<div class="legend">
<span><i></i> Scheduled</span>
<span><i class="done-key"></i> Complete</span>
<span><i class="bad-key"></i> Dependency order problem</span>
</div>
<div id="taskDetail" class="task-detail"></div>
</section>
<section class="panel">
<h2>Morning report</h2>
<p class="panel-intro">
The report follows the physical belongings and the final destination of each character.
</p>
<div id="summary" class="summary-list"></div>
</section>
<section class="panel">
<h2>How to play</h2>
<p class="help-text">
<strong>1.</strong> Move Pip’s <em>Head out</em> block until both the satchel and keys
finish before it.<br />
<strong>2.</strong> Check the dependency arrows in the timeline.<br />
<strong>3.</strong> Press replay. A blocked character walks to the task, stops there, and
displays the missing prerequisite beside them.<br />
<strong>4.</strong> Inspect the final report to see who reached the door and what they
physically carried.
</p>
</section>
</aside>
</main>
<div id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Application data
// -------------------------------------------------------------------------
const TOTAL_MINUTES = 12;
const TRACK_WIDTH = 520;
const MINUTE_WIDTH = TRACK_WIDTH / TOTAL_MINUTES;
const rooms = {
bedroom: { name: "Bedroom", color: 0xd8c7b5 },
bathroom: { name: "Bathroom", color: 0xb9d5d3 },
kitchen: { name: "Kitchen", color: 0xe4d4ad },
foyer: { name: "Front door", color: 0xc9d1c2 }
};
const tasks = [
{
id: "p-face",
actor: "pip",
name: "Rinse face",
short: "Face",
room: "bathroom",
location: new THREE.Vector3(3.2, 0, -2.65),
duration: 1,
start: 0,
deps: [],
produces: null,
prerequisiteText: ""
},
{
id: "p-bag",
actor: "pip",
name: "Pack canvas satchel",
short: "Satchel",
room: "bedroom",
location: new THREE.Vector3(-4.25, 0, -2.15),
duration: 1,
start: 1,
deps: [],
produces: "bag",
prerequisiteText: "Pip's packed canvas satchel"
},
{
id: "p-leave",
actor: "pip",
name: "Head out",
short: "Out",
room: "foyer",
location: new THREE.Vector3(4.65, 0, 3.65),
duration: 1,
start: 2,
deps: ["p-bag", "p-keys"],
produces: null,
prerequisiteText: "Pip's departure requirements"
},
{
id: "p-keys",
actor: "pip",
name: "Collect house keys",
short: "Keys",
room: "foyer",
location: new THREE.Vector3(6.15, 0, 1.45),
duration: 1,
start: 3,
deps: [],
produces: "keys",
prerequisiteText: "Pip's house keys"
},
{
id: "n-shower",
actor: "nia",
name: "Take a quick shower",
short: "Shower",
room: "bathroom",
location: new THREE.Vector3(5.15, 0, -3.15),
duration: 2,
start: 0,
deps: [],
produces: null,
prerequisiteText: ""
},
{
id: "n-prep",
actor: "nia",
name: "Prepare lunch",
short: "Cook",
room: "kitchen",
location: new THREE.Vector3(-4.05, 0, 0.95),
duration: 2,
start: 2,
deps: [],
produces: "lunch",
prerequisiteText: "prepared lunch"
},
{
id: "n-pack",
actor: "nia",
name: "Pack the lunchbox",
short: "Box",
room: "kitchen",
location: new THREE.Vector3(-2.95, 0, 1.15),
duration: 1,
start: 4,
deps: ["n-prep"],
produces: "lunchbox",
prerequisiteText: "prepared lunch"
},
{
id: "n-bag",
actor: "nia",
name: "Pack market tote",
short: "Tote",
room: "bedroom",
location: new THREE.Vector3(-2.25, 0, -2.75),
duration: 1,
start: 5,
deps: [],
produces: "bag",
prerequisiteText: "Nia's packed market tote"
},
{
id: "n-keys",
actor: "nia",
name: "Collect house keys",
short: "Keys",
room: "foyer",
location: new THREE.Vector3(6.15, 0, 1.05),
duration: 1,
start: 6,
deps: [],
produces: "keys",
prerequisiteText: "Nia's house keys"
},
{
id: "n-leave",
actor: "nia",
name: "Head out",
short: "Out",
room: "foyer",
location: new THREE.Vector3(5.25, 0, 3.65),
duration: 1,
start: 7,
deps: ["n-bag", "n-keys"],
produces: null,
prerequisiteText: "Nia's departure requirements"
}
];
const taskById = Object.fromEntries(tasks.map(task => [task.id, task]));
const defaultStarts = Object.fromEntries(tasks.map(task => [task.id, task.start]));
const actors = {
pip: {
name: "Pip",
initials: "P",
home: new THREE.Vector3(-2.35, 0, -1.55),
accent: 0xd77e4f,
skin: 0xd9a27d,
hair: 0x41332e
},
nia: {
name: "Nia",
initials: "N",
home: new THREE.Vector3(-1.25, 0, -2.7),
accent: 0x4f91a4,
skin: 0x8c5f43,
hair: 0x242326
}
};
const carryNames = {
"p-bag": "canvas satchel",
"p-keys": "house keys",
"n-bag": "market tote",
"n-keys": "house keys",
"n-pack": "packed lunchbox"
};
// -------------------------------------------------------------------------
// Three.js setup
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e1d3);
scene.fog = new THREE.Fog(0xe9e1d3, 25, 42);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const ambient = new THREE.HemisphereLight(0xfff8e9, 0x7d8e91, 2.15);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xffe7bc, 3.3);
sun.position.set(-8, 13, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0007;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7d8e8, 0.75);
fill.position.set(8, 7, -9);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0,
flatShading: true,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
function addBox(width, height, depth, x, y, z, color, parent = scene, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color, options)
);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function addCylinder(radiusTop, radiusBottom, height, x, y, z, color, parent = scene, sides = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, sides),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeFloorLabel(text, x, z, width = 2.3) {
const c = document.createElement("canvas");
c.width = 512;
c.height = 128;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
ctx.font = "800 58px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "rgba(50,60,62,0.45)";
ctx.fillText(text.toUpperCase(), 256, 64);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width / 4),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.018, z);
scene.add(mesh);
return mesh;
}
function roundedRectPath(ctx, x, y, w, h, radius) {
const r = Math.min(radius, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeTextSprite() {
const c = document.createElement("canvas");
c.width = 640;
c.height = 190;
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.65, 1.08, 1);
sprite.visible = false;
sprite.renderOrder = 30;
sprite.userData.canvas = c;
sprite.userData.texture = texture;
sprite.userData.signature = "";
scene.add(sprite);
return sprite;
}
function setSpriteText(sprite, title, subtitle, blocked = false) {
const signature = `${title}|${subtitle}|${blocked}`;
if (sprite.userData.signature === signature) return;
sprite.userData.signature = signature;
const c = sprite.userData.canvas;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
roundedRectPath(ctx, 8, 8, 624, 174, 24);
ctx.fillStyle = blocked ? "rgba(112,43,39,0.94)" : "rgba(38,54,62,0.9)";
ctx.fill();
ctx.strokeStyle = blocked ? "#f1aaa2" : "#d4e6ec";
ctx.lineWidth = 5;
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = blocked ? "#ffd4ce" : "#d9f0f6";
ctx.font = "900 37px system-ui, sans-serif";
ctx.fillText(title, 320, 67);
ctx.fillStyle = "white";
ctx.font = "700 31px system-ui, sans-serif";
ctx.fillText(subtitle, 320, 124);
sprite.userData.texture.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Apartment geometry
// -------------------------------------------------------------------------
function buildApartment() {
addBox(15.5, 0.28, 9.4, 0, -0.18, 0, 0xc9bba7);
addBox(7.1, 0.045, 4.4, -4.1, 0.005, 2.2, 0xe4d4ad);
addBox(7.1, 0.045, 4.4, -4.1, 0.005, -2.2, 0xd8c7b5);
addBox(7.1, 0.045, 4.4, 3.8, 0.005, -2.2, 0xb9d5d3);
addBox(7.1, 0.045, 4.4, 3.8, 0.005, 2.2, 0xc9d1c2);
// Cutaway walls.
addBox(15.1, 1.45, 0.22, 0, 0.7, -4.65, 0xf1e9dc);
addBox(0.22, 1.45, 9.1, -7.55, 0.7, 0, 0xf1e9dc);
addBox(0.22, 0.72, 9.1, 7.55, 0.34, 0, 0xe8dfd2);
addBox(5.2, 0.58, 0.22, -4.85, 0.27, 4.55, 0xe8dfd2);
addBox(1.9, 0.58, 0.22, 6.35, 0.27, 4.55, 0xe8dfd2);
// Kitchen.
addBox(2.35, 0.88, 1.1, -6.15, 0.44, 2.15, 0x8fa7a0);
addBox(2.5, 0.12, 1.2, -6.15, 0.94, 2.15, 0xf3eee2);
addBox(0.72, 0.06, 0.55, -6.05, 1.02, 2.12, 0x62777c);
addBox(0.08, 0.42, 0.08, -6.05, 1.24, 2.47, 0xa8b9b8);
addBox(0.42, 0.07, 0.07, -6.05, 1.45, 2.47, 0xa8b9b8);
addBox(1.45, 2.05, 1.1, -6.45, 1.02, -0.05, 0xe6e8df);
addBox(0.08, 0.52, 0.06, -5.75, 1.22, 0.52, 0x708b8e);
addBox(0.08, 0.06, 0.48, -5.75, 0.87, 0.25, 0x708b8e);
// Island and stools.
addBox(2.75, 0.78, 1.45, -3.65, 0.39, 1.25, 0xb99268);
addBox(2.95, 0.11, 1.62, -3.65, 0.83, 1.25, 0xf0d9ad);
addCylinder(0.28, 0.35, 0.65, -4.45, 0.32, 2.45, 0x6b7d78);
addCylinder(0.28, 0.35, 0.65, -2.95, 0.32, 2.45, 0x6b7d78);
// Bedroom.
addBox(3.15, 0.38, 2.05, -5.05, 0.22, -3.0, 0x8d7765);
addBox(2.95, 0.25, 1.85, -5.05, 0.52, -3.0, 0xf5f0e4);
addBox(2.95, 0.10, 1.25, -5.05, 0.69, -2.63, 0x6f9a9d);
addBox(1.05, 0.16, 0.52, -5.05, 0.72, -3.63, 0xfaf5e9);
addBox(1.7, 0.9, 0.72, -2.15, 0.45, -3.88, 0xa78467);
addBox(1.84, 0.12, 0.82, -2.15, 0.97, -3.88, 0xc9ab83);
addBox(0.12, 0.32, 0.12, -2.15, 1.17, -3.88, 0x6f8c80);
// Bathroom.
addBox(1.55, 0.18, 1.65, 5.35, 0.1, -3.25, 0xdfe9e7);
addBox(1.45, 1.95, 0.12, 5.35, 1.0, -4.08, 0x9fc6c8, scene, {
transparent: true,
opacity: 0.48,
roughness: 0.3
});
addBox(0.12, 1.95, 1.55, 6.08, 1.0, -3.25, 0x9fc6c8, scene, {
transparent: true,
opacity: 0.35,
roughness: 0.3
});
addBox(0.9, 0.14, 0.9, 5.4, 0.25, -3.25, 0xf8faf7);
addBox(0.74, 0.13, 0.74, 5.4, 0.39, -3.25, 0xa6c8cc);
addBox(1.15, 0.82, 0.66, 2.0, 0.41, -3.85, 0xa9c2bf);
addBox(1.28, 0.12, 0.78, 2.0, 0.88, -3.85, 0xf7f4ec);
addBox(0.72, 0.05, 0.46, 2.0, 0.965, -3.85, 0x657f83);
addBox(0.06, 0.5, 0.06, 2.0, 1.2, -4.05, 0x9eb7b8);
// Foyer.
addBox(1.45, 0.06, 0.95, 5.25, 0.04, 2.05, 0xb76d59);
addBox(1.2, 0.05, 0.75, 6.25, 0.04, 0.95, 0xc5a471);
// Door frame and hinged panel.
addBox(0.16, 2.45, 0.28, 3.95, 1.2, 4.52, 0x6f756f);
addBox(0.16, 2.45, 0.28, 5.95, 1.2, 4.52, 0x6f756f);
addBox(2.16, 0.16, 0.28, 4.95, 2.4, 4.52, 0x6f756f);
const doorPivot = new THREE.Group();
doorPivot.position.set(4.03, 0, 4.47);
scene.add(doorPivot);
addBox(1.84, 2.25, 0.13, 0.92, 1.12, 0, 0xc98558, doorPivot);
addBox(0.62, 0.62, 0.04, 1.12, 1.48, 0.085, 0x86a9a4, doorPivot);
addCylinder(0.06, 0.06, 0.28, 1.55, 1.08, 0.13, 0xe2bc59, doorPivot, 10);
doorPivot.rotation.y = 0;
// Key rack.
addBox(1.25, 0.72, 0.16, 6.38, 1.55, 1.78, 0x92775c);
addBox(1.05, 0.52, 0.08, 6.38, 1.55, 1.67, 0xb8956f);
makeFloorLabel("Kitchen", -4.1, 3.75, 2.0);
makeFloorLabel("Bedroom", -4.1, -0.75, 2.0);
makeFloorLabel("Bathroom", 3.8, -0.75, 2.0);
makeFloorLabel("Entry", 3.8, 3.45, 1.7);
return { doorPivot };
}
const apartment = buildApartment();
// -------------------------------------------------------------------------
// Characters and physical belongings
// -------------------------------------------------------------------------
function createCharacter(spec) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.31, 0.39, 0.78, 7),
material(spec.accent)
);
body.position.y = 1.02;
body.castShadow = true;
group.add(body);
const neck = addCylinder(0.11, 0.11, 0.13, 0, 1.47, 0, spec.skin, group, 8);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.33, 0),
material(spec.skin)
);
head.position.y = 1.67;
head.castShadow = true;
group.add(head);
const hair = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.335, 0),
material(spec.hair)
);
hair.position.set(0, 1.76, -0.035);
hair.scale.set(1, 0.72, 0.95);
hair.castShadow = true;
group.add(hair);
const leftEye = new THREE.Mesh(
new THREE.SphereGeometry(0.034, 8, 6),
material(0x25292a)
);
leftEye.position.set(-0.105, 1.69, 0.292);
group.add(leftEye);
const rightEye = leftEye.clone();
rightEye.position.x = 0.105;
group.add(rightEye);
const leftArm = addBox(0.15, 0.65, 0.17, -0.43, 1.02, 0, spec.accent, group);
const rightArm = addBox(0.15, 0.65, 0.17, 0.43, 1.02, 0, spec.accent, group);
leftArm.geometry.translate(0, -0.25, 0);
rightArm.geometry.translate(0, -0.25, 0);
leftArm.position.y = 1.25;
rightArm.position.y = 1.25;
const leftLeg = addBox(0.18, 0.65, 0.2, -0.18, 0.4, 0, 0x3e535b, group);
const rightLeg = addBox(0.18, 0.65, 0.2, 0.18, 0.4, 0, 0x3e535b, group);
leftLeg.geometry.translate(0, -0.27, 0);
rightLeg.geometry.translate(0, -0.27, 0);
leftLeg.position.y = 0.68;
rightLeg.position.y = 0.68;
addBox(0.22, 0.12, 0.36, -0.18, 0.09, 0.08, 0x394146, group);
addBox(0.22, 0.12, 0.36, 0.18, 0.09, 0.08, 0x394146, group);
const label = makeTextSprite();
setSpriteText(label, spec.name.toUpperCase(), "ready for the morning", false);
label.scale.set(1.65, 0.49, 1);
label.position.set(0, 2.38, 0);
label.visible = true;
group.position.copy(spec.home);
scene.add(group);
return {
...spec,
group,
label,
leftArm,
rightArm,
leftLeg,
rightLeg,
moving: false,
doing: false
};
}
actors.pip = createCharacter(actors.pip);
actors.nia = createCharacter(actors.nia);
function createBag(color, kind) {
const group = new THREE.Group();
if (kind === "satchel") {
addBox(0.48, 0.48, 0.24, 0, 0, 0, color, group);
addBox(0.50, 0.13, 0.26, 0, 0.16, 0.015, 0xc3a36d, group);
addBox(0.08, 0.43, 0.03, 0, -0.02, 0.135, 0x866c4b, group);
addBox(0.08, 0.37, 0.03, -0.18, 0.30, 0, 0x725b42, group);
addBox(0.08, 0.37, 0.03, 0.18, 0.30, 0, 0x725b42, group);
} else {
addBox(0.55, 0.52, 0.3, 0, 0, 0, color, group);
addBox(0.39, 0.07, 0.03, 0, 0.08, 0.165, 0xe2c58d, group);
addBox(0.07, 0.43, 0.07, -0.2, 0.35, 0, 0x84684c, group);
addBox(0.07, 0.43, 0.07, 0.2, 0.35, 0, 0x84684c, group);
addBox(0.47, 0.07, 0.07, 0, 0.56, 0, 0x84684c, group);
}
group.visible = false;
return group;
}
function createKeys() {
const group = new THREE.Group();
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.10, 0.025, 5, 12),
material(0xe1b94f, { metalness: 0.55, roughness: 0.35 })
);
group.add(ring);
addBox(0.055, 0.25, 0.035, 0.04, -0.18, 0, 0xe1b94f, group);
addBox(0.14, 0.05, 0.035, 0.10, -0.27, 0, 0xe1b94f, group);
addBox(0.11, 0.05, 0.035, 0.09, -0.16, 0, 0xe1b94f, group);
return group;
}
function createLunchbox() {
const group = new THREE.Group();
addBox(0.56, 0.29, 0.35, 0, 0, 0, 0xda765b, group);
addBox(0.59, 0.08, 0.37, 0, 0.16, 0, 0xf0aa78, group);
addBox(0.22, 0.04, 0.05, 0, 0.25, 0, 0x6d756f, group);
addBox(0.05, 0.18, 0.05, -0.13, 0.27, 0, 0x6d756f, group);
addBox(0.05, 0.18, 0.05, 0.13, 0.27, 0, 0x6d756f, group);
return group;
}
actors.pip.bag = createBag(0xb6874f, "satchel");
actors.pip.bag.position.set(0.42, 0.72, -0.18);
actors.pip.group.add(actors.pip.bag);
actors.pip.keys = createKeys();
actors.pip.keys.position.set(0.48, 0.92, 0.18);
actors.pip.group.add(actors.pip.keys);
actors.nia.bag = createBag(0x74978a, "tote");
actors.nia.bag.position.set(-0.42, 0.67, -0.12);
actors.nia.group.add(actors.nia.bag);
actors.nia.keys = createKeys();
actors.nia.keys.position.set(0.48, 0.92, 0.18);
actors.nia.group.add(actors.nia.keys);
actors.nia.lunchbox = createLunchbox();
actors.nia.lunchbox.position.set(-0.48, 0.73, 0.16);
actors.nia.group.add(actors.nia.lunchbox);
const sandwich = new THREE.Group();
addBox(0.48, 0.11, 0.37, 0, 0, 0, 0xe5c77c, sandwich);
addBox(0.44, 0.055, 0.33, 0, 0.075, 0, 0x83a965, sandwich);
addBox(0.42, 0.05, 0.31, 0, 0.125, 0, 0xd98661, sandwich);
sandwich.position.set(-4.05, 0.94, 1.15);
sandwich.visible = false;
scene.add(sandwich);
const spareKeys = createKeys();
spareKeys.position.set(6.37, 1.58, 1.57);
spareKeys.scale.setScalar(1.15);
scene.add(spareKeys);
// Small physical rings identify task locations.
for (const task of tasks) {
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.22, 0.035, 12),
new THREE.MeshBasicMaterial({ color: 0x8cb9c9 })
);
marker.position.set(task.location.x, 0.06, task.location.z);
scene.add(marker);
const blockedSprite = makeTextSprite();
blockedSprite.position.set(
task.location.x + (task.actor === "pip" ? -0.55 : 0.55),
2.65,
task.location.z
);
task.marker = marker;
task.blockedSprite = blockedSprite;
}
// -------------------------------------------------------------------------
// Timeline UI
// -------------------------------------------------------------------------
const ruler = document.getElementById("ruler");
const timelineInner = document.getElementById("timelineInner");
const dependencySvg = document.getElementById("dependencySvg");
const timeCursor = document.getElementById("timeCursor");
const taskDetail = document.getElementById("taskDetail");
const scheduleWarning = document.getElementById("scheduleWarning");
const summary = document.getElementById("summary");
const playButton = document.getElementById("playButton");
const scrub = document.getElementById("scrub");
const timeNow = document.getElementById("timeNow");
const replayState = document.getElementById("replayState");
for (let minute = 0; minute <= TOTAL_MINUTES; minute++) {
const label = document.createElement("span");
label.textContent = minute;
label.style.left = `${minute * MINUTE_WIDTH}px`;
ruler.appendChild(label);
}
let selectedTaskId = "p-leave";
let currentTime = 0;
let playing = false;
let simulation;
let drag = null;
let toastTimer;
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2200);
}
for (const task of tasks) {
const block = document.createElement("div");
block.className = `task-block ${task.actor}`;
block.dataset.id = task.id;
block.tabIndex = 0;
block.setAttribute("role", "button");
block.setAttribute("aria-label", `${task.name}, ${task.duration} fictional minutes`);
block.innerHTML = `
<span class="task-short">${task.short}</span>
<span class="task-duration">${task.duration}m</span>
`;
block.title = `${task.name} · ${task.duration} fictional minutes`;
const track = document.getElementById(task.actor === "pip" ? "pipTrack" : "niaTrack");
track.appendChild(block);
task.block = block;
block.addEventListener("pointerdown", event => {
event.preventDefault();
selectTask(task.id);
drag = {
task,
startX: event.clientX,
originalStart: task.start,
candidate: task.start,
valid: true
};
block.setPointerCapture?.(event.pointerId);
});
block.addEventListener("keydown", event => {
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
event.preventDefault();
const direction = event.key === "ArrowLeft" ? -0.5 : 0.5;
moveTask(task, task.start + direction);
});
}
window.addEventListener("pointermove", event => {
if (!drag) return;
const delta = (event.clientX - drag.startX) / MINUTE_WIDTH;
const snapped = Math.round((drag.originalStart + delta) * 2) / 2;
const candidate = THREE.MathUtils.clamp(snapped, 0, TOTAL_MINUTES - drag.task.duration);
const overlaps = tasks.some(other =>
other.id !== drag.task.id &&
other.actor === drag.task.actor &&
candidate < other.start + other.duration &&
candidate + drag.task.duration > other.start
);
drag.candidate = candidate;
drag.valid = !overlaps;
drag.task.block.style.left = `${candidate * MINUTE_WIDTH}px`;
drag.task.block.style.opacity = overlaps ? "0.55" : "1";
});
window.addEventListener("pointerup", () => {
if (!drag) return;
if (drag.valid && drag.candidate !== drag.task.start) {
drag.task.start = drag.candidate;
scheduleChanged();
showToast(`${drag.task.name} moved to ${formatMinute(drag.task.start)}.`);
} else if (!drag.valid) {
showToast("One character cannot perform two tasks at the same time.");
}
drag.task.block.style.opacity = "1";
drag = null;
});
function moveTask(task, candidate) {
candidate = THREE.MathUtils.clamp(candidate, 0, TOTAL_MINUTES - task.duration);
const overlaps = tasks.some(other =>
other.id !== task.id &&
other.actor === task.actor &&
candidate < other.start + other.duration &&
candidate + task.duration > other.start
);
if (overlaps) {
showToast("That move would overlap another task in the same lane.");
return;
}
task.start = candidate;
scheduleChanged();
}
function formatMinute(value) {
const rounded = Math.round(value * 100) / 100;
const whole = Math.floor(rounded);
const fraction = rounded - whole;
const symbols = [":00", ":15", ":30", ":45"];
const index = Math.round(fraction * 4);
return `${whole}${symbols[index]}`;
}
function invalidDependencies(task) {
return task.deps.filter(depId => {
const dep = taskById[depId];
return dep.start + dep.duration > task.start + 0.0001;
});
}
function selectTask(id) {
selectedTaskId = id;
renderTimeline();
}
function renderTaskDetail() {
const task = taskById[selectedTaskId];
if (!task) return;
const invalid = invalidDependencies(task);
const dependencies = task.deps.length
? task.deps.map(depId => {
const dep = taskById[depId];
return `<span class="dependency-chip">${dep.name}</span>`;
}).join("")
: `<span class="dependency-chip">No prerequisites</span>`;
taskDetail.innerHTML = `
<h3>${task.name}</h3>
<p><strong>${task.duration} fictional minute${task.duration === 1 ? "" : "s"}</strong>
· ${rooms[task.room].name}</p>
<p>${task.deps.length ? "Must follow:" : "This task can be moved freely unless it overlaps another task."}</p>
<div>${dependencies}</div>
${invalid.length
? `<p style="color:#a24842"><strong>Order problem:</strong>
${invalid.map(id => taskById[id].name).join(" and ")} finish after this task starts.</p>`
: ""}
`;
}
function renderTimeline() {
for (const task of tasks) {
task.block.style.left = `${task.start * MINUTE_WIDTH}px`;
task.block.style.width = `${task.duration * MINUTE_WIDTH}px`;
task.block.classList.toggle("selected", task.id === selectedTaskId);
task.block.classList.toggle("invalid", invalidDependencies(task).length > 0);
}
const invalidTasks = tasks.filter(task => invalidDependencies(task).length);
if (invalidTasks.length) {
scheduleWarning.classList.remove("good");
scheduleWarning.innerHTML = `
<strong>Dependency warning.</strong>
${invalidTasks.map(task => `${task.actor === "pip" ? "Pip" : "Nia"}: ${task.name}`).join("; ")}.
Move the missing prerequisite earlier or the dependent task later.
`;
} else {
scheduleWarning.classList.add("good");
scheduleWarning.innerHTML =
"<strong>Schedule order looks sound.</strong> Replay to check the physical belongings and door outcomes.";
}
renderTaskDetail();
requestAnimationFrame(drawDependencyArrows);
}
function drawDependencyArrows() {
const existing = dependencySvg.querySelectorAll("path.dependency-path");
existing.forEach(path => path.remove());
const innerRect = timelineInner.getBoundingClientRect();
for (const task of tasks) {
for (const depId of task.deps) {
const dep = taskById[depId];
const depRect = dep.block.getBoundingClientRect();
const taskRect = task.block.getBoundingClientRect();
const x1 = depRect.left - innerRect.left;
const y1 = depRect.top - innerRect.top + depRect.height / 2;
const x2 = taskRect.left - innerRect.left;
const y2 = taskRect.top - innerRect.top + taskRect.height / 2;
const invalid = invalidDependencies(task).includes(depId);
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
path.setAttribute("class", "dependency-path");
path.setAttribute("fill", "none");
path.setAttribute("stroke", invalid ? "#c85d54" : "#b47b46");
path.setAttribute("stroke-width", invalid ? "2.5" : "2");
path.setAttribute("stroke-dasharray", invalid ? "5 4" : "0");
path.setAttribute("marker-end", invalid ? "url(#badArrowHead)" : "url(#arrowHead)");
path.setAttribute("opacity", "0.9");
if (invalid) {
const sx = x1 + depRect.width / 2;
const sy = y1;
const ex = x2 + taskRect.width / 2;
const ey = y2;
const bend = 36;
path.setAttribute(
"d",
`M ${sx} ${sy} C ${sx + bend} ${sy + bend}, ${ex + bend} ${ey + bend}, ${ex} ${ey}`
);
} else {
const mid = (x1 + depRect.width + x2) / 2;
path.setAttribute(
"d",
`M ${x1 + depRect.width} ${y1} C ${mid} ${y1}, ${mid} ${y2}, ${x2} ${y2}`
);
}
dependencySvg.appendChild(path);
}
}
}
// -------------------------------------------------------------------------
// Simulation
// -------------------------------------------------------------------------
function simulateSchedule() {
const result = {
actors: {
pip: { segments: [], taskInfo: {} },
nia: { segments: [], taskInfo: {} }
}
};
for (const actorId of ["pip", "nia"]) {
const actorTasks = tasks
.filter(task => task.actor === actorId)
.slice()
.sort((a, b) => a.start - b.start);
const actorResult = result.actors[actorId];
const completions = {};
let previousLocation = actors[actorId].home.clone();
let previousEnd = 0;
let stopped = false;
for (const task of actorTasks) {
if (stopped) {
actorResult.taskInfo[task.id] = {
status: "skipped",
completion: null,
unmet: []
};
continue;
}
if (task.start > previousEnd + 0.0001) {
actorResult.segments.push({
type: "hold",
start: previousEnd,
end: task.start,
location: previousLocation.clone()
});
}
const unmet = task.deps.filter(depId => {
const dep = taskById[depId];
const completion = completions[depId];
return completion === undefined || completion > task.start + 0.0001;
});
const arrival = task.start + Math.min(0.28, task.duration * 0.22);
actorResult.segments.push({
type: "move",
start: task.start,
end: arrival,
from: previousLocation.clone(),
to: task.location.clone()
});
if (unmet.length) {
actorResult.segments.push({
type: "blocked",
start: arrival,
end: TOTAL_MINUTES + 1,
location: task.location.clone()
});
actorResult.taskInfo[task.id] = {
status: "blocked",
completion: null,
unmet,
blockedAt: arrival
};
stopped = true;
previousEnd = TOTAL_MINUTES + 1;
previousLocation = task.location.clone();
continue;
}
actorResult.segments.push({
type: "work",
start: arrival,
end: task.end ?? (task.start + task.duration),
location: task.location.clone()
});
const completion = task.start + task.duration;
completions[task.id] = completion;
actorResult.taskInfo[task.id] = {
status: "complete",
completion,
unmet: []
};
previousEnd = completion;
previousLocation = task.location.clone();
}
if (previousEnd < TOTAL_MINUTES + 1) {
actorResult.segments.push({
type: "hold",
start: previousEnd,
end: TOTAL_MINUTES + 1,
location: previousLocation.clone()
});
}
}
return result;
}
function scheduleChanged() {
currentTime = 0;
playing = false;
simulation = simulateSchedule();
scrub.value = 0;
playButton.textContent = "▶ Replay morning";
replayState.textContent = "fictional time";
renderTimeline();
updateScene(0);
}
function smoothstep(t) {
return t * t * (3 - 2 * t);
}
function sampleActor(actorId, time) {
const segments = simulation.actors[actorId].segments;
let segment = segments[segments.length - 1];
for (const candidate of segments) {
if (time >= candidate.start && time < candidate.end) {
segment = candidate;
break;
}
}
if (segment.type === "move") {
const t = THREE.MathUtils.clamp(
(time - segment.start) / Math.max(0.0001, segment.end - segment.start),
0,
1
);
const eased = smoothstep(t);
const location = segment.from.clone().lerp(segment.to, eased);
const delta = segment.to.clone().sub(segment.from);
const angle = Math.atan2(delta.x, delta.z);
return { location, moving: true, doing: false, angle };
}
return {
location: segment.location.clone(),
moving: false,
doing: segment.type === "work",
angle: null
};
}
function taskIsComplete(taskId, time = currentTime) {
const task = taskById[taskId];
const info = simulation.actors[task.actor].taskInfo[taskId];
return Boolean(info?.completion !== null && info?.completion !== undefined && time >= info.completion);
}
function updateCharacterVisual(actor, moving, doing) {
const phase = performance.now() * 0.012;
if (moving) {
actor.leftLeg.rotation.x = Math.sin(phase) * 0.48;
actor.rightLeg.rotation.x = -Math.sin(phase) * 0.48;
actor.leftArm.rotation.x = -Math.sin(phase) * 0.38;
actor.rightArm.rotation.x = Math.sin(phase) * 0.38;
} else {
actor.leftLeg.rotation.x *= 0.8;
actor.rightLeg.rotation.x *= 0.8;
actor.leftArm.rotation.x *= 0.8;
actor.rightArm.rotation.x *= 0.8;
}
if (doing) {
actor.rightArm.rotation.x = -0.72 + Math.sin(phase * 1.3) * 0.16;
actor.leftArm.rotation.x = -0.32;
}
}
// -------------------------------------------------------------------------
// Status, report, and scene synchronization
// -------------------------------------------------------------------------
let lastSummarySignature = "";
function renderStatus() {
for (const task of tasks) {
const info = simulation.actors[task.actor].taskInfo[task.id];
let status = "planned";
if (info?.status === "skipped") {
status = "skipped";
} else if (info?.status === "blocked") {
status = currentTime >= info.blockedAt ? "blocked" : "planned";
} else if (info?.completion !== null && info?.completion !== undefined) {
status = currentTime >= info.completion ? "done" :
currentTime >= task.start ? "doing" : "planned";
}
task.block.classList.toggle("doing", status === "doing");
task.block.classList.toggle("done", status === "done");
task.block.classList.toggle("blocked", status === "blocked");
if (status === "blocked") {
const missing = info.unmet.map(id => taskById[id].prerequisiteText).join(" + ");
setSpriteText(
task.blockedSprite,
"BLOCKED",
`Missing: ${missing}`,
true
);
task.blockedSprite.visible = true;
} else {
task.blockedSprite.visible = false;
}
const markerColor = status === "done" ? 0x65a482 :
status === "doing" ? 0x3f91b4 :
status === "blocked" ? 0xd35e54 : 0x8cb9c9;
task.marker.material.color.setHex(markerColor);
}
const report = [];
for (const actorId of ["pip", "nia"]) {
const actor = actors[actorId];
const actorTasks = tasks.filter(task => task.actor === actorId);
const leave = actorTasks.find(task => task.id.endsWith("-leave"));
const leaveInfo = simulation.actors[actorId].taskInfo[leave.id];
const blocked = actorTasks.find(task =>
simulation.actors[actorId].taskInfo[task.id]?.status === "blocked"
);
let reachedDoor = leaveInfo?.completion !== null &&
leaveInfo?.completion !== undefined &&
currentTime >= leaveInfo.completion;
let statusText = reachedDoor ? "Reached the door" :
blocked ? `Stopped in ${rooms[blocked.room].name.toLowerCase()}` : "Not at the door yet";
let statusClass = reachedDoor ? "reached" : blocked ? "blocked" : "";
const carried = actorTasks
.filter(task => carryNames[task.id])
.filter(task => taskIsComplete(task.id))
.map(task => carryNames[task.id]);
const carryHTML = carried.length
? carried.map(name => `<span class="carry-chip">✓ ${name}</span>`).join("")
: `<span class="carry-chip">Nothing carried yet</span>`;
let blockedHTML = "";
if (blocked) {
const info = simulation.actors[actorId].taskInfo[blocked.id];
const missing = info.unmet.map(id => taskById[id].prerequisiteText).join(" + ");
blockedHTML = `
<div class="summary-line">
<strong>Unfinished action:</strong> ${blocked.name}.<br />
<strong>Unmet dependency:</strong>
<span class="missing-chip">${missing}</span>
</div>
`;
}
report.push(`
<div class="summary-card ${statusClass}">
<div class="summary-head">
<strong>${actor.name}</strong>
<span class="status-pill">${statusText}</span>
</div>
${blockedHTML}
<div class="summary-line"><strong>Carried:</strong></div>
<div class="carry-list">${carryHTML}</div>
</div>
`);
}
const signature = report.join("") + currentTime.toFixed(2);
if (signature !== lastSummarySignature) {
summary.innerHTML = report.join("");
lastSummarySignature = signature;
}
}
function updateScene(time) {
for (const actorId of ["pip", "nia"]) {
const actor = actors[actorId];
const sampled = sampleActor(actorId, time);
actor.group.position.set(sampled.location.x, 0, sampled.location.z);
if (sampled.angle !== null) {
const targetAngle = sampled.angle;
let difference = targetAngle - actor.group.rotation.y;
while (difference > Math.PI) difference -= Math.PI * 2;
while (difference < -Math.PI) difference += Math.PI * 2;
actor.group.rotation.y += difference * 0.2;
}
updateCharacterVisual(actor, sampled.moving, sampled.doing);
}
actors.pip.bag.visible = taskIsComplete("p-bag", time);
actors.pip.keys.visible = taskIsComplete("p-keys", time);
actors.nia.bag.visible = taskIsComplete("n-bag", time);
actors.nia.keys.visible = taskIsComplete("n-keys", time);
actors.nia.lunchbox.visible = taskIsComplete("n-pack", time);
sandwich.visible =
taskIsComplete("n-prep", time) &&
!taskIsComplete("n-pack", time);
const pipLeft = taskIsComplete("p-leave", time);
const niaLeft = taskIsComplete("n-leave", time);
const doorTarget = pipLeft || niaLeft ? -1.12 : 0;
apartment.doorPivot.rotation.y +=
(doorTarget - apartment.doorPivot.rotation.y) * 0.08;
timeCursor.style.left = `${80 + time * MINUTE_WIDTH}px`;
timeNow.textContent = formatMinute(time);
scrub.value = time;
renderStatus();
}
// -------------------------------------------------------------------------
// Playback and controls
// -------------------------------------------------------------------------
playButton.addEventListener("click", () => {
if (currentTime >= TOTAL_MINUTES - 0.001) {
currentTime = 0;
}
playing = !playing;
playButton.textContent = playing ? "Ⅱ Pause replay" : "▶ Replay morning";
replayState.textContent = playing ? "replaying" : "fictional time";
});
scrub.addEventListener("input", event => {
playing = false;
currentTime = Number(event.target.value);
playButton.textContent = "▶ Replay morning";
replayState.textContent = "fictional time";
});
document.getElementById("resetButton").addEventListener("click", () => {
for (const task of tasks) {
task.start = defaultStarts[task.id];
}
scheduleChanged();
showToast("The original schedule has been restored.");
});
// Direct camera controls, implemented without Three.js addons.
const cameraState = {
yaw: 0.47,
elevation: 0.59,
distance: 18.3,
target: new THREE.Vector3(0, 0.25, 0)
};
function updateCamera() {
const horizontal = Math.cos(cameraState.elevation) * cameraState.distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.elevation) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
let cameraDragging = false;
let cameraLastX = 0;
let cameraLastY = 0;
canvas.addEventListener("pointerdown", event => {
cameraDragging = true;
cameraLastX = event.clientX;
cameraLastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!cameraDragging) return;
const dx = event.clientX - cameraLastX;
const dy = event.clientY - cameraLastY;
cameraLastX = event.clientX;
cameraLastY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.0045,
0.28,
1.12
);
updateCamera();
});
canvas.addEventListener("pointerup", event => {
cameraDragging = false;
canvas.releasePointerCapture?.(event.pointerId);
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.012,
11,
26
);
updateCamera();
}, { passive: false });
document.getElementById("viewButton").addEventListener("click", () => {
cameraState.yaw = 0.47;
cameraState.elevation = 0.59;
cameraState.distance = 18.3;
cameraState.target.set(0, 0.25, 0);
updateCamera();
});
document.getElementById("zoomIn").addEventListener("click", () => {
cameraState.distance = Math.max(11, cameraState.distance - 1.5);
updateCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
cameraState.distance = Math.min(26, cameraState.distance + 1.5);
updateCamera();
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(1, height);
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
// -------------------------------------------------------------------------
// Start
// -------------------------------------------------------------------------
simulation = simulateSchedule();
renderTimeline();
resize();
updateCamera();
let previousFrame = performance.now();
function animate(now) {
const dt = Math.min(0.05, (now - previousFrame) / 1000);
previousFrame = now;
if (playing) {
const speed = Number(document.getElementById("speedSelect").value);
currentTime = Math.min(TOTAL_MINUTES, currentTime + dt * speed);
if (currentTime >= TOTAL_MINUTES) {
playing = false;
playButton.textContent = "↻ Replay again";
replayState.textContent = "morning complete";
}
}
updateScene(currentTime);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```