Prompt specification
Build or customize the Three.js 3D scene "Book page marker transfer" 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: Book page marker transfer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/book-page-marker-transfer-x0050
Scene Description Prompt:
I'd like to see this as a voxel Three.js scene: book page marker transfer. Display an open notebook with several thick page groups; move the bookmark from one section to another and visibly preserve the selected spread when closing. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (book-page-marker-transfer-x0050):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Notebook — Marker Transfer</title>
<style>
:root {
--ink: #243638;
--paper: #f5eddd;
--paper-deep: #dfd0b6;
--coral: #e85d4f;
--teal: #318b87;
--gold: #d69a45;
--blue: #4b6fa8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8dece;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app,
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.grain {
position: absolute;
inset: 0;
pointer-events: none;
opacity: 0.13;
z-index: 2;
background-image:
radial-gradient(circle at 15% 20%, rgba(36, 54, 56, 0.18) 0 0.7px, transparent 0.8px),
radial-gradient(circle at 75% 65%, rgba(36, 54, 56, 0.14) 0 0.6px, transparent 0.8px);
background-size: 7px 7px, 11px 11px;
mix-blend-mode: multiply;
}
.masthead {
position: absolute;
z-index: 5;
top: 30px;
left: 34px;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 11px;
color: rgba(36, 54, 56, 0.66);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 3px;
background: var(--coral);
box-shadow: 6px 0 0 var(--gold);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5vw, 68px);
font-weight: 500;
line-height: 0.92;
letter-spacing: -0.045em;
}
.masthead p {
max-width: 315px;
margin: 15px 0 0;
color: rgba(36, 54, 56, 0.72);
font-size: 13px;
line-height: 1.55;
}
.panel {
position: absolute;
z-index: 6;
border: 1px solid rgba(36, 54, 56, 0.15);
background: rgba(248, 242, 230, 0.88);
box-shadow: 0 18px 50px rgba(45, 50, 43, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.marker-panel {
top: 28px;
right: 28px;
width: 304px;
padding: 18px;
border-radius: 4px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: rgba(36, 54, 56, 0.64);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.marker-chip {
min-width: 31px;
padding: 5px 7px 4px;
border-radius: 2px;
background: var(--coral);
color: #fff8ed;
text-align: center;
letter-spacing: 0.1em;
}
.spread-list {
display: grid;
gap: 7px;
}
.spread-btn {
display: grid;
grid-template-columns: 10px 34px 1fr auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 11px 10px;
border: 1px solid rgba(36, 54, 56, 0.12);
border-radius: 3px;
background: rgba(255, 255, 255, 0.38);
color: var(--ink);
cursor: pointer;
text-align: left;
transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}
.spread-btn:hover {
transform: translateX(-3px);
border-color: rgba(36, 54, 56, 0.28);
background: rgba(255, 255, 255, 0.72);
}
.spread-btn.selected {
border-color: var(--coral);
background: #fffaf0;
box-shadow: inset 3px 0 0 var(--coral);
}
.spread-btn .swatch {
width: 8px;
height: 26px;
background: var(--accent);
border-radius: 1px;
}
.spread-btn .roman {
font-family: Georgia, serif;
font-size: 20px;
}
.spread-btn .name {
font-size: 12px;
font-weight: 750;
letter-spacing: 0.015em;
}
.spread-btn .pages {
color: rgba(36, 54, 56, 0.48);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
}
.action-btn {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
margin-top: 12px;
padding: 12px 13px;
border: 0;
border-radius: 3px;
background: var(--ink);
color: #fff7e9;
cursor: pointer;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.035em;
transition: transform 160ms ease, background 160ms ease;
}
.action-btn:hover {
transform: translateY(-2px);
background: #17292b;
}
.action-btn:active {
transform: translateY(0);
}
.panel-note {
margin: 10px 2px 0;
color: rgba(36, 54, 56, 0.52);
font-size: 9px;
line-height: 1.4;
}
.control-panel {
bottom: 28px;
left: 30px;
display: flex;
gap: 8px;
padding: 8px;
border-radius: 4px;
}
.control-btn {
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 0;
border-radius: 2px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
transition: background 160ms ease;
}
.control-btn:hover {
background: rgba(36, 54, 56, 0.08);
}
.control-btn.primary {
background: var(--coral);
color: #fff8ed;
}
.control-btn.primary:hover {
background: #d94e42;
}
.control-icon {
font-size: 15px;
line-height: 1;
}
.spread-card {
position: absolute;
z-index: 7;
right: 28px;
bottom: 28px;
width: 318px;
padding: 14px;
border: 1px solid rgba(36, 54, 56, 0.18);
border-radius: 4px;
background: rgba(248, 242, 230, 0.94);
box-shadow: 0 20px 60px rgba(36, 44, 39, 0.18);
opacity: 0;
transform: translateY(18px) scale(0.96);
pointer-events: none;
transition: opacity 420ms ease, transform 520ms cubic-bezier(.2,.8,.2,1);
}
.spread-card.visible {
opacity: 1;
transform: translateY(0) scale(1);
}
.card-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
color: rgba(36, 54, 56, 0.62);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.preserved-badge {
padding: 4px 6px;
border-radius: 2px;
background: rgba(49, 139, 135, 0.12);
color: var(--teal);
}
.spread-preview {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 2px;
padding: 6px;
background: #d5c7ae;
box-shadow: inset 0 0 0 1px rgba(36, 54, 56, 0.1);
}
.leaf {
position: relative;
min-height: 124px;
padding: 15px 14px;
overflow: hidden;
background:
repeating-linear-gradient(
to bottom,
transparent 0,
transparent 12px,
rgba(36, 54, 56, 0.12) 13px,
transparent 14px
),
#fffaf0;
box-shadow: inset 0 -12px 22px rgba(91, 70, 41, 0.05);
}
.leaf:first-child {
box-shadow: inset -8px 0 14px rgba(91, 70, 41, 0.07);
}
.leaf small {
display: block;
margin-bottom: 12px;
color: rgba(36, 54, 56, 0.46);
font-size: 8px;
font-weight: 800;
}
.leaf-title {
position: relative;
z-index: 1;
margin-bottom: 17px;
font-family: Georgia, serif;
font-size: 17px;
}
.leaf-rule {
width: 54%;
height: 4px;
background: var(--coral);
}
.card-footer {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
padding: 12px 2px 1px;
}
.card-footer strong {
font-family: Georgia, serif;
font-size: 17px;
font-weight: 500;
}
.card-footer span {
color: rgba(36, 54, 56, 0.54);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
}
.status {
position: absolute;
z-index: 5;
left: 50%;
bottom: 31px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
padding: 8px 12px;
border: 1px solid rgba(36, 54, 56, 0.11);
border-radius: 99px;
background: rgba(248, 242, 230, 0.73);
color: rgba(36, 54, 56, 0.7);
pointer-events: none;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.04em;
white-space: nowrap;
backdrop-filter: blur(10px);
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 3px rgba(49, 139, 135, 0.13);
}
.hover-tip {
position: fixed;
z-index: 10;
display: none;
padding: 7px 9px;
border-radius: 2px;
background: var(--ink);
color: #fff8ed;
pointer-events: none;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
transform: translate(12px, 12px);
}
@media (max-width: 900px) {
.masthead {
top: 22px;
left: 22px;
}
.masthead p {
display: none;
}
.marker-panel {
top: 20px;
right: 20px;
width: 270px;
}
.control-panel {
left: 20px;
bottom: 20px;
}
.status {
display: none;
}
.spread-card {
right: 20px;
bottom: 20px;
width: 290px;
}
}
@media (max-width: 620px) {
.masthead {
top: 18px;
left: 18px;
}
.masthead h1 {
font-size: 36px;
}
.eyebrow {
font-size: 8px;
}
.marker-panel {
top: 96px;
right: 12px;
width: 220px;
padding: 12px;
}
.spread-btn {
grid-template-columns: 8px 27px 1fr;
padding: 9px 7px;
}
.spread-btn .pages,
.panel-note {
display: none;
}
.control-panel {
left: 12px;
bottom: 12px;
}
.control-btn {
padding: 9px;
font-size: 8px;
}
.spread-card {
right: 12px;
bottom: 67px;
width: 260px;
}
.leaf {
min-height: 104px;
padding: 12px 10px;
}
}
</style>
</head>
<body>
<div id="app">
<div id="scene"></div>
<div class="grain"></div>
<header class="masthead">
<div class="eyebrow">Voxel study · No. 04</div>
<h1>The Margin</h1>
<p>Move a ribbon between thick page groups. The selected spread is held outside the binding when the notebook closes.</p>
</header>
<section class="panel marker-panel" aria-label="Bookmark controls">
<div class="panel-heading">
<span>Marker transfer</span>
<span id="markerState" class="marker-chip">II</span>
</div>
<div class="spread-list">
<button class="spread-btn" data-section="0" style="--accent: var(--gold)">
<span class="swatch"></span>
<span class="roman">I</span>
<span class="name">The Threshold</span>
<span class="pages">01–08</span>
</button>
<button class="spread-btn selected" data-section="1" style="--accent: var(--teal)">
<span class="swatch"></span>
<span class="roman">II</span>
<span class="name">Field Notes</span>
<span class="pages">17–24</span>
</button>
<button class="spread-btn" data-section="2" style="--accent: var(--blue)">
<span class="swatch"></span>
<span class="roman">III</span>
<span class="name">The Archive</span>
<span class="pages">41–48</span>
</button>
</div>
<button id="transferBtn" class="action-btn">
<span>Transfer to next spread</span>
<span>→</span>
</button>
<p class="panel-note">Or select any thick page group directly in the scene.</p>
</section>
<section id="spreadCard" class="spread-card" aria-live="polite">
<div class="card-heading">
<span>Selected spread</span>
<span class="preserved-badge">Preserved</span>
</div>
<div class="spread-preview">
<article class="leaf">
<small>17</small>
<div id="leftTitle" class="leaf-title">Observations</div>
<div class="leaf-rule"></div>
</article>
<article class="leaf">
<small>18</small>
<div id="rightTitle" class="leaf-title">Cartographic index</div>
<div class="leaf-rule"></div>
</article>
</div>
<div class="card-footer">
<strong id="cardTitle">Field Notes</strong>
<span id="cardPages">PAGES 17–24</span>
</div>
</section>
<nav class="panel control-panel" aria-label="Notebook controls">
<button id="closeBtn" class="control-btn primary">
<span class="control-icon">▣</span>
<span id="closeLabel">Close notebook</span>
</button>
<button id="resetBtn" class="control-btn">
<span class="control-icon">↺</span>
<span>Reset view</span>
</button>
</nav>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">Notebook open · marker on Spread II</span>
</div>
<div id="hoverTip" class="hover-tip"></div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.getElementById("scene");
const markerState = document.getElementById("markerState");
const transferBtn = document.getElementById("transferBtn");
const closeBtn = document.getElementById("closeBtn");
const closeLabel = document.getElementById("closeLabel");
const resetBtn = document.getElementById("resetBtn");
const statusText = document.getElementById("statusText");
const spreadCard = document.getElementById("spreadCard");
const leftTitle = document.getElementById("leftTitle");
const rightTitle = document.getElementById("rightTitle");
const cardTitle = document.getElementById("cardTitle");
const cardPages = document.getElementById("cardPages");
const hoverTip = document.getElementById("hoverTip");
const spreadButtons = [...document.querySelectorAll(".spread-btn")];
const sections = [
{
roman: "I",
title: "The Threshold",
left: "Opening note",
right: "A map of beginnings",
pages: "01–08",
color: 0xd69a45
},
{
roman: "II",
title: "Field Notes",
left: "Observations",
right: "Cartographic index",
pages: "17–24",
color: 0x318b87
},
{
roman: "III",
title: "The Archive",
left: "Collected fragments",
right: "Postscript & source",
pages: "41–48",
color: 0x4b6fa8
}
];
const sectionZ = [2.08, 0, -2.08];
const state = {
section: 1,
opened: true,
closeAmount: 0,
closeTarget: 0,
markerFromZ: sectionZ[1],
markerTargetZ: sectionZ[1],
markerT: 1,
hovered: -1
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8dece);
scene.fog = new THREE.Fog(0xe8dece, 18, 34);
const camera = new THREE.PerspectiveCamera(38, innerWidth / innerHeight, 0.1, 80);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
mount.appendChild(renderer.domElement);
renderer.domElement.setAttribute("aria-label", "Interactive voxel notebook");
const hemi = new THREE.HemisphereLight(0xfff7e8, 0x6f7b72, 2.25);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff1d5, 4.2);
keyLight.position.set(6, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8d4d1, 1.5);
fillLight.position.set(-8, 5, -4);
scene.add(fillLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xe5dac7,
roughness: 1,
metalness: 0
});
const floor = new THREE.Mesh(new THREE.PlaneGeometry(44, 44), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.73;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x77837a, 0x9b9f91);
grid.position.y = -0.72;
grid.material.transparent = true;
grid.material.opacity = 0.15;
scene.add(grid);
const coverMaterial = new THREE.MeshStandardMaterial({
color: 0x263a3e,
roughness: 0.78,
metalness: 0.04
});
const coverEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x182a2e,
roughness: 0.88
});
const pageMaterials = [
new THREE.MeshStandardMaterial({ color: 0xe6d8bd, roughness: 0.95 }),
new THREE.MeshStandardMaterial({ color: 0xf0e5cf, roughness: 0.96 }),
new THREE.MeshStandardMaterial({ color: 0xdfd0b4, roughness: 0.94 })
];
const topPageMaterial = new THREE.MeshStandardMaterial({
color: 0xfff5df,
roughness: 0.92
});
const inkMaterial = new THREE.MeshStandardMaterial({
color: 0x5e655d,
roughness: 0.9
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0xd69a45,
roughness: 0.7,
emissive: 0x6e3b0b,
emissiveIntensity: 0.05
});
const frameMaterial = new THREE.MeshBasicMaterial({
color: 0xe85d4f,
transparent: true,
opacity: 0.84,
depthTest: false,
depthWrite: false
});
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xe85d4f,
roughness: 0.5,
emissive: 0x7a1e17,
emissiveIntensity: 0.32,
depthTest: false,
depthWrite: false
});
function box(width, height, depth, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const book = new THREE.Group();
scene.add(book);
const leftCover = box(4.7, 0.28, 7.45, coverMaterial, -2.47, -0.42, 0, book);
box(4.72, 0.1, 7.47, coverEdgeMaterial, -2.47, -0.58, 0, book);
box(0.22, 0.31, 7.45, coverEdgeMaterial, 0, -0.4, 0, book);
const rightCoverPivot = new THREE.Group();
book.add(rightCoverPivot);
box(4.7, 0.28, 7.45, coverMaterial, 2.47, -0.42, 0, rightCoverPivot);
box(4.72, 0.1, 7.47, coverEdgeMaterial, 2.47, -0.58, 0, rightCoverPivot);
const coverMarkMaterial = new THREE.MeshStandardMaterial({
color: 0xd6a75d,
roughness: 0.68,
metalness: 0.12
});
box(1.45, 0.025, 0.085, coverMarkMaterial, 2.47, -0.265, -2.2, rightCoverPivot);
box(0.95, 0.025, 0.065, coverMarkMaterial, 2.47, -0.265, -2.42, rightCoverPivot);
box(0.22, 0.025, 0.22, coverMarkMaterial, 2.47, -0.26, -2.78, rightCoverPivot);
const rightPagePivot = new THREE.Group();
book.add(rightPagePivot);
const leftGroups = [];
const rightGroups = [];
const pickables = [];
function makeSelectionFrame(parent, sectionIndex) {
const frame = new THREE.Group();
frame.position.y = 0.565;
frame.visible = false;
const width = 4.17;
const depth = 1.94;
const thickness = 0.055;
const pieces = [
box(width, 0.026, thickness, frameMaterial, 0, 0, depth / 2, frame),
box(width, 0.026, thickness, frameMaterial, 0, 0, -depth / 2, frame),
box(thickness, 0.026, depth, frameMaterial, width / 2, 0, 0, frame),
box(thickness, 0.026, depth, frameMaterial, -width / 2, 0, 0, frame)
];
pieces.forEach(mesh => {
mesh.castShadow = false;
mesh.receiveShadow = false;
mesh.renderOrder = 30;
mesh.userData.section = sectionIndex;
});
parent.add(frame);
return frame;
}
function makePageGroup(side, index) {
const group = new THREE.Group();
for (let layer = 0; layer < 7; layer++) {
const material = pageMaterials[(layer + index) % pageMaterials.length];
const width = 4.05 - layer * 0.012;
const mesh = box(width, 0.067, 1.82, material, 0, -0.075 + layer * 0.082, 0, group);
mesh.userData.section = index;
pickables.push(mesh);
}
const top = box(4.05, 0.045, 1.84, topPageMaterial, 0, 0.49, 0, group);
top.userData.section = index;
pickables.push(top);
const lineWidths = [2.65, 2.3, 2.72, 2.48, 1.72];
for (let row = 0; row < lineWidths.length; row++) {
const line = box(
lineWidths[row],
0.016,
0.045,
inkMaterial,
-0.12,
0.522,
-0.48 + row * 0.18,
group
);
line.material = inkMaterial;
line.userData.section = index;
pickables.push(line);
}
const tabMaterial = new THREE.MeshStandardMaterial({
color: sections[index].color,
roughness: 0.68,
emissive: sections[index].color,
emissiveIntensity: 0.05
});
const tab = box(0.11, 0.036, 0.88, tabMaterial, side * 2.02, 0.525, 0.05, group);
tab.userData.section = index;
pickables.push(tab);
const header = box(0.85, 0.02, 0.075, tabMaterial, -0.75, 0.53, -0.72, group);
header.userData.section = index;
pickables.push(header);
const frame = makeSelectionFrame(group, index);
group.userData.tab = tab;
group.userData.frame = frame;
return group;
}
for (let i = 0; i < sections.length; i++) {
const leftGroup = makePageGroup(-1, i);
leftGroup.position.set(-2.18, 0, sectionZ[i]);
book.add(leftGroup);
leftGroups.push(leftGroup);
const rightGroup = makePageGroup(1, i);
rightGroup.position.set(2.18, 0, sectionZ[i]);
rightPagePivot.add(rightGroup);
rightGroups.push(rightGroup);
}
const marker = new THREE.Group();
marker.position.set(2.18, 0.62, sectionZ[state.section]);
rightPagePivot.add(marker);
const ribbonStrip = box(0.16, 0.045, 1.42, markerMaterial, 0, 0, 0, marker);
const ribbonTail = box(0.16, 0.68, 0.14, markerMaterial, 0, -0.32, 0.61, marker);
const ribbonKnot = box(0.23, 0.09, 0.23, markerMaterial, 0, 0.015, -0.72, marker);
[ribbonStrip, ribbonTail, ribbonKnot].forEach(mesh => {
mesh.castShadow = true;
mesh.renderOrder = 40;
});
// A few tiny voxel motes give the diorama a quiet sense of depth.
const dustCount = 24;
const dustGeometry = new THREE.BoxGeometry(0.045, 0.045, 0.045);
const dustMaterial = new THREE.MeshBasicMaterial({
color: 0xfff6dc,
transparent: true,
opacity: 0.56
});
const dust = new THREE.InstancedMesh(dustGeometry, dustMaterial, dustCount);
dust.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
scene.add(dust);
const dustData = [];
for (let i = 0; i < dustCount; i++) {
dustData.push({
x: (Math.random() - 0.5) * 13,
y: 0.7 + Math.random() * 4.3,
z: (Math.random() - 0.5) * 11,
phase: Math.random() * Math.PI * 2,
scale: 0.55 + Math.random() * 1.2
});
}
const dustDummy = new THREE.Object3D();
// Custom camera controls: orbit, pan, zoom, and reset.
const controls = {
yaw: 0.51,
pitch: 0.79,
distance: 13.8,
target: new THREE.Vector3(0, 0.05, 0)
};
function updateCamera() {
const horizontal = Math.sin(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.cos(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.yaw = 0.51;
controls.pitch = 0.79;
controls.distance = 13.8;
controls.target.set(0, 0.05, 0);
updateCamera();
}
updateCamera();
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const pointerState = {
down: false,
moved: false,
button: 0,
x: 0,
y: 0
};
function sectionAtEvent(event) {
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 hits = raycaster.intersectObjects(pickables, false);
for (const hit of hits) {
if (Number.isInteger(hit.object.userData.section)) {
return hit.object.userData.section;
}
}
return -1;
}
function setHovered(index) {
if (state.hovered === index) return;
state.hovered = index;
leftGroups.forEach((group, i) => {
group.userData.tab.material.emissiveIntensity = i === index ? 0.25 : 0.05;
});
rightGroups.forEach((group, i) => {
group.userData.tab.material.emissiveIntensity = i === index ? 0.25 : 0.05;
});
renderer.domElement.style.cursor = index >= 0 ? "pointer" : "grab";
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerState.down = true;
pointerState.moved = false;
pointerState.button = event.button;
pointerState.x = event.clientX;
pointerState.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (pointerState.down) {
const dx = event.clientX - pointerState.x;
const dy = event.clientY - pointerState.y;
if (Math.abs(event.clientX - pointerState.x) + Math.abs(event.clientY - pointerState.y) > 4) {
pointerState.moved = true;
}
if (pointerState.button === 2 || event.shiftKey) {
const right = new THREE.Vector3(Math.cos(controls.yaw), 0, -Math.sin(controls.yaw));
const forward = new THREE.Vector3(-Math.sin(controls.yaw), 0, -Math.cos(controls.yaw));
const panScale = controls.distance * 0.00125;
controls.target.addScaledVector(right, -dx * panScale);
controls.target.addScaledVector(forward, -dy * panScale);
} else {
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(controls.pitch + dy * 0.005, 0.28, 1.28);
}
pointerState.x = event.clientX;
pointerState.y = event.clientY;
updateCamera();
hoverTip.style.display = "none";
} else {
const index = sectionAtEvent(event);
setHovered(index);
if (index >= 0 && index !== state.section) {
hoverTip.textContent = `Transfer to Spread ${sections[index].roman}`;
hoverTip.style.left = `${event.clientX}px`;
hoverTip.style.top = `${event.clientY}px`;
hoverTip.style.display = "block";
} else {
hoverTip.style.display = "none";
}
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointerState.down) return;
const wasClick = !pointerState.moved && pointerState.button === 0;
pointerState.down = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (wasClick) {
const index = sectionAtEvent(event);
if (index >= 0 && index !== state.section) {
transferMarker(index);
}
}
renderer.domElement.style.cursor = state.hovered >= 0 ? "pointer" : "grab";
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerState.down = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointerState.down) {
setHovered(-1);
hoverTip.style.display = "none";
}
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
8.2,
19
);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("dblclick", resetCamera);
function updateSelectionUI() {
const current = sections[state.section];
markerState.textContent = current.roman;
spreadButtons.forEach((button, index) => {
button.classList.toggle("selected", index === state.section);
button.setAttribute("aria-pressed", String(index === state.section));
});
leftGroups.forEach((group, index) => {
group.userData.frame.visible = index === state.section;
});
rightGroups.forEach((group, index) => {
group.userData.frame.visible = index === state.section;
});
leftTitle.textContent = current.left;
rightTitle.textContent = current.right;
cardTitle.textContent = current.title;
cardPages.textContent = `PAGES ${current.pages}`;
}
function transferMarker(index) {
state.section = index;
state.markerFromZ = marker.position.z;
state.markerTargetZ = sectionZ[index];
state.markerT = 0;
updateSelectionUI();
if (!state.opened) {
statusText.textContent =
`Closed · Spread ${sections[index].roman} preserved and marker transferred`;
}
}
function toggleNotebook() {
state.opened = !state.opened;
state.closeTarget = state.opened ? 0 : 1;
if (state.opened) {
closeLabel.textContent = "Close notebook";
spreadCard.classList.remove("visible");
statusText.textContent =
`Opening · marker remains on Spread ${sections[state.section].roman}`;
} else {
closeLabel.textContent = "Open notebook";
spreadCard.classList.add("visible");
statusText.textContent =
`Closing around Spread ${sections[state.section].roman} · selection preserved`;
}
}
transferBtn.addEventListener("click", () => {
transferMarker((state.section + 1) % sections.length);
});
closeBtn.addEventListener("click", toggleNotebook);
resetBtn.addEventListener("click", resetCamera);
spreadButtons.forEach(button => {
button.addEventListener("click", () => {
transferMarker(Number(button.dataset.section));
});
});
updateSelectionUI();
const clock = new THREE.Clock();
let elapsed = 0;
function damp(current, target, lambda, dt) {
return THREE.MathUtils.lerp(current, target, 1 - Math.exp(-lambda * dt));
}
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
state.closeAmount = damp(state.closeAmount, state.closeTarget, 4.2, dt);
const closeAngle = Math.PI * 0.96 * state.closeAmount;
rightPagePivot.rotation.z = closeAngle;
rightCoverPivot.rotation.z = closeAngle;
if (state.markerT < 1) {
state.markerT = Math.min(1, state.markerT + dt / 0.86);
const eased = 1 - Math.pow(1 - state.markerT, 3);
marker.position.z = THREE.MathUtils.lerp(state.markerFromZ, state.markerTargetZ, eased);
marker.position.y = 0.62 + Math.sin(state.markerT * Math.PI) * 0.54;
} else {
marker.position.y = 0.62;
}
frameMaterial.opacity = 0.76 + Math.sin(elapsed * 3.1) * 0.12;
markerMaterial.emissiveIntensity = 0.3 + Math.sin(elapsed * 3.4) * 0.08;
if (state.closeAmount > 0.985 && !state.opened) {
statusText.textContent =
`Closed · Spread ${sections[state.section].roman} preserved outside the binding`;
} else if (state.closeAmount < 0.015 && state.opened) {
statusText.textContent =
`Notebook open · marker on Spread ${sections[state.section].roman}`;
}
for (let i = 0; i < dustCount; i++) {
const d = dustData[i];
dustDummy.position.set(
d.x + Math.sin(elapsed * 0.23 + d.phase) * 0.08,
d.y + Math.sin(elapsed * 0.42 + d.phase) * 0.11,
d.z + Math.cos(elapsed * 0.19 + d.phase) * 0.07
);
dustDummy.scale.setScalar(d.scale);
dustDummy.updateMatrix();
dust.setMatrixAt(i, dustDummy.matrix);
}
dust.instanceMatrix.needsUpdate = true;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
</script>
</body>
</html>
```