Prompt specification
Build or customize the Three.js 3D scene "Correct a copied passage without losing order" 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: Correct a copied passage without losing order
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/correct-a-copied-passage-without-losing-order-x2372
Scene Description Prompt:
A low-poly manuscript-binding puzzle: reorder page gatherings and identify a duplicated leaf using neutral symbols. One HTML file with Three.js from cdnjs.
Working Three.js Starter (correct-a-copied-passage-without-losing-order-x2372):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#10191e">
<title>The Quire — A Manuscript Binding Puzzle</title>
<style>
:root {
--ink: #172126;
--night: #0d171c;
--night-2: #142229;
--paper: #e8d8b7;
--paper-light: #f3e8ce;
--paper-dark: #cbb98f;
--gold: #c4a66b;
--gold-bright: #e2c68d;
--muted: #9ca9a9;
--line: rgba(226, 198, 141, 0.18);
--danger: #d89078;
--success: #a7c59d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--night);
color: var(--paper-light);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 2px solid var(--gold-bright);
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
#app {
display: grid;
grid-template-columns: minmax(350px, 410px) minmax(0, 1fr);
width: 100%;
height: 100%;
}
#panel {
position: relative;
z-index: 5;
min-width: 0;
height: 100%;
overflow-y: auto;
padding: 28px 26px 24px;
background:
radial-gradient(circle at 15% 0%, rgba(196, 166, 107, 0.09), transparent 34%),
linear-gradient(155deg, #18262c 0%, #111c21 58%, #0d171c 100%);
border-right: 1px solid var(--line);
box-shadow: 18px 0 60px rgba(0, 0, 0, 0.26);
scrollbar-width: thin;
scrollbar-color: rgba(196, 166, 107, 0.35) transparent;
}
#panel::after {
content: "";
position: absolute;
inset: 0;
pointer-events: none;
opacity: 0.035;
background-image:
repeating-linear-gradient(
0deg,
transparent,
transparent 3px,
rgba(255, 255, 255, 0.35) 4px
);
}
.masthead {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 26px;
}
.seal {
display: grid;
place-items: center;
width: 49px;
height: 49px;
flex: 0 0 auto;
color: var(--gold-bright);
border: 1px solid rgba(226, 198, 141, 0.44);
transform: rotate(45deg);
background: rgba(0, 0, 0, 0.12);
}
.seal svg {
width: 25px;
height: 25px;
transform: rotate(-45deg);
}
.eyebrow {
margin: 0 0 4px;
color: var(--gold);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 42px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.025em;
}
.lede {
margin: 0 0 24px;
color: #c1c8c4;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
line-height: 1.55;
}
.steps {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 28px;
}
.step {
position: relative;
display: flex;
align-items: center;
gap: 9px;
min-height: 42px;
padding: 9px 10px;
color: #7f9091;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
border: 1px solid transparent;
}
.step::after {
content: "";
position: absolute;
right: -8px;
z-index: 2;
width: 8px;
height: 1px;
background: var(--line);
}
.step:last-child::after {
display: none;
}
.step-number {
display: grid;
place-items: center;
width: 23px;
height: 23px;
flex: 0 0 auto;
border: 1px solid currentColor;
border-radius: 50%;
font-size: 10px;
}
.step.active {
color: var(--gold-bright);
border-color: rgba(226, 198, 141, 0.14);
background: rgba(226, 198, 141, 0.035);
}
.step.done {
color: var(--success);
}
.section-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 400;
}
.section-heading small {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.clue {
display: grid;
grid-template-columns: 48px 1fr;
align-items: center;
gap: 13px;
margin-bottom: 16px;
padding: 12px 13px;
color: #c8c9be;
background: rgba(0, 0, 0, 0.16);
border: 1px solid var(--line);
border-left: 2px solid var(--gold);
}
.clue-mark {
display: grid;
place-items: center;
width: 43px;
height: 43px;
color: var(--gold-bright);
border: 1px solid rgba(226, 198, 141, 0.3);
background: rgba(226, 198, 141, 0.04);
}
.clue p {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
line-height: 1.45;
}
#gathers {
display: grid;
gap: 8px;
min-height: 50px;
}
.gather {
position: relative;
display: grid;
grid-template-columns: 18px minmax(90px, 1fr) auto 26px;
align-items: center;
gap: 9px;
min-height: 66px;
padding: 9px 9px 9px 7px;
background: linear-gradient(90deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012));
border: 1px solid rgba(226, 198, 141, 0.13);
cursor: grab;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
opacity 160ms ease;
}
.gather:hover {
border-color: rgba(226, 198, 141, 0.35);
transform: translateX(2px);
}
.gather.dragging {
opacity: 0.42;
cursor: grabbing;
border-color: var(--gold-bright);
}
.grip {
color: rgba(226, 198, 141, 0.45);
font-size: 17px;
letter-spacing: -3px;
user-select: none;
}
.gather-copy {
min-width: 0;
}
.gather-name {
display: block;
overflow: hidden;
color: #e8e4d6;
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
white-space: nowrap;
text-overflow: ellipsis;
}
.gather-code {
display: block;
margin-top: 4px;
color: #728487;
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.mark-pair {
display: flex;
align-items: center;
gap: 5px;
}
.mark {
display: grid;
place-items: center;
width: 36px;
height: 36px;
color: var(--paper);
background: rgba(232, 216, 183, 0.045);
border: 1px solid rgba(232, 216, 183, 0.13);
}
.mark svg,
.answer-button svg,
.clue-mark svg,
.seal svg {
width: 23px;
height: 23px;
overflow: visible;
}
.connector {
width: 12px;
height: 1px;
background: rgba(232, 216, 183, 0.27);
}
.move-controls {
display: grid;
gap: 2px;
}
.move-controls button {
display: grid;
place-items: center;
width: 24px;
height: 22px;
padding: 0;
color: #a7b1ae;
background: transparent;
border: 1px solid rgba(232, 216, 183, 0.12);
cursor: pointer;
font-size: 11px;
}
.move-controls button:hover {
color: var(--paper-light);
border-color: rgba(232, 216, 183, 0.35);
}
.actions {
display: grid;
grid-template-columns: 0.75fr 1.25fr;
gap: 9px;
margin-top: 18px;
}
.button {
min-height: 46px;
padding: 11px 13px;
color: #d8ddd8;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
border: 1px solid rgba(232, 216, 183, 0.22);
background: rgba(255, 255, 255, 0.025);
cursor: pointer;
transition:
color 150ms ease,
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.button:hover {
color: var(--paper-light);
border-color: rgba(232, 216, 183, 0.48);
background: rgba(255, 255, 255, 0.05);
}
.button:active {
transform: translateY(1px);
}
.button.primary {
color: #172126;
background: var(--gold);
border-color: var(--gold);
}
.button.primary:hover {
background: var(--gold-bright);
border-color: var(--gold-bright);
}
.button:disabled {
opacity: 0.42;
cursor: default;
transform: none;
}
.message {
min-height: 43px;
margin: 12px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.message.error {
color: var(--danger);
}
.message.success {
color: var(--success);
}
#panel.shake {
animation: panel-shake 340ms ease;
}
@keyframes panel-shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-5px); }
75% { transform: translateX(5px); }
}
.spread-nav {
display: grid;
grid-template-columns: 44px 1fr 44px;
align-items: center;
gap: 10px;
margin: 17px 0;
}
.spread-nav button {
height: 42px;
color: var(--paper-light);
background: rgba(255, 255, 255, 0.035);
border: 1px solid rgba(232, 216, 183, 0.2);
cursor: pointer;
font-size: 18px;
}
.spread-nav button:hover:not(:disabled) {
border-color: var(--gold);
}
.spread-nav button:disabled {
opacity: 0.25;
cursor: default;
}
.spread-label {
text-align: center;
}
.spread-label strong {
display: block;
color: var(--gold-bright);
font-family: Georgia, "Times New Roman", serif;
font-size: 18px;
font-weight: 400;
}
.spread-label span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.inspection-note {
margin: 0 0 16px;
color: #bac2be;
font-family: Georgia, "Times New Roman", serif;
font-size: 13px;
line-height: 1.55;
}
.answer-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 8px;
}
.answer-button {
position: relative;
display: grid;
place-items: center;
aspect-ratio: 1;
color: var(--paper);
background: rgba(232, 216, 183, 0.035);
border: 1px solid rgba(232, 216, 183, 0.17);
cursor: pointer;
transition:
transform 150ms ease,
color 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
.answer-button:hover {
color: var(--gold-bright);
border-color: var(--gold);
transform: translateY(-2px);
}
.answer-button.correct {
color: #172126;
background: var(--success);
border-color: var(--success);
}
.answer-button.wrong {
color: var(--danger);
border-color: var(--danger);
animation: answer-wrong 280ms ease;
}
@keyframes answer-wrong {
50% { transform: translateX(-4px); }
75% { transform: translateX(4px); }
}
.answer-label {
margin: 15px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.completion {
margin-top: 19px;
padding: 17px;
background: rgba(167, 197, 157, 0.07);
border: 1px solid rgba(167, 197, 157, 0.25);
}
.completion strong {
display: block;
margin-bottom: 6px;
color: var(--success);
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 400;
}
.completion p {
margin: 0 0 14px;
color: #bdc8bd;
font-size: 12px;
line-height: 1.5;
}
.panel-footer {
margin-top: 27px;
padding-top: 17px;
color: #6f8082;
border-top: 1px solid rgba(232, 216, 183, 0.1);
font-size: 10px;
line-height: 1.6;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #101a20;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.stage-status {
position: absolute;
top: 24px;
right: 26px;
z-index: 2;
display: flex;
align-items: center;
gap: 9px;
max-width: calc(100% - 52px);
padding: 9px 12px;
color: #b8c2bf;
background: rgba(10, 17, 21, 0.7);
border: 1px solid rgba(232, 216, 183, 0.14);
backdrop-filter: blur(9px);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.status-dot {
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 10px rgba(196, 166, 107, 0.7);
}
.stage-status.ready .status-dot {
background: var(--success);
box-shadow: 0 0 10px rgba(167, 197, 157, 0.7);
}
.camera-help {
position: absolute;
right: 26px;
bottom: 22px;
z-index: 2;
color: rgba(202, 211, 206, 0.53);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
.stage-index {
position: absolute;
left: 28px;
bottom: 19px;
z-index: 2;
color: rgba(226, 198, 141, 0.34);
font-family: Georgia, "Times New Roman", serif;
font-size: 11px;
letter-spacing: 0.15em;
pointer-events: none;
}
#loading {
position: absolute;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--gold-bright);
background: #101a20;
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
letter-spacing: 0.12em;
}
#loading::before {
content: "";
width: 34px;
height: 34px;
margin-right: 13px;
border: 1px solid rgba(226, 198, 141, 0.25);
border-top-color: var(--gold-bright);
border-radius: 50%;
animation: spin 900ms linear infinite;
}
#loading {
grid-auto-flow: column;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 820px) {
#app {
grid-template-columns: 1fr;
grid-template-rows: 47vh 53vh;
}
#stage {
grid-row: 1;
}
#panel {
grid-row: 2;
padding: 20px 20px 28px;
border-right: 0;
border-top: 1px solid var(--line);
}
.masthead {
margin-bottom: 16px;
}
.seal {
width: 38px;
height: 38px;
}
h1 {
font-size: 30px;
}
.lede {
margin-bottom: 16px;
}
.steps {
margin-bottom: 20px;
}
.stage-status {
top: 14px;
right: 15px;
}
.camera-help {
right: 15px;
bottom: 13px;
}
.stage-index {
left: 15px;
bottom: 12px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
animation-duration: 0.001ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<main id="app">
<aside id="panel">
<header class="masthead">
<div class="seal" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<path d="M5 19V8l7-4 7 4v11M8 8h8M8 11h8M8 14h8M8 17h8"/>
</svg>
</div>
<div>
<p class="eyebrow">Manuscript workshop</p>
<h1>The Quire</h1>
</div>
</header>
<p class="lede">
Six gatherings were folded in the wrong order. Bind their spine marks,
then inspect the finished leaves for a mark copied twice.
</p>
<div class="steps" aria-label="Puzzle progress">
<div class="step active" id="stepOne">
<span class="step-number">1</span>
<span>Order gatherings</span>
</div>
<div class="step" id="stepTwo">
<span class="step-number">2</span>
<span>Find duplicate</span>
</div>
</div>
<section id="orderPanel">
<div class="section-heading">
<h2>Order the gatherings</h2>
<small>6 unbound</small>
</div>
<div class="clue">
<div class="clue-mark" id="startMark" aria-hidden="true"></div>
<p>
Begin with the gathering whose head bears this mark.
Every tail must become the next gathering’s head.
</p>
</div>
<div id="gathers" aria-label="Gathering order"></div>
<div class="actions">
<button class="button" id="hintButton" type="button">Need a clue?</button>
<button class="button primary" id="bindButton" type="button">Bind gatherings</button>
</div>
<p class="message" id="orderMessage" aria-live="polite">
Drag a gathering, or use its arrow buttons, to rearrange the stack.
</p>
</section>
<section id="inspectPanel" hidden>
<div class="section-heading">
<h2>Inspect the leaves</h2>
<small>bound volume</small>
</div>
<p class="inspection-note">
Turn through all four openings. Eight neutral marks were copied onto the
leaves, and exactly one of those marks was used twice.
</p>
<div class="spread-nav">
<button id="previousSpread" type="button" aria-label="Previous opening">←</button>
<div class="spread-label">
<strong id="spreadCount">Opening 1 / 4</strong>
<span>leaves 1–2</span>
</div>
<button id="nextSpread" type="button" aria-label="Next opening">→</button>
</div>
<div class="answer-label">Select the duplicated mark</div>
<div class="answer-grid" id="answers"></div>
<p class="message" id="answerMessage" aria-live="polite">
Inspect every opening before choosing.
</p>
<div class="completion" id="completion" hidden>
<strong>The volume is sound.</strong>
<p id="completionText"></p>
<button class="button" id="resetButton" type="button">Rebind the gatherings</button>
</div>
</section>
<footer class="panel-footer">
Neutral marks only; no letters or numbers belong to the manuscript.
Drag the scene to orbit and use the wheel to zoom.
</footer>
</aside>
<section id="stage" aria-label="Interactive manuscript workbench">
<div id="loading">Preparing the workbench</div>
<div class="stage-status" id="stageStatus">
<span class="status-dot"></span>
<span id="stageStatusText">Six gatherings await a spine</span>
</div>
<div class="stage-index">WORKSHOP · FOLIO STUDY</div>
<div class="camera-help">Drag empty space to orbit · scroll to zoom</div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const SYMBOL_PATHS = {
ring: "M18 12a6 6 0 1 1-12 0a6 6 0 1 1 12 0",
triangle: "M12 4L20 19H4Z",
square: "M5 5H19V19H5Z",
diamond: "M12 3L21 12L12 21L3 12Z",
hexagon: "M7 4H17L21 12L17 20H7L3 12Z",
star: "M12 3L14.6 8.4L20.5 9.2L16.2 13.5L17.3 19.4L12 16.6L6.7 19.4L7.8 13.5L3.5 9.2L9.4 8.4Z",
cross: "M12 4V20M4 12H20",
crescent: "M15.5 4.5A7.5 7.5 0 1 0 15.5 19.5A6.2 6.2 0 1 1 15.5 4.5Z",
wave: "M3 14C6 8 8 8 11 14S16 20 21 11",
bars: "M7 5V19M17 5V19",
spiral: "M19 12a7 7 0 1 1-7-7c3.6 0 5.7 2.2 5.7 5.3c0 2.8-2 4.5-4.4 4.5c-2 0-3.2-1.3-3.2-3c0-1.4 1-2.4 2.3-2.4",
chevron: "M4 13L12 6L20 13M4 19L12 12L20 19"
};
const SYMBOL_LABELS = {
ring: "open ring",
triangle: "triangle",
square: "square",
diamond: "diamond",
hexagon: "hexagon",
star: "six-point star",
cross: "cross",
crescent: "crescent",
wave: "wave",
bars: "double bars",
spiral: "spiral",
chevron: "double chevron"
};
const gatherings = [
{
id: "a",
name: "Gathering · cinnabar",
code: "Q–17 / vermilion",
head: "ring",
tail: "triangle",
color: 0x7f4438
},
{
id: "b",
name: "Gathering · slate",
code: "Q–42 / blue-grey",
head: "triangle",
tail: "square",
color: 0x4d6470
},
{
id: "c",
name: "Gathering · ochre",
code: "Q–08 / mineral",
head: "square",
tail: "diamond",
color: 0x8a7138
},
{
id: "d",
name: "Gathering · moss",
code: "Q–31 / green-grey",
head: "diamond",
tail: "hexagon",
color: 0x526354
},
{
id: "e",
name: "Gathering · indigo",
code: "Q–26 / deep blue",
head: "hexagon",
tail: "star",
color: 0x3e4c70
},
{
id: "f",
name: "Gathering · ash",
code: "Q–53 / pale grey",
head: "star",
tail: "ring",
color: 0x686d69
}
];
const initialOrder = ["c", "f", "a", "e", "b", "d"];
const leafMarks = [
"crescent", "cross",
"triangle", "spiral",
"bars", "cross",
"wave", "chevron"
];
const answerOptions = [
"cross", "crescent", "triangle", "spiral",
"bars", "wave", "chevron"
];
let order = [...initialOrder];
let mode = "order";
let hintLevel = 0;
let solved = false;
let currentSpread = 0;
let bindingStart = 0;
let turnState = null;
const panel = document.getElementById("panel");
const gathersElement = document.getElementById("gathers");
const orderPanel = document.getElementById("orderPanel");
const inspectPanel = document.getElementById("inspectPanel");
const orderMessage = document.getElementById("orderMessage");
const answerMessage = document.getElementById("answerMessage");
const bindButton = document.getElementById("bindButton");
const hintButton = document.getElementById("hintButton");
const stage = document.getElementById("stage");
const stageStatus = document.getElementById("stageStatus");
const stageStatusText = document.getElementById("stageStatusText");
const spreadCount = document.getElementById("spreadCount");
const previousSpreadButton = document.getElementById("previousSpread");
const nextSpreadButton = document.getElementById("nextSpread");
const completion = document.getElementById("completion");
const completionText = document.getElementById("completionText");
function symbolSVG(symbol) {
return `
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"
aria-hidden="true">
<path d="${SYMBOL_PATHS[symbol]}"></path>
</svg>
`;
}
document.getElementById("startMark").innerHTML = symbolSVG("ring");
function expectedOrder() {
const byHead = new Map(gatherings.map((g) => [g.head, g]));
const result = [];
let nextHead = "ring";
while (result.length < gatherings.length) {
const gathering = byHead.get(nextHead);
if (!gathering || result.includes(gathering.id)) break;
result.push(gathering.id);
nextHead = gathering.tail;
}
return result;
}
function renderGathers() {
gathersElement.innerHTML = order.map((id, index) => {
const gathering = gatherings.find((g) => g.id === id);
return `
<article class="gather" draggable="true" data-id="${gathering.id}">
<div class="grip" aria-hidden="true">⋮⋮</div>
<div class="gather-copy">
<span class="gather-name">${gathering.name}</span>
<span class="gather-code">${gathering.code}</span>
</div>
<div class="mark-pair" aria-label="head ${SYMBOL_LABELS[gathering.head]}, tail ${SYMBOL_LABELS[gathering.tail]}">
<span class="mark" title="Head: ${SYMBOL_LABELS[gathering.head]}">${symbolSVG(gathering.head)}</span>
<span class="connector"></span>
<span class="mark" title="Tail: ${SYMBOL_LABELS[gathering.tail]}">${symbolSVG(gathering.tail)}</span>
</div>
<div class="move-controls">
<button type="button" data-move="-1" aria-label="Move ${gathering.name} up" ${index === 0 ? "disabled" : ""}>↑</button>
<button type="button" data-move="1" aria-label="Move ${gathering.name} down" ${index === order.length - 1 ? "disabled" : ""}>↓</button>
</div>
</article>
`;
}).join("");
gatherCards().forEach((card) => {
card.addEventListener("dragstart", onDragStart);
card.addEventListener("dragend", onDragEnd);
});
gathersElement.querySelectorAll("[data-move]").forEach((button) => {
button.addEventListener("click", () => {
const id = button.closest(".gather").dataset.id;
moveGathering(id, Number(button.dataset.move));
});
});
updateQuireTargets();
}
const gatherCards = () => [...gathersElement.querySelectorAll(".gather")];
function moveGathering(id, direction) {
const index = order.indexOf(id);
const next = index + direction;
if (next < 0 || next >= order.length) return;
[order[index], order[next]] = [order[next], order[index]];
renderGathers();
orderMessage.className = "message";
orderMessage.textContent = "The gatherings have been rearranged.";
}
let draggedId = null;
function onDragStart(event) {
const card = event.currentTarget;
draggedId = card.dataset.id;
card.classList.add("dragging");
event.dataTransfer.effectAllowed = "move";
event.dataTransfer.setData("text/plain", draggedId);
}
function onDragEnd(event) {
event.currentTarget.classList.remove("dragging");
const ids = gatherCards().map((card) => card.dataset.id);
order = ids;
draggedId = null;
renderGathers();
}
gathersElement.addEventListener("dragover", (event) => {
event.preventDefault();
if (!draggedId) return;
const dragging = gathersElement.querySelector(".dragging");
const target = event.target.closest(".gather");
if (!target || target === dragging) return;
const rect = target.getBoundingClientRect();
const after = event.clientY > rect.top + rect.height / 2;
gathersElement.insertBefore(dragging, after ? target.nextSibling : target);
});
gathersElement.addEventListener("drop", (event) => {
event.preventDefault();
});
function updateSteps(step) {
document.getElementById("stepOne").classList.toggle("active", step === 1);
document.getElementById("stepOne").classList.toggle("done", step > 1);
document.getElementById("stepTwo").classList.toggle("active", step === 2);
}
function showHint() {
const hints = [
"The open ring identifies the first head. Find the bundle carrying that mark.",
"Read each gathering from left to right: its tail must equal the next gathering’s head.",
"The six spine marks form one closed circuit. The ring-headed bundle begins it.",
"Try this beginning: ring-headed, then triangle-headed, then square-headed."
];
orderMessage.className = "message";
orderMessage.textContent = hints[Math.min(hintLevel, hints.length - 1)];
hintLevel = Math.min(hintLevel + 1, hints.length - 1);
}
function validateOrder() {
const correct = order.every((id, index) => id === expectedOrder()[index]);
if (!correct) {
orderMessage.className = "message error";
orderMessage.textContent =
"The spine marks do not meet. Follow one tail until you find the matching head.";
panel.classList.remove("shake");
void panel.offsetWidth;
panel.classList.add("shake");
return;
}
mode = "binding";
bindingStart = performance.now();
bindButton.disabled = true;
hintButton.disabled = true;
orderMessage.className = "message success";
orderMessage.textContent = "The gatherings agree. Binding the spine…";
stageStatusText.textContent = "Binding the gatherings";
stageStatus.classList.remove("ready");
setTimeout(() => {
orderPanel.hidden = true;
inspectPanel.hidden = false;
updateSteps(2);
updateSpreadUI();
answerMessage.textContent = "Inspect every opening before choosing.";
}, 500);
}
function renderAnswers() {
const answers = document.getElementById("answers");
answers.innerHTML = answerOptions.map((symbol) => `
<button
type="button"
class="answer-button"
data-symbol="${symbol}"
title="${SYMBOL_LABELS[symbol]}"
aria-label="Choose the ${SYMBOL_LABELS[symbol]}"
>
${symbolSVG(symbol)}
</button>
`).join("");
answers.querySelectorAll(".answer-button").forEach((button) => {
button.addEventListener("click", () => chooseAnswer(button));
});
}
function chooseAnswer(button) {
if (solved || mode !== "inspect") return;
const symbol = button.dataset.symbol;
if (symbol === "cross") {
solved = true;
button.classList.add("correct");
answerMessage.className = "message success";
answerMessage.textContent =
"Correct. The cross appears on leaves 2 and 6; every other mark appears once.";
completionText.textContent =
"The cross was copied onto the second and sixth leaves. The gatherings are now bound in the correct order.";
completion.hidden = false;
stageStatusText.textContent = "Duplicate confirmed · the volume is sound";
stageStatus.classList.add("ready");
paintPages(true);
} else {
button.classList.add("wrong");
answerMessage.className = "message error";
answerMessage.textContent =
"That mark occurs only once. Compare the remaining openings.";
setTimeout(() => button.classList.remove("wrong"), 400);
}
}
function updateSpreadUI() {
spreadCount.textContent = `Opening ${currentSpread + 1} / 4`;
spreadCount.nextElementSibling.textContent =
`leaves ${currentSpread * 2 + 1}–${currentSpread * 2 + 2}`;
previousSpreadButton.disabled = currentSpread === 0 || Boolean(turnState);
nextSpreadButton.disabled = currentSpread === 3 || Boolean(turnState);
}
function resetPuzzle() {
mode = "order";
solved = false;
currentSpread = 0;
hintLevel = 0;
turnState = null;
order = [...initialOrder];
orderPanel.hidden = false;
inspectPanel.hidden = true;
completion.hidden = true;
bindButton.disabled = false;
hintButton.disabled = false;
orderMessage.className = "message";
orderMessage.textContent =
"Drag a gathering, or use its arrow buttons, to rearrange the stack.";
answerMessage.className = "message";
answerMessage.textContent = "Inspect every opening before choosing.";
updateSteps(1);
document.querySelectorAll(".answer-button").forEach((button) => {
button.classList.remove("correct", "wrong");
});
paintPages(false);
quireGroups.forEach((group) => {
group.visible = true;
group.scale.setScalar(1);
});
bookGroup.visible = false;
updateQuireTargets();
stageStatusText.textContent = "Six gatherings await a spine";
stageStatus.classList.remove("ready");
}
bindButton.addEventListener("click", validateOrder);
hintButton.addEventListener("click", showHint);
previousSpreadButton.addEventListener("click", () => turnSpread(-1));
nextSpreadButton.addEventListener("click", () => turnSpread(1));
document.getElementById("resetButton").addEventListener("click", resetPuzzle);
/* -----------------------------------------------------------
Three.js scene
----------------------------------------------------------- */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101a20);
scene.fog = new THREE.Fog(0x101a20, 12, 23);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.12;
stage.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(39, 1, 0.1, 60);
const cameraTarget = new THREE.Vector3(0, 0.05, 0);
let cameraAzimuth = 0.22;
let cameraPolar = 0.84;
let cameraRadius = 9.4;
let targetCameraRadius = 9.4;
function updateCamera() {
const sinPolar = Math.sin(cameraPolar);
camera.position.set(
cameraTarget.x + cameraRadius * sinPolar * Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * Math.cos(cameraPolar),
cameraTarget.z + cameraRadius * sinPolar * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
const hemisphere = new THREE.HemisphereLight(0xb9d2d3, 0x33251f, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe2ae, 3.4);
keyLight.position.set(-4.5, 8.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7da5b5, 1.25);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
const tableMaterial = new THREE.MeshStandardMaterial({
color: 0x5a4435,
roughness: 0.92,
metalness: 0,
flatShading: true
});
const table = new THREE.Mesh(
new THREE.CylinderGeometry(5.9, 5.9, 0.32, 10),
tableMaterial
);
table.position.y = -0.42;
table.receiveShadow = true;
scene.add(table);
const tableEdge = new THREE.Mesh(
new THREE.CylinderGeometry(5.95, 5.95, 0.08, 10),
new THREE.MeshStandardMaterial({
color: 0x3a2d29,
roughness: 1,
flatShading: true
})
);
tableEdge.position.y = -0.58;
tableEdge.receiveShadow = true;
scene.add(tableEdge);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
new THREE.MeshStandardMaterial({ color: 0x10191e, roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.1;
floor.receiveShadow = true;
scene.add(floor);
function makeCanvas(width, height) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
return canvas;
}
function drawSymbol(ctx, symbol, centerX, centerY, size, color = "#27302f") {
ctx.save();
ctx.translate(centerX - size / 2, centerY - size / 2);
ctx.scale(size / 24, size / 24);
ctx.strokeStyle = color;
ctx.lineWidth = 1.65;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.stroke(new Path2D(SYMBOL_PATHS[symbol]));
ctx.restore();
}
function makeMarkTexture(symbol) {
const canvas = makeCanvas(128, 128);
const ctx = canvas.getContext("2d");
drawSymbol(ctx, symbol, 64, 64, 82, "#e4d5b5");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function seededRandom(seed) {
let value = seed % 2147483647;
if (value <= 0) value += 2147483646;
return () => {
value = value * 16807 % 2147483647;
return (value - 1) / 2147483646;
};
}
function paintPage(canvas, symbol, leafIndex, isSolved) {
const ctx = canvas.getContext("2d");
const random = seededRandom(1047 + leafIndex * 97);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = leafIndex % 2 ? "#e7d7b5" : "#eadcbd";
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < 950; i++) {
const alpha = 0.015 + random() * 0.035;
ctx.fillStyle = `rgba(76,57,38,${alpha})`;
const x = random() * canvas.width;
const y = random() * canvas.height;
const length = 1 + random() * 8;
ctx.fillRect(x, y, length, random() > 0.5 ? 1 : 0.5);
}
ctx.strokeStyle = "rgba(91,67,43,0.22)";
ctx.lineWidth = 2;
ctx.strokeRect(34, 32, canvas.width - 68, canvas.height - 64);
ctx.strokeStyle = "rgba(91,67,43,0.13)";
ctx.lineWidth = 1;
ctx.strokeRect(45, 43, canvas.width - 90, canvas.height - 86);
const corner = 62;
ctx.strokeStyle = "rgba(78,61,42,0.34)";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(65, 95);
ctx.lineTo(65, 65);
ctx.lineTo(95, 65);
ctx.moveTo(canvas.width - 65, canvas.height - 95);
ctx.lineTo(canvas.width - 65, canvas.height - 65);
ctx.lineTo(canvas.width - 95, canvas.height - 65);
ctx.stroke();
drawSymbol(ctx, symbol, canvas.width / 2, canvas.height / 2 - 8, 150);
if (isSolved && symbol === "cross") {
ctx.strokeStyle = "rgba(99,132,91,0.72)";
ctx.lineWidth = 4;
ctx.beginPath();
ctx.arc(canvas.width / 2, canvas.height / 2 - 8, 105, 0, Math.PI * 2);
ctx.stroke();
}
ctx.fillStyle = "rgba(70,52,34,0.52)";
for (let i = 0; i < 3; i++) {
ctx.fillRect(canvas.width / 2 - 15, canvas.height - 103 + i * 8, 30, 2);
}
}
const pageCanvases = [makeCanvas(512, 640), makeCanvas(512, 640)];
const pageTextures = pageCanvases.map((canvas) => {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
});
const turnCanvas = makeCanvas(512, 640);
const turnTexture = new THREE.CanvasTexture(turnCanvas);
turnTexture.colorSpace = THREE.SRGBColorSpace;
turnTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
function paintPages(isSolved = solved) {
paintPage(pageCanvases[0], leafMarks[currentSpread * 2], currentSpread * 2, isSolved);
paintPage(pageCanvases[1], leafMarks[currentSpread * 2 + 1], currentSpread * 2 + 1, isSolved);
pageTextures[0].needsUpdate = true;
pageTextures[1].needsUpdate = true;
}
paintPages(false);
const quireGroups = new Map();
const quireTargets = new Map();
function addBox(group, size, position, material, rotationZ = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), material);
mesh.position.set(...position);
mesh.rotation.z = rotationZ;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function createQuire(gathering) {
const group = new THREE.Group();
const coverMaterial = new THREE.MeshStandardMaterial({
color: gathering.color,
roughness: 0.83,
metalness: 0,
flatShading: true
});
const paperMaterial = new THREE.MeshStandardMaterial({
color: 0xdccda9,
roughness: 0.96,
flatShading: true
});
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0xbba987,
roughness: 1,
flatShading: true
});
for (const side of [-1, 1]) {
addBox(
group,
[0.65, 0.07, 0.88],
[side * 0.31, 0.02, 0],
coverMaterial,
side * 0.035
);
addBox(
group,
[0.59, 0.16, 0.80],
[side * 0.30, 0.13, 0],
paperMaterial,
side * 0.035
);
for (let layer = 0; layer < 3; layer++) {
addBox(
group,
[0.605, 0.012, 0.815],
[side * 0.30, 0.07 + layer * 0.045, 0],
edgeMaterial,
side * 0.035
);
}
}
const spine = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.86, 8),
coverMaterial
);
spine.rotation.x = Math.PI / 2;
spine.position.y = 0.14;
spine.castShadow = true;
group.add(spine);
const holeMaterial = new THREE.MeshStandardMaterial({
color: 0x211b17,
roughness: 1
});
for (const z of [-0.25, 0, 0.25]) {
const hole = new THREE.Mesh(
new THREE.CylinderGeometry(0.026, 0.026, 0.045, 7),
holeMaterial
);
hole.position.set(0, 0.222, z);
group.add(hole);
}
const stitchPoints = [];
for (let i = 0; i <= 20; i++) {
const z = -0.31 + (i / 20) * 0.62;
const x = Math.sin(i * Math.PI) * 0.075;
const y = 0.238 + Math.sin(i * Math.PI) * 0.008;
stitchPoints.push(new THREE.Vector3(x, y, z));
}
const stitch = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(stitchPoints),
new THREE.LineBasicMaterial({ color: 0xb69258 })
);
group.add(stitch);
const markGeometry = new THREE.PlaneGeometry(0.32, 0.32);
const headMaterial = new THREE.MeshBasicMaterial({
map: makeMarkTexture(gathering.head),
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const tailMaterial = new THREE.MeshBasicMaterial({
map: makeMarkTexture(gathering.tail),
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const headMark = new THREE.Mesh(markGeometry, headMaterial);
headMark.rotation.x = -Math.PI / 2;
headMark.position.set(-0.30, 0.255, 0.02);
group.add(headMark);
const tailMark = new THREE.Mesh(markGeometry, tailMaterial);
tailMark.rotation.x = -Math.PI / 2;
tailMark.position.set(0.30, 0.255, 0.02);
group.add(tailMark);
group.userData.gathering = gathering;
return group;
}
gatherings.forEach((gathering) => {
const group = createQuire(gathering);
scene.add(group);
quireGroups.set(gathering.id, group);
});
function updateQuireTargets() {
order.forEach((id, index) => {
const target = new THREE.Vector3(
(index - (order.length - 1) / 2) * 1.42,
0,
Math.abs(index - (order.length - 1) / 2) * 0.035
);
quireTargets.set(id, target);
});
}
updateQuireTargets();
const bookGroup = new THREE.Group();
bookGroup.visible = false;
scene.add(bookGroup);
const bookCoverMaterial = new THREE.MeshStandardMaterial({
color: 0x334b4b,
roughness: 0.72,
metalness: 0.03,
flatShading: true
});
const coverEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x253a3a,
roughness: 0.8,
flatShading: true
});
const bookPaperMaterial = new THREE.MeshStandardMaterial({
color: 0xd8c7a4,
roughness: 0.95,
flatShading: true
});
const bookEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xb8a47e,
roughness: 1,
flatShading: true
});
for (const side of [-1, 1]) {
addBox(
bookGroup,
[1.46, 0.10, 2.05],
[side * 0.72, 0.015, 0],
bookCoverMaterial
);
addBox(
bookGroup,
[1.38, 0.24, 1.91],
[side * 0.69, 0.17, 0],
bookPaperMaterial
);
for (let layer = 0; layer < 5; layer++) {
addBox(
bookGroup,
[1.39, 0.012, 1.925],
[side * 0.69, 0.075 + layer * 0.038, 0],
bookEdgeMaterial
);
}
}
const spine = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 2.03, 10),
coverEdgeMaterial
);
spine.rotation.x = Math.PI / 2;
spine.position.y = 0.12;
spine.castShadow = true;
bookGroup.add(spine);
const pageGeometry = new THREE.PlaneGeometry(1.34, 1.87);
const leftPage = new THREE.Mesh(
pageGeometry,
new THREE.MeshStandardMaterial({
map: pageTextures[0],
roughness: 0.97,
side: THREE.DoubleSide
})
);
leftPage.rotation.x = -Math.PI / 2;
leftPage.position.set(-0.69, 0.302, 0);
leftPage.receiveShadow = true;
bookGroup.add(leftPage);
const rightPage = new THREE.Mesh(
pageGeometry,
new THREE.MeshStandardMaterial({
map: pageTextures[1],
roughness: 0.97,
side: THREE.DoubleSide
})
);
rightPage.rotation.x = -Math.PI / 2;
rightPage.position.set(0.69, 0.302, 0);
rightPage.receiveShadow = true;
bookGroup.add(rightPage);
const turnPivot = new THREE.Group();
turnPivot.position.set(0, 0.31, 0);
turnPivot.visible = false;
bookGroup.add(turnPivot);
const turningPage = new THREE.Mesh(
pageGeometry,
new THREE.MeshStandardMaterial({
map: turnTexture,
roughness: 0.97,
side: THREE.DoubleSide
})
);
turningPage.rotation.x = -Math.PI / 2;
turningPage.position.x = 0.67;
turningPage.castShadow = true;
turnPivot.add(turningPage);
const bookmark = new THREE.Mesh(
new THREE.BoxGeometry(0.085, 0.018, 1.25),
new THREE.MeshStandardMaterial({
color: 0x8f4d3f,
roughness: 0.86
})
);
bookmark.position.set(0.82, 0.325, 0.15);
bookmark.rotation.y = -0.08;
bookGroup.add(bookmark);
const threadMaterial = new THREE.LineBasicMaterial({ color: 0xb79258 });
for (let i = 0; i < 5; i++) {
const z = -0.72 + i * 0.36;
const points = [
new THREE.Vector3(-0.08, 0.328, z - 0.08),
new THREE.Vector3(0, 0.335, z),
new THREE.Vector3(0.08, 0.328, z + 0.08)
];
const stitch = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
threadMaterial
);
bookGroup.add(stitch);
}
function turnSpread(direction) {
if (mode !== "inspect" || turnState) return;
const next = currentSpread + direction;
if (next < 0 || next > 3) return;
const sourceIndex = direction > 0 ? currentSpread * 2 + 1 : currentSpread * 2;
const ctx = turnCanvas.getContext("2d");
ctx.clearRect(0, 0, turnCanvas.width, turnCanvas.height);
ctx.drawImage(pageCanvases[sourceIndex === currentSpread * 2 ? 0 : 1], 0, 0);
turnTexture.needsUpdate = true;
turningPage.position.x = direction > 0 ? 0.67 : -0.67;
turnPivot.rotation.z = 0;
turnPivot.visible = true;
turnState = {
direction,
next,
start: performance.now(),
duration: 520
};
updateSpreadUI();
}
function updateTurningPage(now) {
if (!turnState) return;
const progress = Math.min((now - turnState.start) / turnState.duration, 1);
const eased = 1 - Math.pow(1 - progress, 3);
turnPivot.rotation.z =
turnState.direction > 0 ? -Math.PI * eased : Math.PI * eased;
if (progress >= 1) {
currentSpread = turnState.next;
turnPivot.visible = false;
turnState = null;
paintPages();
updateSpreadUI();
}
}
/* Low-poly workshop props */
function createSpool(x, z, color) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
flatShading: true
});
const cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(0.24, 0.24, 0.46, 10),
material
);
cylinder.castShadow = true;
group.add(cylinder);
for (const y of [-0.25, 0.25]) {
const flange = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.29, 0.055, 10),
new THREE.MeshStandardMaterial({
color: 0x8f7049,
roughness: 1,
flatShading: true
})
);
flange.position.y = y;
flange.castShadow = true;
group.add(flange);
}
group.position.set(x, -0.04, z);
scene.add(group);
}
createSpool(-4.15, -1.75, 0xa88956);
createSpool(-3.48, -2.05, 0x765547);
createSpool(-4.25, -2.42, 0x56696a);
const inkpot = new THREE.Group();
const inkBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.31, 0.36, 0.42, 8),
new THREE.MeshStandardMaterial({
color: 0x283133,
roughness: 0.55,
metalness: 0.08,
flatShading: true
})
);
inkBody.position.y = 0.2;
inkBody.castShadow = true;
inkpot.add(inkBody);
const inkRim = new THREE.Mesh(
new THREE.TorusGeometry(0.285, 0.035, 6, 12),
new THREE.MeshStandardMaterial({ color: 0x171d1e, roughness: 0.6 })
);
inkRim.rotation.x = Math.PI / 2;
inkRim.position.y = 0.42;
inkpot.add(inkRim);
inkpot.position.set(4.05, -0.25, -1.4);
scene.add(inkpot);
const parchmentScrapMaterial = new THREE.MeshStandardMaterial({
color: 0xcbb98f,
roughness: 1,
side: THREE.DoubleSide
});
for (let i = 0; i < 3; i++) {
const scrap = new THREE.Mesh(
new THREE.PlaneGeometry(0.82, 0.58),
parchmentScrapMaterial
);
scrap.rotation.x = -Math.PI / 2;
scrap.rotation.z = (i - 1) * 0.28;
scrap.position.set(3.75 + i * 0.12, -0.248 + i * 0.003, 1.45 + i * 0.16);
scrap.receiveShadow = true;
scene.add(scrap);
}
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = [];
const dustRandom = seededRandom(7781);
for (let i = 0; i < 85; i++) {
dustPositions.push(
(dustRandom() - 0.5) * 10,
dustRandom() * 4 + 0.2,
(dustRandom() - 0.5) * 8
);
}
dustGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xe1d3af,
size: 0.025,
transparent: true,
opacity: 0.27,
depthWrite: false
})
);
scene.add(dust);
/* Direct camera controls, without add-ons */
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.abs(dx) + Math.abs(dy) > 2) pointerMoved = true;
cameraAzimuth -= dx * 0.0045;
cameraPolar = THREE.MathUtils.clamp(cameraPolar - dy * 0.0035, 0.48, 1.23);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
if (!pointerMoved && mode === "inspect" && !turnState) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects([leftPage, rightPage], false);
if (hit.length) {
if (hit[0].object === rightPage) turnSpread(1);
else turnSpread(-1);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetCameraRadius = THREE.MathUtils.clamp(
targetCameraRadius + event.deltaY * 0.006,
5.3,
12.5
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (mode !== "inspect") return;
if (event.key === "ArrowLeft") turnSpread(-1);
if (event.key === "ArrowRight") turnSpread(1);
});
let bindingStartPositions = new Map();
function beginBindingAnimation() {
bindingStartPositions = new Map();
quireGroups.forEach((group, id) => {
bindingStartPositions.set(id, group.position.clone());
});
}
beginBindingAnimation();
const clock = new THREE.Clock();
function animate(now) {
const delta = Math.min(clock.getDelta(), 0.05);
if (mode === "order") {
quireGroups.forEach((group, id) => {
const target = quireTargets.get(id);
group.position.lerp(target, 1 - Math.pow(0.001, delta));
const targetRotation = (order.indexOf(id) % 2 ? 1 : -1) * 0.045;
group.rotation.y = THREE.MathUtils.lerp(
group.rotation.y,
targetRotation,
1 - Math.pow(0.002, delta)
);
});
}
if (mode === "binding") {
const elapsed = (now - bindingStart) / 1550;
const progress = THREE.MathUtils.smoothstep(elapsed, 0, 1);
order.forEach((id, index) => {
const group = quireGroups.get(id);
const start = bindingStartPositions.get(id) || new THREE.Vector3();
const end = new THREE.Vector3(0, index * 0.13, -0.55);
group.position.lerpVectors(start, end, progress);
group.rotation.y = THREE.MathUtils.lerp(group.rotation.y, 0, 0.08);
group.scale.setScalar(1 - progress * 0.35);
});
if (elapsed > 0.52) {
bookGroup.visible = true;
const bookProgress = THREE.MathUtils.smoothstep(elapsed, 0.52, 1.12);
bookGroup.scale.setScalar(0.72 + bookProgress * 0.28);
bookGroup.rotation.y = THREE.MathUtils.lerp(-0.18, -0.045, bookProgress);
}
targetCameraRadius = THREE.MathUtils.lerp(9.4, 6.45, progress);
if (elapsed >= 1.12) {
mode = "inspect";
bookGroup.visible = true;
bookGroup.scale.setScalar(1);
quireGroups.forEach((group) => {
group.visible = false;
});
stageStatusText.textContent = "Bound volume · turn the pages";
updateSpreadUI();
}
}
if (mode === "inspect") {
updateTurningPage(now);
}
cameraRadius = THREE.MathUtils.lerp(
cameraRadius,
targetCameraRadius,
1 - Math.pow(0.002, delta)
);
updateCamera();
dust.rotation.y += delta * 0.012;
dust.position.y = Math.sin(now * 0.00018) * 0.08;
renderer.render(scene, camera);
}
renderGathers();
renderAnswers();
renderer.setAnimationLoop(animate);
window.setTimeout(() => {
document.getElementById("loading").remove();
}, 300);
</script>
</body>
</html>
```