Prompt specification
Build or customize the Three.js 3D scene "Dual-height service counter section" 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: Dual-height service counter section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/dual-height-service-counter-section-x0417
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts accessible service counters. Model one counter with standing and seated service sections, visible knee space, and document tray; compare their relative heights using two simple visitor silhouettes. Voxel style.
Working Three.js Starter (dual-height-service-counter-section-x0417):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Accessible Service Counter — Voxel Scene</title>
<style>
:root {
color-scheme: light;
--ink: #15343b;
--paper: rgba(255, 255, 255, 0.91);
--teal: #176f78;
--blue: #3f6fa6;
--green: #138a63;
--orange: #ee8b3d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7efed;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
canvas:focus-visible {
box-shadow: inset 0 0 0 4px #f0a447;
}
.panel {
position: fixed;
z-index: 10;
border: 2px solid rgba(21, 52, 59, 0.18);
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 30px rgba(31, 57, 61, 0.12);
backdrop-filter: blur(8px);
}
.title-card {
top: 18px;
left: 18px;
width: min(440px, calc(100vw - 36px));
padding: 16px 18px;
border-left: 7px solid var(--teal);
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2.3vw, 27px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 8px 0 0;
max-width: 390px;
color: #49636a;
font-size: 12px;
line-height: 1.45;
}
.controls {
top: 18px;
right: 18px;
display: flex;
gap: 7px;
padding: 8px;
}
button {
min-height: 38px;
padding: 8px 11px;
border: 2px solid #173a42;
background: #fff;
color: #173a42;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
cursor: pointer;
box-shadow: 3px 3px 0 #173a42;
}
button:hover {
background: #e9f5f3;
transform: translateY(-1px);
}
button:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 #173a42;
}
button:focus-visible {
outline: 3px solid #f0a447;
outline-offset: 3px;
}
.legend {
left: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: min(760px, calc(100vw - 36px));
padding: 10px;
pointer-events: none;
}
.key {
display: flex;
align-items: center;
gap: 8px;
min-height: 38px;
padding: 8px 10px;
background: rgba(255, 255, 255, 0.92);
border: 1px solid rgba(21, 52, 59, 0.12);
font-size: 11px;
font-weight: 750;
}
.swatch {
width: 13px;
height: 13px;
flex: 0 0 auto;
border: 2px solid rgba(21, 52, 59, 0.22);
}
.swatch.orange { background: var(--orange); }
.swatch.blue { background: var(--blue); }
.swatch.green { background: var(--green); }
.swatch.teal { background: var(--teal); }
.help {
right: 18px;
bottom: 18px;
padding: 10px 12px;
color: #49636a;
font-size: 10px;
line-height: 1.5;
text-align: right;
pointer-events: none;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 760px) {
.title-card {
padding: 12px 14px;
}
.subtitle,
.help {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 76px;
flex-direction: column;
}
.legend {
left: 12px;
right: 12px;
bottom: 12px;
max-width: none;
}
.key {
flex: 1 1 42%;
font-size: 10px;
}
}
</style>
</head>
<body>
<header class="panel title-card">
<p class="eyebrow">Inclusive architecture / 01</p>
<h1>Accessible Service Counter</h1>
<p class="subtitle">
One connected counter with a standing section, a lowered seated section,
open knee clearance, and a reachable document tray.
</p>
</header>
<nav class="panel controls" aria-label="Camera views">
<button type="button" data-view="front">FRONT</button>
<button type="button" data-view="angle">3/4 VIEW</button>
<button type="button" data-view="knee">KNEE VIEW</button>
<button type="button" data-view="reset">RESET</button>
</nav>
<aside class="panel legend" aria-label="Scene legend">
<div class="key"><span class="swatch orange"></span>Standing visitor</div>
<div class="key"><span class="swatch blue"></span>Seated wheelchair visitor</div>
<div class="key"><span class="swatch teal"></span>Counter sections</div>
<div class="key"><span class="swatch green"></span>71 × 74 cm knee opening</div>
</aside>
<div class="panel help">
DRAG TO ORBIT · SCROLL TO ZOOM<br>
ARROW KEYS TO MOVE · R TO RESET
</div>
<p id="scene-description" class="sr-only">
A voxel-style accessible service counter. The standing counter top is
105 centimeters above the floor and is used by an orange standing visitor.
The adjacent seated counter top is 76 centimeters above the floor and is
used by a blue seated wheelchair visitor. The seated section has a clearly
outlined green knee opening measuring 71 centimeters high and 74
centimeters deep. A low document tray is positioned on the seated top.
The seated service surface is 29 centimeters lower than the standing one.
</p>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7efed);
scene.fog = new THREE.Fog(0xe7efed, 13, 24);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of an accessible service counter"
);
renderer.domElement.setAttribute("aria-describedby", "scene-description");
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const target = new THREE.Vector3(0, 0.86, 0.18);
let radius = 9.2;
let theta = 0;
let phi = 1.13;
const hemisphere = new THREE.HemisphereLight(0xf6fcff, 0x73837d, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 3.25);
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 = -6;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9ddff, 1.1);
fill.position.set(6, 4, 3);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = new Map();
function standardMaterial(color) {
if (!materials.has(color)) {
materials.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materials.get(color);
}
function addBox(w, h, d, x, y, z, color, parent = scene) {
const mesh = new THREE.Mesh(unitBox, standardMaterial(color));
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addTransparentBox(w, h, d, x, y, z, color, opacity) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
function makeLabel(
text,
background = "#173f48",
foreground = "#ffffff",
worldWidth = 2.4,
worldHeight = 0.42
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 180;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = foreground;
context.globalAlpha = 0.28;
context.lineWidth = 6;
context.strokeRect(9, 9, canvas.width - 18, canvas.height - 18);
context.globalAlpha = 1;
let size = 54;
context.font = `800 ${size}px ui-monospace, SFMono-Regular, Menlo, monospace`;
while (context.measureText(text).width > 930 && size > 24) {
size -= 2;
context.font = `800 ${size}px ui-monospace, SFMono-Regular, Menlo, monospace`;
}
context.fillStyle = foreground;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function addLineSegments(points, color = 0x38535a, opacity = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((p) => new THREE.Vector3(...p))
);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
const lines = new THREE.LineSegments(geometry, material);
scene.add(lines);
return lines;
}
// ------------------------------------------------------------------
// Voxel room
// ------------------------------------------------------------------
addBox(16, 0.16, 10, 0, -0.09, 1.3, 0xd8e3df);
addBox(12, 3.5, 0.18, 0, 1.68, -1.58, 0xf4f6ef);
// Subtle floor tile grid.
for (let x = -6; x <= 6; x += 1.5) {
addBox(0.018, 0.008, 9, x, 0.002, 1.2, 0xc8d6d1);
}
for (let z = -1; z <= 5; z += 1.5) {
addBox(12, 0.008, 0.018, 0, 0.002, z, 0xc8d6d1);
}
// Wall accent blocks.
addBox(0.62, 0.62, 0.13, -3.75, 2.15, -1.44, 0xe8b25f);
addBox(0.62, 0.62, 0.13, -3.75, 1.43, -1.44, 0x8ebdb3);
addBox(0.62, 0.62, 0.13, 3.75, 2.15, -1.44, 0x7597ba);
addBox(0.62, 0.62, 0.13, 3.75, 1.43, -1.44, 0xc98d71);
const wallSign = makeLabel(
"ACCESSIBLE SERVICE COUNTER",
"#163d46",
"#effbf8",
4.45,
0.66
);
wallSign.position.set(0, 2.63, -1.36);
// ------------------------------------------------------------------
// One connected counter with two service heights
// ------------------------------------------------------------------
// Standing module: cabinet, toe kick, top, and front panels.
addBox(1.78, 0.92, 0.72, -1.25, 0.50, -0.02, 0x287982);
addBox(1.72, 0.08, 0.68, -1.25, 0.04, -0.02, 0x173f46);
addBox(1.80, 0.08, 0.90, -1.25, 1.01, 0, 0x1e7078);
addBox(0.018, 0.62, 0.025, -1.25, 0.55, 0.355, 0x75b8b4);
addBox(1.52, 0.035, 0.025, -1.25, 0.78, 0.36, 0x8ac7c1);
// Seated module: low top, open knee bay, back panel, and end supports.
addBox(2.45, 0.07, 0.90, 0.875, 0.745, 0, 0x3f76a1);
addBox(2.27, 0.69, 0.12, 0.875, 0.35, -0.34, 0x315e82);
addBox(0.13, 0.69, 0.78, -0.285, 0.345, 0, 0x315e82);
addBox(0.13, 0.69, 0.78, 2.035, 0.345, 0, 0x315e82);
addBox(2.45, 0.055, 0.025, 0.875, 0.665, 0.456, 0x79a7c8);
// A shared vertical transition makes the two worktops read as one unit.
addBox(0.09, 0.34, 0.84, -0.35, 0.875, 0, 0x245f72);
// Clear knee-space zone: 1.25 m wide, 0.71 m high, 0.74 m deep.
addTransparentBox(1.25, 0.012, 0.74, 0.55, 0.012, 0.03, 0x20b77a, 0.20);
const kneeGeometry = new THREE.BoxGeometry(1.25, 0.70, 0.74);
const kneeEdges = new THREE.EdgesGeometry(kneeGeometry);
const kneeLines = new THREE.LineSegments(
kneeEdges,
new THREE.LineBasicMaterial({
color: 0x18a86f,
transparent: true,
opacity: 0.72
})
);
kneeLines.position.set(0.55, 0.35, 0.03);
scene.add(kneeLines);
// Green floor corner markers emphasize the unobstructed approach.
const green = 0x159767;
addBox(0.26, 0.025, 0.05, -0.04, 0.018, -0.31, green);
addBox(0.26, 0.025, 0.05, 1.14, 0.018, -0.31, green);
addBox(0.05, 0.025, 0.26, -0.04, 0.018, -0.31, green);
addBox(0.05, 0.025, 0.26, 1.14, 0.018, -0.31, green);
// Accessible document tray on the lowered worktop.
addBox(0.60, 0.035, 0.44, 1.42, 0.80, 0.03, 0x183b46);
addBox(0.035, 0.065, 0.44, 1.135, 0.825, 0.03, 0x244f5b);
addBox(0.035, 0.065, 0.44, 1.705, 0.825, 0.03, 0x244f5b);
addBox(0.60, 0.065, 0.035, 1.42, 0.825, -0.175, 0x244f5b);
addBox(0.60, 0.035, 0.025, 1.42, 0.81, 0.24, 0x244f5b);
addBox(0.31, 0.012, 0.27, 1.35, 0.827, 0.02, 0xf5f0df);
addBox(0.025, 0.015, 0.25, 1.35, 0.838, 0.02, 0xb8c6c2);
// Small service monitor on the standing section.
addBox(0.38, 0.04, 0.23, -0.72, 1.08, -0.12, 0x1c3037);
addBox(0.06, 0.22, 0.06, -0.72, 1.19, -0.15, 0x1c3037);
addBox(0.45, 0.30, 0.055, -0.72, 1.36, -0.17, 0x18343b);
addBox(0.37, 0.22, 0.012, -0.72, 1.36, -0.134, 0x8cc9c3);
// Section labels.
const standingLabel = makeLabel(
"STANDING / 105 cm",
"#174d55",
"#f4fff9",
2.65,
0.43
);
standingLabel.position.set(-1.25, 2.02, 0.82);
const seatedLabel = makeLabel(
"SEATED / 76 cm",
"#294f79",
"#f4f9ff",
2.45,
0.43
);
seatedLabel.position.set(0.78, 1.56, 0.90);
const differenceLabel = makeLabel(
"29 cm LOWER",
"#138a63",
"#ffffff",
1.50,
0.30
);
differenceLabel.position.set(1.50, 1.02, 0.88);
// ------------------------------------------------------------------
// Dimension lines
// ------------------------------------------------------------------
function addHeightDimension(x, height, label) {
addLineSegments([
[x, 0, 0.60, x, height, 0.60],
[x - 0.10, 0, 0.60, x + 0.10, 0, 0.60],
[x - 0.10, height, 0.60, x + 0.10, height, 0.60]
], 0x38535a, 0.85);
const tag = makeLabel(label, "#ffffff", "#173d46", 0.90, 0.26);
tag.position.set(x - 0.23, height * 0.5, 0.62);
}
addHeightDimension(-2.37, 1.05, "105 cm");
addHeightDimension(2.38, 0.78, "76 cm");
// ------------------------------------------------------------------
// Standing visitor silhouette
// ------------------------------------------------------------------
const standingX = -1.25;
const standingZ = 1.30;
const orange = 0xee8b3d;
const orangeLight = 0xf6ad68;
const navy = 0x283c49;
// Shoes and legs.
addBox(0.19, 0.12, 0.34, standingX - 0.14, 0.07, standingZ - 0.03, navy);
addBox(0.19, 0.12, 0.34, standingX + 0.14, 0.07, standingZ - 0.03, navy);
addBox(0.15, 0.67, 0.18, standingX - 0.14, 0.45, standingZ, navy);
addBox(0.15, 0.67, 0.18, standingX + 0.14, 0.45, standingZ, navy);
// Torso, arms, neck, and cube head.
addBox(0.46, 0.63, 0.27, standingX, 1.10, standingZ, orange);
addBox(0.14, 0.58, 0.17, standingX - 0.32, 1.08, standingZ, orangeLight);
addBox(0.14, 0.58, 0.17, standingX + 0.32, 1.08, standingZ, orangeLight);
addBox(0.15, 0.12, 0.15, standingX, 1.47, standingZ, orangeLight);
addBox(0.32, 0.32, 0.32, standingX, 1.68, standingZ, orangeLight);
// A simple held document reinforces the service-counter use.
addBox(0.27, 0.025, 0.20, standingX + 0.34, 0.82, standingZ - 0.15, 0xf6f0db);
// ------------------------------------------------------------------
// Seated wheelchair visitor silhouette
// ------------------------------------------------------------------
const seatedX = 0.55;
const seatedZ = 1.35;
const blue = 0x4d77ad;
const blueLight = 0x80a8d1;
const wheelchair = 0x263943;
// Wheelchair seat, back, frame, and casters.
addBox(0.62, 0.10, 0.58, seatedX, 0.48, seatedZ - 0.04, wheelchair);
addBox(0.62, 0.62, 0.09, seatedX, 0.79, seatedZ + 0.23, wheelchair);
addBox(0.055, 0.055, 0.78, seatedX - 0.37, 0.30, seatedZ - 0.19, 0x667984);
addBox(0.055, 0.055, 0.78, seatedX + 0.37, 0.30, seatedZ - 0.19, 0x667984);
addBox(0.12, 0.19, 0.12, seatedX - 0.37, 0.13, seatedZ - 0.58, 0x344b56);
addBox(0.12, 0.19, 0.12, seatedX + 0.37, 0.13, seatedZ - 0.58, 0x344b56);
// Voxel rings make the large wheels without using smooth geometry.
function addVoxelWheel(x) {
const centerY = 0.38;
const centerZ = seatedZ + 0.16;
const radius = 0.31;
const count = 12;
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
const y = centerY + Math.sin(angle) * radius;
const z = centerZ + Math.cos(angle) * radius;
addBox(0.10, 0.11, 0.11, x, y, z, 0x263943);
}
addBox(0.12, 0.12, 0.12, x, centerY, centerZ, 0x71858c);
}
addVoxelWheel(seatedX - 0.43);
addVoxelWheel(seatedX + 0.43);
// Seated body.
addBox(0.44, 0.59, 0.28, seatedX, 0.86, seatedZ, blue);
addBox(0.30, 0.30, 0.30, seatedX, 1.31, seatedZ, blueLight);
addBox(0.13, 0.11, 0.13, seatedX, 1.11, seatedZ, blueLight);
// Horizontal thighs and vertical shins.
addBox(0.16, 0.16, 0.56, seatedX - 0.13, 0.55, seatedZ - 0.33, blue);
addBox(0.16, 0.16, 0.56, seatedX + 0.13, 0.55, seatedZ - 0.33, blue);
addBox(0.14, 0.42, 0.15, seatedX - 0.13, 0.29, seatedZ - 0.59, blue);
addBox(0.14, 0.42, 0.15, seatedX + 0.13, 0.29, seatedZ - 0.59, blue);
addBox(0.18, 0.10, 0.29, seatedX - 0.13, 0.08, seatedZ - 0.62, navy);
addBox(0.18, 0.10, 0.29, seatedX + 0.13, 0.08, seatedZ - 0.62, navy);
// Arms reach toward the accessible work surface.
addBox(0.13, 0.39, 0.15, seatedX - 0.30, 0.79, seatedZ - 0.09, blueLight);
addBox(0.13, 0.39, 0.15, seatedX + 0.30, 0.79, seatedZ - 0.09, blueLight);
addBox(0.13, 0.12, 0.53, seatedX - 0.30, 0.71, seatedZ - 0.36, blueLight);
addBox(0.13, 0.12, 0.53, seatedX + 0.30, 0.71, seatedZ - 0.36, blueLight);
// Small visitor labels.
const standingVisitorLabel = makeLabel(
"180 cm VISITOR",
"#ffffff",
"#9b4d19",
1.45,
0.28
);
standingVisitorLabel.position.set(standingX, 0.18, 2.02);
const seatedVisitorLabel = makeLabel(
"SEATED VISITOR",
"#ffffff",
"#294f79",
1.55,
0.28
);
seatedVisitorLabel.position.set(seatedX, 0.18, 2.03);
// ------------------------------------------------------------------
// Camera controls implemented directly, without Three.js addons
// ------------------------------------------------------------------
function updateCamera() {
camera.position.setFromSpherical(
new THREE.Spherical(radius, phi, theta)
).add(target);
camera.lookAt(target);
}
const presets = {
front: {
target: new THREE.Vector3(0, 0.86, 0.18),
radius: 9.2,
theta: 0,
phi: 1.13
},
angle: {
target: new THREE.Vector3(0, 0.86, 0.18),
radius: 9.0,
theta: 0.43,
phi: 1.10
},
knee: {
target: new THREE.Vector3(0.55, 0.53, 0.08),
radius: 5.9,
theta: 0.30,
phi: 1.37
},
reset: {
target: new THREE.Vector3(0, 0.86, 0.18),
radius: 9.2,
theta: 0,
phi: 1.13
}
};
function applyPreset(name) {
const preset = presets[name] || presets.front;
target.copy(preset.target);
radius = preset.radius;
theta = preset.theta;
phi = preset.phi;
updateCamera();
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
applyPreset(button.dataset.view);
});
});
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.focus({ preventScroll: true });
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.35, 1.46);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
radius = THREE.MathUtils.clamp(
radius * (previousPinchDistance / distance),
5.2,
13
);
}
previousPinchDistance = distance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
5.2,
13
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
applyPreset("reset");
});
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
theta += 0.08;
break;
case "ArrowRight":
theta -= 0.08;
break;
case "ArrowUp":
phi = THREE.MathUtils.clamp(phi - 0.06, 0.35, 1.46);
break;
case "ArrowDown":
phi = THREE.MathUtils.clamp(phi + 0.06, 0.35, 1.46);
break;
case "+":
case "=":
radius = Math.max(5.2, radius - 0.35);
break;
case "-":
case "_":
radius = Math.min(13, radius + 0.35);
break;
case "r":
case "R":
applyPreset("reset");
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateCamera();
renderer.setAnimationLoop(() => renderer.render(scene, camera));
</script>
</body>
</html>
```