Prompt specification
Build or customize the Three.js 3D scene "Lift cabin threshold alignment" 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: Lift cabin threshold alignment
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/lift-cabin-threshold-alignment-x0429
Scene Description Prompt:
Show an elevator cabin meeting a landing, with doorway, floor edge, and contrasting threshold strips; use a cutaway to expose the aligned floor surfaces. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (lift-cabin-threshold-alignment-x0429):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Elevator Cabin Meets Landing — Cutaway</title>
<style>
:root {
color-scheme: light;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce6ea;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
color: #19313b;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
max-width: min(390px, calc(100vw - 48px));
padding: 16px 18px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 15px;
background: rgba(248, 251, 252, 0.84);
box-shadow: 0 14px 38px rgba(43, 67, 78, 0.14);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 6px;
color: #dd6f51;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 3vw, 28px);
font-weight: 760;
letter-spacing: -0.035em;
line-height: 1.08;
}
.subtitle {
margin-top: 8px;
color: #61747d;
font-size: 13px;
line-height: 1.45;
}
.status {
position: absolute;
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 999px;
background: rgba(248, 251, 252, 0.86);
box-shadow: 0 10px 28px rgba(43, 67, 78, 0.11);
color: #39535e;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #46b987;
box-shadow: 0 0 0 4px rgba(70, 185, 135, 0.15);
}
.legend {
position: absolute;
bottom: 24px;
left: 24px;
display: flex;
flex-wrap: wrap;
gap: 10px 16px;
max-width: calc(100vw - 48px);
padding: 11px 14px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 13px;
background: rgba(248, 251, 252, 0.84);
box-shadow: 0 12px 32px rgba(43, 67, 78, 0.1);
color: #506771;
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(10px);
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
display: inline-block;
width: 16px;
height: 8px;
border-radius: 2px;
}
.swatch.threshold {
background: #f3bd35;
border: 1px solid #bd8519;
}
.swatch.cut {
background: #df785c;
}
.swatch.aligned {
background: #55ba89;
}
.instructions {
position: absolute;
right: 24px;
bottom: 24px;
color: rgba(38, 61, 71, 0.68);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
}
#loading {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
background: #dce6ea;
color: #405b67;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
padding: 13px 15px;
}
.status {
top: auto;
right: 14px;
bottom: 58px;
}
.legend {
bottom: 14px;
left: 14px;
}
.instructions {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Building cutaway scene…</div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Architectural Cutaway</div>
<h1>Elevator cabin meets landing</h1>
<div class="subtitle">
Open doorway, exposed floor sections, and contrasting threshold strips
show the cabin and landing surfaces meeting at the same level.
</div>
</section>
<div class="status">
<span class="status-dot"></span>
Level 01 · Aligned
</div>
<div class="legend">
<span class="legend-item">
<span class="swatch threshold"></span>
Threshold strips
</span>
<span class="legend-item">
<span class="swatch cut"></span>
Cut section
</span>
<span class="legend-item">
<span class="swatch aligned"></span>
Matching floor level
</span>
</div>
<div class="instructions">Drag to orbit · Scroll to zoom · Double-click to reset</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 and scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce6ea);
scene.fog = new THREE.Fog(0xdce6ea, 14, 27);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
document.body.prepend(renderer.domElement);
const architecture = new THREE.Group();
scene.add(architecture);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.02,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 1,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
const mats = {
cabinBase: material(0x354d5a),
landingBase: material(0x6f5a50),
cabinFloor: material(0x718991, { roughness: 0.62 }),
landingFloor: material(0xd1bfa7, { roughness: 0.7 }),
wall: material(0xe7e4db),
cabinInset: material(0xcbdadd),
landingInset: material(0xe9dfd1),
section: material(0xdf785c),
frame: material(0x273840, { roughness: 0.42, metalness: 0.48 }),
trim: material(0x82929a, { roughness: 0.32, metalness: 0.72 }),
door: material(0xa5a39b, { roughness: 0.38, metalness: 0.66 }),
rubber: material(0x182328, { roughness: 0.94 }),
brass: material(0xc6a76b, { roughness: 0.3, metalness: 0.72 }),
dark: material(0x1e343e, { roughness: 0.48 }),
light: material(0x75f0b4, {
emissive: 0x36d989,
emissiveIntensity: 2.2,
roughness: 0.25
}),
ground: material(0xd4e0e4, { roughness: 1 })
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addBox(parent, size, position, mat, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x30444d, opacity = 0.18) {
const edgeMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 25),
edgeMaterial
);
mesh.add(edges);
return edges;
}
function addCylinderX(parent, radius, length, position, mat) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 20),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.z = Math.PI / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderZ(parent, radius, depth, position, mat) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, depth, 24),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.x = Math.PI / 2;
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function addTextPlane({
parent,
width,
height,
position,
texture,
rotation = [0, 0, 0]
}) {
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
parent.add(mesh);
return mesh;
}
function createTextTexture({
title,
subtitle = "",
background = "rgba(0,0,0,0)",
titleColor = "#29434e",
subtitleColor = "#607781",
align = "center"
}) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (background !== "rgba(0,0,0,0)") {
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
const x = align === "center" ? 384 : 48;
ctx.fillStyle = titleColor;
ctx.textAlign = align;
ctx.textBaseline = "middle";
ctx.font = "700 72px system-ui, sans-serif";
ctx.fillText(title, x, subtitle ? 104 : 128);
if (subtitle) {
ctx.fillStyle = subtitleColor;
ctx.font = "600 31px system-ui, sans-serif";
ctx.fillText(subtitle, x, 180);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function createHazardTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f3bd35";
ctx.fillRect(0, 0, 128, 128);
ctx.strokeStyle = "#28343a";
ctx.lineWidth = 22;
for (let x = -128; x < 256; x += 58) {
ctx.beginPath();
ctx.moveTo(x, 128);
ctx.lineTo(x + 128, 0);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1, 8);
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
// -------------------------------------------------------------------------
// Ground
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
mats.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.255;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Raised floor slabs
//
// Both walking surfaces finish at y = 0:
// cabin: x = -2.90 ... -0.05
// seam: x = -0.05 ... 0.05
// landing:x = 0.05 ... 3.65
// -------------------------------------------------------------------------
const cabinBase = addBox(
architecture,
[2.85, 0.20, 2.90],
[-1.475, -0.14, 0],
mats.cabinBase
);
addEdges(cabinBase);
const landingBase = addBox(
architecture,
[3.60, 0.20, 2.90],
[1.85, -0.14, 0],
mats.landingBase
);
addEdges(landingBase);
const cabinTop = addBox(
architecture,
[2.85, 0.04, 2.90],
[-1.475, -0.02, 0],
mats.cabinFloor,
false
);
addEdges(cabinTop, 0x314c57, 0.12);
const landingTop = addBox(
architecture,
[3.60, 0.04, 2.90],
[1.85, -0.02, 0],
mats.landingFloor,
false
);
addEdges(landingTop, 0x6d5b50, 0.12);
// Exposed front edges and section hatching make the cutaway explicit.
addBox(
architecture,
[2.85, 0.045, 0.025],
[-1.475, -0.035, 1.462],
mats.section,
false
);
addBox(
architecture,
[3.60, 0.045, 0.025],
[1.85, -0.035, 1.462],
mats.section,
false
);
const hatchPoints = [];
const addHatches = (startX, endX) => {
for (let x = startX; x < endX; x += 0.22) {
hatchPoints.push(
new THREE.Vector3(x - 0.055, -0.225, 1.477),
new THREE.Vector3(x + 0.055, -0.055, 1.477)
);
}
};
addHatches(-2.76, -0.16);
addHatches(0.18, 3.48);
const hatchGeometry = new THREE.BufferGeometry().setFromPoints(hatchPoints);
const hatchLines = new THREE.LineSegments(
hatchGeometry,
new THREE.LineBasicMaterial({
color: 0xf2a78f,
transparent: true,
opacity: 0.9
})
);
architecture.add(hatchLines);
// -------------------------------------------------------------------------
// Cutaway walls
// -------------------------------------------------------------------------
const cabinBack = addBox(
architecture,
[2.85, 2.55, 0.16],
[-1.475, 1.275, -1.45],
mats.wall
);
addEdges(cabinBack);
const cabinInner = addBox(
architecture,
[2.50, 1.88, 0.018],
[-1.475, 1.32, -1.358],
mats.cabinInset,
false
);
addEdges(cabinInner, 0x607984, 0.1);
const cabinLeft = addBox(
architecture,
[0.16, 2.55, 2.83],
[-2.82, 1.275, 0.015],
mats.wall
);
addEdges(cabinLeft);
// Colored face marks where the wall has been sectioned.
addBox(
architecture,
[0.16, 2.55, 0.025],
[-2.82, 1.275, 1.427],
mats.section
);
const landingBack = addBox(
architecture,
[3.60, 2.55, 0.16],
[1.85, 1.275, -1.45],
mats.wall
);
addEdges(landingBack);
const landingInner = addBox(
architecture,
[3.22, 1.92, 0.018],
[1.85, 1.32, -1.358],
mats.landingInset,
false
);
addEdges(landingInner, 0x8e7d70, 0.1);
// Only the rear portion of the landing's side wall remains.
const landingSide = addBox(
architecture,
[0.16, 2.55, 1.18],
[3.57, 1.275, -0.79],
mats.wall
);
addEdges(landingSide);
addBox(
architecture,
[0.16, 2.55, 0.025],
[3.57, 1.275, -0.187],
mats.section
);
// -------------------------------------------------------------------------
// Doorway and parked sliding-door panels
// -------------------------------------------------------------------------
const doorway = new THREE.Group();
architecture.add(doorway);
const leftJamb = addBox(
doorway,
[0.24, 2.22, 0.14],
[0, 1.11, -0.94],
mats.frame
);
addEdges(leftJamb, 0x0f2028, 0.28);
const rightJamb = addBox(
doorway,
[0.24, 2.22, 0.14],
[0, 1.11, 0.94],
mats.frame
);
addEdges(rightJamb, 0x0f2028, 0.28);
const header = addBox(
doorway,
[0.24, 0.15, 2.02],
[0, 2.22, 0],
mats.frame
);
addEdges(header, 0x0f2028, 0.28);
// Fine metallic strips define the actual opening.
addBox(
doorway,
[0.255, 2.12, 0.035],
[0.012, 1.08, -0.861],
mats.brass
);
addBox(
doorway,
[0.255, 2.12, 0.035],
[0.012, 1.08, 0.861],
mats.brass
);
// Door leaves are open and parked to either side.
for (const side of [-1, 1]) {
const panel = addBox(
doorway,
[0.08, 2.05, 0.42],
[-0.015, 1.025, side * 1.205],
mats.door
);
addEdges(panel, 0x3b494e, 0.32);
addBox(
doorway,
[0.018, 1.84, 0.29],
[0.035, 1.025, side * 1.205],
mats.trim,
false
);
}
// Door position indicator.
const indicatorTexture = createTextTexture({
title: "▲ 01",
subtitle: "",
background: "#1c3039",
titleColor: "#72f2b5"
});
addTextPlane({
parent: doorway,
width: 0.56,
height: 0.19,
position: [0.132, 2.22, 0.48],
texture: indicatorTexture,
rotation: [0, Math.PI / 2, 0]
});
// -------------------------------------------------------------------------
// Threshold: dark recessed seam plus two high-contrast safety strips
// -------------------------------------------------------------------------
addBox(
architecture,
[0.10, 0.032, 1.78],
[0, -0.003, 0],
mats.rubber,
false
);
const hazardTexture = createHazardTexture();
const hazardMaterial = new THREE.MeshStandardMaterial({
map: hazardTexture,
roughness: 0.55,
metalness: 0.12,
side: THREE.DoubleSide
});
for (const x of [-0.105, 0.105]) {
addTextPlane({
parent: architecture,
width: 0.13,
height: 1.78,
position: [x, 0.018, 0],
texture: hazardTexture,
rotation: [-Math.PI / 2, 0, 0]
});
}
// Small side trim marks emphasize the floor edge around the interface.
addBox(
architecture,
[0.18, 0.035, 0.035],
[-0.16, 0.017, -0.90],
mats.brass,
false
);
addBox(
architecture,
[0.18, 0.035, 0.035],
[0.16, 0.017, -0.90],
mats.brass,
false
);
// -------------------------------------------------------------------------
// Handrails and cabin fittings
// -------------------------------------------------------------------------
addCylinderX(
architecture,
0.028,
2.18,
[-1.47, 0.93, -1.275],
mats.trim
);
for (const x of [-2.35, -0.59]) {
addBox(
architecture,
[0.055, 0.055, 0.15],
[x, 0.93, -1.32],
mats.trim
);
}
addCylinderX(
architecture,
0.028,
2.58,
[1.83, 0.93, -1.275],
mats.trim
);
for (const x of [0.72, 2.94]) {
addBox(
architecture,
[0.055, 0.055, 0.15],
[x, 0.93, -1.32],
mats.trim
);
}
// Cabin control panel.
const controlPanel = addBox(
architecture,
[0.29, 0.68, 0.075],
[-0.43, 1.18, -1.295],
mats.dark
);
addEdges(controlPanel, 0x08171c, 0.4);
addCylinderZ(
architecture,
0.055,
0.025,
[-0.50, 1.31, -1.245],
mats.light
);
addCylinderZ(
architecture,
0.055,
0.025,
[-0.36, 1.31, -1.245],
mats.brass
);
// A vertical illuminated strip suggests cabin lighting without a ceiling.
addBox(
architecture,
[0.035, 1.55, 0.035],
[-2.715, 1.62, 0.91],
mats.light,
false
);
// Landing sign.
const landingSignTexture = createTextTexture({
title: "LEVEL 01",
subtitle: "LANDING",
background: "#254550",
titleColor: "#f4f0e8",
subtitleColor: "#86d9b5"
});
addTextPlane({
parent: architecture,
width: 1.22,
height: 0.49,
position: [2.33, 1.73, -1.274],
texture: landingSignTexture
});
// Flat floor labels.
const cabinLabelTexture = createTextTexture({
title: "CABIN",
subtitle: "",
titleColor: "#eaf2f3"
});
const landingLabelTexture = createTextTexture({
title: "LANDING",
subtitle: "",
titleColor: "#665344"
});
addTextPlane({
parent: architecture,
width: 1.10,
height: 0.30,
position: [-1.62, 0.012, 0.74],
texture: cabinLabelTexture,
rotation: [-Math.PI / 2, 0, 0]
});
addTextPlane({
parent: architecture,
width: 1.22,
height: 0.30,
position: [1.64, 0.012, 0.74],
texture: landingLabelTexture,
rotation: [-Math.PI / 2, 0, 0]
});
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf5fbff, 0x75848a, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff1dd, 3.25);
keyLight.position.set(5.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dce7, 1.25);
fillLight.position.set(-6, 4, 2);
scene.add(fillLight);
const cabinLight = new THREE.PointLight(0xd8f8ff, 13, 5, 2);
cabinLight.position.set(-1.55, 2.15, 0.12);
scene.add(cabinLight);
const landingLight = new THREE.PointLight(0xffe5bc, 8, 4.5, 2);
landingLight.position.set(2.15, 2.15, -0.2);
scene.add(landingLight);
// -------------------------------------------------------------------------
// Custom camera controls — no external controls/addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0.15, 0.90, 0);
const view = {
azimuth: 0.72,
polar: 1.03,
radius: 10.6,
targetAzimuth: 0.72,
targetPolar: 1.03,
targetRadius: 10.6
};
function updateCamera() {
const sinPolar = Math.sin(view.polar);
camera.position.set(
cameraTarget.x +
view.radius * sinPolar * Math.sin(view.azimuth),
cameraTarget.y + view.radius * Math.cos(view.polar),
cameraTarget.z +
view.radius * sinPolar * Math.cos(view.azimuth)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
view.targetAzimuth = 0.72;
view.targetPolar = 1.03;
view.targetRadius = 10.6;
}
const pointer = {
active: false,
lastX: 0,
lastY: 0,
pointerId: null
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.pointerId = event.pointerId;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.pointerId) return;
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
view.targetAzimuth -= dx * 0.006;
view.targetPolar = THREE.MathUtils.clamp(
view.targetPolar - dy * 0.005,
0.38,
1.38
);
});
const releasePointer = (event) => {
if (event.pointerId !== pointer.pointerId) return;
pointer.active = false;
pointer.pointerId = null;
};
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.targetRadius = THREE.MathUtils.clamp(
view.targetRadius * Math.exp(event.deltaY * 0.001),
6.4,
15.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
view.targetAzimuth += 0.08;
} else if (event.key === "ArrowRight") {
view.targetAzimuth -= 0.08;
} else if (event.key === "ArrowUp") {
view.targetPolar = Math.max(0.38, view.targetPolar - 0.05);
} else if (event.key === "ArrowDown") {
view.targetPolar = Math.min(1.38, view.targetPolar + 0.05);
} else if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
const damping = 1 - Math.pow(0.001, Math.max(0.001, elapsed * 0.001));
view.azimuth +=
(view.targetAzimuth - view.azimuth) * 0.10;
view.polar +=
(view.targetPolar - view.polar) * 0.10;
view.radius +=
(view.targetRadius - view.radius) * 0.10;
updateCamera();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("hidden");
}
});
</script>
</body>
</html>
```