Prompt specification
Build or customize the Three.js 3D scene "Memory-and-clue search 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: Memory-and-clue search game
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/memory-and-clue-search-game-x3876
Scene Description Prompt:
Use Three.js from cdnjs to create a bounded room with a scripted toy-placement event and several plausible locations; users inspect evidence in order while the toy stays fixed until discovered. Deliver one self-contained HTML file with low-poly forms.
Working Three.js Starter (memory-and-clue-search-game-x3876):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Still Room — Toy Placement Investigation</title>
<style>
:root {
--paper: #f2ecdf;
--paper-deep: #e6ddcc;
--ink: #202925;
--muted: #6f756e;
--line: #d5cbb8;
--rust: #c95f3d;
--rust-dark: #98442d;
--teal: #376c65;
--gold: #d7a844;
--white: #fffdf7;
--shadow: 0 12px 35px rgba(34, 38, 32, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background: #cfc7b8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
display: grid;
grid-template-columns: minmax(0, 1fr) 370px;
width: 100%;
height: 100dvh;
}
#stage {
position: relative;
min-width: 0;
overflow: hidden;
background:
radial-gradient(circle at 45% 35%, #e7dfcf 0, #c8bead 64%, #aea593 100%);
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.stage-card {
position: absolute;
z-index: 4;
pointer-events: none;
color: #fffaf0;
background: rgba(29, 39, 35, 0.86);
border: 1px solid rgba(255, 255, 255, 0.15);
box-shadow: var(--shadow);
backdrop-filter: blur(10px);
}
#brand {
top: 22px;
left: 24px;
padding: 15px 17px 14px;
border-radius: 4px 18px 18px 18px;
}
.eyebrow {
margin: 0 0 5px;
color: #dfc27f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
#brand h1 {
margin: 0;
font-size: clamp(20px, 2.2vw, 30px);
line-height: 1;
letter-spacing: -0.04em;
}
#brand .sub {
margin-top: 7px;
color: #d5d9d2;
font-size: 11px;
}
#event-chip {
top: 22px;
right: 24px;
padding: 10px 13px;
border-radius: 999px;
color: #f6df9e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#stage-help {
left: 24px;
bottom: 22px;
max-width: 410px;
padding: 10px 13px;
border-radius: 12px;
color: #e7e6de;
font-size: 11px;
line-height: 1.45;
}
#stage-help strong {
color: #fff7df;
}
#camera-reset {
position: absolute;
z-index: 5;
right: 24px;
bottom: 22px;
padding: 10px 13px;
color: #fffaf0;
background: rgba(29, 39, 35, 0.84);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 10px;
cursor: pointer;
box-shadow: var(--shadow);
}
#camera-reset:hover {
background: rgba(47, 63, 56, 0.95);
}
#tooltip {
position: absolute;
z-index: 10;
display: none;
max-width: 230px;
padding: 8px 10px;
color: #fff;
background: rgba(24, 30, 27, 0.94);
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 8px;
box-shadow: 0 7px 24px rgba(0, 0, 0, 0.25);
font-size: 11px;
line-height: 1.35;
pointer-events: none;
}
#toast {
position: absolute;
z-index: 20;
left: 50%;
bottom: 82px;
max-width: min(520px, calc(100% - 36px));
padding: 13px 17px;
color: #fffaf0;
background: rgba(30, 41, 36, 0.95);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 12px;
box-shadow: var(--shadow);
opacity: 0;
transform: translate(-50%, 14px);
transition: opacity 180ms ease, transform 180ms ease;
pointer-events: none;
font-size: 12px;
line-height: 1.45;
text-align: center;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#toast.success {
background: rgba(43, 102, 82, 0.96);
}
#toast.warning {
background: rgba(142, 71, 43, 0.96);
}
aside {
position: relative;
z-index: 6;
overflow-y: auto;
padding: 25px 23px 30px;
background:
linear-gradient(rgba(242, 236, 223, 0.96), rgba(242, 236, 223, 0.96)),
repeating-linear-gradient(90deg, transparent 0 24px, rgba(0, 0, 0, 0.05) 24px 25px);
border-left: 1px solid rgba(64, 54, 40, 0.16);
box-shadow: -10px 0 30px rgba(43, 40, 33, 0.12);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
margin-bottom: 18px;
}
.panel-heading h2 {
margin: 3px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 600;
line-height: 1.05;
letter-spacing: -0.025em;
}
.lock-badge {
flex: 0 0 auto;
padding: 7px 9px;
color: var(--teal);
background: rgba(55, 108, 101, 0.1);
border: 1px solid rgba(55, 108, 101, 0.25);
border-radius: 999px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.card {
margin-bottom: 15px;
padding: 15px;
background: rgba(255, 253, 247, 0.72);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 6px 18px rgba(55, 48, 37, 0.04);
}
.card-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.card-title .time {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.05em;
}
.event-title {
margin: 0 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 19px;
line-height: 1.2;
}
.card p {
margin: 0;
color: #5f655f;
font-size: 12px;
line-height: 1.55;
}
.timeline {
position: relative;
display: grid;
gap: 9px;
margin-top: 14px;
padding-left: 18px;
}
.timeline::before {
position: absolute;
top: 5px;
bottom: 5px;
left: 4px;
width: 1px;
content: "";
background: var(--line);
}
.timeline div {
position: relative;
color: #656a64;
font-size: 10px;
}
.timeline div::before {
position: absolute;
top: 4px;
left: -18px;
width: 9px;
height: 9px;
content: "";
background: var(--gold);
border: 2px solid var(--paper);
border-radius: 50%;
box-shadow: 0 0 0 1px rgba(143, 104, 35, 0.2);
}
.timeline b {
margin-right: 5px;
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 23px 2px 10px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.progress {
color: var(--rust);
font-size: 10px;
letter-spacing: 0.05em;
}
.clue-list,
.location-list {
display: grid;
gap: 9px;
}
.clue {
display: grid;
grid-template-columns: 36px 1fr auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 11px;
color: var(--ink);
text-align: left;
background: rgba(255, 253, 247, 0.75);
border: 1px solid var(--line);
border-radius: 12px;
cursor: pointer;
transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.clue:hover:not(:disabled) {
transform: translateY(-1px);
background: var(--white);
border-color: #bca98d;
}
.clue:disabled {
cursor: not-allowed;
opacity: 0.58;
}
.clue.complete {
background: rgba(55, 108, 101, 0.08);
border-color: rgba(55, 108, 101, 0.32);
opacity: 1;
}
.clue-num {
display: grid;
width: 34px;
height: 34px;
place-items: center;
color: #fffaf0;
background: var(--rust);
border-radius: 9px;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 700;
}
.clue.complete .clue-num {
background: var(--teal);
}
.clue strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.clue small {
display: block;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.chevron {
color: #9b9a90;
font-size: 18px;
}
.clue-detail {
min-height: 0;
padding: 0 5px;
color: #555d57;
font-size: 11px;
line-height: 1.5;
}
.clue-detail:not(:empty) {
padding: 9px 5px 3px;
}
.clue-detail b {
color: var(--rust-dark);
}
.location {
display: grid;
grid-template-columns: 1fr auto;
gap: 4px 10px;
width: 100%;
padding: 11px 12px;
color: var(--ink);
text-align: left;
background: rgba(255, 253, 247, 0.63);
border: 1px solid var(--line);
border-radius: 11px;
cursor: pointer;
}
.location:disabled {
cursor: not-allowed;
opacity: 0.57;
}
.location.suspect {
background: rgba(215, 168, 68, 0.12);
border-color: rgba(183, 132, 26, 0.4);
opacity: 1;
}
.location.lead {
background: rgba(201, 95, 61, 0.1);
border-color: rgba(201, 95, 61, 0.48);
opacity: 1;
}
.location.searched {
background: rgba(80, 86, 79, 0.08);
opacity: 0.72;
}
.location.found {
color: #fff;
background: var(--teal);
border-color: var(--teal);
opacity: 1;
}
.loc-name {
font-size: 12px;
font-weight: 750;
}
.loc-meta {
grid-column: 1 / -1;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.found .loc-meta {
color: rgba(255, 255, 255, 0.76);
}
.loc-state {
align-self: start;
color: #9b6b2f;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#status-card {
border-left: 4px solid var(--rust);
}
#status-title {
margin-bottom: 6px;
color: var(--ink);
font-size: 13px;
font-weight: 800;
}
.panel-actions {
display: flex;
gap: 8px;
margin-top: 14px;
}
.panel-actions button {
flex: 1;
padding: 10px;
color: var(--ink);
background: transparent;
border: 1px solid var(--line);
border-radius: 9px;
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.panel-actions button:hover {
background: var(--paper-deep);
}
.fine-print {
margin: 16px 3px 0;
color: #777b74;
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 900px) {
body {
overflow: auto;
}
#app {
display: block;
height: auto;
}
#stage {
height: 62dvh;
min-height: 430px;
}
aside {
overflow: visible;
border-top: 1px solid var(--line);
border-left: 0;
}
#event-chip {
top: auto;
right: 14px;
bottom: 65px;
}
#brand {
top: 14px;
left: 14px;
}
#stage-help {
left: 14px;
bottom: 14px;
max-width: calc(100% - 145px);
}
#camera-reset {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<main id="app">
<section id="stage" aria-label="Interactive three-dimensional room">
<div class="stage-card" id="brand">
<p class="eyebrow">Room 07 · Lost & Found</p>
<h1>The Still Room</h1>
<div class="sub">A fixed-placement reconstruction</div>
</div>
<div class="stage-card" id="event-chip">
Placement PL-0714 · position locked
</div>
<div class="stage-card" id="stage-help">
<strong>Drag</strong> to orbit · <strong>scroll</strong> to zoom ·
<strong>right-drag / Shift-drag</strong> to pan · inspect the numbered evidence.
</div>
<button id="camera-reset" type="button" title="Reset camera">Reset camera</button>
<div id="tooltip"></div>
<div id="toast" role="status" aria-live="polite"></div>
</section>
<aside aria-label="Investigation controls">
<div class="panel-heading">
<div>
<p class="eyebrow">Investigation</p>
<h2>Find the fixed toy.</h2>
</div>
<div class="lock-badge">No moving</div>
</div>
<section class="card">
<div class="card-title">
<span>Placement event</span>
<span class="time">PL-0714</span>
</div>
<p class="event-title">A plush fox was placed during the room reset.</p>
<p>
The position was committed before the investigation began. Searching
records a result but cannot move or hide the toy.
</p>
<div class="timeline">
<div><b>14:31:58</b> Reset route armed</div>
<div><b>14:32:04</b> Zone and surface tags written</div>
<div><b>14:32:06</b> Position checksum locked</div>
</div>
</section>
<div class="section-label">
<span>Inspect evidence</span>
<span class="progress" id="evidence-progress">0 / 3</span>
</div>
<div class="clue-list">
<button class="clue" type="button" data-clue="0">
<span class="clue-num">01</span>
<span>
<strong>Placement ticket</strong>
<small>Read the recorded room zone</small>
</span>
<span class="chevron">›</span>
</button>
<div class="clue-detail" id="clue-detail-0"></div>
<button class="clue" type="button" data-clue="1" disabled>
<span class="clue-num">02</span>
<span>
<strong>Contact swatch</strong>
<small>Match the surface signature</small>
</span>
<span class="chevron">›</span>
</button>
<div class="clue-detail" id="clue-detail-1"></div>
<button class="clue" type="button" data-clue="2" disabled>
<span class="clue-num">03</span>
<span>
<strong>Pressure trace</strong>
<small>Confirm the fixed placement</small>
</span>
<span class="chevron">›</span>
</button>
<div class="clue-detail" id="clue-detail-2"></div>
</div>
<div class="section-label">
<span>Search locations</span>
<span class="progress" id="search-progress">Locked</span>
</div>
<div class="location-list" id="location-list"></div>
<section class="card" id="status-card">
<div class="card-title">
<span>Current result</span>
<span class="time" id="status-time">—</span>
</div>
<div id="status-title">Evidence required</div>
<p id="status-copy">
Inspect evidence 01 through 03 in order. The numbered objects are also
clickable inside the room.
</p>
<div class="panel-actions">
<button id="replay-case" type="button">Replay case</button>
<button id="read-log" type="button">Read event log</button>
</div>
</section>
<p class="fine-print">
Low-poly procedural scene. Camera controls, interaction, event logic, and
placement locking are implemented directly with Three.js core.
</p>
</aside>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const tooltip = document.getElementById("tooltip");
const toast = document.getElementById("toast");
const locationList = document.getElementById("location-list");
const clueButtons = [...document.querySelectorAll(".clue")];
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.prepend(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional room. Drag to orbit, scroll to zoom, and click evidence or locations."
);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcac1b1);
scene.fog = new THREE.Fog(0xcac1b1, 24, 43);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xfff4da, 0x68756b, 1.65);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefcf, 2.7);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa9c8d0, 0.75);
fill.position.set(7, 6, -8);
scene.add(fill);
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const M = {
cream: material(0xe7ddc9),
paleWall: material(0xd7cebb),
darkWood: material(0x5c4130),
wood: material(0x9b6943),
oak: material(0xb98a57),
teal: material(0x477b73),
rust: material(0xb65336),
ochre: material(0xc89543),
moss: material(0x64774c),
leaf: material(0x789258),
soil: material(0x47372b),
terracotta: material(0xa75f42),
white: material(0xf3eee4),
black: material(0x252521),
brass: material(0xa87b2e, { metalness: 0.55, roughness: 0.42 }),
blue: material(0x567f8c),
pink: material(0xc9857f),
paper: material(0xf7f0dc)
};
function box(parent, sx, sy, sz, x, y, z, mat) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(sx, sy, sz), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, rt, rb, h, x, y, z, mat, segments = 8) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function ico(parent, radius, detail, x, y, z, mat) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cone(parent, radius, height, x, y, z, mat, segments = 6) {
const mesh = new THREE.Mesh(
new THREE.ConeGeometry(radius, height, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function group(name) {
const g = new THREE.Group();
g.name = name;
scene.add(g);
return g;
}
// ------------------------------------------------------------
// Bounded room: floor, four walls, skirting and upper frame
// ------------------------------------------------------------
const room = group("Bounded room");
box(room, 12.2, 0.18, 9.2, 0, -0.11, 0, M.darkWood);
const floorA = material(0xb98e60);
const floorB = material(0xad8055);
const floorC = material(0xc39a6d);
for (let i = 0; i < 12; i++) {
const floorMaterial = [floorA, floorB, floorC][i % 3];
box(
room,
0.96,
0.06,
8.9,
-5.52 + i,
0.015,
0,
floorMaterial
);
}
const wallDefinitions = [
{
size: [12.2, 4.4, 0.2],
position: [0, 2.2, -4.5],
normal: new THREE.Vector3(0, 0, -1),
center: new THREE.Vector3(0, 2.2, -4.5)
},
{
size: [12.2, 4.4, 0.2],
position: [0, 2.2, 4.5],
normal: new THREE.Vector3(0, 0, 1),
center: new THREE.Vector3(0, 2.2, 4.5)
},
{
size: [0.2, 4.4, 9.2],
position: [-6, 2.2, 0],
normal: new THREE.Vector3(-1, 0, 0),
center: new THREE.Vector3(-6, 2.2, 0)
},
{
size: [0.2, 4.4, 9.2],
position: [6, 2.2, 0],
normal: new THREE.Vector3(1, 0, 0),
center: new THREE.Vector3(6, 2.2, 0)
}
];
const fadingWalls = [];
wallDefinitions.forEach((definition, index) => {
const wallMaterial = material(
index === 0 ? 0xd6cdb9 : index === 1 ? 0xc9c0ad : 0xd1c8b5,
{ transparent: true, opacity: 0.94, side: THREE.DoubleSide }
);
const wall = box(
room,
...definition.size,
...definition.position,
wallMaterial
);
fadingWalls.push({
wall,
material: wallMaterial,
normal: definition.normal,
center: definition.center
});
});
// Permanent skirting makes the room boundary readable even when a near wall fades.
box(room, 12, 0.18, 0.13, 0, 0.13, -4.36, M.cream);
box(room, 12, 0.18, 0.13, 0, 0.13, 4.36, M.cream);
box(room, 0.13, 0.18, 9, -5.86, 0.13, 0, M.cream);
box(room, 0.13, 0.18, 9, 5.86, 0.13, 0, M.cream);
box(room, 12, 0.14, 0.18, 0, 4.28, -4.37, M.cream);
box(room, 12, 0.14, 0.18, 0, 4.28, 4.37, M.cream);
box(room, 0.18, 0.14, 9, -5.87, 4.28, 0, M.cream);
box(room, 0.18, 0.14, 9, 5.87, 4.28, 0, M.cream);
// Central rug.
box(room, 5.7, 0.045, 3.7, 0, 0.075, 0.15, material(0x8e5948));
box(room, 5.35, 0.025, 3.35, 0, 0.105, 0.15, material(0xb77a5d));
box(room, 4.65, 0.018, 2.65, 0, 0.125, 0.15, material(0xc9a17e));
// Decorative back-wall art.
const artFrame = box(room, 1.65, 1.2, 0.12, -4.4, 2.65, -4.35, M.darkWood);
box(room, 1.42, 0.97, 0.04, -4.4, 2.65, -4.27, material(0xd1a35e));
box(room, 0.54, 0.62, 0.03, -4.65, 2.63, -4.23, material(0x6c8170));
box(room, 0.33, 0.49, 0.03, -4.13, 2.73, -4.22, material(0xb65e43));
// Window and sill.
const windowGroup = group("Window");
const glass = material(0x9dbbc0, {
roughness: 0.25,
emissive: 0x42585b,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.9
});
box(windowGroup, 2.45, 2.15, 0.08, 1.65, 2.62, -4.36, glass);
box(windowGroup, 0.12, 2.3, 0.15, 1.65, 2.62, -4.25, M.white);
box(windowGroup, 2.55, 0.12, 0.15, 1.65, 2.62, -4.25, M.white);
box(windowGroup, 2.55, 0.12, 0.15, 1.65, 1.5, -4.25, M.white);
// ------------------------------------------------------------
// Plausible location groups
// ------------------------------------------------------------
const candidateRoots = {};
const candidateData = [
{
id: "chest",
name: "Toy chest",
zone: "children’s storage wall",
material: "turquoise-painted pine"
},
{
id: "shelf",
name: "Bookshelf, middle shelf",
zone: "children’s storage wall",
material: "oak veneer with a brass bookend"
},
{
id: "sofa",
name: "Sofa cushion",
zone: "reading corner",
material: "ochre woven cloth"
},
{
id: "plant",
name: "Plant pot",
zone: "window garden",
material: "unglazed terracotta"
},
{
id: "sill",
name: "Window ledge",
zone: "window garden",
material: "chalk-white plaster"
},
{
id: "basket",
name: "Laundry basket",
zone: "reading corner",
material: "split willow"
}
];
// Toy chest.
const toyChest = group("Toy chest candidate");
candidateRoots.chest = toyChest;
box(toyChest, 2.2, 0.88, 1.35, 0, 0.48, 0, M.teal);
box(toyChest, 1.88, 0.08, 1.16, 0, 0.93, 0, M.darkWood);
box(toyChest, 0.16, 0.25, 1.42, -0.8, 0.6, 0, M.oak);
box(toyChest, 0.16, 0.25, 1.42, 0.8, 0.6, 0, M.oak);
const chestLidPivot = new THREE.Group();
chestLidPivot.position.set(0, 0.94, -0.66);
chestLidPivot.rotation.x = -1.02;
toyChest.add(chestLidPivot);
box(chestLidPivot, 2.28, 0.18, 1.4, 0, 0.07, 0.66, M.oak);
toyChest.position.set(-4.45, 0, -2.55);
// Bookshelf.
const bookshelf = group("Bookshelf candidate");
candidateRoots.shelf = bookshelf;
box(bookshelf, 3.2, 3.25, 0.12, 0, 1.63, -0.3, M.darkWood);
box(bookshelf, 0.16, 3.25, 0.72, -1.6, 1.63, 0.02, M.oak);
box(bookshelf, 0.16, 3.25, 0.72, 1.6, 1.63, 0.02, M.oak);
box(bookshelf, 3.2, 0.14, 0.72, 0, 0.25, 0.02, M.oak);
box(bookshelf, 3.2, 0.14, 0.72, 0, 1.55, 0.02, M.oak);
box(bookshelf, 3.2, 0.14, 0.72, 0, 2.85, 0.02, M.oak);
const bookColors = [M.rust, M.blue, M.ochre, M.teal, M.pink, M.moss];
function addBook(parent, x, y, z, width, height, color, tilt = 0) {
const book = box(parent, width, height, 0.34, x, y, z, color);
book.rotation.z = tilt;
return book;
}
for (let i = 0; i < 7; i++) {
addBook(
bookshelf,
-1.34 + i * 0.2,
0.68 + (i % 2) * 0.06,
0.08,
0.15 + (i % 3) * 0.025,
0.55 + (i % 3) * 0.11,
bookColors[i % bookColors.length],
i === 6 ? -0.08 : 0
);
}
for (let i = 0; i < 6; i++) {
addBook(
bookshelf,
-1.28 + i * 0.2,
1.96 + (i % 2) * 0.07,
0.08,
0.15 + (i % 2) * 0.025,
0.58 + (i % 3) * 0.1,
bookColors[(i + 2) % bookColors.length]
);
}
for (let i = 0; i < 6; i++) {
addBook(
bookshelf,
0.42 + i * 0.19,
3.23 + (i % 2) * 0.05,
0.08,
0.14 + (i % 2) * 0.03,
0.56 + (i % 3) * 0.09,
bookColors[(i + 4) % bookColors.length]
);
}
box(bookshelf, 0.11, 0.42, 0.42, -0.78, 1.79, 0.08, M.brass);
box(bookshelf, 0.11, 0.42, 0.42, 0.55, 1.79, 0.08, M.brass);
bookshelf.position.set(-1.25, 0, -3.96);
// Sofa.
const sofa = group("Sofa candidate");
candidateRoots.sofa = sofa;
box(sofa, 2.05, 0.48, 3.25, 0, 0.37, 0, M.darkWood);
box(sofa, 0.38, 1.42, 3.25, 0.78, 1.1, 0, M.ochre);
box(sofa, 1.72, 0.3, 3.0, -0.18, 0.75, 0, M.ochre);
box(sofa, 1.72, 0.3, 2.75, -0.18, 0.88, 0, material(0xd1a253));
box(sofa, 0.35, 0.78, 3.2, 0.75, 0.72, 0, M.rust);
box(sofa, 0.35, 0.78, 3.2, 0.75, 0.72, 0, M.rust);
sofa.position.set(4.52, 0, -0.05);
// Plant.
const plant = group("Plant candidate");
candidateRoots.plant = plant;
cylinder(plant, 0.47, 0.33, 0.68, 0, 0.34, 0, M.terracotta, 9);
cylinder(plant, 0.43, 0.43, 0.08, 0, 0.68, 0, M.soil, 9);
cylinder(plant, 0.055, 0.075, 1.55, 0, 1.35, 0, M.moss, 6);
const leafData = [
[-0.26, 1.2, 0.02, 0.6],
[0.27, 1.45, 0.02, -0.55],
[-0.12, 1.75, 0.02, 0.22],
[0.18, 1.94, 0.01, -0.2],
[0.02, 1.32, -0.25, 0.15]
];
leafData.forEach(([x, y, z, rz], index) => {
const leaf = cone(
plant,
0.25,
0.85,
x,
y,
z,
index % 2 ? M.leaf : M.moss,
5
);
leaf.rotation.z = rz;
leaf.rotation.y = index * 0.9;
});
plant.position.set(4.72, 0, -3.48);
// Window ledge candidate.
const windowLedge = group("Window ledge candidate");
candidateRoots.sill = windowLedge;
box(windowLedge, 2.58, 0.18, 0.65, 0, 1.25, 0, M.white);
box(windowLedge, 2.3, 0.08, 0.46, 0, 1.37, 0.02, material(0xe3dfd3));
windowLedge.position.set(1.65, 0, -4.14);
// Laundry basket.
const laundryBasket = group("Laundry basket candidate");
candidateRoots.basket = laundryBasket;
box(laundryBasket, 1.15, 0.12, 0.88, 0, 0.12, 0, M.oak);
for (let i = 0; i < 6; i++) {
const x = -0.5 + i * 0.2;
box(laundryBasket, 0.075, 0.68, 0.88, x, 0.45, 0, M.oak);
}
for (let i = 0; i < 5; i++) {
const z = -0.36 + i * 0.18;
box(laundryBasket, 1.15, 0.07, 0.065, 0, 0.3 + i * 0.1, z, M.oak);
}
box(laundryBasket, 1.12, 0.1, 0.87, 0, 0.8, 0, M.oak);
laundryBasket.position.set(-0.25, 0, 2.45);
// ------------------------------------------------------------
// Supporting furniture
// ------------------------------------------------------------
const desk = group("Entry desk");
box(desk, 2.45, 0.14, 1.18, -3.85, 1.18, 2.16, M.oak);
box(desk, 0.12, 1.12, 0.12, -4.87, 0.58, 1.72, M.darkWood);
box(desk, 0.12, 1.12, 0.12, -2.83, 0.58, 1.72, M.darkWood);
box(desk, 0.12, 1.12, 0.12, -4.87, 0.58, 2.6, M.darkWood);
box(desk, 0.12, 1.12, 0.12, -2.83, 0.58, 2.6, M.darkWood);
box(desk, 0.72, 0.12, 0.54, -4.35, 1.32, 2.05, M.teal);
const stool = group("Evidence stool");
cylinder(stool, 0.46, 0.46, 0.14, 2.35, 0.78, 2.3, M.rust, 8);
cylinder(stool, 0.11, 0.14, 0.72, 2.35, 0.36, 2.3, M.darkWood, 6);
const lamp = group("Floor lamp");
cylinder(lamp, 0.38, 0.48, 0.12, -5.25, 0.08, 0.75, M.darkWood, 8);
cylinder(lamp, 0.055, 0.07, 2.25, -5.25, 1.18, 0.75, M.brass, 6);
cone(lamp, 0.48, 0.55, -5.25, 2.45, 0.75, M.ochre, 8);
const lampLight = new THREE.PointLight(0xffd69a, 0.75, 5.5, 2);
lampLight.position.set(-5.25, 2.25, 0.75);
scene.add(lampLight);
// A few low-poly blocks.
box(scene, 0.42, 0.42, 0.42, 1.0, 0.25, 0.9, M.rust);
box(scene, 0.36, 0.36, 0.36, 1.37, 0.24, 0.67, M.blue);
box(scene, 0.32, 0.32, 0.32, 0.98, 0.68, 0.9, M.ochre);
// ------------------------------------------------------------
// Evidence objects
// ------------------------------------------------------------
const evidenceRoots = [];
function makeBadge(number, color) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
context.beginPath();
context.arc(64, 64, 51, 0, Math.PI * 2);
context.fillStyle = color;
context.fill();
context.lineWidth = 7;
context.strokeStyle = "rgba(255,255,255,.95)";
context.stroke();
context.fillStyle = "#ffffff";
context.font = "700 58px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(String(number), 64, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.46, 0.46, 0.46);
sprite.renderOrder = 20;
return sprite;
}
// Evidence 1: placement ticket clipboard.
const clipboard = group("Evidence 01 placement ticket");
clipboard.userData.kind = "evidence";
clipboard.userData.id = 0;
clipboard.userData.label = "01 · Placement ticket";
box(clipboard, 0.62, 0.055, 0.82, 0, 0, 0, M.darkWood);
box(clipboard, 0.5, 0.025, 0.68, 0, 0.042, -0.02, M.paper);
box(clipboard, 0.2, 0.045, 0.09, 0, 0.075, 0.28, M.brass);
for (let i = 0; i < 4; i++) {
box(
clipboard,
0.32,
0.009,
0.018,
-0.035,
0.061,
-0.16 + i * 0.09,
M.blue
);
}
clipboard.position.set(-3.75, 1.31, 2.13);
clipboard.rotation.y = -0.17;
const badge1 = makeBadge(1, "#c95f3d");
badge1.position.set(0, 0.54, 0);
clipboard.add(badge1);
clipboard.userData.badge = badge1;
evidenceRoots.push(clipboard);
// Evidence 2: contact swatch and magnifier.
const swatch = group("Evidence 02 contact swatch");
swatch.userData.kind = "evidence";
swatch.userData.id = 1;
swatch.userData.label = "02 · Contact swatch";
box(swatch, 0.6, 0.035, 0.45, 0, 0, 0, M.cream);
box(swatch, 0.22, 0.025, 0.24, -0.13, 0.035, 0, M.oak);
box(swatch, 0.07, 0.018, 0.16, 0.15, 0.03, 0.05, M.brass);
const magnifier = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.025, 6, 18),
M.brass
);
magnifier.rotation.x = Math.PI / 2;
magnifier.position.set(0.16, 0.075, -0.08);
magnifier.castShadow = true;
swatch.add(magnifier);
const handle = cylinder(
swatch,
0.025,
0.025,
0.38,
0.16,
0.045,
-0.27,
M.darkWood,
6
);
handle.rotation.x = Math.PI / 2;
swatch.position.set(2.35, 0.88, 2.27);
swatch.rotation.y = 0.2;
const badge2 = makeBadge(2, "#376c65");
badge2.position.set(0, 0.47, 0);
swatch.add(badge2);
swatch.userData.badge = badge2;
evidenceRoots.push(swatch);
// Evidence 3: wall-mounted pressure trace terminal.
const terminal = group("Evidence 03 pressure trace");
terminal.userData.kind = "evidence";
terminal.userData.id = 2;
terminal.userData.label = "03 · Pressure trace terminal";
box(terminal, 0.95, 0.68, 0.14, 0, 0, 0, M.darkWood);
box(terminal, 0.75, 0.44, 0.04, 0, 0.03, 0.09, material(0x93b5aa));
box(terminal, 0.56, 0.045, 0.025, -0.02, 0.13, 0.115, M.teal);
box(terminal, 0.37, 0.045, 0.025, -0.11, 0.02, 0.115, M.cream);
cylinder(terminal, 0.045, 0.045, 0.03, 0.32, -0.24, 0.09, M.rust, 8);
terminal.position.set(2.95, 2.08, -4.31);
const badge3 = makeBadge(3, "#d09c31");
badge3.position.set(0, 0.58, 0.08);
terminal.add(badge3);
terminal.userData.badge = badge3;
evidenceRoots.push(terminal);
// ------------------------------------------------------------
// The fixed toy: hidden until the correct location is discovered
// ------------------------------------------------------------
const toy = group("Fixed plush fox");
toy.visible = false;
const foxOrange = material(0xc87842);
const foxLight = material(0xe5b478);
const foxDark = material(0x54382d);
ico(toy, 0.34, 1, 0, 0.34, 0, foxOrange).scale.set(0.9, 1.18, 0.78);
ico(toy, 0.27, 1, 0, 0.78, 0.03, foxOrange);
ico(toy, 0.16, 1, 0, 0.72, 0.23, foxLight);
cone(toy, 0.105, 0.38, -0.13, 1.1, 0.01, foxOrange, 5);
cone(toy, 0.105, 0.38, 0.13, 1.1, 0.01, foxOrange, 5);
cone(toy, 0.065, 0.22, -0.13, 1.11, 0.01, foxDark, 5);
cone(toy, 0.065, 0.22, 0.13, 1.11, 0.01, foxDark, 5);
cylinder(toy, 0.085, 0.085, 0.28, -0.18, 0.4, 0.02, foxOrange, 6).rotation.z = 0.55;
cylinder(toy, 0.085, 0.085, 0.28, 0.18, 0.4, 0.02, foxOrange, 6).rotation.z = -0.55;
ico(toy, 0.11, 0, -0.2, 0.11, 0.04, foxOrange);
ico(toy, 0.11, 0, 0.2, 0.11, 0.04, foxOrange);
ico(toy, 0.035, 0, -0.09, 0.83, 0.255, M.black);
ico(toy, 0.035, 0, 0.09, 0.83, 0.255, M.black);
ico(toy, 0.045, 0, 0, 0.75, 0.278, M.black);
const tail = ico(toy, 0.22, 1, 0, 0.37, -0.3, foxOrange);
tail.scale.set(0.75, 1.4, 0.75);
tail.rotation.x = -0.5;
const lockedToyPosition = new THREE.Vector3(-1.25, 1.64, -3.76);
toy.position.copy(lockedToyPosition);
toy.rotation.y = -0.18;
const toyBaseScale = 0.62;
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.56, 0.025, 6, 28),
new THREE.MeshBasicMaterial({
color: 0xf4ce62,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
halo.rotation.x = Math.PI / 2;
halo.position.copy(lockedToyPosition).add(new THREE.Vector3(0, 0.035, 0));
halo.visible = false;
scene.add(halo);
// ------------------------------------------------------------
// Interaction metadata
// ------------------------------------------------------------
const locationLabels = Object.fromEntries(
candidateData.map((candidate) => [candidate.id, candidate.name])
);
candidateData.forEach((candidate) => {
const root = candidateRoots[candidate.id];
root.userData.kind = "location";
root.userData.id = candidate.id;
root.userData.label = candidate.name;
candidate.searched = false;
});
const interactiveRoots = [...evidenceRoots, ...Object.values(candidateRoots)];
// ------------------------------------------------------------
// Scripted evidence and investigation state
// ------------------------------------------------------------
const target = candidateData.find((candidate) => candidate.id === "shelf");
const clueContent = [
{
title: "Placement zone",
detail:
"Placement zone: <b>children’s storage wall</b>. Two candidate locations carry this zone tag."
},
{
title: "Contact signature",
detail:
"Contact signature: <b>oak veneer with a brass bookend</b>. Match this surface against the candidate list."
},
{
title: "Fixed location",
detail:
"Pressure trace: <b>bookshelf, middle shelf</b> at 1.62 m. The position is fixed and ready to search."
}
];
let currentClue = 0;
let cluesRead = 0;
let solved = false;
let revealStarted = 0;
let toastTimer = 0;
const locationButtons = new Map();
candidateData.forEach((candidate) => {
const button = document.createElement("button");
button.type = "button";
button.className = "location";
button.disabled = true;
button.innerHTML = `
<span class="loc-name">${candidate.name}</span>
<span class="loc-state"></span>
<span class="loc-meta">Evidence required</span>
`;
button.addEventListener("click", () => searchLocation(candidate.id));
locationList.appendChild(button);
locationButtons.set(candidate.id, button);
});
function updateUI() {
document.getElementById("evidence-progress").textContent =
`${cluesRead} / 3`;
clueButtons.forEach((button, index) => {
const inspected = index < cluesRead;
button.disabled = inspected || index !== currentClue;
button.classList.toggle("complete", inspected);
const detail = document.getElementById(`clue-detail-${index}`);
detail.innerHTML = inspected ? clueContent[index].detail : "";
});
const unlocked = cluesRead === 3;
document.getElementById("search-progress").textContent = unlocked
? "6 candidates"
: "Locked";
candidateData.forEach((candidate) => {
const button = locationButtons.get(candidate.id);
const meta = button.querySelector(".loc-meta");
const state = button.querySelector(".loc-state");
button.classList.remove("suspect", "lead", "found", "searched");
if (cluesRead === 0) {
meta.textContent = "Evidence required";
state.textContent = "";
} else if (cluesRead === 1) {
meta.textContent = candidate.zone;
state.textContent =
candidate.zone === target.zone ? "Zone match" : "";
button.classList.toggle(
"suspect",
candidate.zone === target.zone
);
} else if (cluesRead === 2) {
meta.textContent = candidate.material;
state.textContent =
candidate.material === target.material ? "Surface match" : "";
button.classList.toggle(
"lead",
candidate.material === target.material
);
} else {
meta.textContent =
candidate.id === target.id
? "Pressure-log match"
: candidate.material;
state.textContent =
candidate.id === target.id ? "Confirm" : "Candidate";
}
if (candidate.searched && !solved) {
button.classList.add("searched");
state.textContent = "No toy";
}
if (solved && candidate.id === target.id) {
button.classList.add("found");
state.textContent = "Found";
meta.textContent = "The plush fox was here all along.";
}
button.disabled = !unlocked || solved || candidate.searched;
});
if (!unlocked) {
setStatus(
"Evidence required",
`Inspect evidence 01 through 03 in order. ${3 - cluesRead} record${
3 - cluesRead === 1 ? "" : "s"
} remaining.`
);
} else if (!solved) {
setStatus(
"Search authorized",
"The evidence identifies a likely location. Click the location in the room or choose it from the candidate list."
);
}
}
function setStatus(title, copy, time = "—") {
document.getElementById("status-title").textContent = title;
document.getElementById("status-copy").textContent = copy;
document.getElementById("status-time").textContent = time;
}
function showToast(message, type = "") {
toast.textContent = message;
toast.className = `show ${type}`;
window.clearTimeout(toastTimer);
toastTimer = window.setTimeout(() => {
toast.className = "";
}, 3600);
}
function playTone(frequency, duration = 0.08, type = "sine") {
try {
const AudioContextClass =
window.AudioContext || window.webkitAudioContext;
if (!AudioContextClass) return;
const audio = new AudioContextClass();
const oscillator = audio.createOscillator();
const gain = audio.createGain();
oscillator.type = type;
oscillator.frequency.value = frequency;
gain.gain.setValueAtTime(0.0001, audio.currentTime);
gain.gain.exponentialRampToValueAtTime(0.07, audio.currentTime + 0.01);
gain.gain.exponentialRampToValueAtTime(
0.0001,
audio.currentTime + duration
);
oscillator.connect(gain);
gain.connect(audio.destination);
oscillator.start();
oscillator.stop(audio.currentTime + duration + 0.02);
} catch {
// Audio is optional.
}
}
function inspectClue(index) {
if (index < cluesRead) {
showToast("That evidence has already been recorded.");
return;
}
if (index !== currentClue) {
showToast(
`Out of order. Inspect evidence ${String(currentClue + 1).padStart(
2,
"0"
)} first.`,
"warning"
);
return;
}
cluesRead++;
currentClue++;
playTone(410 + index * 85, 0.07);
showToast(`Evidence ${String(index + 1).padStart(2, "0")} recorded.`);
if (cluesRead === 3) {
setStatus(
"Search authorized",
"The pressure trace confirms the middle bookshelf. Search the candidate to discover the toy.",
"Now"
);
showToast("All three records are complete. Searching is now unlocked.");
} else {
setStatus(
`Evidence ${cluesRead} of 3 recorded`,
"Continue with the next numbered object. Evidence cannot be inspected out of order.",
"Next"
);
}
updateUI();
}
function searchLocation(id) {
if (cluesRead < 3) {
showToast(
"Inspect all three evidence records before searching a location.",
"warning"
);
return;
}
if (solved) return;
const candidate = candidateData.find((item) => item.id === id);
if (!candidate || candidate.searched) return;
candidate.searched = true;
if (id === target.id) {
solved = true;
toy.visible = true;
halo.visible = true;
revealStarted = performance.now();
// The position is never animated. Only the scale reveals the toy.
toy.scale.setScalar(0.001);
setStatus(
"Toy discovered",
"The plush fox was fixed on the middle bookshelf. Wrong searches did not alter its position.",
"Found"
);
showToast(
"Found: the plush fox was on the bookshelf’s middle shelf.",
"success"
);
playTone(520, 0.1);
window.setTimeout(() => playTone(780, 0.16), 100);
} else {
setStatus(
"No toy at this location",
"The placement lock is unchanged. Continue searching the remaining candidates.",
"Empty"
);
showToast(
`No toy at the ${candidate.name.toLowerCase()}. The toy has not moved.`,
"warning"
);
playTone(190, 0.1, "triangle");
}
updateUI();
}
clueButtons.forEach((button, index) => {
button.addEventListener("click", () => inspectClue(index));
});
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan and keyboard access
// ------------------------------------------------------------
const cameraState = {
yaw: 0.68,
pitch: 0.59,
radius: 15.4,
target: new THREE.Vector3(0, 1.05, 0)
};
function resetCamera() {
cameraState.yaw = 0.68;
cameraState.pitch = 0.59;
cameraState.radius = 15.4;
cameraState.target.set(0, 1.05, 0);
showToast("Camera reset.");
}
function updateCamera() {
const horizontal = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x +
cameraState.radius *
Math.sin(cameraState.yaw) *
horizontal,
cameraState.target.y +
cameraState.radius *
Math.sin(cameraState.pitch),
cameraState.target.z +
cameraState.radius *
Math.cos(cameraState.yaw) *
horizontal
);
camera.lookAt(cameraState.target);
}
document.getElementById("camera-reset").addEventListener("click", resetCamera);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const canvas = renderer.domElement;
let dragging = false;
let dragButton = 0;
let dragMoved = false;
let lastPointerX = 0;
let lastPointerY = 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 pickInteractive(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(interactiveRoots, true);
for (const intersection of intersections) {
let object = intersection.object;
while (object && !object.userData.kind) {
object = object.parent;
}
if (object && object.userData.kind) {
return {
kind: object.userData.kind,
id: object.userData.id,
label: object.userData.label,
object
};
}
}
return null;
}
function showTooltip(event, hit) {
let text = hit.label;
if (hit.kind === "location") {
text =
cluesRead < 3
? `${hit.label} · inspect evidence first`
: `${hit.label} · click to search`;
} else {
const index = Number(hit.id);
text =
index < cluesRead
? `${hit.label} · already recorded`
: `${hit.label} · click to inspect`;
}
tooltip.textContent = text;
tooltip.style.display = "block";
const rect = stage.getBoundingClientRect();
const left = Math.min(
event.clientX - rect.left + 14,
rect.width - tooltip.offsetWidth - 10
);
const top = Math.min(
event.clientY - rect.top + 14,
rect.height - tooltip.offsetHeight - 10
);
tooltip.style.left = `${Math.max(10, left)}px`;
tooltip.style.top = `${Math.max(10, top)}px`;
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
dragButton = event.button;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
const wantsPan = dragButton === 2 || event.shiftKey;
if (wantsPan) {
const scale = cameraState.radius * 0.0011;
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.yaw),
0,
-Math.cos(cameraState.yaw)
);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-4.2,
4.2
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-3.2,
3.2
);
} else {
cameraState.yaw -= dx * 0.005;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.24,
1.08
);
}
} else {
const hit = pickInteractive(event);
if (hit) {
canvas.style.cursor = "pointer";
showTooltip(event, hit);
} else {
canvas.style.cursor = "grab";
tooltip.style.display = "none";
}
}
});
canvas.addEventListener("pointerup", (event) => {
const wasDragging = dragging;
dragging = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (wasDragging && !dragMoved && event.button === 0) {
const hit = pickInteractive(event);
if (hit) {
if (hit.kind === "evidence") {
inspectClue(Number(hit.id));
} else {
searchLocation(hit.id);
}
}
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointerleave", () => {
if (!dragging) tooltip.style.display = "none";
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
9.5,
21
);
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.yaw += 0.08;
break;
case "ArrowRight":
cameraState.yaw -= 0.08;
break;
case "ArrowUp":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + 0.06,
0.24,
1.08
);
break;
case "ArrowDown":
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch - 0.06,
0.24,
1.08
);
break;
case "+":
case "=":
cameraState.radius = Math.max(9.5, cameraState.radius - 0.8);
break;
case "-":
cameraState.radius = Math.min(21, cameraState.radius + 0.8);
break;
case "r":
resetCamera();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
// ------------------------------------------------------------
// Case replay and event log
// ------------------------------------------------------------
function replayCase() {
currentClue = 0;
cluesRead = 0;
solved = false;
revealStarted = 0;
candidateData.forEach((candidate) => {
candidate.searched = false;
});
toy.visible = false;
halo.visible = false;
toy.position.copy(lockedToyPosition);
toy.scale.setScalar(toyBaseScale);
updateUI();
setStatus(
"Evidence required",
"Inspect evidence 01 through 03 in order. The numbered objects are also clickable inside the room."
);
showToast("Placement event PL-0714 replayed. The toy remains fixed.");
playTone(330, 0.07);
}
document
.getElementById("replay-case")
.addEventListener("click", replayCase);
document.getElementById("read-log").addEventListener("click", () => {
showToast(
"PL-0714: reset armed at 14:31:58; tags written at 14:32:04; position locked at 14:32:06."
);
});
// ------------------------------------------------------------
// Animation and rendering
// ------------------------------------------------------------
const clock = new THREE.Clock();
function easeOutBack(value) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(value - 1, 3) + c1 * Math.pow(value - 1, 2);
}
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
// Fade the two walls closest to the camera to preserve the cutaway view.
fadingWalls.forEach((definition) => {
const relative = camera.position.clone().sub(definition.center);
const isNearSide = definition.normal.dot(relative) > 0.1;
const desiredOpacity = isNearSide ? 0.13 : 0.94;
definition.material.opacity = THREE.MathUtils.lerp(
definition.material.opacity,
desiredOpacity,
0.08
);
definition.material.depthWrite =
definition.material.opacity > 0.45;
});
// The current evidence marker receives a subtle pulse.
evidenceRoots.forEach((root, index) => {
const badge = root.userData.badge;
if (!badge) return;
const base = 0.46;
const pulse = index === currentClue ? 1 + Math.sin(elapsed * 3.5) * 0.07 : 1;
badge.scale.set(base * pulse, base * pulse, base * pulse);
});
// Discovery changes only scale. The toy position is never animated.
if (solved && toy.visible) {
const progress = THREE.MathUtils.clamp(
(performance.now() - revealStarted) / 760,
0,
1
);
const eased = easeOutBack(progress);
toy.scale.setScalar(toyBaseScale * Math.max(0.001, eased));
halo.material.opacity = 0.58 + Math.sin(elapsed * 3.2) * 0.22;
halo.rotation.z = elapsed * 0.25;
}
renderer.render(scene, camera);
}
const resizeObserver = new ResizeObserver(() => {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
});
resizeObserver.observe(stage);
updateCamera();
updateUI();
// The scripted event is already committed when the scene opens.
setStatus(
"Evidence required",
"Inspect evidence 01 through 03 in order. The numbered objects are also clickable inside the room."
);
window.setTimeout(() => {
showToast(
"Placement event PL-0714 committed. The toy is fixed; inspect the numbered evidence."
);
}, 550);
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```