Prompt specification
Build or customize the Three.js 3D scene "Alternate Choices Different Story Outcomes" 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: Alternate Choices Different Story Outcomes
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/alternate-choices-different-story-outcomes-x3704
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a low-poly interactive story about a misplaced sketchbook. Two original characters share a small workshop containing a table, shelf, and clearly marked lost-and-found tray. The player can leave the sketchbook where it was found or move it to the tray and place a visible note. Replay a short sequence showing the returning character searching according to the objects and clues actually present. Keep the book's identity and location consistent across both branches. Show different observable outcomes without labeling either character dishonest or inferring an intention that the animation has not established.
Working Three.js Starter (alternate-choices-different-story-outcomes-x3704):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Sketchbook Between Us</title>
<style>
:root {
--ink: #23312f;
--muted: #66726d;
--paper: #fffaf0;
--teal: #196b68;
--teal-dark: #104c4a;
--coral: #df765f;
--ochre: #d6a641;
--line: rgba(35, 49, 47, 0.14);
--shadow: 0 18px 60px rgba(32, 44, 40, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e0d8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
textarea {
font: inherit;
}
button {
cursor: pointer;
}
button:focus-visible,
textarea:focus-visible {
outline: 3px solid rgba(214, 166, 65, 0.8);
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 5;
top: 0;
left: 0;
right: 0;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18px;
padding: 20px 24px;
pointer-events: none;
}
.brand {
max-width: 460px;
padding: 13px 16px 14px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 16px;
background: rgba(255, 250, 240, 0.86);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 0.69rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(1.28rem, 2.4vw, 2rem);
font-weight: 600;
line-height: 1.05;
}
.brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 0.79rem;
}
.top-tools {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
pointer-events: auto;
}
.badge {
max-width: min(360px, 42vw);
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 999px;
background: rgba(255, 250, 240, 0.88);
box-shadow: 0 8px 30px rgba(32, 44, 40, 0.12);
color: var(--muted);
font-size: 0.74rem;
font-weight: 700;
text-align: right;
backdrop-filter: blur(12px);
}
.badge strong {
color: var(--teal-dark);
}
.small-button {
border: 1px solid rgba(35, 49, 47, 0.18);
border-radius: 999px;
padding: 8px 12px;
background: rgba(255, 250, 240, 0.84);
color: var(--ink);
font-size: 0.72rem;
font-weight: 750;
box-shadow: 0 6px 20px rgba(32, 44, 40, 0.09);
}
.small-button:hover {
background: #fff;
transform: translateY(-1px);
}
.panel {
position: fixed;
z-index: 4;
width: min(375px, calc(100vw - 28px));
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 20px;
background: rgba(255, 250, 240, 0.93);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
overflow: hidden;
}
#story-panel {
left: 18px;
bottom: 18px;
padding: 19px;
}
#replay-panel {
right: 18px;
bottom: 18px;
padding: 18px;
}
.panel h2 {
margin: 0 0 9px;
font-family: Georgia, "Times New Roman", serif;
font-size: 1.28rem;
font-weight: 600;
}
.panel p {
margin: 0;
color: var(--muted);
font-size: 0.82rem;
line-height: 1.55;
}
.facts {
display: grid;
grid-template-columns: 54px 1fr;
gap: 7px 10px;
margin: 15px 0;
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.43);
font-size: 0.76rem;
}
.facts span:nth-child(odd) {
color: var(--teal);
font-size: 0.65rem;
font-weight: 850;
letter-spacing: 0.09em;
}
.choice-grid {
display: grid;
gap: 9px;
}
.choice-button {
width: 100%;
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: #fff;
color: var(--ink);
font-size: 0.82rem;
font-weight: 800;
text-align: left;
transition: 150ms ease;
}
.choice-button span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.69rem;
font-weight: 500;
}
.choice-button:hover:not(:disabled) {
border-color: rgba(25, 107, 104, 0.48);
background: #f4fbf8;
transform: translateY(-1px);
}
.choice-button.primary {
border-color: var(--teal);
background: var(--teal);
color: white;
}
.choice-button.primary span {
color: rgba(255, 255, 255, 0.72);
}
.choice-button.primary:hover:not(:disabled) {
background: var(--teal-dark);
}
.choice-button:disabled {
cursor: default;
opacity: 0.52;
}
#note-composer {
margin-top: 11px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
#note-composer label {
display: block;
margin-bottom: 6px;
color: var(--teal-dark);
font-size: 0.72rem;
font-weight: 850;
}
#note-text {
width: 100%;
min-height: 76px;
resize: vertical;
padding: 10px;
border: 1px solid rgba(35, 49, 47, 0.2);
border-radius: 10px;
background: #fffdf7;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
font-size: 0.82rem;
line-height: 1.35;
}
#place-button {
width: 100%;
margin-top: 8px;
border: 0;
border-radius: 10px;
padding: 11px;
background: var(--coral);
color: #fff;
font-weight: 800;
}
#place-button:hover:not(:disabled) {
background: #c9614e;
}
#decision-state {
margin-top: 12px;
padding: 10px 12px;
border-left: 3px solid var(--ochre);
background: rgba(214, 166, 65, 0.11);
color: var(--muted);
font-size: 0.73rem;
line-height: 1.45;
}
.sequence-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.sequence-heading h2 {
margin-bottom: 3px;
}
#sequence {
display: grid;
gap: 8px;
margin: 14px 0;
padding: 0;
list-style: none;
counter-reset: sequence;
}
#sequence li {
position: relative;
min-height: 34px;
padding: 8px 8px 8px 36px;
border-radius: 10px;
color: var(--muted);
font-size: 0.75rem;
line-height: 1.4;
opacity: 0.45;
transition: 220ms ease;
counter-increment: sequence;
}
#sequence li::before {
content: counter(sequence);
position: absolute;
top: 7px;
left: 7px;
display: grid;
width: 21px;
height: 21px;
place-items: center;
border-radius: 50%;
background: #e6ece7;
color: var(--teal-dark);
font-size: 0.64rem;
font-weight: 850;
}
#sequence li.current {
background: rgba(214, 166, 65, 0.13);
color: var(--ink);
opacity: 1;
}
#sequence li.current::before {
background: var(--ochre);
color: #fff;
}
#sequence li.done {
color: var(--teal-dark);
opacity: 1;
}
#sequence li.done::before {
content: "✓";
background: var(--teal);
color: #fff;
}
#outcome {
margin-bottom: 13px;
padding: 12px;
border: 1px solid rgba(25, 107, 104, 0.18);
border-radius: 12px;
background: rgba(25, 107, 104, 0.07);
}
#outcome h3 {
margin: 0 0 5px;
color: var(--teal-dark);
font-family: Georgia, "Times New Roman", serif;
font-size: 1rem;
}
#outcome p {
font-size: 0.73rem;
}
.replay-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.replay-actions button {
border-radius: 10px;
padding: 10px 8px;
font-size: 0.72rem;
font-weight: 800;
}
#replay-button {
border: 0;
background: var(--teal);
color: white;
}
#change-button {
border: 1px solid var(--line);
background: #fff;
color: var(--ink);
}
.observational-note {
margin-top: 10px !important;
font-size: 0.66rem !important;
color: #89928d !important;
}
#toast {
position: fixed;
z-index: 10;
left: 50%;
bottom: 25px;
max-width: min(500px, calc(100vw - 34px));
padding: 11px 15px;
border-radius: 999px;
background: rgba(35, 49, 47, 0.92);
color: white;
box-shadow: 0 12px 35px rgba(25, 35, 32, 0.2);
font-size: 0.76rem;
text-align: center;
pointer-events: none;
opacity: 0;
transform: translate(-50%, 12px);
transition: 200ms ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #e8e8dc;
color: var(--teal-dark);
font-family: Georgia, "Times New Roman", serif;
font-size: 1.2rem;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
padding: 10px;
}
.brand {
max-width: calc(100vw - 112px);
padding: 10px 12px;
}
.brand p {
display: none;
}
.brand h1 {
font-size: 1.12rem;
}
.badge {
max-width: 92px;
border-radius: 12px;
text-align: left;
font-size: 0.65rem;
}
#story-panel {
left: 8px;
right: 8px;
bottom: 8px;
width: auto;
max-height: 43vh;
overflow-y: auto;
padding: 14px;
}
#replay-panel {
left: 8px;
right: 8px;
bottom: 8px;
width: auto;
max-height: 47vh;
overflow-y: auto;
padding: 14px;
}
.facts {
margin: 10px 0;
}
#toast {
bottom: auto;
top: 74px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly workshop scene"></canvas>
<header class="topbar">
<div class="brand">
<p class="eyebrow">An interactive miniature</p>
<h1>The Sketchbook Between Us</h1>
<p>Drag empty space to orbit · Scroll to zoom · Click the book to inspect it</p>
</div>
<div class="top-tools">
<div class="badge" id="location-badge">
<strong>Book:</strong> blue cover, ochre corner tab<br>
<strong>Location:</strong> worktable, beside the blue mug
</div>
<button class="small-button" id="reset-view" type="button">Reset view</button>
</div>
</header>
<section class="panel" id="story-panel" aria-labelledby="story-title">
<p class="eyebrow">Mara finds something</p>
<h2 id="story-title">One book. Two possible places.</h2>
<p>
Mara finds a blue field sketchbook with an ochre corner tab beside a blue mug.
Jules returns in a moment. Leave the book where it was found, or place it in
the marked lost-and-found tray with a visible note.
</p>
<div class="facts" aria-label="Object facts">
<span>BOOK</span><span>Blue cover · ochre corner tab · small brass clasp</span>
<span>FOUND</span><span>On the worktable beside the blue mug</span>
<span>PEOPLE</span><span>Mara, the maker, and Jules, returning to the workshop</span>
</div>
<div class="choice-grid" id="choice-grid">
<button class="choice-button" id="leave-button" type="button">
Leave it on the worktable
<span>The book stays exactly beside the blue mug.</span>
</button>
<button class="choice-button primary" id="move-button" type="button">
Move it to lost-and-found
<span>The book and your note will be placed in the marked tray.</span>
</button>
</div>
<div id="note-composer" hidden>
<label for="note-text">Visible note for the tray</label>
<textarea id="note-text" maxlength="130">Moved from the worktable beside the blue mug. Please leave it in the lost-and-found tray.</textarea>
<button id="place-button" type="button">Place the book and note in the tray</button>
</div>
<div id="decision-state" hidden></div>
</section>
<section class="panel" id="replay-panel" aria-labelledby="replay-title" hidden>
<div class="sequence-heading">
<div>
<p class="eyebrow">Jules returns</p>
<h2 id="replay-title">Replay the search</h2>
</div>
</div>
<ol id="sequence" aria-live="polite"></ol>
<div id="outcome" hidden>
<h3 id="outcome-title"></h3>
<p id="outcome-text"></p>
</div>
<div class="replay-actions">
<button id="replay-button" type="button">Replay sequence</button>
<button id="change-button" type="button">Change the decision</button>
</div>
<p class="observational-note">
Outcomes describe visible objects and actions only; no motive is assigned.
</p>
</section>
<div id="toast" role="status"></div>
<div id="loading">Opening the workshop…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const canvas = $("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce3da");
scene.fog = new THREE.Fog("#dce3da", 14, 28);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraState = {
target: new THREE.Vector3(-0.15, 1.35, -0.55),
yaw: 0.46,
pitch: 0.34,
distance: 12.1
};
function updateCamera() {
const cp = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * cp * cameraState.distance,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * cp * cameraState.distance
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight("#fff6df", "#718579", 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff1cb", 3.1);
sun.position.set(-3.5, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -9;
sun.shadow.camera.right = 9;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.PointLight("#9ed7cf", 12, 14, 2);
fill.position.set(4, 4.5, 2);
scene.add(fill);
function standard(color, roughness = 0.86, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
}
const materials = {
floor: standard("#c8b996"),
wall: standard("#eee5d2"),
wallTrim: standard("#d3c4aa"),
wood: standard("#a87548"),
woodLight: standard("#c8945e"),
woodDark: standard("#76503a"),
teal: standard("#1f7773"),
tealDark: standard("#174f50"),
blue: standard("#477e9e"),
coral: standard("#db765e"),
ochre: standard("#d4a641"),
cream: standard("#fff0c9"),
metal: standard("#88928b", 0.45, 0.55),
green: standard("#66865d"),
greenDark: standard("#466844"),
soil: standard("#58483b"),
black: standard("#27312e")
};
function addMesh(geometry, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
return addMesh(new THREE.BoxGeometry(w, h, d), material, x, y, z, parent);
}
function cylinder(rt, rb, h, material, x = 0, y = 0, z = 0, segments = 8, parent = scene) {
return addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material,
x,
y,
z,
parent
);
}
function sphere(radius, material, x = 0, y = 0, z = 0, detail = 0, parent = scene) {
return addMesh(
new THREE.IcosahedronGeometry(radius, detail),
material,
x,
y,
z,
parent
);
}
function wrapText(ctx, text, maxWidth) {
const output = [];
for (const paragraph of text.split("\n")) {
const words = paragraph.split(/\s+/).filter(Boolean);
if (!words.length) {
output.push("");
continue;
}
let line = words[0];
for (let i = 1; i < words.length; i++) {
const test = `${line} ${words[i]}`;
if (ctx.measureText(test).width > maxWidth) {
output.push(line);
line = words[i];
} else {
line = test;
}
}
output.push(line);
}
return output;
}
function makeTextTexture(text, options = {}) {
const {
width = 1024,
height = 512,
background = "#fff0c9",
foreground = "#23312f",
fontSize = 74,
padding = 48,
align = "center",
transparent = false
} = options;
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
if (!transparent) {
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
}
ctx.fillStyle = foreground;
ctx.textBaseline = "middle";
ctx.textAlign = align;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
const x = align === "left" ? padding : width / 2;
const lines = wrapText(ctx, text, width - padding * 2);
const lineHeight = fontSize * 1.12;
let y = (height - lines.length * lineHeight) / 2 + lineHeight / 2;
for (const line of lines) {
ctx.fillText(line, x, y, width - padding * 2);
y += lineHeight;
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function textPlane(text, w, h, options = {}) {
const texture = makeTextTexture(text, options);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: !!options.transparent,
toneMapped: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(w, h), material);
mesh.castShadow = false;
mesh.receiveShadow = false;
return mesh;
}
function nameSprite(name) {
const c = document.createElement("canvas");
c.width = 512;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(255,250,240,.94)";
ctx.beginPath();
ctx.roundRect(8, 8, 496, 112, 56);
ctx.fill();
ctx.strokeStyle = "rgba(35,49,47,.16)";
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = "#23312f";
ctx.font = "800 54px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(name, 256, 66);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
toneMapped: false
})
);
sprite.scale.set(1.35, 0.34, 1);
return sprite;
}
// Room shell.
box(12.5, 0.18, 10.5, materials.floor, 0, -0.12, -0.2);
box(12.5, 6.2, 0.22, materials.wall, 0, 3.0, -4.7);
box(0.22, 6.2, 10.5, materials.wall, -6.15, 3.0, -0.2);
box(12.5, 0.16, 0.25, materials.wallTrim, 0, 0.12, -4.52);
box(0.25, 0.16, 10.5, materials.wallTrim, -5.98, 0.12, -0.2);
for (let x = -5; x <= 5; x += 1) {
box(0.012, 0.004, 10, standard("#b6a887"), x, -0.025, -0.2);
}
for (let z = -5; z <= 4; z += 1) {
box(12, 0.004, 0.012, standard("#b6a887"), 0, -0.025, z);
}
// Back-wall window.
box(2.35, 1.75, 0.12, materials.woodDark, -3.65, 3.65, -4.48);
box(2.06, 1.46, 0.06, standard("#a8d0d3"), -3.65, 3.65, -4.39);
box(0.09, 1.5, 0.08, materials.cream, -3.65, 3.65, -4.33);
box(2.1, 0.09, 0.08, materials.cream, -3.65, 3.65, -4.32);
box(2.65, 0.16, 0.42, materials.woodLight, -3.65, 2.72, -4.31);
// Small pinned sketches.
const art1 = textPlane("COLOR\nSTUDY", 0.75, 0.95, {
background: "#f7d889",
foreground: "#385d64",
fontSize: 70
});
art1.position.set(-1.15, 3.9, -4.54);
scene.add(art1);
box(0.11, 0.11, 0.04, materials.coral, -1.15, 4.31, -4.49);
const art2 = textPlane("FORM &\nLIGHT", 0.74, 0.92, {
background: "#d7e5d4",
foreground: "#3b6657",
fontSize: 68
});
art2.position.set(-0.16, 3.9, -4.54);
scene.add(art2);
box(0.11, 0.11, 0.04, materials.ochre, -0.16, 4.31, -4.49);
// Wall shelf.
box(8.5, 0.18, 0.72, materials.woodLight, -0.95, 2.62, -4.12);
box(8.5, 0.18, 0.72, materials.woodLight, -0.95, 3.83, -4.12);
box(0.18, 1.6, 0.6, materials.woodDark, -4.85, 3.15, -4.18);
box(0.18, 1.6, 0.6, materials.woodDark, 2.95, 3.15, -4.18);
const shelfLabel = textPlane("SUPPLIES", 1.25, 0.36, {
background: "#ead9b8",
foreground: "#6b513b",
fontSize: 72
});
shelfLabel.position.set(-1.1, 2.25, -3.73);
scene.add(shelfLabel);
const jarColors = ["#91a9a0", "#d2a25d", "#b66e60", "#7d91a6"];
for (let i = 0; i < 4; i++) {
const x = -4.05 + i * 0.67;
cylinder(0.19, 0.22, 0.48, standard(jarColors[i]), x, 2.95, -4.05, 8);
cylinder(0.21, 0.21, 0.08, materials.woodDark, x, 3.22, -4.05, 8);
}
const shelfBookColors = ["#637e78", "#9e6d5e", "#c69e5a", "#687b91", "#8d8068"];
for (let i = 0; i < 5; i++) {
const h = 0.55 + (i % 3) * 0.1;
box(0.18, h, 0.42, standard(shelfBookColors[i]), -0.62 + i * 0.24, 4.12 + h / 2, -4.04);
}
for (let i = 0; i < 3; i++) {
cylinder(0.22, 0.25, 0.43, standard(["#d7c9a8", "#aebbaa", "#d3a58d"][i]), 0.55 + i * 0.67, 4.13, -4.05, 8);
cylinder(0.23, 0.23, 0.07, materials.woodDark, 0.55 + i * 0.67, 4.37, -4.05, 8);
}
// Worktable.
box(5.0, 0.18, 3.0, materials.woodLight, -0.6, 1.55, 0);
box(4.72, 0.06, 2.73, materials.wood, -0.6, 1.42, 0);
for (const x of [-2.75, 1.55]) {
for (const z of [-1.15, 1.15]) {
box(0.2, 1.42, 0.2, materials.woodDark, x, 0.7, z);
}
}
box(4.5, 0.15, 0.16, materials.woodDark, -0.6, 0.42, -1.1);
box(4.5, 0.15, 0.16, materials.woodDark, -0.6, 0.42, 1.1);
// Blue mug beside the book.
const mug = new THREE.Group();
mug.position.set(-1.3, 1.64, 0.12);
scene.add(mug);
cylinder(0.23, 0.2, 0.34, materials.blue, 0, 0.17, 0, 10, mug);
cylinder(0.19, 0.19, 0.018, standard("#60483c"), 0, 0.345, 0, 10, mug);
const mugHandle = addMesh(
new THREE.TorusGeometry(0.15, 0.045, 6, 12),
materials.blue,
-0.25,
0.18,
0,
mug
);
mugHandle.rotation.y = Math.PI / 2;
// Pencil cup.
const pencilCup = new THREE.Group();
pencilCup.position.set(0.92, 1.64, -0.55);
scene.add(pencilCup);
cylinder(0.24, 0.19, 0.43, standard("#806f5d"), 0, 0.22, 0, 8, pencilCup);
const pencilColors = ["#d86951", "#d6a641", "#3d7776", "#5f668f"];
for (let i = 0; i < 4; i++) {
const pencil = cylinder(
0.025,
0.025,
0.72,
standard(pencilColors[i]),
(i - 1.5) * 0.07,
0.57,
(i % 2) * 0.035,
6,
pencilCup
);
pencil.rotation.z = (i - 1.5) * 0.055;
}
// Task lamp.
cylinder(0.34, 0.38, 0.08, materials.metal, 1.45, 1.69, -0.72, 10);
cylinder(0.045, 0.045, 0.88, materials.metal, 1.45, 2.1, -0.72, 7);
const lampArm = cylinder(0.045, 0.045, 0.75, materials.metal, 1.18, 2.47, -0.72, 7);
lampArm.rotation.z = Math.PI / 2;
addMesh(new THREE.ConeGeometry(0.28, 0.32, 8), materials.coral, 0.83, 2.47, -0.72);
// A folded plan, deliberately unlike the sketchbook.
const plan = box(0.85, 0.015, 0.62, standard("#ede0bd"), -1.72, 1.66, 0.87);
plan.rotation.y = -0.18;
const planLine = box(0.58, 0.008, 0.025, standard("#74908a"), -1.72, 1.674, 0.87);
planLine.rotation.y = -0.18;
// Right-hand counter and clearly marked tray.
box(2.55, 0.18, 1.8, materials.woodLight, 4.25, 1.15, -2.25);
for (const x of [3.25, 5.25]) {
for (const z of [-2.9, -1.65]) {
box(0.16, 1.08, 0.16, materials.woodDark, x, 0.54, z);
}
}
const tray = new THREE.Group();
tray.position.set(4.15, 1.3, -2.18);
scene.add(tray);
box(2.15, 0.12, 1.5, materials.tealDark, 0, 0, 0, tray);
box(2.15, 0.32, 0.09, materials.teal, 0, 0.14, -0.705, tray);
box(2.15, 0.32, 0.09, materials.teal, 0, 0.14, 0.705, tray);
box(0.09, 0.32, 1.5, materials.teal, -1.03, 0.14, 0, tray);
box(0.09, 0.32, 1.5, materials.teal, 1.03, 0.14, 0, tray);
const traySign = textPlane("LOST & FOUND", 1.55, 0.38, {
background: "#f3df9b",
foreground: "#264b48",
fontSize: 76
});
traySign.position.set(4.15, 1.54, -1.38);
scene.add(traySign);
const wallSign = textPlane("LOST & FOUND", 2.35, 0.66, {
background: "#f3df9b",
foreground: "#264b48",
fontSize: 82
});
wallSign.position.set(4.18, 3.22, -4.54);
scene.add(wallSign);
// A small plant.
cylinder(0.25, 0.2, 0.42, standard("#b66f54"), 2.55, 2.96, -4.05, 8);
cylinder(0.22, 0.22, 0.03, materials.soil, 2.55, 3.18, -4.05, 8);
for (let i = 0; i < 5; i++) {
const leaf = addMesh(
new THREE.ConeGeometry(0.18, 0.72, 5),
i % 2 ? materials.green : materials.greenDark,
2.55 + (i - 2) * 0.08,
3.5,
-4.05,
scene
);
leaf.rotation.z = (i - 2) * 0.18;
leaf.rotation.x = (i % 2 ? 0.18 : -0.14);
}
// Stool.
cylinder(0.48, 0.48, 0.14, materials.woodDark, -2.8, 0.78, 2.25, 10);
for (const a of [0, 2.1, 4.2]) {
const leg = cylinder(0.07, 0.09, 0.8, materials.woodDark, -2.8, 0.4, 2.25, 7);
leg.rotation.z = Math.cos(a) * 0.24;
leg.rotation.x = Math.sin(a) * 0.24;
}
// Entry mat.
box(1.35, 0.035, 0.65, standard("#8fa69b"), 4.95, -0.01, 3.35);
// The one sketchbook: blue cover, ochre corner, coral stripe, brass clasp.
const book = new THREE.Group();
scene.add(book);
box(1.05, 0.055, 1.35, materials.tealDark, 0, -0.055, 0, book);
box(0.98, 0.08, 1.27, materials.cream, 0, 0, 0, book);
box(1.05, 0.055, 1.35, materials.blue, 0, 0.055, 0, book);
box(0.1, 0.16, 1.35, materials.tealDark, -0.49, 0, 0, book);
box(0.25, 0.025, 0.48, materials.ochre, 0.42, 0.095, 0.46, book);
box(0.075, 0.018, 1.19, materials.coral, 0.25, 0.095, 0, book);
box(0.16, 0.05, 0.16, materials.ochre, 0.53, 0.01, -0.57, book);
const bookLabel = textPlane("FIELD SKETCHBOOK\nM. K.", 0.67, 0.28, {
background: "#e8dfbf",
foreground: "#263f43",
fontSize: 70
});
bookLabel.rotation.x = -Math.PI / 2;
bookLabel.position.set(-0.1, 0.086, -0.18);
book.add(bookLabel);
const bookHalo = new THREE.Mesh(
new THREE.RingGeometry(0.78, 0.84, 40),
new THREE.MeshBasicMaterial({
color: "#f4d474",
transparent: true,
opacity: 0.65,
side: THREE.DoubleSide,
depthWrite: false
})
);
bookHalo.rotation.x = -Math.PI / 2;
bookHalo.position.y = -0.095;
bookHalo.visible = false;
bookHalo.raycast = () => {};
book.add(bookHalo);
const BOOK_FOUND = new THREE.Vector3(-0.12, 1.735, 0.48);
const BOOK_TRAY = new THREE.Vector3(3.92, 1.435, -2.18);
book.position.copy(BOOK_FOUND);
book.rotation.set(0, -0.22, 0);
// The visible note is a real textured plane in the tray.
const noteCanvas = document.createElement("canvas");
noteCanvas.width = 896;
noteCanvas.height = 640;
const noteCtx = noteCanvas.getContext("2d");
const noteTexture = new THREE.CanvasTexture(noteCanvas);
noteTexture.colorSpace = THREE.SRGBColorSpace;
noteTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
function updateNoteTexture(text) {
noteCtx.clearRect(0, 0, noteCanvas.width, noteCanvas.height);
noteCtx.fillStyle = "#fff9df";
noteCtx.fillRect(0, 0, noteCanvas.width, noteCanvas.height);
noteCtx.strokeStyle = "#c6b789";
noteCtx.lineWidth = 8;
noteCtx.strokeRect(16, 16, noteCanvas.width - 32, noteCanvas.height - 32);
noteCtx.fillStyle = "#40605a";
noteCtx.font = "800 50px system-ui, sans-serif";
noteCtx.textAlign = "center";
noteCtx.fillText("A NOTE FOR JULES", noteCanvas.width / 2, 82);
noteCtx.strokeStyle = "#d5c795";
noteCtx.lineWidth = 3;
noteCtx.beginPath();
noteCtx.moveTo(85, 112);
noteCtx.lineTo(noteCanvas.width - 85, 112);
noteCtx.stroke();
noteCtx.fillStyle = "#334b47";
noteCtx.font = "500 43px Georgia, serif";
noteCtx.textBaseline = "middle";
const lines = wrapText(noteCtx, text || "Please return this book to the lost-and-found tray.", 730);
let y = 185;
for (const line of lines.slice(0, 8)) {
noteCtx.fillText(line, noteCanvas.width / 2, y, 740);
y += 57;
}
noteTexture.needsUpdate = true;
}
updateNoteTexture($("#note-text").value);
const noteGroup = new THREE.Group();
noteGroup.position.set(4.82, 1.39, -1.94);
noteGroup.rotation.y = -0.08;
noteGroup.visible = false;
scene.add(noteGroup);
box(0.91, 0.025, 0.66, materials.cream, 0, 0, 0, noteGroup);
const notePlane = new THREE.Mesh(
new THREE.PlaneGeometry(0.88, 0.63),
new THREE.MeshBasicMaterial({ map: noteTexture, toneMapped: false })
);
notePlane.rotation.x = -Math.PI / 2;
notePlane.position.y = 0.016;
noteGroup.add(notePlane);
// Original low-poly characters.
function createPerson(options) {
const {
name,
shirt,
pants,
hair,
skin,
glasses = false,
apron = false,
curls = false
} = options;
const root = new THREE.Group();
scene.add(root);
const body = new THREE.Group();
root.add(body);
box(0.67, 0.82, 0.4, standard(shirt), 0, 1.25, 0, body);
box(0.56, 0.11, 0.42, standard(pants), 0, 0.86, 0, body);
if (apron) {
box(0.55, 0.7, 0.055, materials.coral, 0, 1.15, 0.225, body);
box(0.15, 0.43, 0.035, materials.coral, 0.23, 1.61, 0.228, body);
box(0.15, 0.43, 0.035, materials.coral, -0.23, 1.61, 0.228, body);
}
const head = new THREE.Group();
head.position.set(0, 1.94, 0);
body.add(head);
const face = sphere(0.32, standard(skin), 0, 0, 0, 1, head);
face.scale.set(0.93, 1.05, 0.92);
sphere(0.035, materials.black, -0.105, 0.035, 0.277, 0, head);
sphere(0.035, materials.black, 0.105, 0.035, 0.277, 0, head);
sphere(0.045, standard(skin), 0, -0.045, 0.3, 0, head);
if (curls) {
const hairMat = standard(hair);
for (let i = 0; i < 9; i++) {
const a = (i / 9) * Math.PI * 2;
const curl = sphere(0.14, hairMat, Math.cos(a) * 0.25, 0.2 + Math.sin(i) * 0.035, Math.sin(a) * 0.21, 0, head);
curl.scale.set(1, 0.9, 1);
}
} else {
const cap = sphere(0.33, standard(hair), 0, 0.21, -0.015, 0, head);
cap.scale.set(1, 0.55, 0.95);
box(0.48, 0.09, 0.16, standard(hair), 0, 0.19, 0.25, head);
}
if (glasses) {
for (const x of [-0.11, 0.11]) {
const lens = addMesh(
new THREE.TorusGeometry(0.085, 0.015, 5, 12),
materials.black,
x,
0.035,
0.285,
head
);
lens.scale.set(1, 0.82, 1);
}
box(0.07, 0.015, 0.015, materials.black, 0, 0.035, 0.29, head);
}
function makeArm(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.43, 1.57, 0);
body.add(pivot);
cylinder(0.13, 0.115, 0.54, standard(shirt), 0, -0.25, 0, 7, pivot);
const hand = sphere(0.13, standard(skin), 0, -0.61, 0, 0, pivot);
return { pivot, hand };
}
function makeLeg(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.18, 0.84, 0);
body.add(pivot);
cylinder(0.145, 0.12, 0.68, standard(pants), 0, -0.34, 0, 7, pivot);
box(0.26, 0.16, 0.37, materials.black, 0, -0.72, 0.065, pivot);
return pivot;
}
const leftArm = makeArm(-1);
const rightArm = makeArm(1);
const leftLeg = makeLeg(-1);
const rightLeg = makeLeg(1);
const label = nameSprite(name);
label.position.set(0, 2.77, 0);
root.add(label);
return {
root,
body,
head,
leftArm: leftArm.pivot,
rightArm: rightArm.pivot,
leftHand: leftArm.hand,
rightHand: rightArm.hand,
leftLeg,
rightLeg,
carrying: false
};
}
const mara = createPerson({
name: "Mara",
shirt: "#d2a148",
pants: "#375e62",
hair: "#3d2b29",
skin: "#8f5e46",
apron: true,
curls: true
});
const jules = createPerson({
name: "Jules",
shirt: "#3c8987",
pants: "#ded3b9",
hair: "#8f5139",
skin: "#d4a27b",
glasses: true
});
function resetPeople() {
mara.root.position.set(2.85, 0, 2.15);
mara.root.rotation.y = -2.25;
mara.head.rotation.set(0, 0, 0);
mara.leftArm.rotation.set(0, 0, 0);
mara.rightArm.rotation.set(0, 0, 0);
mara.leftLeg.rotation.set(0, 0, 0);
mara.rightLeg.rotation.set(0, 0, 0);
mara.carrying = false;
jules.root.position.set(5.2, 0, 3.35);
jules.root.rotation.y = Math.PI;
jules.head.rotation.set(0, 0, 0);
jules.leftArm.rotation.set(0, 0, 0);
jules.rightArm.rotation.set(0, 0, 0);
jules.leftLeg.rotation.set(0, 0, 0);
jules.rightLeg.rotation.set(0, 0, 0);
jules.carrying = false;
}
resetPeople();
// Animation helpers, implemented locally without camera-control addons.
const easeInOut = (t) =>
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
const easeOut = (t) => 1 - Math.pow(1 - t, 3);
function tween(duration, update, easing = easeInOut) {
return new Promise((resolve) => {
const start = performance.now();
function frame(now) {
const raw = Math.min(1, (now - start) / duration);
update(easing(raw), raw);
if (raw < 1) {
requestAnimationFrame(frame);
} else {
resolve();
}
}
requestAnimationFrame(frame);
});
}
function wait(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function shortestAngle(from, to) {
let delta = (to - from + Math.PI) % (Math.PI * 2);
if (delta < 0) delta += Math.PI * 2;
return delta - Math.PI;
}
function setGait(person, amount, phase) {
const swing = Math.sin(phase) * 0.52 * amount;
person.leftLeg.rotation.x = swing;
person.rightLeg.rotation.x = -swing;
person.leftArm.rotation.x = -swing * 0.72;
if (!person.carrying) {
person.rightArm.rotation.x = swing * 0.72;
}
}
async function walkTo(person, target, duration = 1800) {
const from = person.root.position.clone();
const to = new THREE.Vector3(target.x, 0, target.z);
const targetYaw = Math.atan2(to.x - from.x, to.z - from.z);
const startYaw = person.root.rotation.y;
const delta = shortestAngle(startYaw, targetYaw);
await tween(
duration,
(e, raw) => {
person.root.position.lerpVectors(from, to, e);
person.root.position.y = Math.abs(Math.sin(raw * duration * 0.011)) * 0.035;
person.root.rotation.y = startYaw + delta * e;
setGait(person, Math.sin(e * Math.PI), raw * duration * 0.012);
},
(t) => t
);
person.root.position.y = 0;
person.leftLeg.rotation.x = 0;
person.rightLeg.rotation.x = 0;
if (!person.carrying) person.rightArm.rotation.x = 0;
}
async function turnTo(person, target, duration = 650) {
const dx = target.x - person.root.position.x;
const dz = target.z - person.root.position.z;
const desired = Math.atan2(dx, dz);
const start = person.root.rotation.y;
const delta = shortestAngle(start, desired);
await tween(duration, (e) => {
person.root.rotation.y = start + delta * e;
});
}
async function lookAt(person, target, duration = 750) {
const dx = target.x - person.root.position.x;
const dz = target.z - person.root.position.z;
const worldYaw = Math.atan2(dx, dz);
const desired = shortestAngle(0, worldYaw - person.root.rotation.y);
const start = person.head.rotation.y;
await tween(duration, (e) => {
person.head.rotation.y = start + desired * e;
person.head.rotation.x = -0.08 * e;
});
}
async function focusOn(target, distance, yaw, pitch, duration = 800) {
const from = {
target: cameraState.target.clone(),
distance: cameraState.distance,
yaw: cameraState.yaw,
pitch: cameraState.pitch
};
const toTarget = target.clone();
const yawDelta = shortestAngle(from.yaw, yaw);
await tween(duration, (e) => {
cameraState.target.lerpVectors(from.target, toTarget, e);
cameraState.distance = THREE.MathUtils.lerp(from.distance, distance, e);
cameraState.yaw = from.yaw + yawDelta * e;
cameraState.pitch = THREE.MathUtils.lerp(from.pitch, pitch, e);
});
}
function placeBookAt(location) {
scene.attach(book);
book.visible = true;
if (location === "table") {
book.position.copy(BOOK_FOUND);
book.rotation.set(0, -0.22, 0);
} else {
book.position.copy(BOOK_TRAY);
book.rotation.set(0, 0.06, 0);
}
book.scale.set(1, 1, 1);
}
async function moveBookToTray() {
const start = book.position.clone();
const startQ = book.quaternion.clone();
const endQ = new THREE.Quaternion().setFromEuler(new THREE.Euler(0, 0.06, 0));
await tween(1050, (e) => {
book.position.lerpVectors(start, BOOK_TRAY, e);
book.position.y += Math.sin(e * Math.PI) * 0.8;
book.quaternion.slerpQuaternions(startQ, endQ, e);
}, easeOut);
}
async function reachAndPick(person) {
const armStart = person.rightArm.rotation.x;
await tween(500, (e) => {
person.rightArm.rotation.x = THREE.MathUtils.lerp(armStart, -1.18, e);
});
const startPos = book.getWorldPosition(new THREE.Vector3());
const startQ = book.getWorldQuaternion(new THREE.Quaternion());
await tween(720, (e) => {
person.rightHand.updateWorldMatrix(true, false);
const handPos = person.rightHand.getWorldPosition(new THREE.Vector3());
book.position.lerpVectors(startPos, handPos, e);
book.position.y += Math.sin(e * Math.PI) * 0.12;
book.quaternion.slerpQuaternions(startQ, startQ, e);
});
person.rightHand.attach(book);
book.position.set(0, -0.01, 0.04);
book.rotation.set(1.18, 0, 0);
person.carrying = true;
await tween(350, (e) => {
person.rightArm.rotation.x = THREE.MathUtils.lerp(-1.18, -0.45, e);
book.rotation.x = THREE.MathUtils.lerp(1.18, 0.45, e);
});
}
async function handOffToMara() {
await turnTo(mara, jules.root.position, 650);
const maraArmStart = mara.leftArm.rotation.x;
await tween(500, (e) => {
mara.leftArm.rotation.x = THREE.MathUtils.lerp(maraArmStart, -0.95, e);
});
mara.leftHand.attach(book);
book.position.set(0, -0.01, 0.04);
book.rotation.set(0.95, 0, 0);
mara.carrying = true;
await tween(450, (e) => {
mara.leftArm.rotation.x = THREE.MathUtils.lerp(-0.95, -0.35, e);
book.rotation.x = THREE.MathUtils.lerp(0.95, 0.35, e);
jules.rightArm.rotation.x = THREE.MathUtils.lerp(-0.45, 0, e);
});
jules.carrying = false;
}
// UI and branch state.
let branch = null;
let replayBusy = false;
let toastTimer = 0;
function showToast(message) {
const toast = $("#toast");
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2600);
}
function updateLocationBadge(holder = "table") {
const badge = $("#location-badge");
if (holder === "table") {
badge.innerHTML =
"<strong>Book:</strong> blue cover, ochre corner tab<br>" +
"<strong>Location:</strong> worktable, beside the blue mug";
} else if (holder === "tray") {
badge.innerHTML =
"<strong>Book:</strong> blue cover, ochre corner tab<br>" +
"<strong>Location:</strong> lost-and-found tray, beside the note";
} else if (holder === "jules") {
badge.innerHTML =
"<strong>Book:</strong> blue cover, ochre corner tab<br>" +
"<strong>Location:</strong> held by Jules";
} else {
badge.innerHTML =
"<strong>Book:</strong> blue cover, ochre corner tab<br>" +
"<strong>Location:</strong> returned to Mara";
}
}
function addSequenceItem(text) {
const li = document.createElement("li");
li.textContent = text;
$("#sequence").appendChild(li);
return li;
}
async function finishItem(li, action) {
li.classList.add("current");
await action();
li.classList.remove("current");
li.classList.add("done");
}
async function replaySequence() {
if (replayBusy) return;
replayBusy = true;
$("#replay-button").disabled = true;
$("#change-button").disabled = true;
$("#outcome").hidden = true;
$("#sequence").innerHTML = "";
placeBookAt(branch === "tray" ? "tray" : "table");
noteGroup.visible = branch === "tray";
resetPeople();
updateLocationBadge(branch === "tray" ? "tray" : "table");
await focusOn(new THREE.Vector3(0.4, 1.45, 0.2), 12.1, 0.46, 0.34, 600);
let item = addSequenceItem("Jules steps into the workshop through the open doorway.");
await finishItem(item, async () => {
await walkTo(jules, { x: 4.62, z: 2.7 }, 750);
await wait(250);
});
if (branch === "table") {
item = addSequenceItem("Jules approaches the worktable; the blue mug is still beside the sketchbook.");
await finishItem(item, async () => {
await focusOn(new THREE.Vector3(-0.35, 1.55, 0.35), 7.9, 0.38, 0.42, 850);
await walkTo(jules, { x: 0.35, z: 1.23 }, 2200);
});
item = addSequenceItem("The sketchbook's blue cover and ochre corner tab are visible in the place where Mara found it.");
await finishItem(item, async () => {
await lookAt(jules, BOOK_FOUND, 750);
bookHalo.visible = true;
await wait(700);
bookHalo.visible = false;
});
item = addSequenceItem("Jules reaches to the worktable and lifts the sketchbook.");
await finishItem(item, async () => {
await reachAndPick(jules);
updateLocationBadge("jules");
});
item = addSequenceItem("Jules carries the same sketchbook back to Mara.");
await finishItem(item, async () => {
await focusOn(new THREE.Vector3(1.8, 1.45, 1.45), 8.6, 0.5, 0.34, 800);
await walkTo(jules, { x: 2.05, z: 1.83 }, 1900);
await handOffToMara();
updateLocationBadge("mara");
});
$("#outcome-title").textContent = "Found at the first place checked";
$("#outcome-text").textContent =
"The sketchbook never changes location before Jules arrives. Its ochre tab is visible beside the blue mug, so Jules lifts that same book from the worktable and carries it back to Mara.";
} else {
item = addSequenceItem("Jules approaches the worktable and looks at the spot beside the blue mug.");
await finishItem(item, async () => {
await focusOn(new THREE.Vector3(-0.3, 1.55, 0.35), 7.8, 0.38, 0.42, 800);
await walkTo(jules, { x: 0.35, z: 1.23 }, 2100);
await lookAt(jules, new THREE.Vector3(-0.12, 1.74, 0.48), 700);
});
item = addSequenceItem("There is no sketchbook at the mug; the blue mug and pencil cup remain in place.");
await finishItem(item, async () => {
await wait(650);
});
item = addSequenceItem("Jules walks around the table and checks the wall shelf and its jars.");
await finishItem(item, async () => {
await focusOn(new THREE.Vector3(-0.8, 2.9, -3.9), 8.5, 0.36, 0.3, 900);
await walkTo(jules, { x: 2.25, z: 0.7 }, 1550);
await walkTo(jules, { x: 2.25, z: -2.9 }, 1850);
await walkTo(jules, { x: 1.05, z: -3.2 }, 1250);
await lookAt(jules, new THREE.Vector3(-1.0, 3.25, -4.05), 800);
});
item = addSequenceItem("The shelf holds jars and supplies, but no sketchbook with an ochre corner tab.");
await finishItem(item, async () => {
await wait(750);
});
item = addSequenceItem("Jules moves to the counter marked LOST & FOUND; a written note is visible beside the tray.");
await finishItem(item, async () => {
await focusOn(new THREE.Vector3(4.15, 1.65, -2.0), 7.4, 0.44, 0.43, 900);
await walkTo(jules, { x: 2.55, z: -2.65 }, 1450);
await walkTo(jules, { x: 4.05, z: -0.88 }, 1850);
await lookAt(jules, new THREE.Vector3(4.7, 1.45, -1.95), 850);
});
item = addSequenceItem("Jules reaches into the tray and lifts the same blue, ochre-tabbed sketchbook.");
await finishItem(item, async () => {
await reachAndPick(jules);
updateLocationBadge("jules");
});
item = addSequenceItem("Jules carries the sketchbook back to Mara; the note remains in the tray.");
await finishItem(item, async () => {
await focusOn(new THREE.Vector3(2.8, 1.5, 1.4), 8.6, 0.5, 0.34, 800);
await walkTo(jules, { x: 3.0, z: 1.55 }, 1900);
await handOffToMara();
updateLocationBadge("mara");
});
$("#outcome-title").textContent = "Found after the table, shelf, and tray are checked";
$("#outcome-text").textContent =
"The sketchbook is no longer at the mug, and the shelf has no matching ochre tab. At the marked counter, a visible note sits beside the same sketchbook in the tray, where Jules lifts it before carrying it back to Mara.";
}
$("#outcome").hidden = false;
replayBusy = false;
$("#replay-button").disabled = false;
$("#change-button").disabled = false;
}
async function commitBranch(selectedBranch) {
branch = selectedBranch;
$("#leave-button").disabled = true;
$("#move-button").disabled = true;
$("#note-composer").hidden = true;
$("#decision-state").hidden = false;
if (branch === "tray") {
$("#decision-state").textContent =
"Recorded: the sketchbook and the visible note are being placed together in the LOST & FOUND tray.";
noteGroup.visible = false;
await moveBookToTray();
noteGroup.visible = true;
updateLocationBadge("tray");
} else {
$("#decision-state").textContent =
"Recorded: the sketchbook will stay exactly where Mara found it, beside the blue mug.";
placeBookAt("table");
updateLocationBadge("table");
}
$("#replay-panel").hidden = false;
await wait(450);
await replaySequence();
}
$("#leave-button").addEventListener("click", () => {
if (!branch) commitBranch("table");
});
$("#move-button").addEventListener("click", () => {
if (branch) return;
$("#note-composer").hidden = false;
$("#note-text").focus();
});
$("#note-text").addEventListener("input", (event) => {
updateNoteTexture(event.target.value.trim());
});
$("#place-button").addEventListener("click", () => {
if (branch) return;
const note = $("#note-text").value.trim() || "Please return this book to the lost-and-found tray.";
$("#note-text").value = note;
updateNoteTexture(note);
commitBranch("tray");
});
$("#replay-button").addEventListener("click", replaySequence);
$("#change-button").addEventListener("click", () => {
branch = null;
placeBookAt("table");
noteGroup.visible = false;
resetPeople();
$("#replay-panel").hidden = true;
$("#note-composer").hidden = true;
$("#leave-button").disabled = false;
$("#move-button").disabled = false;
$("#decision-state").hidden = true;
updateLocationBadge("table");
focusOn(new THREE.Vector3(-0.15, 1.35, -0.55), 12.1, 0.46, 0.34, 700);
});
$("#reset-view").addEventListener("click", () => {
focusOn(new THREE.Vector3(-0.15, 1.35, -0.55), 12.1, 0.46, 0.34, 650);
});
// Direct pointer camera controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let moved = false;
let lastX = 0;
let lastY = 0;
function setPointerFromEvent(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function hitsBook(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObject(book, true).length > 0;
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
moved = false;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(event.clientX - lastX) + Math.abs(event.clientY - lastY) > 3) {
moved = true;
}
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.14,
0.82
);
lastX = event.clientX;
lastY = event.clientY;
} else {
canvas.style.cursor = hitsBook(event) ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
canvas.releasePointerCapture(event.pointerId);
canvas.style.cursor = "grab";
if (!moved && hitsBook(event)) {
bookHalo.visible = true;
setTimeout(() => {
bookHalo.visible = false;
}, 900);
showToast(
"The blue field sketchbook has an ochre corner tab and a small brass clasp. It was found beside the blue mug."
);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.007,
5.8,
17
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLTextAreaElement) return;
if (event.key === "ArrowLeft") cameraState.yaw += 0.12;
if (event.key === "ArrowRight") cameraState.yaw -= 0.12;
if (event.key === "ArrowUp") cameraState.pitch = Math.min(0.82, cameraState.pitch + 0.08);
if (event.key === "ArrowDown") cameraState.pitch = Math.max(0.14, cameraState.pitch - 0.08);
if (event.key === "+" || event.key === "=") {
cameraState.distance = Math.max(5.8, cameraState.distance - 0.6);
}
if (event.key === "-") {
cameraState.distance = Math.min(17, cameraState.distance + 0.6);
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// Main loop.
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
if (bookHalo.visible) {
const pulse = 0.48 + Math.sin(elapsed * 5.2) * 0.17;
bookHalo.material.opacity = pulse;
bookHalo.scale.setScalar(1 + Math.sin(elapsed * 3.4) * 0.025);
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
setTimeout(() => $("#loading").classList.add("hidden"), 250);
</script>
</body>
</html>
```