Prompt specification
Build or customize the Three.js 3D scene "Doorway with a covered threshold" 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: Doorway with a covered threshold
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/doorway-with-a-covered-threshold-x2209
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: doorway with a covered threshold. Model a doorway, shallow porch, and exterior path as three distinct spaces. Use a human-scale figure to make the transition in access and shelter readable. Return one self-contained HTML file.
Working Three.js Starter (doorway-with-a-covered-threshold-x2209):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Covered Threshold — Voxel Scene</title>
<style>
:root {
color-scheme: light;
--ink: #24312e;
--muted: #65716b;
--paper: rgba(248, 246, 238, 0.86);
--door: #b8844f;
--porch: #b96f50;
--path: #c4c0ad;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce3db;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 48%, rgba(38, 49, 44, 0.09) 100%);
}
.panel {
position: fixed;
z-index: 2;
pointer-events: none;
}
#title-card {
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px 17px;
background: var(--paper);
border: 1px solid rgba(45, 60, 53, 0.12);
box-shadow: 0 12px 36px rgba(49, 60, 53, 0.12);
backdrop-filter: blur(10px);
}
.eyebrow {
margin: 0 0 7px;
color: #6c776f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
line-height: 1.02;
letter-spacing: -0.045em;
font-weight: 760;
}
#title-card p:last-child {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#legend {
left: 24px;
bottom: 24px;
display: grid;
gap: 8px;
padding: 13px 15px;
background: var(--paper);
border: 1px solid rgba(45, 60, 53, 0.12);
box-shadow: 0 10px 28px rgba(49, 60, 53, 0.1);
backdrop-filter: blur(10px);
}
.legend-row {
display: grid;
grid-template-columns: 11px 22px minmax(0, 1fr);
gap: 9px;
align-items: center;
color: #35423e;
font-size: 11px;
white-space: nowrap;
}
.swatch {
width: 11px;
height: 11px;
box-shadow: inset 0 0 0 1px rgba(20, 30, 26, 0.12);
}
.number {
color: #7b857f;
font-variant-numeric: tabular-nums;
font-weight: 750;
}
#controls {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
color: #56645e;
font-size: 10px;
letter-spacing: 0.03em;
}
#reset {
pointer-events: auto;
border: 1px solid rgba(45, 60, 53, 0.16);
background: rgba(248, 246, 238, 0.9);
color: #35423e;
padding: 9px 12px;
font: inherit;
font-weight: 750;
cursor: pointer;
box-shadow: 0 6px 18px rgba(49, 60, 53, 0.1);
}
#reset:hover {
background: #fffdf7;
}
#reset:active {
transform: translateY(1px);
}
@media (max-width: 680px) {
#title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
#title-card p:last-child {
display: none;
}
#legend {
left: 14px;
bottom: 14px;
padding: 10px 12px;
}
.legend-row {
grid-template-columns: 10px 19px minmax(0, 1fr);
gap: 7px;
font-size: 10px;
}
#controls {
right: 14px;
bottom: 14px;
}
#controls span {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel scene of a doorway, covered threshold, porch, and path"></main>
<div id="vignette"></div>
<section id="title-card" class="panel">
<p class="eyebrow">Access sequence / 01</p>
<h1>Covered threshold</h1>
<p>A sheltered doorway opens onto a raised, shallow porch and then a lower exterior path. The figure is approximately 1.8 m tall.</p>
</section>
<section id="legend" class="panel" aria-label="Scene legend">
<div class="legend-row">
<span class="swatch" style="background: var(--door)"></span>
<span class="number">01</span>
<span>Doorway + covered threshold</span>
</div>
<div class="legend-row">
<span class="swatch" style="background: var(--porch)"></span>
<span class="number">02</span>
<span>Shallow raised porch</span>
</div>
<div class="legend-row">
<span class="swatch" style="background: var(--path)"></span>
<span class="number">03</span>
<span>Lower exterior path</span>
</div>
</section>
<div id="controls" class="panel">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce3db);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 80);
const cameraTarget = new THREE.Vector3(0.35, 1.2, 1.35);
const hemisphere = new THREE.HemisphereLight(0xf4f7ed, 0x6e765f, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffefcf, 3.25);
sun.position.set(-6, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xdce9f2, 0.65);
fill.position.set(9, 6, -8);
scene.add(fill);
const unitCube = new THREE.BoxGeometry(1, 1, 1);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
const M = {
grass: material(0x879b6c),
grassDark: material(0x71865d),
grassLight: material(0x9aab78),
soil: material(0x8a765c),
gravel: material(0xc0b8a2),
gravelDark: material(0xa9a38f),
stone: material(0xc9c6b5),
stoneDark: material(0xa9aa9d),
stoneLight: material(0xded9c7),
mortar: material(0x9e8e78),
brick: [
material(0xc49a73),
material(0xcda57d),
material(0xbd8e68),
material(0xd2aa83)
],
frame: material(0x5a4031),
frameLight: material(0x77523b),
door: material(0x8b5b3f),
doorDark: material(0x6d422f),
interiorWall: material(0xe5d9be),
interiorTrim: material(0xc3aa83),
woodFloor: [
material(0xa87548),
material(0xb47c4d),
material(0x9e6c42),
material(0xbd8351)
],
porchBase: material(0x875443),
porch: [
material(0xb96f50),
material(0xc17a58),
material(0xae6248),
material(0xc88763)
],
threshold: [
material(0xd5cbb5),
material(0xc8bea9),
material(0xded4be)
],
roof: [
material(0x4f6862),
material(0x58736c),
material(0x435d58),
material(0x627b73)
],
roofEdge: material(0x3d554f),
window: material(0x405f65, { roughness: 0.38 }),
windowLight: material(0x91a9a6, { roughness: 0.5 }),
post: material(0x5f4535),
pot: material(0x9e5f45),
potDark: material(0x7f4938),
leaf: [
material(0x537a50),
material(0x658a59),
material(0x426b48)
],
skin: material(0xd8a27d),
skinDark: material(0xbd8462),
hair: material(0x493a31),
jacket: material(0x286b70),
jacketDark: material(0x20575d),
trousers: material(0x31414b),
shoes: material(0x252c2d),
bag: material(0x8a6040),
lamp: material(0xffd89b, {
emissive: 0xffb55f,
emissiveIntensity: 1.8,
roughness: 0.5
})
};
function box(w, h, d, x, y, z, mat, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(unitCube, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Landscape base and the lower exterior route.
box(18, 0.46, 18, 0, -0.32, 2.0, M.grass);
box(3.55, 0.075, 7.4, 0.45, -0.055, 5.75, M.gravel, scene, false);
box(3.15, 0.025, 7.0, 0.45, -0.009, 5.8, M.gravelDark, scene, false);
for (let i = 0; i < 9; i++) {
const z = 2.95 + i * 0.79;
const x = 0.45 + Math.sin(i * 0.88) * 0.22;
const stone = i % 3 === 0 ? M.stoneLight : M.stone;
box(1.28 + (i % 2) * 0.12, 0.16, 0.64, x, 0.02, z, stone);
box(1.06, 0.035, 0.43, x + 0.03, 0.107, z, i % 2 ? M.stoneLight : M.stoneDark, scene, false);
}
// Small voxel grass and gravel details around the route.
let seed = 9137;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
for (let i = 0; i < 65; i++) {
const x = -7.6 + random() * 15.2;
const z = -1.2 + random() * 9.7;
if (Math.abs(x - 0.45) < 2.15 && z > 2.45) continue;
if (x > -4.6 && x < 4.6 && z < 2.6) continue;
const h = 0.10 + random() * 0.18;
box(0.12, h, 0.12, x, -0.07 + h / 2, z, random() > 0.5 ? M.grassDark : M.grassLight);
if (random() > 0.55) {
box(0.11, h * 0.7, 0.11, x + 0.13, -0.07 + h * 0.35, z + 0.04, M.grassDark);
}
}
for (let i = 0; i < 30; i++) {
const side = random() > 0.5 ? 1 : -1;
const x = 0.45 + side * (1.78 + random() * 0.35);
const z = 2.8 + random() * 6.2;
box(0.13, 0.07, 0.13, x, 0.005, z, random() > 0.5 ? M.stoneDark : M.stoneLight);
}
// Raised shallow porch, its front step, and distinct terracotta paving.
box(4.2, 0.30, 1.78, 0.45, 0.07, 1.68, M.porchBase);
box(3.1, 0.16, 0.40, 0.45, 0.005, 2.76, M.stoneDark);
box(3.35, 0.07, 0.42, 0.45, 0.115, 2.76, M.stone);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 5; col++) {
const x = -1.275 + col * 0.84 + (row % 2) * 0.035;
const z = 1.23 + row * 0.88;
box(0.79, 0.08, 0.82, x, 0.26, z, M.porch[(row + col) % M.porch.length]);
}
}
// The threshold is a separate pale paved band immediately inside the porch.
box(3.0, 0.34, 1.36, 0.45, 0.12, 0.12, M.stoneDark);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
box(0.94, 0.08, 0.61, -0.03 + col * 0.96, 0.33, -0.20 + row * 0.66, M.threshold[(row + col) % M.threshold.length]);
}
}
// Interior floor and the simple room visible through the open doorway.
box(8.45, 0.12, 3.62, 0, 0.28, -2.36, M.interiorTrim);
for (let i = 0; i < 16; i++) {
box(0.50, 0.08, 3.55, -3.91 + i * 0.525, 0.34, -2.36, M.woodFloor[i % M.woodFloor.length]);
}
box(8.55, 3.48, 0.30, 0, 2.08, -4.20, M.interiorWall);
box(0.30, 3.48, 3.62, -4.20, 2.08, -2.40, M.interiorWall);
box(8.65, 0.16, 0.42, 0, 3.82, -4.20, M.interiorTrim);
box(0.40, 0.16, 3.72, -4.20, 3.82, -2.40, M.interiorTrim);
// Interior rug and a small console give the doorway a readable depth.
box(2.15, 0.035, 1.45, 0.47, 0.397, -1.48, material(0x7c6757));
box(1.55, 0.55, 0.55, 1.72, 0.98, -3.64, M.frameLight);
box(0.14, 0.45, 0.14, 1.22, 0.62, -3.49, M.frame);
box(0.14, 0.45, 0.14, 2.22, 0.62, -3.49, M.frame);
box(0.14, 0.45, 0.14, 1.22, 0.62, -3.79, M.frame);
box(0.14, 0.45, 0.14, 2.22, 0.62, -3.79, M.frame);
box(0.38, 0.24, 0.30, 1.72, 1.37, -3.64, M.lamp);
box(0.90, 0.75, 0.08, 1.68, 2.10, -4.01, M.frame);
box(0.74, 0.59, 0.06, 1.68, 2.10, -3.96, material(0x78928a));
const interiorLight = new THREE.PointLight(0xffc47a, 18, 5.2, 2);
interiorLight.position.set(0.45, 2.42, -1.25);
scene.add(interiorLight);
// Brick facade with a precisely reserved doorway.
const wallMin = -4.25;
const wallMax = 4.25;
const wallTop = 3.74;
const doorLeft = -0.55;
const doorRight = 1.45;
const doorTop = 2.75;
box(wallMax - wallMin, 0.24, 0.52, 0, 0.12, -0.64, M.stoneDark);
box(doorLeft - wallMin, wallTop, 0.27, (wallMin + doorLeft) / 2, wallTop / 2, -0.66, M.mortar);
box(wallMax - doorRight, wallTop, 0.27, (doorRight + wallMax) / 2, wallTop / 2, -0.66, M.mortar);
box(doorRight - doorLeft, wallTop - doorTop, 0.27, (doorLeft + doorRight) / 2, (doorTop + wallTop) / 2, -0.66, M.mortar);
const brickWidth = 0.55;
const brickHeight = 0.24;
for (let row = 0; row < 14; row++) {
const yBottom = 0.24 + row * brickHeight;
const yTop = yBottom + brickHeight;
let x = wallMin - (row % 2 ? brickWidth / 2 : 0);
while (x < wallMax) {
const left = x;
const right = Math.min(x + brickWidth, wallMax);
const width = right - left;
const overlapsDoorX = right > doorLeft && left < doorRight;
const overlapsDoorY = yTop > 0.35 && yBottom < doorTop;
if (width > 0.06 && !(overlapsDoorX && overlapsDoorY)) {
const brick = M.brick[(row + Math.floor(x * 2.7)) % M.brick.length];
box(width - 0.014, brickHeight - 0.014, 0.30, (left + right) / 2, (yBottom + yTop) / 2, -0.49, brick);
}
x += brickWidth;
}
}
// Door frame, open door leaf, handle and threshold nosing.
box(0.16, 2.48, 0.22, -0.63, 1.61, -0.25, M.frame);
box(0.16, 2.48, 0.22, 1.53, 1.61, -0.25, M.frame);
box(2.32, 0.18, 0.22, 0.45, 2.84, -0.25, M.frame);
box(2.18, 0.12, 0.34, 0.45, 0.40, -0.22, M.frameLight);
box(0.14, 2.31, 1.76, -0.54, 1.54, -1.72, M.door);
for (let i = 0; i < 4; i++) {
box(0.035, 0.075, 1.56, -0.462, 0.62 + i * 0.57, -1.72, M.doorDark);
}
box(0.09, 0.09, 0.26, -0.41, 1.45, -2.43, M.frameLight);
// A small window helps identify the wall as a dwelling rather than a freestanding frame.
box(1.34, 1.02, 0.08, -2.30, 1.90, -0.285, M.window);
box(0.12, 1.24, 0.16, -3.01, 1.90, -0.20, M.frame);
box(0.12, 1.24, 0.16, -1.59, 1.90, -0.20, M.frame);
box(1.54, 0.12, 0.16, -2.30, 2.46, -0.20, M.frame);
box(1.54, 0.12, 0.16, -2.30, 1.34, -0.20, M.frame);
box(0.07, 1.02, 0.10, -2.30, 1.90, -0.18, M.frameLight);
box(1.34, 0.07, 0.10, -2.30, 1.90, -0.18, M.frameLight);
box(1.62, 0.13, 0.34, -2.30, 1.25, -0.11, M.frameLight);
// Covered threshold: timber posts, beams, and a block-tiled canopy.
const postHeight = 2.68;
box(0.18, postHeight, 0.18, -1.08, 0.30 + postHeight / 2, 0.66, M.post);
box(0.18, postHeight, 0.18, 1.98, 0.30 + postHeight / 2, 0.66, M.post);
box(0.30, 0.18, 0.30, -1.08, 0.40, 0.66, M.stoneDark);
box(0.30, 0.18, 0.30, 1.98, 0.40, 0.66, M.stoneDark);
box(3.50, 0.18, 0.20, 0.45, 2.99, 0.66, M.post);
box(3.50, 0.18, 0.20, 0.45, 2.99, -0.55, M.post);
box(0.18, 0.18, 1.42, -1.08, 3.01, 0.05, M.post);
box(0.18, 0.18, 1.42, 1.98, 3.01, 0.05, M.post);
box(3.82, 0.18, 1.80, 0.45, 3.18, 0.02, M.roofEdge);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 9; col++) {
const x = -1.24 + col * 0.422;
const z = -0.72 + row * 0.37;
box(0.395, 0.09, 0.34, x, 3.305, z, M.roof[(row + col * 2) % M.roof.length]);
}
}
// Stepped voxel brackets beneath the canopy beam.
for (let i = 0; i < 3; i++) {
box(0.18, 0.18, 0.44, -1.08 + (i + 1) * 0.18, 2.79 - i * 0.15, 0.66, M.post);
box(0.18, 0.18, 0.44, 1.98 - (i + 1) * 0.18, 2.79 - i * 0.15, 0.66, M.post);
}
box(0.23, 0.12, 0.23, 0.45, 2.87, -0.34, M.lamp);
box(0.34, 0.06, 0.34, 0.45, 2.94, -0.34, M.roofEdge);
// A block-built plant marks the edge of the porch without obscuring the route.
const plant = new THREE.Group();
plant.position.set(2.05, 0.30, 1.92);
scene.add(plant);
box(0.52, 0.32, 0.52, 0, 0.16, 0, M.pot, plant);
box(0.58, 0.13, 0.58, 0, 0.34, 0, M.potDark, plant);
box(0.45, 0.06, 0.45, 0, 0.42, 0, M.soil, plant);
box(0.10, 0.42, 0.10, 0, 0.63, 0, M.leaf[0], plant);
box(0.34, 0.20, 0.23, -0.13, 0.69, 0, M.leaf[1], plant);
box(0.27, 0.23, 0.30, 0.16, 0.76, 0.03, M.leaf[2], plant);
box(0.25, 0.22, 0.24, 0.02, 0.91, -0.02, M.leaf[0], plant);
// Human-scale figure, standing within the sheltered threshold.
const person = new THREE.Group();
person.position.set(0.46, 0.37, 0.04);
scene.add(person);
function pbox(w, h, d, x, y, z, mat) {
return box(w, h, d, x, y, z, mat, person);
}
pbox(0.25, 0.15, 0.38, -0.14, 0.075, 0.09, M.shoes);
pbox(0.25, 0.15, 0.38, 0.14, 0.075, -0.02, M.shoes);
pbox(0.22, 0.64, 0.25, -0.14, 0.47, 0.09, M.trousers);
pbox(0.22, 0.64, 0.25, 0.14, 0.47, -0.02, M.trousers);
pbox(0.56, 0.66, 0.34, 0, 1.08, 0.01, M.jacket);
pbox(0.18, 0.62, 0.22, -0.38, 1.05, 0.01, M.jacketDark);
pbox(0.18, 0.62, 0.22, 0.38, 1.05, 0.01, M.jacket);
pbox(0.16, 0.18, 0.18, -0.38, 0.68, 0.02, M.skin);
pbox(0.16, 0.18, 0.18, 0.38, 0.68, 0.01, M.skin);
pbox(0.20, 0.10, 0.20, 0, 1.47, 0.01, M.skinDark);
pbox(0.38, 0.38, 0.36, 0, 1.69, 0.01, M.skin);
pbox(0.40, 0.10, 0.38, 0, 1.86, 0.005, M.hair);
pbox(0.08, 0.19, 0.12, -0.18, 1.68, 0.16, M.hair);
pbox(0.045, 0.045, 0.025, -0.09, 1.73, 0.195, M.hair);
pbox(0.045, 0.045, 0.025, 0.09, 1.73, 0.195, M.hair);
// Small carried parcel reinforces arrival/departure without adding another figure.
pbox(0.25, 0.34, 0.17, 0.49, 0.59, 0.02, M.bag);
pbox(0.12, 0.16, 0.025, 0.49, 0.62, 0.115, M.frameLight);
// Small edge blocks clarify the transition from porch to path.
for (let i = 0; i < 7; i++) {
box(0.34, 0.13, 0.27, -1.42 + i * 0.62, 0.10, 2.58, M.stoneDark);
}
// Custom orthographic orbit controls, implemented directly without addons.
const controls = {
theta: 0.62,
phi: 1.03,
zoom: 1,
desiredTheta: 0.62,
desiredPhi: 1.03,
desiredZoom: 1
};
function updateCamera() {
const radius = 16;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(controls.theta),
cameraTarget.y + radius * Math.cos(controls.phi),
cameraTarget.z + radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(cameraTarget);
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const halfHeight = aspect < 1 ? 9.3 : 6.65;
renderer.setSize(width, height, false);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
updateCamera();
}
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;
controls.desiredTheta -= dx * 0.005;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.004,
0.48,
1.34
);
});
function endDrag(event) {
dragging = false;
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("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desiredZoom = THREE.MathUtils.clamp(
controls.desiredZoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.15
);
},
{ passive: false }
);
function resetView() {
controls.desiredTheta = 0.62;
controls.desiredPhi = 1.03;
controls.desiredZoom = 1;
}
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "r" || event.key === "R") resetView();
if (event.key === "ArrowLeft") controls.desiredTheta += 0.1;
if (event.key === "ArrowRight") controls.desiredTheta -= 0.1;
if (event.key === "ArrowUp") controls.desiredPhi = Math.max(0.48, controls.desiredPhi - 0.08);
if (event.key === "ArrowDown") controls.desiredPhi = Math.min(1.34, controls.desiredPhi + 0.08);
if (event.key === "+" || event.key === "=") {
controls.desiredZoom = Math.min(2.15, controls.desiredZoom * 1.1);
}
if (event.key === "-" || event.key === "_") {
controls.desiredZoom = Math.max(0.68, controls.desiredZoom / 1.1);
}
});
window.addEventListener("resize", resize);
resize();
function animate() {
const smoothing = 0.12;
controls.theta += (controls.desiredTheta - controls.theta) * smoothing;
controls.phi += (controls.desiredPhi - controls.phi) * smoothing;
controls.zoom += (controls.desiredZoom - controls.zoom) * smoothing;
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
updateCamera();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```