Prompt specification
Build or customize the Three.js 3D scene "Folded manuscript gathering and binding holes" 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: Folded manuscript gathering and binding holes
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/folded-manuscript-gathering-and-binding-holes-x2369
Scene Description Prompt:
A stylized folded parchment gathering with ordered leaves and visible binding holes, without imitation historical writing. Three.js from cdnjs, one HTML file.
Working Three.js Starter (folded-manuscript-gathering-and-binding-holes-x2369):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Folded Parchment Gathering</title>
<style>
:root {
color-scheme: dark;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #17110e;
}
body {
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.title {
position: fixed;
top: clamp(20px, 4vw, 48px);
left: clamp(20px, 4vw, 48px);
z-index: 3;
max-width: min(390px, calc(100vw - 40px));
color: #f0dfc2;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.7);
}
.title .eyebrow {
margin-bottom: 9px;
color: #b99564;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.24em;
text-transform: uppercase;
}
.title h1 {
margin: 0;
font-size: clamp(23px, 3.2vw, 42px);
font-weight: 450;
line-height: 1.02;
letter-spacing: -0.035em;
}
.title p {
margin: 13px 0 0;
color: rgba(231, 211, 180, 0.66);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: fixed;
right: clamp(18px, 3vw, 38px);
bottom: clamp(18px, 3vw, 34px);
z-index: 4;
display: flex;
align-items: center;
gap: 12px;
}
.hint {
color: rgba(235, 217, 188, 0.55);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
transition: opacity 500ms ease;
}
.hint.hidden {
opacity: 0;
}
button {
appearance: none;
border: 1px solid rgba(220, 190, 146, 0.22);
border-radius: 999px;
padding: 10px 15px;
color: #e7d4b6;
background: rgba(32, 23, 17, 0.58);
backdrop-filter: blur(12px);
font: inherit;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition:
background 180ms ease,
border-color 180ms ease,
transform 180ms ease;
}
button:hover {
border-color: rgba(220, 190, 146, 0.5);
background: rgba(66, 47, 32, 0.7);
transform: translateY(-1px);
}
.vignette {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
background:
radial-gradient(
ellipse at 52% 44%,
transparent 35%,
rgba(8, 5, 4, 0.2) 73%,
rgba(5, 3, 2, 0.67) 100%
),
linear-gradient(
to bottom,
rgba(10, 6, 4, 0.12),
transparent 25%,
transparent 76%,
rgba(7, 4, 3, 0.25)
);
}
.loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: #d8c09b;
background: #17110e;
font-size: 10px;
letter-spacing: 0.22em;
text-transform: uppercase;
transition: opacity 700ms ease;
}
.loading.done {
opacity: 0;
pointer-events: none;
}
.loading span {
position: relative;
padding-bottom: 18px;
}
.loading span::after {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 1px;
content: "";
background: linear-gradient(
90deg,
transparent,
#c7a16b,
transparent
);
transform-origin: left;
animation: breathe 1.4s ease-in-out infinite;
}
@keyframes breathe {
0%,
100% {
transform: scaleX(0.25);
opacity: 0.35;
}
50% {
transform: scaleX(1);
opacity: 1;
}
}
@media (max-width: 620px) {
.title p {
display: none;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="A stylized stack of folded parchment leaves with visible binding holes"
></canvas>
<header class="title">
<div class="eyebrow">Material study · 01</div>
<h1>Folded Parchment</h1>
<p>
An ordered gathering of blank folios, shaped by warm light,
shallow folds, and paired binding holes.
</p>
</header>
<div class="vignette"></div>
<div class="controls">
<div class="hint" id="hint">Drag to orbit · Scroll to zoom</div>
<button id="reset" type="button">Reset view</button>
</div>
<div class="loading" id="loading">
<span>Preparing parchment</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const hint = document.querySelector("#hint");
const resetButton = document.querySelector("#reset");
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17110e);
scene.fog = new THREE.FogExp2(0x17110e, 0.035);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
let currentYaw = 0.67;
let currentPitch = 1.02;
let currentRadius = 11.4;
let targetYaw = currentYaw;
let targetPitch = currentPitch;
let targetRadius = currentRadius;
let lastInteraction = performance.now();
// -------------------------------------------------------------------------
// Procedural parchment: fibers, mottling, and bump detail only.
// No letters, glyphs, or imitation writing are generated.
// -------------------------------------------------------------------------
function mulberry32(seed) {
return function random() {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
function hexToRgb(hex) {
const value = parseInt(hex.replace("#", ""), 16);
return {
r: (value >> 16) & 255,
g: (value >> 8) & 255,
b: value & 255
};
}
function makeParchmentMap(seed, baseHex) {
const size = 512;
const random = mulberry32(seed);
const base = hexToRgb(baseHex);
const parchmentCanvas = document.createElement("canvas");
parchmentCanvas.width = size;
parchmentCanvas.height = size;
const context = parchmentCanvas.getContext("2d");
const image = context.createImageData(size, size);
for (let y = 0; y < size; y++) {
for (let x = 0; x < size; x++) {
const index = (y * size + x) * 4;
const broadWave =
Math.sin(x * 0.026 + Math.sin(y * 0.011)) * 3.2 +
Math.sin(y * 0.043 + x * 0.006) * 1.8;
const grain = (random() - 0.5) * 18;
const variation = grain + broadWave;
image.data[index] =
THREE.MathUtils.clamp(base.r + variation + 4, 0, 255);
image.data[index + 1] =
THREE.MathUtils.clamp(base.g + variation, 0, 255);
image.data[index + 2] =
THREE.MathUtils.clamp(base.b + variation - 2, 0, 255);
image.data[index + 3] = 255;
}
}
context.putImageData(image, 0, 0);
// Soft irregular edge discoloration.
for (let i = 0; i < 24; i++) {
const x = random() * size;
const y = random() * size;
const radius = 35 + random() * 125;
const gradient = context.createRadialGradient(
x, y, 0,
x, y, radius
);
gradient.addColorStop(
0,
`rgba(103, 70, 31, ${0.018 + random() * 0.025})`
);
gradient.addColorStop(1, "rgba(103, 70, 31, 0)");
context.fillStyle = gradient;
context.fillRect(x - radius, y - radius, radius * 2, radius * 2);
}
// Fine, non-symbolic fibers.
for (let i = 0; i < 1800; i++) {
const x = random() * size;
const y = random() * size;
const length = 2 + random() * 15;
const angle = (random() - 0.5) * 0.7 + (random() > 0.82 ? 1.4 : 0);
const alpha = 0.018 + random() * 0.045;
context.beginPath();
context.moveTo(x, y);
context.lineTo(
x + Math.cos(angle) * length,
y + Math.sin(angle) * length
);
context.strokeStyle =
random() > 0.42
? `rgba(92, 63, 28, ${alpha})`
: `rgba(255, 247, 215, ${alpha * 0.9})`;
context.lineWidth = 0.35 + random() * 0.65;
context.stroke();
}
// Gentle perimeter darkening.
const edgeGradient = context.createRadialGradient(
size / 2,
size / 2,
size * 0.25,
size / 2,
size / 2,
size * 0.72
);
edgeGradient.addColorStop(0, "rgba(70, 40, 15, 0)");
edgeGradient.addColorStop(1, "rgba(70, 40, 15, 0.12)");
context.fillStyle = edgeGradient;
context.fillRect(0, 0, size, size);
const texture = new THREE.CanvasTexture(parchmentCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(0.18, 0.18);
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeBumpMap(seed) {
const size = 256;
const random = mulberry32(seed);
const bumpCanvas = document.createElement("canvas");
bumpCanvas.width = size;
bumpCanvas.height = size;
const context = bumpCanvas.getContext("2d");
const image = context.createImageData(size, size);
for (let index = 0; index < image.data.length; index += 4) {
const value = 120 + Math.floor(random() * 26);
image.data[index] = value;
image.data[index + 1] = value;
image.data[index + 2] = value;
image.data[index + 3] = 255;
}
context.putImageData(image, 0, 0);
for (let i = 0; i < 650; i++) {
const x = random() * size;
const y = random() * size;
const length = 2 + random() * 10;
context.beginPath();
context.moveTo(x, y);
context.lineTo(x + length, y + (random() - 0.5) * 2);
context.strokeStyle = `rgba(210,210,210,${0.04 + random() * 0.08})`;
context.lineWidth = 0.5;
context.stroke();
}
const texture = new THREE.CanvasTexture(bumpCanvas);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(0.28, 0.28);
return texture;
}
const parchmentMaps = [
makeParchmentMap(11, "#e5cc97"),
makeParchmentMap(29, "#d9b87c"),
makeParchmentMap(47, "#ead3a0"),
makeParchmentMap(83, "#cfad72")
];
const bumpMap = makeBumpMap(103);
function makeFaceMaterial(map, tint, roughness = 0.94) {
return new THREE.MeshStandardMaterial({
color: tint,
map,
bumpMap,
bumpScale: 0.022,
roughness,
metalness: 0,
side: THREE.DoubleSide
});
}
const faceMaterials = [
makeFaceMaterial(parchmentMaps[0], 0xfff5df),
makeFaceMaterial(parchmentMaps[1], 0xfff1d7),
makeFaceMaterial(parchmentMaps[2], 0xfff8e8),
makeFaceMaterial(parchmentMaps[3], 0xffe8c2)
];
const edgeMaterials = [
new THREE.MeshStandardMaterial({
color: 0x9e7947,
roughness: 1,
metalness: 0,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x8d693d,
roughness: 1,
metalness: 0,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0xa88755,
roughness: 1,
metalness: 0,
side: THREE.DoubleSide
})
];
// -------------------------------------------------------------------------
// Folded panels with true geometric binding holes
// -------------------------------------------------------------------------
const HALF_WIDTH = 2.55;
const PANEL_HEIGHT = 6.65;
const PAPER_DEPTH = 0.016;
const INNER_GAP = 0.05;
const HOLE_OFFSET = 0.285;
const HOLE_RADIUS = 0.086;
const HOLE_POSITIONS = [-2.36, -0.79, 0.79, 2.36];
function roundedRectShape(x0, x1, y0, y1, radius) {
const shape = new THREE.Shape();
shape.moveTo(x0 + radius, y0);
shape.lineTo(x1 - radius, y0);
shape.quadraticCurveTo(x1, y0, x1, y0 + radius);
shape.lineTo(x1, y1 - radius);
shape.quadraticCurveTo(x1, y1, x1 - radius, y1);
shape.lineTo(x0 + radius, y1);
shape.quadraticCurveTo(x0, y1, x0, y1 - radius);
shape.lineTo(x0, y0 + radius);
shape.quadraticCurveTo(x0, y0, x0 + radius, y0);
return shape;
}
function makePanelShape(side) {
const x0 = side < 0 ? -HALF_WIDTH : INNER_GAP / 2;
const x1 = side < 0 ? -INNER_GAP / 2 : HALF_WIDTH;
const shape = roundedRectShape(
x0,
x1,
-PANEL_HEIGHT / 2,
PANEL_HEIGHT / 2,
0.15
);
for (const y of HOLE_POSITIONS) {
const hole = new THREE.Path();
const x = side < 0 ? -HOLE_OFFSET : HOLE_OFFSET;
// Clockwise path identifies an interior hole.
hole.absarc(x, y, HOLE_RADIUS, 0, Math.PI * 2, true);
shape.holes.push(hole);
}
return shape;
}
function makePanelGeometry(side) {
const geometry = new THREE.ExtrudeGeometry(
makePanelShape(side),
{
depth: PAPER_DEPTH,
steps: 1,
curveSegments: 18,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.003,
bevelThickness: 0.003,
bevelOffset: 0
}
);
geometry.computeVertexNormals();
return geometry;
}
const leftPanelGeometry = makePanelGeometry(-1);
const rightPanelGeometry = makePanelGeometry(1);
const holeDiskGeometry = new THREE.CircleGeometry(0.079, 28);
const holeDiskMaterial = new THREE.MeshBasicMaterial({
color: 0x21150f,
side: THREE.DoubleSide,
toneMapped: false
});
function addHoleCavities(panel, side) {
for (const y of HOLE_POSITIONS) {
const cavity = new THREE.Mesh(
holeDiskGeometry,
holeDiskMaterial
);
cavity.position.set(
side < 0 ? -HOLE_OFFSET : HOLE_OFFSET,
y,
-0.006
);
cavity.renderOrder = 1;
panel.add(cavity);
}
}
const leafCount = 11;
for (let index = 0; index < leafCount; index++) {
const isHeroLeaf = index === leafCount - 1;
const root = new THREE.Group();
root.position.set(
-0.035 + Math.sin(index * 0.73) * 0.035,
0.085 + index * 0.058,
-0.035 + Math.cos(index * 0.81) * 0.025
);
root.rotation.y = -0.045 + index * 0.007;
const orientation = new THREE.Group();
orientation.rotation.x = -Math.PI / 2;
orientation.rotation.z =
(index - (leafCount - 1) / 2) * 0.0017;
root.add(orientation);
const materialIndex = isHeroLeaf
? 0
: [1, 2, 0, 3][index % 4];
const faceMaterial = faceMaterials[materialIndex];
const edgeMaterial = edgeMaterials[materialIndex % edgeMaterials.length];
const leftPanel = new THREE.Mesh(
leftPanelGeometry,
[faceMaterial, edgeMaterial]
);
leftPanel.position.z = -PAPER_DEPTH / 2;
leftPanel.castShadow = true;
leftPanel.receiveShadow = true;
orientation.add(leftPanel);
addHoleCavities(leftPanel, -1);
const rightPanel = new THREE.Mesh(
rightPanelGeometry,
[faceMaterial, edgeMaterial]
);
rightPanel.position.z = -PAPER_DEPTH / 2;
const openingAngle = isHeroLeaf
? 0.46
: 0.006 + index * 0.0032;
rightPanel.rotation.y = -openingAngle;
rightPanel.castShadow = true;
rightPanel.receiveShadow = true;
orientation.add(rightPanel);
addHoleCavities(rightPanel, 1);
// A narrow recessed fold bridges the two halves.
const fold = new THREE.Mesh(
new THREE.BoxGeometry(
0.034,
PANEL_HEIGHT * 0.985,
0.009
),
edgeMaterial
);
fold.position.z = -0.003;
fold.castShadow = true;
orientation.add(fold);
scene.add(root);
}
// -------------------------------------------------------------------------
// Display table, floor, and contact shadow
// -------------------------------------------------------------------------
const tableMaterial = new THREE.MeshStandardMaterial({
color: 0x2b1d16,
roughness: 0.78,
metalness: 0.03
});
const table = new THREE.Mesh(
new THREE.CylinderGeometry(6.35, 6.65, 0.38, 96),
tableMaterial
);
table.position.y = -0.24;
table.receiveShadow = true;
scene.add(table);
const tableRing = new THREE.Mesh(
new THREE.TorusGeometry(5.98, 0.035, 10, 128),
new THREE.MeshStandardMaterial({
color: 0x6d4a2e,
roughness: 0.58,
metalness: 0.08
})
);
tableRing.rotation.x = Math.PI / 2;
tableRing.position.y = -0.044;
scene.add(tableRing);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0x120d0b,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.44;
floor.receiveShadow = true;
scene.add(floor);
function makeContactShadow() {
const shadowCanvas = document.createElement("canvas");
shadowCanvas.width = 256;
shadowCanvas.height = 256;
const context = shadowCanvas.getContext("2d");
const gradient = context.createRadialGradient(
128, 128, 8,
128, 128, 126
);
gradient.addColorStop(0, "rgba(0,0,0,0.58)");
gradient.addColorStop(0.45, "rgba(0,0,0,0.34)");
gradient.addColorStop(1, "rgba(0,0,0,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(shadowCanvas);
return new THREE.Mesh(
new THREE.PlaneGeometry(8.2, 9.5),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
}
const contactShadow = makeContactShadow();
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.position.y = -0.041;
scene.add(contactShadow);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(
new THREE.HemisphereLight(
0xffe6b7,
0x261711,
1.35
)
);
const keyLight = new THREE.DirectionalLight(
0xffe5b5,
3.15
);
keyLight.position.set(4.8, 8.5, 5.4);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
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 = 24;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const coolFill = new THREE.DirectionalLight(
0x9bb6c9,
0.78
);
coolFill.position.set(-6, 4.5, -3.5);
scene.add(coolFill);
const warmRim = new THREE.PointLight(
0xff9d50,
28,
18,
2
);
warmRim.position.set(3.5, 3.6, -4.2);
scene.add(warmRim);
const lowFill = new THREE.PointLight(
0xe4b878,
9,
12,
2
);
lowFill.position.set(-4, 1.2, 4);
scene.add(lowFill);
// -------------------------------------------------------------------------
// Suspended dust
// -------------------------------------------------------------------------
const dustCount = 110;
const dustPositions = new Float32Array(dustCount * 3);
const dustRandom = mulberry32(901);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] =
(dustRandom() - 0.5) * 12;
dustPositions[i * 3 + 1] =
0.2 + dustRandom() * 5;
dustPositions[i * 3 + 2] =
(dustRandom() - 0.5) * 10;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xf2d3a0,
size: 0.022,
transparent: true,
opacity: 0.22,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Custom camera controls; no external controls module is used.
// -------------------------------------------------------------------------
const pointers = new Map();
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
function markInteraction() {
lastInteraction = performance.now();
hint.classList.add("hidden");
}
canvas.addEventListener("pointerdown", event => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.setPointerCapture(event.pointerId);
markInteraction();
if (pointers.size === 2) {
pinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
targetYaw -= deltaX * 0.006;
targetPitch = THREE.MathUtils.clamp(
targetPitch - deltaY * 0.005,
0.48,
1.38
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0 && distance > 0) {
targetRadius *= pinchDistance / distance;
targetRadius = THREE.MathUtils.clamp(
targetRadius,
6.7,
17
);
}
pinchDistance = distance;
}
markInteraction();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = pointers.size === 2
? pointerDistance()
: 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
targetRadius *= Math.exp(event.deltaY * 0.001);
targetRadius = THREE.MathUtils.clamp(
targetRadius,
6.7,
17
);
markInteraction();
},
{ passive: false }
);
function resetView() {
targetYaw = 0.67;
targetPitch = 1.02;
targetRadius = window.innerWidth < 700 ? 13.2 : 11.4;
markInteraction();
}
canvas.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", event => {
if (event.key.toLowerCase() === "r") {
resetView();
}
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height);
renderer.setPixelRatio(
Math.min(window.devicePixelRatio, 2)
);
camera.aspect = width / height;
camera.fov = camera.aspect < 0.8 ? 46 : 36;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
let firstFrame = true;
function updateCamera(delta) {
const idleTime = performance.now() - lastInteraction;
if (
pointers.size === 0 &&
idleTime > 4200
) {
targetYaw += delta * 0.027;
}
const damping = 1 - Math.exp(-delta * 7.5);
currentYaw = THREE.MathUtils.lerp(
currentYaw,
targetYaw,
damping
);
currentPitch = THREE.MathUtils.lerp(
currentPitch,
targetPitch,
damping
);
currentRadius = THREE.MathUtils.lerp(
currentRadius,
targetRadius,
damping
);
const sinPitch = Math.sin(currentPitch);
camera.position.set(
cameraTarget.x +
currentRadius *
sinPitch *
Math.sin(currentYaw),
cameraTarget.y +
currentRadius *
Math.cos(currentPitch),
cameraTarget.z +
currentRadius *
sinPitch *
Math.cos(currentYaw)
);
camera.lookAt(cameraTarget);
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
updateCamera(delta);
const positions = dustGeometry.attributes.position;
for (let i = 0; i < dustCount; i++) {
let y = positions.getY(i) + delta * 0.035;
let x = positions.getX(i) + delta * 0.004;
if (y > 5.4) y = 0.15;
if (x > 6.2) x = -6.2;
positions.setY(i, y);
positions.setX(i, x);
}
positions.needsUpdate = true;
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
setTimeout(() => {
loading.classList.add("done");
}, 250);
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```