Prompt specification
Build or customize the Three.js 3D scene "Keepsake toy missing-part display" 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: Keepsake toy missing-part display
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/keepsake-toy-missing-part-display-x3901
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: keepsake toy missing-part display. Show a small wooden toy with a detached wheel beside an old gift tag; make the missing connection visible while preserving distinctive wear marks on the body. Return one self-contained HTML file.
Working Three.js Starter (keepsake-toy-missing-part-display-x3901):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Missing Wheel — A Keepsake Display</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded8ca;
color: #302d28;
font-family: Georgia, "Times New Roman", serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas:focus-visible {
outline: 2px solid rgba(70, 104, 103, 0.65);
outline-offset: -4px;
}
.caption {
position: fixed;
top: clamp(24px, 5vw, 58px);
left: clamp(24px, 5vw, 68px);
z-index: 2;
width: min(420px, calc(100vw - 48px));
pointer-events: none;
user-select: none;
}
.eyebrow {
margin-bottom: 13px;
color: #68736c;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.27em;
text-transform: uppercase;
}
h1 {
max-width: 390px;
margin: 0;
font-size: clamp(35px, 5vw, 66px);
font-weight: 400;
line-height: 0.96;
letter-spacing: -0.045em;
}
.description {
max-width: 315px;
margin: 20px 0 0;
color: rgba(48, 45, 40, 0.72);
font-size: 14px;
line-height: 1.6;
}
.object-label {
position: fixed;
right: clamp(20px, 4vw, 55px);
top: 50%;
z-index: 2;
display: flex;
align-items: center;
gap: 13px;
color: rgba(48, 45, 40, 0.62);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
writing-mode: vertical-rl;
pointer-events: none;
user-select: none;
}
.object-label::before {
width: 1px;
height: 50px;
background: rgba(48, 45, 40, 0.3);
content: "";
}
.instructions {
position: fixed;
bottom: 25px;
left: 50%;
z-index: 2;
padding: 9px 13px;
border: 1px solid rgba(48, 45, 40, 0.15);
border-radius: 999px;
background: rgba(244, 239, 226, 0.58);
color: rgba(48, 45, 40, 0.62);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.08em;
transform: translateX(-50%);
backdrop-filter: blur(7px);
pointer-events: none;
white-space: nowrap;
user-select: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #ded8ca;
color: #68736c;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.25em;
text-transform: uppercase;
transition: opacity 0.7s ease;
pointer-events: none;
}
#loading.out {
opacity: 0;
}
@media (max-width: 700px) {
.caption {
top: 22px;
left: 22px;
}
h1 {
max-width: 250px;
font-size: 39px;
}
.description {
display: none;
}
.object-label {
right: 12px;
}
.instructions {
bottom: 17px;
}
}
</style>
</head>
<body>
<main id="scene"></main>
<section class="caption" aria-label="Exhibit description">
<div class="eyebrow">Archive of Small Things · Object 07</div>
<h1>The missing wheel</h1>
<p class="description">
A painted wooden toy car, its detached wheel, and an old gift tag.
The exposed axle and worn blue paint preserve the story of use.
</p>
</section>
<div class="object-label">Found with one part missing</div>
<div class="instructions">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="loading">Opening the keepsake display</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 loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xded8ca);
scene.fog = new THREE.Fog(0xded8ca, 10, 19);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
mount.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional display of a worn wooden toy car with a detached wheel and an old gift tag"
);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
50
);
const target = new THREE.Vector3(0.05, 0.82, 0.05);
const spherical = new THREE.Spherical(7.5, 1.05, 0.66);
function updateCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
updateCamera();
// Lighting gives the small objects soft museum-display shadows.
scene.add(new THREE.HemisphereLight(0xfff8e8, 0x766a5e, 1.7));
const keyLight = new THREE.DirectionalLight(0xffedc7, 3.25);
keyLight.position.set(4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
keyLight.shadow.radius = 4;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc4d7dc, 1.15);
fillLight.position.set(-5, 3.5, -2.5);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xffd9a1, 0.65, 9, 2);
rimLight.position.set(-2.8, 2.7, 2.5);
scene.add(rimLight);
// Deterministic procedural wood grain.
let seed = 7391;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function makeWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 256, 0);
gradient.addColorStop(0, "#b97842");
gradient.addColorStop(0.45, "#d59a5f");
gradient.addColorStop(1, "#b87843");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 256, 256);
for (let i = 0; i < 115; i++) {
const y = random() * 256;
const amplitude = 1 + random() * 5;
ctx.strokeStyle = `rgba(83, 43, 22, ${0.035 + random() * 0.085})`;
ctx.lineWidth = 0.5 + random() * 1.7;
ctx.beginPath();
ctx.moveTo(0, y);
ctx.bezierCurveTo(
65,
y + Math.sin(i) * amplitude,
145,
y - Math.cos(i * 0.7) * amplitude,
256,
y + (random() - 0.5) * 4
);
ctx.stroke();
}
for (let i = 0; i < 34; i++) {
ctx.fillStyle = `rgba(255, 223, 169, ${0.025 + random() * 0.06})`;
ctx.fillRect(random() * 256, random() * 256, 10 + random() * 55, 1);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.7, 1.7);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const woodTexture = makeWoodTexture();
const materials = {
wood: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xffffff,
roughness: 0.83
}),
rawWood: new THREE.MeshStandardMaterial({
color: 0xd8a06a,
roughness: 0.9
}),
darkWood: new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0x6f4932,
roughness: 0.88
}),
teal: new THREE.MeshStandardMaterial({
color: 0x4d7d79,
roughness: 0.73
}),
tealDark: new THREE.MeshStandardMaterial({
color: 0x365e60,
roughness: 0.78
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe2d3aa,
roughness: 0.86
}),
coral: new THREE.MeshStandardMaterial({
color: 0xa85d4e,
roughness: 0.82
}),
window: new THREE.MeshStandardMaterial({
color: 0x344b51,
roughness: 0.48,
metalness: 0.05
}),
dark: new THREE.MeshStandardMaterial({
color: 0x2d2823,
roughness: 0.9
}),
paper: new THREE.MeshStandardMaterial({
color: 0xc6a66d,
roughness: 1
}),
paperEdge: new THREE.MeshStandardMaterial({
color: 0x9f7e4c,
roughness: 1
}),
string: new THREE.MeshStandardMaterial({
color: 0xbda478,
roughness: 1
}),
plinth: new THREE.MeshStandardMaterial({
color: 0xe7dfcf,
roughness: 0.95
}),
floor: new THREE.MeshStandardMaterial({
color: 0xd8d1c2,
roughness: 1
})
};
function addBox(parent, size, position, material, rotation = null) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
if (rotation) mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// The display surface is intentionally simple so the wear remains legible.
addBox(
scene,
[7.6, 0.15, 4.45],
[0, -0.095, 0],
materials.plinth
);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.18;
floor.receiveShadow = true;
scene.add(floor);
// A block-built wooden pull car.
const car = new THREE.Group();
car.position.set(-0.72, 0.018, -0.08);
car.rotation.y = -0.055;
scene.add(car);
addBox(car, [2.78, 0.2, 1.16], [0, 0.43, 0], materials.darkWood);
addBox(car, [3.02, 0.34, 1.34], [0, 0.72, 0], materials.wood);
addBox(car, [2.72, 0.45, 1.2], [0, 1.01, 0], materials.teal);
addBox(car, [1.18, 0.48, 1.19], [0.82, 1.36, 0], materials.teal);
addBox(car, [1.22, 0.86, 1.18], [-0.49, 1.43, 0], materials.teal);
addBox(car, [1.43, 0.15, 1.36], [-0.49, 1.91, 0], materials.cream);
// Recessed-looking side window and a smaller rear window.
addBox(car, [0.73, 0.37, 0.035], [-0.47, 1.56, 0.605], materials.window);
addBox(car, [0.28, 0.34, 0.035], [-0.92, 1.56, 0.607], materials.window);
addBox(car, [0.73, 0.07, 0.045], [-0.47, 1.34, 0.619], materials.tealDark);
// Front block, lights, and bumper.
addBox(car, [0.12, 0.67, 1.12], [1.47, 1.3, 0], materials.cream);
addBox(car, [0.13, 0.18, 0.22], [1.545, 1.45, -0.36], materials.cream);
addBox(car, [0.13, 0.18, 0.22], [1.545, 1.45, 0.36], materials.cream);
addBox(car, [0.18, 0.13, 1.42], [1.49, 1.0, 0], materials.rawWood);
// Faded painted stripe.
addBox(car, [1.64, 0.085, 0.018], [0.12, 1.015, 0.613], materials.coral);
/*
Permanent wear marks:
- chipped paint at the front corner,
- exposed wooden gouges,
- a rubbed stripe,
- roof scuffs,
- small dark dents.
These are built as tiny blocks instead of a texture so they remain crisp.
*/
addBox(car, [0.13, 0.13, 0.025], [1.34, 1.49, 0.617], materials.rawWood);
addBox(car, [0.09, 0.16, 0.026], [1.41, 1.36, 0.618], materials.rawWood);
addBox(car, [0.11, 0.075, 0.026], [1.26, 1.29, 0.619], materials.rawWood);
addBox(car, [0.07, 0.09, 0.026], [1.47, 1.18, 0.619], materials.rawWood);
addBox(
car,
[0.31, 0.018, 0.018],
[0.61, 1.28, 0.621],
materials.rawWood,
[0, 0, -0.36]
);
addBox(
car,
[0.25, 0.016, 0.018],
[0.69, 1.18, 0.622],
materials.rawWood,
[0, 0, -0.28]
);
addBox(
car,
[0.18, 0.014, 0.018],
[0.79, 1.10, 0.623],
materials.rawWood,
[0, 0, -0.42]
);
// Gaps in the coral stripe reveal the wood below.
addBox(car, [0.07, 0.1, 0.025], [0.55, 1.015, 0.626], materials.rawWood);
addBox(car, [0.045, 0.095, 0.025], [0.76, 1.015, 0.626], materials.rawWood);
addBox(car, [0.055, 0.1, 0.015], [0.22, 1.29, 0.622], materials.darkWood);
addBox(car, [0.22, 0.012, 0.16], [-0.67, 1.988, 0.18], materials.rawWood);
addBox(car, [0.12, 0.012, 0.13], [-0.18, 1.988, -0.23], materials.rawWood);
addBox(car, [0.08, 0.07, 0.02], [-1.04, 1.23, 0.612], materials.darkWood);
// Voxel wheel: stepped circular silhouette made from small square cells.
function createVoxelWheel(chipped = false) {
const wheel = new THREE.Group();
const cell = 0.15;
const positions = [];
for (let ix = -3; ix <= 3; ix++) {
for (let iy = -3; iy <= 3; iy++) {
if (ix * ix + iy * iy <= 10) {
positions.push([ix * cell, iy * cell]);
}
}
}
const geometry = new THREE.BoxGeometry(cell * 0.98, cell * 0.98, 0.24);
const cells = new THREE.InstancedMesh(
geometry,
materials.tealDark,
positions.length
);
const dummy = new THREE.Object3D();
positions.forEach(([x, y], index) => {
dummy.position.set(x, y, 0);
dummy.updateMatrix();
cells.setMatrixAt(index, dummy.matrix);
});
cells.instanceMatrix.needsUpdate = true;
cells.castShadow = true;
cells.receiveShadow = true;
wheel.add(cells);
addBox(wheel, [0.32, 0.32, 0.28], [0, 0, 0.01], materials.wood);
// Square axle hole, deliberately matching the square axle peg.
addBox(wheel, [0.115, 0.115, 0.035], [0, 0, 0.162], materials.dark);
if (chipped) {
addBox(wheel, [0.1, 0.13, 0.022], [0.45, 0.015, 0.127], materials.rawWood);
addBox(wheel, [0.095, 0.075, 0.022], [-0.45, 0.13, 0.127], materials.rawWood);
addBox(wheel, [0.11, 0.018, 0.021], [0.19, -0.27, 0.126], materials.rawWood);
}
return wheel;
}
function attachWheel(parent, x, y, z, outward = 1, chipped = false) {
const wheel = createVoxelWheel(chipped);
wheel.position.set(x, y, z);
wheel.rotation.y = outward > 0 ? 0 : Math.PI;
parent.add(wheel);
return wheel;
}
// Three wheels remain attached.
attachWheel(car, -0.95, 0.5, -0.79, -1, true);
attachWheel(car, 0.95, 0.5, -0.79, -1, false);
attachWheel(car, -0.95, 0.5, 0.79, 1, true);
/*
The missing connection is explicit:
a dark recessed socket and a bare square axle peg remain on the car,
while the detached wheel has a matching square hole.
*/
addBox(car, [0.205, 0.205, 0.035], [0.95, 0.5, 0.622], materials.dark);
addBox(car, [0.095, 0.095, 0.48], [0.95, 0.5, 0.84], materials.rawWood);
addBox(car, [0.103, 0.103, 0.022], [0.95, 0.5, 1.088], materials.wood);
// Small abraded patches around the exposed axle.
addBox(car, [0.09, 0.16, 0.024], [0.82, 0.54, 0.625], materials.rawWood);
addBox(car, [0.07, 0.11, 0.024], [1.08, 0.47, 0.625], materials.rawWood);
addBox(car, [0.14, 0.045, 0.024], [0.95, 0.62, 0.625], materials.rawWood);
// The loose wheel is set down beside the tag.
const looseWheel = createVoxelWheel(true);
looseWheel.position.set(1.01, 0.525, 0.93);
looseWheel.rotation.set(0.08, -0.18, -0.11);
scene.add(looseWheel);
// Old gift tag, assembled from narrow paper blocks with clipped corners.
const tag = new THREE.Group();
tag.position.set(2.08, 0.005, 0.18);
tag.rotation.set(-0.11, -0.31, 0.045);
scene.add(tag);
const tagWidth = 1.34;
const tagHeight = 0.86;
const columns = 7;
const columnWidth = tagWidth / columns;
for (let i = 0; i < columns; i++) {
const bottom = i === 0 ? 0.14 : 0;
const top = i === columns - 1 ? tagHeight - 0.14 : tagHeight;
const height = top - bottom;
addBox(
tag,
[columnWidth + 0.004, height, 0.065],
[-tagWidth / 2 + (i + 0.5) * columnWidth, bottom + height / 2, 0],
materials.paper
);
}
// A faded, hand-written message on a transparent canvas.
const tagCanvas = document.createElement("canvas");
tagCanvas.width = 640;
tagCanvas.height = 390;
const tagCtx = tagCanvas.getContext("2d");
tagCtx.clearRect(0, 0, tagCanvas.width, tagCanvas.height);
tagCtx.textAlign = "center";
tagCtx.fillStyle = "rgba(63, 47, 31, 0.86)";
tagCtx.font = '600 65px "Segoe Print", "Bradley Hand", cursive';
tagCtx.fillText("To: Nora", 320, 93);
tagCtx.font = '42px "Segoe Print", "Bradley Hand", cursive';
tagCtx.fillText("one little car", 320, 174);
tagCtx.fillStyle = "rgba(92, 67, 42, 0.7)";
tagCtx.font = '31px "Segoe Print", "Bradley Hand", cursive';
tagCtx.fillText("Christmas 1998", 320, 258);
const tagTexture = new THREE.CanvasTexture(tagCanvas);
tagTexture.colorSpace = THREE.SRGBColorSpace;
const writing = new THREE.Mesh(
new THREE.PlaneGeometry(1.13, 0.69),
new THREE.MeshBasicMaterial({
map: tagTexture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
writing.position.set(-0.07, 0.43, 0.038);
tag.add(writing);
// Ruled border and punched hole.
addBox(tag, [0.012, 0.57, 0.014], [-0.57, 0.43, 0.039], materials.paperEdge);
addBox(tag, [0.012, 0.57, 0.014], [0.57, 0.43, 0.039], materials.paperEdge);
addBox(tag, [1.13, 0.012, 0.014], [0, 0.15, 0.039], materials.paperEdge);
addBox(tag, [1.13, 0.012, 0.014], [0, 0.71, 0.039], materials.paperEdge);
addBox(tag, [0.105, 0.105, 0.025], [0.45, 0.755, 0.045], materials.dark);
// Small age stains and rubbed paper edges.
const stainMaterial = new THREE.MeshStandardMaterial({
color: 0x705032,
transparent: true,
opacity: 0.16,
roughness: 1,
depthWrite: false
});
addBox(tag, [0.17, 0.12, 0.009], [-0.5, 0.66, 0.047], stainMaterial);
addBox(tag, [0.11, 0.16, 0.009], [-0.54, 0.29, 0.047], stainMaterial);
addBox(tag, [0.13, 0.08, 0.009], [0.49, 0.34, 0.047], stainMaterial);
addBox(tag, [0.09, 0.12, 0.009], [0.18, 0.18, 0.047], stainMaterial);
// A tiny support behind the leaning tag.
addBox(
scene,
[0.48, 0.11, 0.24],
[2.0, 0.045, 0.04],
materials.paperEdge,
[0, -0.2, 0.04]
);
// Loose, frayed string curling from the punched hole.
tag.updateMatrixWorld(true);
const holeWorld = tag.localToWorld(new THREE.Vector3(0.45, 0.755, 0.052));
const stringCurve = new THREE.CatmullRomCurve3([
holeWorld.clone(),
holeWorld.clone().add(new THREE.Vector3(0.11, 0.21, -0.035)),
new THREE.Vector3(holeWorld.x - 0.08, 0.25, 0.63),
new THREE.Vector3(holeWorld.x - 0.52, 0.035, 0.91),
new THREE.Vector3(holeWorld.x - 0.12, 0.025, 1.11),
new THREE.Vector3(holeWorld.x + 0.24, 0.03, 1.03)
]);
function beamBetween(a, b, thickness, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(thickness, length, thickness),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
const stringPoints = stringCurve.getPoints(30);
for (let i = 0; i < stringPoints.length - 1; i++) {
beamBetween(stringPoints[i], stringPoints[i + 1], 0.024, materials.string);
}
const stringEnd = stringPoints[stringPoints.length - 1];
beamBetween(
stringEnd,
stringEnd.clone().add(new THREE.Vector3(0.06, -0.01, 0.09)),
0.018,
materials.string
);
beamBetween(
stringEnd,
stringEnd.clone().add(new THREE.Vector3(0.08, 0.015, 0.035)),
0.016,
materials.string
);
// Tiny paper and wood dust on the display surface.
const dustMaterial = new THREE.MeshStandardMaterial({
color: 0x9f8d70,
roughness: 1,
transparent: true,
opacity: 0.34
});
const dust = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.025, 0.016, 0.025),
dustMaterial,
34
);
const dustDummy = new THREE.Object3D();
for (let i = 0; i < 34; i++) {
dustDummy.position.set(
-3.25 + random() * 6.5,
-0.005 + random() * 0.01,
-1.7 + random() * 3.55
);
dustDummy.rotation.y = random() * Math.PI;
const scale = 0.45 + random() * 1.1;
dustDummy.scale.setScalar(scale);
dustDummy.updateMatrix();
dust.setMatrixAt(i, dustDummy.matrix);
}
dust.instanceMatrix.needsUpdate = true;
dust.receiveShadow = true;
scene.add(dust);
// Custom camera controls, implemented without addons.
let dragging = false;
let lastX = 0;
let lastY = 0;
const defaultSpherical = new THREE.Spherical(
window.innerWidth / window.innerHeight < 0.8 ? 11.5 : 7.5,
1.05,
0.66
);
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.005,
0.43,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius + event.deltaY * 0.006,
4.5,
14
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
spherical.copy(defaultSpherical);
updateCamera();
});
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
spherical.theta += 0.09;
break;
case "ArrowRight":
spherical.theta -= 0.09;
break;
case "ArrowUp":
spherical.phi = Math.max(0.43, spherical.phi - 0.07);
break;
case "ArrowDown":
spherical.phi = Math.min(1.43, spherical.phi + 0.07);
break;
case "+":
case "=":
spherical.radius = Math.max(4.5, spherical.radius - 0.4);
break;
case "-":
spherical.radius = Math.min(14, spherical.radius + 0.4);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
let firstFrame = true;
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("out");
setTimeout(() => loading.remove(), 750);
}
}
render();
</script>
</body>
</html>
```