Prompt specification
Build or customize the Three.js 3D scene "Morning checklist object trio" 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: Morning checklist object trio
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/morning-checklist-object-trio-x3877
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Arrange a lunchbox, schoolbag, and house key beside three checklist symbols; show one missing lunchbox item so an unfinished preparation step is visually identifiable.
Working Three.js Starter (morning-checklist-object-trio-x3877):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel School Checklist</title>
<style>
:root {
--ink: #263640;
--paper: #fffaf0;
--orange: #e76f51;
--green: #3f9b72;
--muted: #68787d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9efe9;
color: var(--ink);
font-family: "Courier New", monospace;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
user-select: none;
}
.title {
top: 24px;
left: 26px;
max-width: 380px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--orange);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 45px);
line-height: 0.95;
letter-spacing: -0.07em;
text-transform: uppercase;
}
.subtitle {
margin-top: 10px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status {
top: 24px;
right: 26px;
display: flex;
align-items: center;
gap: 11px;
max-width: 290px;
padding: 12px 15px;
border: 2px solid var(--ink);
border-radius: 4px;
background: rgba(255, 250, 240, 0.92);
box-shadow: 5px 5px 0 rgba(38, 54, 64, 0.14);
font-size: 11px;
line-height: 1.35;
backdrop-filter: blur(5px);
}
.status-dot {
flex: 0 0 auto;
width: 12px;
height: 12px;
border: 2px solid var(--ink);
background: var(--orange);
animation: pulse 1.5s steps(2, end) infinite;
}
.status strong {
display: block;
margin-bottom: 2px;
text-transform: uppercase;
}
.status span:last-child {
color: var(--muted);
}
.controls {
left: 26px;
bottom: 22px;
padding: 9px 12px;
border: 1px solid rgba(38, 54, 64, 0.25);
background: rgba(255, 250, 240, 0.78);
color: var(--muted);
font-size: 10px;
letter-spacing: 0.04em;
backdrop-filter: blur(4px);
}
.legend {
right: 26px;
bottom: 22px;
display: flex;
gap: 14px;
align-items: center;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.symbol {
display: inline-grid;
width: 15px;
height: 15px;
place-items: center;
border: 2px solid var(--ink);
background: var(--paper);
color: var(--green);
font-size: 11px;
font-weight: bold;
line-height: 1;
}
.symbol.missing {
border-color: var(--orange);
}
@keyframes pulse {
50% {
background: #ffd2bd;
}
}
@media (max-width: 650px) {
.title {
top: 17px;
left: 17px;
}
.subtitle {
display: none;
}
.status {
top: auto;
right: 17px;
bottom: 53px;
max-width: 235px;
padding: 9px 11px;
}
.controls {
left: 17px;
bottom: 14px;
}
.legend {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel school preparation scene"></main>
<section class="hud title">
<div class="eyebrow">Morning preparation</div>
<h1>Ready for school?</h1>
<div class="subtitle">
Three things packed. One lunchbox detail left to finish.
</div>
</section>
<aside class="hud status">
<div class="status-dot"></div>
<div>
<strong>1 item missing</strong>
<span>The sandwich still needs to be packed.</span>
</div>
</aside>
<div class="hud controls">
DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET
</div>
<div class="hud legend">
<div class="legend-item">
<span class="symbol missing"></span>
Lunchbox
</div>
<div class="legend-item">
<span class="symbol">✓</span>
Schoolbag
</div>
<div class="legend-item">
<span class="symbol">✓</span>
House key
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and orthographic camera
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
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;
renderer.domElement.setAttribute(
"aria-label",
"Voxel scene containing a lunchbox, schoolbag, house key, and three checklist markers"
);
renderer.domElement.tabIndex = 0;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9efe9);
scene.fog = new THREE.Fog(0xe9efe9, 16, 30);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 50);
const cameraTarget = new THREE.Vector3(0, 0.85, 0.25);
let azimuth = 0.48;
let polar = 1.02;
let radius = 11.5;
let desiredAzimuth = azimuth;
let desiredPolar = polar;
let desiredRadius = radius;
const hemi = new THREE.HemisphereLight(0xffffff, 0xb6aa92, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff2d6, 3.1);
sun.position.set(5, 9, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcce8ff, 0.8);
fill.position.set(-7, 4, -5);
scene.add(fill);
// -------------------------------------------------------------------------
// Voxel helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, metalness = 0, roughness = 0.78) {
const key = `${color}-${metalness}-${roughness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
metalness,
roughness
})
);
}
return materialCache.get(key);
}
function addBox(
parent,
size,
position,
color,
options = {}
) {
const material =
options.material || getMaterial(
color,
options.metalness ?? 0,
options.roughness ?? 0.78
);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] || 0,
options.rotation[1] || 0,
options.rotation[2] || 0
);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function createLabel(parent, text, position, color = "#263640") {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 80;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "rgba(255,250,240,0.94)";
ctx.fillRect(5, 9, 310, 62);
ctx.strokeStyle = "rgba(38,54,64,0.22)";
ctx.lineWidth = 3;
ctx.strokeRect(5, 9, 310, 62);
ctx.fillStyle = color;
ctx.font = "bold 34px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 160, 41);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(position[0], position[1], position[2]);
sprite.scale.set(1.18, 0.295, 1);
parent.add(sprite);
return sprite;
}
// -------------------------------------------------------------------------
// Countertop
// -------------------------------------------------------------------------
addBox(
scene,
[20, 0.22, 15],
[0, -0.66, 0],
0xd9e1da
);
addBox(
scene,
[12.4, 0.52, 5.6],
[0, -0.28, 0.15],
0xd9c9ae
);
// Pixel-grid seams on the countertop.
for (let x = -5.5; x <= 5.5; x += 1.1) {
addBox(
scene,
[0.025, 0.018, 5.35],
[x, -0.008, 0.15],
0xc8b89e,
{ castShadow: false }
);
}
for (let z = -2.0; z <= 2.25; z += 1.08) {
addBox(
scene,
[12.15, 0.018, 0.025],
[0, -0.008, z],
0xc8b89e,
{ castShadow: false }
);
}
// -------------------------------------------------------------------------
// Schoolbag
// -------------------------------------------------------------------------
const schoolbag = new THREE.Group();
schoolbag.position.set(-3.05, 0, -0.05);
schoolbag.rotation.y = -0.08;
scene.add(schoolbag);
// Shoulder straps behind the bag.
addBox(schoolbag, [0.18, 1.45, 0.18], [-0.5, 1.05, -0.49], 0x244b50);
addBox(schoolbag, [0.18, 1.45, 0.18], [0.5, 1.05, -0.49], 0x244b50);
addBox(schoolbag, [1.12, 0.18, 0.18], [0, 1.72, -0.49], 0x244b50);
// Main stepped bag body.
addBox(schoolbag, [1.48, 0.25, 0.84], [0, 0.13, 0], 0x285f62);
addBox(schoolbag, [1.4, 1.32, 0.76], [0, 0.86, 0], 0x347d78);
addBox(schoolbag, [1.24, 0.42, 0.82], [0, 1.68, 0], 0x4a9690);
addBox(schoolbag, [1.0, 0.24, 0.76], [0, 1.98, 0], 0x3b8883);
// Front pocket.
addBox(schoolbag, [1.04, 0.68, 0.2], [0, 0.63, 0.46], 0x4a9690);
addBox(schoolbag, [0.76, 0.065, 0.06], [0, 0.84, 0.59], 0xf1bd43);
addBox(schoolbag, [0.11, 0.11, 0.07], [0.25, 0.84, 0.63], 0xf8dc72);
// Blocky carry handle.
addBox(schoolbag, [0.56, 0.12, 0.14], [0, 2.2, 0], 0x244b50);
addBox(schoolbag, [0.12, 0.28, 0.14], [-0.25, 2.1, 0], 0x244b50);
addBox(schoolbag, [0.12, 0.28, 0.14], [0.25, 2.1, 0], 0x244b50);
// Side pockets and clasps.
addBox(schoolbag, [0.22, 0.55, 0.68], [-0.78, 0.58, 0], 0x2d696b);
addBox(schoolbag, [0.22, 0.55, 0.68], [0.78, 0.58, 0], 0x2d696b);
addBox(schoolbag, [0.13, 0.2, 0.08], [-0.36, 1.53, 0.46], 0xf1bd43);
addBox(schoolbag, [0.13, 0.2, 0.08], [0.36, 1.53, 0.46], 0xf1bd43);
// -------------------------------------------------------------------------
// Open lunchbox
// -------------------------------------------------------------------------
const lunchbox = new THREE.Group();
lunchbox.position.set(0.4, 0, -0.2);
lunchbox.rotation.y = 0.03;
scene.add(lunchbox);
const lunchboxColor = 0xe76f51;
const lunchboxDark = 0xb94f3a;
const lunchboxLight = 0xf39a73;
// Base and hollow rim.
addBox(lunchbox, [2.4, 0.18, 1.5], [0, 0.08, 0], lunchboxDark);
addBox(lunchbox, [2.16, 0.08, 1.27], [0, 0.21, 0], 0xffead7);
addBox(lunchbox, [0.15, 0.48, 1.5], [-1.12, 0.39, 0], lunchboxColor);
addBox(lunchbox, [0.15, 0.48, 1.5], [1.12, 0.39, 0], lunchboxColor);
addBox(lunchbox, [2.1, 0.48, 0.15], [0, 0.39, -0.68], lunchboxColor);
addBox(lunchbox, [2.1, 0.48, 0.15], [0, 0.39, 0.68], lunchboxColor);
addBox(lunchbox, [0.12, 0.4, 1.23], [-0.36, 0.36, 0], lunchboxLight);
// Upright lid.
addBox(lunchbox, [2.4, 2.12, 0.18], [0, 1.19, -0.74], lunchboxColor);
addBox(lunchbox, [2.05, 1.72, 0.07], [0, 1.2, -0.625], 0xffb18f);
addBox(lunchbox, [1.66, 0.1, 0.08], [0, 1.78, -0.57], lunchboxLight);
addBox(lunchbox, [0.18, 0.35, 0.12], [-0.67, 0.27, -0.59], lunchboxDark);
addBox(lunchbox, [0.18, 0.35, 0.12], [0.67, 0.27, -0.59], lunchboxDark);
// Lid handle.
addBox(lunchbox, [0.64, 0.12, 0.14], [0, 2.34, -0.74], lunchboxDark);
addBox(lunchbox, [0.12, 0.3, 0.14], [-0.26, 2.22, -0.74], lunchboxDark);
addBox(lunchbox, [0.12, 0.3, 0.14], [0.26, 2.22, -0.74], lunchboxDark);
// Packed water bottle.
addBox(lunchbox, [0.37, 0.67, 0.37], [-0.78, 0.61, 0.08], 0x69b9d4);
addBox(lunchbox, [0.24, 0.17, 0.24], [-0.78, 1.02, 0.08], 0xa9dced);
addBox(lunchbox, [0.29, 0.11, 0.29], [-0.78, 1.15, 0.08], 0x327f9c);
addBox(lunchbox, [0.27, 0.09, 0.27], [-0.78, 0.55, 0.08], 0xf4fbff);
// Small packed apple.
addBox(lunchbox, [0.34, 0.32, 0.34], [0.82, 0.43, -0.36], 0xd94b3d);
addBox(lunchbox, [0.07, 0.15, 0.07], [0.82, 0.66, -0.36], 0x705238);
addBox(lunchbox, [0.13, 0.05, 0.08], [0.88, 0.72, -0.36], 0x4e7b3a);
// Ghost sandwich: translucent blueprint of the one missing item.
const ghostBread = new THREE.MeshStandardMaterial({
color: 0xf4c878,
transparent: true,
opacity: 0.24,
depthWrite: false,
roughness: 0.8
});
const ghostGreen = new THREE.MeshStandardMaterial({
color: 0x74a94c,
transparent: true,
opacity: 0.3,
depthWrite: false,
roughness: 0.8
});
const ghostRed = new THREE.MeshStandardMaterial({
color: 0xe75b48,
transparent: true,
opacity: 0.3,
depthWrite: false,
roughness: 0.8
});
const ghostOutline = new THREE.MeshStandardMaterial({
color: 0xf2a93b,
transparent: true,
opacity: 0.72,
depthWrite: false,
roughness: 0.7
});
const ghostSandwich = new THREE.Group();
ghostSandwich.position.set(0.37, 0.26, 0.12);
lunchbox.add(ghostSandwich);
addBox(ghostSandwich, [0.94, 0.12, 0.64], [0, 0.06, 0], 0xffffff, {
material: ghostBread
});
addBox(ghostSandwich, [0.98, 0.055, 0.67], [0, 0.15, 0], 0xffffff, {
material: ghostGreen
});
addBox(ghostSandwich, [0.96, 0.045, 0.66], [0, 0.205, 0], 0xffffff, {
material: ghostRed
});
addBox(ghostSandwich, [0.94, 0.12, 0.64], [0, 0.29, 0], 0xffffff, {
material: ghostBread
});
// Pixel outline around the ghost sandwich.
addBox(ghostSandwich, [0.98, 0.035, 0.035], [0, 0.37, -0.33], 0xffffff, {
material: ghostOutline
});
addBox(ghostSandwich, [0.98, 0.035, 0.035], [0, 0.37, 0.33], 0xffffff, {
material: ghostOutline
});
addBox(ghostSandwich, [0.035, 0.035, 0.64], [-0.48, 0.37, 0], 0xffffff, {
material: ghostOutline
});
addBox(ghostSandwich, [0.035, 0.035, 0.64], [0.48, 0.37, 0], 0xffffff, {
material: ghostOutline
});
// Floating missing-item marker.
const missingMarker = new THREE.Group();
missingMarker.position.set(0.37, 1.28, 0.12);
lunchbox.add(missingMarker);
const warningMaterial = new THREE.MeshStandardMaterial({
color: 0xe85d3c,
emissive: 0x6d1f0c,
emissiveIntensity: 0.16,
roughness: 0.65
});
addBox(missingMarker, [0.1, 0.34, 0.1], [0, 0.1, 0], 0xffffff, {
material: warningMaterial
});
addBox(missingMarker, [0.12, 0.12, 0.12], [0, -0.15, 0], 0xffffff, {
material: warningMaterial
});
// -------------------------------------------------------------------------
// House key
// -------------------------------------------------------------------------
const houseKey = new THREE.Group();
houseKey.position.set(3.2, 0, 0.02);
houseKey.rotation.y = -0.1;
scene.add(houseKey);
const gold = 0xf2bd3f;
// Square key ring.
addBox(houseKey, [0.64, 0.13, 0.13], [-0.55, 0.09, -0.29], gold, {
metalness: 0.48,
roughness: 0.32
});
addBox(houseKey, [0.64, 0.13, 0.13], [-0.55, 0.09, 0.29], gold, {
metalness: 0.48,
roughness: 0.32
});
addBox(houseKey, [0.13, 0.13, 0.46], [-0.81, 0.09, 0], gold, {
metalness: 0.48,
roughness: 0.32
});
addBox(houseKey, [0.13, 0.13, 0.46], [-0.29, 0.09, 0], gold, {
metalness: 0.48,
roughness: 0.32
});
// Key shaft and blocky teeth.
addBox(houseKey, [1.0, 0.14, 0.16], [0.24, 0.09, 0], gold, {
metalness: 0.48,
roughness: 0.32
});
addBox(houseKey, [0.16, 0.13, 0.36], [0.47, 0.09, 0.2], gold, {
metalness: 0.48,
roughness: 0.32
});
addBox(houseKey, [0.16, 0.13, 0.27], [0.72, 0.09, 0.15], gold, {
metalness: 0.48,
roughness: 0.32
});
// Tiny blue house charm attached to the ring.
addBox(houseKey, [0.18, 0.1, 0.13], [-0.98, 0.09, 0], gold, {
metalness: 0.48,
roughness: 0.32
});
addBox(houseKey, [0.4, 0.12, 0.4], [-1.27, 0.09, 0], 0x4f8fb1);
addBox(houseKey, [0.29, 0.12, 0.4], [-1.27, 0.21, 0], 0x69a8c5);
addBox(houseKey, [0.17, 0.12, 0.4], [-1.27, 0.33, 0], 0x8bc2d8);
addBox(houseKey, [0.1, 0.045, 0.1], [-1.22, 0.43, 0], 0xfff3d0);
// -------------------------------------------------------------------------
// Three physical checklist symbols
// -------------------------------------------------------------------------
function addCheckmark(parent, centerX, centerY, z) {
const pixels = [
[-0.16, 0.02],
[-0.09, -0.05],
[-0.02, 0.02],
[0.05, 0.09],
[0.12, 0.16],
[0.19, 0.23]
];
pixels.forEach(([x, y]) => {
addBox(
parent,
[0.078, 0.078, 0.065],
[centerX + x, centerY + y, z],
0x3f9b72
);
});
}
function addMiniLunchbox(parent, x, y, z) {
addBox(parent, [0.43, 0.26, 0.1], [x, y, z], 0xe76f51);
addBox(parent, [0.47, 0.09, 0.1], [x, y + 0.16, z], 0xf39a73);
addBox(parent, [0.18, 0.05, 0.08], [x, y + 0.24, z], 0xb94f3a);
addBox(parent, [0.08, 0.11, 0.11], [x - 0.13, y - 0.05, z], 0xf8dc72);
addBox(parent, [0.08, 0.11, 0.11], [x + 0.13, y - 0.05, z], 0xf8dc72);
}
function addMiniBackpack(parent, x, y, z) {
addBox(parent, [0.31, 0.38, 0.1], [x, y, z], 0x347d78);
addBox(parent, [0.27, 0.14, 0.1], [x, y + 0.13, z], 0x4a9690);
addBox(parent, [0.13, 0.12, 0.08], [x, y + 0.27, z], 0x244b50);
addBox(parent, [0.09, 0.1, 0.11], [x, y - 0.08, z], 0xf1bd43);
}
function addMiniKey(parent, x, y, z) {
addBox(parent, [0.23, 0.055, 0.07], [x - 0.08, y, z], gold);
addBox(parent, [0.055, 0.055, 0.18], [x - 0.18, y, z], gold);
addBox(parent, [0.055, 0.055, 0.18], [x + 0.02, y, z], gold);
addBox(parent, [0.31, 0.055, 0.07], [x + 0.18, y, z], gold);
addBox(parent, [0.055, 0.055, 0.12], [x + 0.25, y - 0.07, z], gold);
}
function makeChecklist(x, text, type, checked) {
const group = new THREE.Group();
group.position.set(x, 0, 1.72);
group.rotation.x = -0.08;
scene.add(group);
const accent = checked ? 0x3f9b72 : 0xe76f51;
addBox(group, [1.52, 1.28, 0.16], [0, 0.72, 0], 0x263f49);
addBox(group, [1.34, 1.1, 0.08], [0, 0.72, 0.11], 0xfffaf0);
// Checkbox.
addBox(group, [0.56, 0.56, 0.09], [-0.3, 0.72, 0.18], accent);
addBox(group, [0.43, 0.43, 0.09], [-0.3, 0.72, 0.24], 0xfffdf5);
if (checked) {
addCheckmark(group, -0.3, 0.72, 0.32);
}
// Small status indicator.
addBox(group, [0.1, 0.1, 0.06], [0.62, 1.19, 0.19], accent);
if (type === "lunchbox") {
addMiniLunchbox(group, 0.34, 0.72, 0.25);
} else if (type === "bag") {
addMiniBackpack(group, 0.34, 0.72, 0.25);
} else {
addMiniKey(group, 0.34, 0.74, 0.25);
}
createLabel(
group,
text,
[0, 1.52, 0.05],
checked ? "#263640" : "#b94f3a"
);
return group;
}
// Exactly three checklist symbols: one unfinished, two complete.
makeChecklist(-3.05, "LUNCHBOX", "lunchbox", false);
makeChecklist(0.4, "SCHOOLBAG", "bag", true);
makeChecklist(3.2, "HOUSE KEY", "key", true);
// -------------------------------------------------------------------------
// Custom orbit controls, implemented without external addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredAzimuth -= dx * 0.006;
desiredPolar = THREE.MathUtils.clamp(
desiredPolar + dy * 0.005,
0.7,
1.36
);
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("lostpointercapture", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius * Math.exp(event.deltaY * 0.001),
8,
15
);
},
{ passive: false }
);
function resetCamera() {
desiredAzimuth = 0.48;
desiredPolar = 1.02;
desiredRadius = 11.5;
}
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = Math.max(3.65, 5.8 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// Gentle camera damping.
azimuth += (desiredAzimuth - azimuth) * 0.09;
polar += (desiredPolar - polar) * 0.09;
radius += (desiredRadius - radius) * 0.09;
const horizontal = radius * Math.sin(polar);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + horizontal * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
// The missing sandwich marker gently bobs.
missingMarker.position.y = 1.28 + Math.sin(elapsed * 3.1) * 0.055;
missingMarker.rotation.y = Math.sin(elapsed * 1.4) * 0.08;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```