Prompt specification
Build or customize the Three.js 3D scene "Clear-path community hallway" 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: Clear-path community hallway
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/clear-path-community-hallway-x0447
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing cane-detectable obstacles. Compose a corridor with noticeboards, chairs, planters, and contrasting edges; rearrange protruding objects so a visitor's continuous navigation route remains visibly free of obstructions. Stylized solid forms.
Working Three.js Starter (clear-path-community-hallway-x0447):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#dce8e7">
<title>Clear-Route Corridor — Accessibility Study</title>
<style>
:root {
--ink: #142c3a;
--muted: #526772;
--paper: rgba(255, 255, 255, 0.91);
--line: rgba(20, 44, 58, 0.14);
--route: #55bdb5;
--yellow: #f5c84b;
--coral: #e66f51;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.72);
box-shadow: 0 12px 40px rgba(20, 44, 58, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 19px 21px 18px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: #377f7b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 20px;
height: 3px;
border-radius: 99px;
background: var(--coral);
content: "";
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 31px);
line-height: 1.06;
letter-spacing: -0.035em;
}
.intro p {
max-width: 390px;
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.metrics {
top: 22px;
right: 22px;
display: grid;
grid-template-columns: repeat(2, minmax(120px, 1fr));
gap: 1px;
overflow: hidden;
border-radius: 16px;
}
.metric {
min-width: 145px;
padding: 15px 17px;
background: rgba(255, 255, 255, 0.86);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-value {
display: flex;
align-items: center;
gap: 7px;
font-size: 17px;
font-weight: 750;
letter-spacing: -0.02em;
}
.status-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #45a56d;
box-shadow: 0 0 0 4px rgba(69, 165, 109, 0.13);
}
.legend {
bottom: 22px;
left: 22px;
padding: 15px 17px;
border-radius: 16px;
}
.legend-title {
margin-bottom: 11px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
color: #405965;
font-size: 11px;
}
.swatch {
position: relative;
width: 30px;
height: 13px;
flex: 0 0 auto;
border-radius: 4px;
}
.swatch.route {
border: 2px solid var(--yellow);
background: #8edbd3;
}
.swatch.edge {
border: 2px solid var(--ink);
background: var(--yellow);
}
.swatch.limit {
height: 3px;
border-radius: 0;
background: repeating-linear-gradient(
90deg,
#476976 0 8px,
transparent 8px 13px
);
}
.controls {
right: 22px;
bottom: 22px;
display: flex;
gap: 5px;
padding: 6px;
border-radius: 14px;
}
button {
min-height: 38px;
padding: 0 14px;
border: 0;
border-radius: 10px;
background: transparent;
color: #405965;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(20, 44, 58, 0.06);
color: var(--ink);
}
button:active {
transform: translateY(1px);
}
button.active {
background: var(--ink);
color: white;
}
button:focus-visible {
outline: 3px solid rgba(85, 189, 181, 0.48);
outline-offset: 2px;
}
.help {
position: fixed;
z-index: 9;
left: 50%;
bottom: 25px;
padding: 8px 12px;
border-radius: 99px;
background: rgba(20, 44, 58, 0.82);
color: rgba(255, 255, 255, 0.88);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #dce8e7;
color: var(--ink);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.metrics,
.legend,
.help {
display: none;
}
.intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
.controls {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive three-dimensional clear-route corridor. Drag to orbit, use the mouse wheel to zoom, and use the view buttons to change perspective."
aria-describedby="controls-help"
></canvas>
<header class="panel intro">
<div class="eyebrow">Spatial access study</div>
<h1>Clear-route corridor</h1>
<p>
Noticeboards, seating and planters use solid, cane-detectable bases with
high-contrast edges. Every projection stays outside the dashed limit,
preserving one uninterrupted 2.6 m navigation route.
</p>
</header>
<aside class="panel metrics" aria-label="Route measurements">
<div class="metric">
<span class="metric-label">Route status</span>
<span class="metric-value"><i class="status-dot"></i>Uninterrupted</span>
</div>
<div class="metric">
<span class="metric-label">Clear width</span>
<span class="metric-value">2.6 m</span>
</div>
</aside>
<aside class="panel legend" aria-label="Scene legend">
<div class="legend-title">Visual key</div>
<div class="legend-row">
<span class="swatch route"></span>
Continuous clear navigation route
</div>
<div class="legend-row">
<span class="swatch edge"></span>
Detectable plinth and contrast edge
</div>
<div class="legend-row">
<span class="swatch limit"></span>
No-projection limit
</div>
</aside>
<nav class="panel controls" aria-label="Camera views">
<button type="button" data-view="overview" class="active">Overview</button>
<button type="button" data-view="plan">Plan</button>
<button type="button" data-view="eye">Eye level</button>
<button type="button" data-view="reset">Reset</button>
</nav>
<div id="controls-help" class="help">Drag to orbit · Scroll to zoom · Arrow keys to inspect</div>
<div id="loading">Building clear-route corridor…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e7);
scene.fog = new THREE.Fog(0xdce8e7, 40, 88);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x748b83, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.25);
sun.position.set(9, 18, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 21;
sun.shadow.camera.bottom = -21;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8e2e7, 1.15);
fill.position.set(-10, 9, -8);
scene.add(fill);
const palette = {
floor: new THREE.MeshStandardMaterial({ color: 0xd8ddd8, roughness: 0.94 }),
wall: new THREE.MeshStandardMaterial({ color: 0xeeeae0, roughness: 0.9 }),
wallTrim: new THREE.MeshStandardMaterial({ color: 0x35535c, roughness: 0.74 }),
navy: new THREE.MeshStandardMaterial({ color: 0x142c3a, roughness: 0.72 }),
yellow: new THREE.MeshStandardMaterial({ color: 0xf5c84b, roughness: 0.68 }),
route: new THREE.MeshStandardMaterial({
color: 0x82d5cd,
roughness: 0.9,
transparent: true,
opacity: 0.94
}),
teal: new THREE.MeshStandardMaterial({ color: 0x287f80, roughness: 0.78 }),
tealLight: new THREE.MeshStandardMaterial({ color: 0x58aaa5, roughness: 0.8 }),
paper: new THREE.MeshStandardMaterial({ color: 0xfff8e8, roughness: 0.98 }),
coral: new THREE.MeshStandardMaterial({ color: 0xe66f51, roughness: 0.8 }),
terracotta: new THREE.MeshStandardMaterial({ color: 0xc9654b, roughness: 0.87 }),
soil: new THREE.MeshStandardMaterial({ color: 0x594a39, roughness: 1 }),
foliage: new THREE.MeshStandardMaterial({
color: 0x397b62,
roughness: 0.95,
flatShading: true
}),
foliageLight: new THREE.MeshStandardMaterial({
color: 0x6aa16f,
roughness: 0.95,
flatShading: true
}),
metal: new THREE.MeshStandardMaterial({
color: 0x31505a,
roughness: 0.52,
metalness: 0.25
})
};
function box(width, height, depth, x, y, z, material, parent = scene, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
x,
y,
z,
material,
parent = scene,
segments = 32
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function textPlane(text, width, height, background = null, foreground = "#142c3a") {
const c = document.createElement("canvas");
c.width = 1024;
c.height = 256;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
if (background) {
roundedRect(ctx, 8, 8, 1008, 240, 34);
ctx.fillStyle = background;
ctx.fill();
}
ctx.fillStyle = foreground;
ctx.font = "800 78px Inter, system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 512, 134, 920);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
return new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
}
// Corridor floor and side bands.
box(12, 0.2, 34, 0, -0.1, 0, palette.floor, scene, false);
box(0.34, 0.045, 34, -5.74, 0.025, 0, palette.navy, scene, false);
box(0.34, 0.045, 34, 5.74, 0.025, 0, palette.navy, scene, false);
// Subtle tile seams on the side bays.
const seamMaterial = new THREE.MeshStandardMaterial({
color: 0xc1c9c5,
roughness: 1
});
for (let z = -15; z <= 15; z += 4) {
box(2.2, 0.012, 0.025, -4.25, 0.009, z, seamMaterial, scene, false);
box(2.2, 0.012, 0.025, 4.25, 0.009, z, seamMaterial, scene, false);
}
// Continuous clear route.
box(2.6, 0.014, 31.5, 0, 0.014, -0.3, palette.route, scene, false);
// Contrasting route edges: dark underlay plus yellow inner stripe.
for (const side of [-1, 1]) {
box(0.12, 0.018, 31.5, side * 1.33, 0.032, -0.3, palette.navy, scene, false);
box(0.06, 0.02, 31.5, side * 1.33, 0.042, -0.3, palette.yellow, scene, false);
}
// Dashed no-projection limit outside the clear lane.
const limitMaterial = new THREE.MeshBasicMaterial({
color: 0x42636f,
transparent: true,
opacity: 0.36,
depthWrite: false
});
for (const side of [-1, 1]) {
for (let z = -15.2; z <= 14.5; z += 1.15) {
box(0.045, 0.014, 0.48, side * 2.05, 0.025, z, limitMaterial, scene, false);
}
}
// Flat directional arrows on the route.
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.12, -0.56);
arrowShape.lineTo(0.12, -0.56);
arrowShape.lineTo(0.12, 0.02);
arrowShape.lineTo(0.39, 0.02);
arrowShape.lineTo(0, 0.57);
arrowShape.lineTo(-0.39, 0.02);
arrowShape.lineTo(-0.12, 0.02);
arrowShape.closePath();
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x174f5a,
transparent: true,
opacity: 0.3,
depthWrite: false,
side: THREE.DoubleSide
});
for (const z of [11.7, 6.8, 1.9, -3, -7.9, -12.8]) {
const arrow = new THREE.Mesh(new THREE.ShapeGeometry(arrowShape), arrowMaterial);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(0, 0.029, z);
scene.add(arrow);
}
const routeLabel = textPlane("CLEAR ROUTE • 2.6 m", 2.15, 0.43, "#142c3a", "#fff8e8");
routeLabel.rotation.x = -Math.PI / 2;
routeLabel.position.set(0, 0.045, 14.35);
scene.add(routeLabel);
// Low corridor walls preserve visibility of all obstacle forms.
for (const side of [-1, 1]) {
box(0.3, 1.05, 32.6, side * 5.82, 0.525, -0.2, palette.wall);
box(0.37, 0.08, 32.6, side * 5.82, 1.09, -0.2, palette.wallTrim);
box(0.055, 0.16, 32.4, side * 5.64, 0.22, -0.2, palette.navy);
for (const z of [-13, -5, 3, 11]) {
box(0.46, 1.48, 0.58, side * 5.79, 0.74, z, palette.wall);
box(0.52, 0.08, 0.64, side * 5.79, 1.52, z, palette.wallTrim);
}
}
// Back wall with an open central doorway, visually extending the route.
box(4.0, 3.3, 0.35, -3.9, 1.65, -16.55, palette.wall);
box(4.0, 3.3, 0.35, 3.9, 1.65, -16.55, palette.wall);
box(11.8, 1.08, 0.35, 0, 2.76, -16.55, palette.wall);
box(11.8, 0.08, 0.43, 0, 3.32, -16.55, palette.wallTrim);
for (const side of [-1, 1]) {
box(0.08, 2.25, 0.43, side * 1.88, 1.125, -16.55, palette.navy);
}
const backLabel = textPlane("CLEAR CORRIDOR", 3.7, 0.56, "#142c3a", "#fff8e8");
backLabel.position.set(0, 2.78, -16.34);
scene.add(backLabel);
box(2.6, 0.016, 0.68, 0, 0.018, -16.32, palette.route, scene, false);
function createNoticeBoard(x, z, rotation, accentMaterial) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
// Low solid plinth creates a cane-detectable obstacle footprint.
box(2.38, 0.14, 0.7, 0, 0.07, 0, palette.navy, group);
box(2.28, 0.085, 0.72, 0, 0.19, 0, palette.yellow, group);
box(0.15, 1.33, 0.17, -0.74, 0.88, 0, palette.metal, group);
box(0.15, 1.33, 0.17, 0.74, 0.88, 0, palette.metal, group);
box(2.3, 1.48, 0.17, 0, 1.68, 0, palette.navy, group);
box(2.08, 1.26, 0.07, 0, 1.68, 0.105, palette.paper, group);
box(1.83, 0.22, 0.045, 0, 2.08, 0.16, accentMaterial, group);
const title = textPlane("NOTICE", 1.18, 0.25, null, "#142c3a");
title.position.set(0, 2.08, 0.19);
group.add(title);
box(0.55, 0.48, 0.025, -0.56, 1.59, 0.155, palette.tealLight, group);
box(0.55, 0.48, 0.025, 0.18, 1.59, 0.155, palette.paper, group);
box(0.7, 0.37, 0.025, 0.56, 1.58, 0.155, palette.paper, group);
for (const xPin of [-0.56, 0.18, 0.56]) {
const pin = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.035, 16),
palette.coral
);
pin.rotation.x = Math.PI / 2;
pin.position.set(xPin, 1.78, 0.19);
group.add(pin);
}
return group;
}
function createChair(x, z, rotation) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
// Contrasting low frame remains physically detectable.
box(1.62, 0.13, 0.94, 0, 0.065, 0, palette.navy, group);
box(1.51, 0.065, 0.84, 0, 0.16, 0, palette.yellow, group);
box(0.13, 0.62, 0.13, -0.61, 0.48, -0.34, palette.metal, group);
box(0.13, 0.62, 0.13, 0.61, 0.48, -0.34, palette.metal, group);
box(1.48, 0.19, 1.13, 0, 0.87, 0.02, palette.teal, group);
box(1.45, 1.02, 0.17, 0, 1.37, -0.47, palette.teal, group);
box(1.16, 0.7, 0.045, 0, 1.38, -0.365, palette.tealLight, group);
box(0.12, 0.17, 0.95, -0.76, 1.14, -0.01, palette.navy, group);
box(0.12, 0.17, 0.95, 0.76, 1.14, -0.01, palette.navy, group);
box(0.12, 0.58, 0.12, -0.61, 0.47, 0.4, palette.metal, group);
box(0.12, 0.58, 0.12, 0.61, 0.47, 0.4, palette.metal, group);
return group;
}
function createPlanter(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinder(0.7, 0.7, 0.13, 0, 0.065, 0, palette.navy, group);
cylinder(0.7, 0.7, 0.085, 0, 0.17, 0, palette.yellow, group);
cylinder(0.62, 0.49, 0.98, 0, 0.69, 0, palette.terracotta, group);
cylinder(0.65, 0.65, 0.1, 0, 1.2, 0, palette.navy, group);
cylinder(0.54, 0.54, 0.04, 0, 1.27, 0, palette.soil, group);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.58, 0.055, 8, 32),
palette.terracotta
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 1.23;
rim.castShadow = true;
group.add(rim);
cylinder(0.065, 0.085, 1.15, 0, 1.82, 0, palette.foliage, group, 12);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.62, 1),
palette.foliage
);
crown.position.set(0, 2.48, 0);
crown.scale.set(1, 1.15, 0.92);
crown.castShadow = true;
group.add(crown);
const leafPositions = [
[-0.43, 2.18, 0.08, 0.5],
[0.43, 2.24, 0.04, 0.47],
[0.08, 1.98, 0.4, 0.42],
[-0.14, 2.72, -0.25, 0.39]
];
for (const [lx, ly, lz, radius] of leafPositions) {
const leaf = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 1),
palette.foliageLight
);
leaf.position.set(lx, ly, lz);
leaf.scale.set(1.15, 0.72, 0.85);
leaf.rotation.set(0.3, lx * 2, lz);
leaf.castShadow = true;
group.add(leaf);
}
return group;
}
// All obstacle groups are deliberately placed beyond the dashed limit.
createNoticeBoard(-4.05, -4.6, Math.PI / 2 - 0.28, palette.coral);
createNoticeBoard(3.95, 2.8, -Math.PI / 2 + 0.28, palette.tealLight);
createChair(-3.55, 4.5, Math.PI / 2);
createChair(3.65, -2.8, -Math.PI / 2);
createPlanter(-3.35, -9.4, 0.93);
createPlanter(3.3, 9, 0.9);
createPlanter(-4.45, 10.7, 0.83);
createPlanter(4.45, -11.7, 0.88);
// Direct camera controls implemented without addons.
const clamp = THREE.MathUtils.clamp;
const views = {
overview: {
theta: 0.63,
phi: 1.02,
radius: 32,
target: new THREE.Vector3(0, 0, -1)
},
plan: {
theta: 0,
phi: 0.055,
radius: 48,
target: new THREE.Vector3(0, 0, -0.5)
},
eye: {
theta: 0.22,
phi: 1.31,
radius: 28,
target: new THREE.Vector3(0, 0.9, 1.2)
},
reset: {
theta: 0.63,
phi: 1.02,
radius: 32,
target: new THREE.Vector3(0, 0, -1)
}
};
const current = {
theta: views.overview.theta,
phi: views.overview.phi,
radius: views.overview.radius,
target: views.overview.target.clone()
};
const goal = {
theta: current.theta,
phi: current.phi,
radius: current.radius,
target: current.target.clone()
};
const buttons = [...document.querySelectorAll("[data-view]")];
function setView(name) {
const view = views[name];
goal.theta = view.theta;
goal.phi = view.phi;
goal.radius = view.radius;
goal.target.copy(view.target);
buttons.forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
buttons.forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
goal.theta = clamp(goal.theta - dx * 0.006, -1.15, 1.15);
goal.phi = clamp(goal.phi - dy * 0.005, 0.055, 1.42);
buttons.forEach((button) => button.classList.remove("active"));
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const delta = Math.sign(event.deltaY) * Math.min(3, Math.abs(event.deltaY) * 0.022);
goal.radius = clamp(goal.radius + delta, 17, 52);
buttons.forEach((button) => button.classList.remove("active"));
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
goal.theta = clamp(goal.theta - 0.08, -1.15, 1.15);
} else if (event.key === "ArrowRight") {
goal.theta = clamp(goal.theta + 0.08, -1.15, 1.15);
} else if (event.key === "ArrowUp") {
goal.phi = clamp(goal.phi - 0.06, 0.055, 1.42);
} else if (event.key === "ArrowDown") {
goal.phi = clamp(goal.phi + 0.06, 0.055, 1.42);
} else if (event.key === "+" || event.key === "=") {
goal.radius = clamp(goal.radius - 1.5, 17, 52);
} else if (event.key === "-") {
goal.radius = clamp(goal.radius + 1.5, 17, 52);
} else if (event.key.toLowerCase() === "r") {
setView("reset");
} else {
return;
}
buttons.forEach((button) => button.classList.remove("active"));
});
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, false);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
const cameraOffset = new THREE.Vector3();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-dt * 8.5);
current.theta += (goal.theta - current.theta) * damping;
current.phi += (goal.phi - current.phi) * damping;
current.radius += (goal.radius - current.radius) * damping;
current.target.lerp(goal.target, damping);
cameraOffset.setFromSphericalCoords(
current.radius,
current.phi,
current.theta
);
camera.position.copy(current.target).add(cameraOffset);
camera.lookAt(current.target);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
renderer.render(scene, camera);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
animate();
</script>
</body>
</html>
```