Prompt specification
Build or customize the Three.js 3D scene "Room heating airflow vignette" 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: Room heating airflow vignette
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/room-heating-airflow-vignette-x1459
Scene Description Prompt:
Compose a small room with heater, window, and furniture; show illustrative circulation arrows while avoiding a claim that this prescribed field predicts real indoor airflow. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (room-heating-airflow-vignette-x1459):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Room — Illustrative Circulation</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: #dce6e2;
color: #173b39;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid rgba(255, 255, 255, 0.72);
background: rgba(248, 250, 247, 0.86);
box-shadow: 0 12px 36px rgba(36, 58, 54, 0.13);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.intro {
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 19px 20px 17px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 6px;
color: #6d827e;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 15px;
color: #58706b;
font-size: 13px;
line-height: 1.5;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 12px;
padding-top: 13px;
border-top: 1px solid rgba(23, 59, 57, 0.11);
color: #49625e;
font-size: 12px;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.09);
}
.controls {
position: fixed;
z-index: 6;
top: 22px;
right: 22px;
display: flex;
gap: 8px;
}
button {
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 12px;
padding: 11px 14px;
background: rgba(248, 250, 247, 0.9);
color: #173b39;
box-shadow: 0 8px 22px rgba(36, 58, 54, 0.11);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
button:hover {
background: #ffffff;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(36, 145, 134, 0.3);
outline-offset: 2px;
}
.disclaimer {
left: 22px;
bottom: 22px;
width: min(430px, calc(100vw - 44px));
padding: 14px 16px;
border-radius: 15px;
color: #425c57;
font-size: 12px;
line-height: 1.5;
}
.disclaimer strong {
display: block;
margin-bottom: 3px;
color: #173b39;
font-size: 12px;
}
.hint {
position: fixed;
z-index: 5;
right: 22px;
bottom: 22px;
padding: 9px 12px;
border-radius: 11px;
background: rgba(248, 250, 247, 0.76);
color: #637873;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
@media (max-width: 700px) {
.intro {
top: 12px;
left: 12px;
width: min(290px, calc(100vw - 24px));
padding: 14px 15px;
}
.subtitle {
margin-bottom: 10px;
}
.legend {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 91px;
flex-direction: column;
}
.disclaimer {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="intro panel">
<p class="eyebrow">Voxel interior study</p>
<h1>Small room,<br>clear pathways.</h1>
<p class="subtitle">
A cutaway room composed from visible blocks, with a heater, window,
furniture, and a conceptual circulation guide.
</p>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch" style="background:#ed8b54"></i>Heater</span>
<span><i class="swatch" style="background:#8ed1e2"></i>Window</span>
<span><i class="swatch" style="background:#d97b67"></i>Furniture</span>
<span><i class="swatch" style="background:#219b91"></i>Conceptual arrows</span>
</div>
</section>
<nav class="controls" aria-label="Scene controls">
<button id="toggleArrows" type="button" aria-pressed="true">Hide arrows</button>
<button id="resetView" type="button">Reset view</button>
</nav>
<aside class="disclaimer panel">
<strong>Conceptual circulation guide</strong>
The arrows are a hand-authored visual sequence. They are not CFD output,
measured airflow, or a prediction of real indoor air movement.
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys to move</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,
alpha: false,
powerPreference: "high-performance"
});
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.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel room. Drag to orbit and scroll to zoom."
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce6e2);
scene.fog = new THREE.Fog(0xdce6e2, 23, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 1.2, 0);
let theta = 0.72;
let phi = 0.57;
let radius = 16.5;
function updateCamera() {
const horizontal = Math.cos(phi) * radius;
camera.position.set(
target.x + horizontal * Math.sin(theta),
target.y + Math.sin(phi) * radius,
target.z + horizontal * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf8fffc, 0x8d806b, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.2);
sun.position.set(7, 12, 7);
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.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbde7ee, 0.8);
fill.position.set(-8, 6, 3);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}:${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
...options
})
);
}
return materialCache.get(key);
}
function block(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(unitBox, material(color, options));
mesh.scale.set(...size);
mesh.position.set(...position);
mesh.castShadow = !options.transparent;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function instanceBlocks(entries) {
const mesh = new THREE.InstancedMesh(
unitBox,
material(0xffffff),
entries.length
);
const dummy = new THREE.Object3D();
entries.forEach((entry, index) => {
dummy.position.set(...entry.position);
dummy.scale.set(...entry.size);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, new THREE.Color(entry.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Ground and the raised room base.
block(scene, [32, 0.18, 32], [0, -0.58, 0], 0xd3dfda);
block(scene, [12.6, 0.30, 8.6], [0, -0.29, 0], 0xb7c3ba);
// Floor: individual visible voxel tiles.
const floorEntries = [];
const floorColors = [
0xd9cfb9,
0xe2d8c3,
0xcec4af,
0xddd3bd,
0xd5cab5
];
const tile = 0.5;
for (let x = 0; x < 24; x++) {
for (let z = 0; z < 16; z++) {
floorEntries.push({
position: [
-6 + (x + 0.5) * tile,
-0.08,
-4 + (z + 0.5) * tile
],
size: [0.475, 0.16, 0.475],
color: floorColors[(x * 7 + z * 3) % floorColors.length]
});
}
}
instanceBlocks(floorEntries);
// Back and left cutaway walls, each built from small blocks.
const wallEntries = [];
const wallColors = [0xe7e8df, 0xe1e4db, 0xebebe2, 0xdde2d9];
for (let x = 0; x < 24; x++) {
for (let y = 0; y < 8; y++) {
const px = -6 + (x + 0.5) * 0.5;
const py = 0.25 + y * 0.5;
// Leave a 3 × 2 block opening for the window.
const inWindow =
px > -1.5 &&
px < 1.5 &&
py > 1.5 &&
py < 3.5;
if (!inWindow) {
wallEntries.push({
position: [px, py, -4],
size: [0.48, 0.48, 0.24],
color: wallColors[(x + y * 2) % wallColors.length]
});
}
}
}
for (let z = 0; z < 16; z++) {
for (let y = 0; y < 8; y++) {
wallEntries.push({
position: [
-6,
0.25 + y * 0.5,
-4 + (z + 0.5) * 0.5
],
size: [0.24, 0.48, 0.48],
color: wallColors[(z * 3 + y) % wallColors.length]
});
}
}
instanceBlocks(wallEntries);
// Window: a simple voxel frame, sky card, square sun, and clouds.
const sky = new THREE.Mesh(
unitBox,
new THREE.MeshBasicMaterial({ color: 0x8bcfe2 })
);
sky.scale.set(3.02, 2.02, 0.05);
sky.position.set(0, 2.5, -4.27);
scene.add(sky);
block(scene, [0.42, 0.42, 0.05], [-0.85, 2.93, -4.21], 0xffd96b);
block(scene, [0.35, 0.18, 0.04], [0.58, 2.88, -4.20], 0xf5fbff);
block(scene, [0.22, 0.18, 0.04], [0.88, 2.88, -4.20], 0xf5fbff);
block(scene, [0.26, 0.18, 0.04], [0.42, 2.72, -4.20], 0xf5fbff);
const glass = new THREE.Mesh(
unitBox,
new THREE.MeshStandardMaterial({
color: 0xb8edf3,
roughness: 0.15,
transparent: true,
opacity: 0.24,
depthWrite: false
})
);
glass.scale.set(2.88, 1.88, 0.035);
glass.position.set(0, 2.5, -4.01);
scene.add(glass);
const frameColor = 0x536d67;
block(scene, [0.16, 2.22, 0.28], [-1.58, 2.5, -3.86], frameColor);
block(scene, [0.16, 2.22, 0.28], [1.58, 2.5, -3.86], frameColor);
block(scene, [3.32, 0.16, 0.28], [0, 1.42, -3.86], frameColor);
block(scene, [3.32, 0.16, 0.28], [0, 3.58, -3.86], frameColor);
block(scene, [0.12, 1.96, 0.18], [0, 2.5, -3.80], frameColor);
block(scene, [3.52, 0.14, 0.54], [0, 1.34, -3.70], 0xb7a88c);
// Heater under the window.
const heater = new THREE.Group();
heater.position.set(0.35, 0, -3.54);
scene.add(heater);
const heaterCase = [0xf2ead9, 0xe8dfce, 0xf7f0e2];
for (let x = 0; x < 5; x++) {
for (let y = 0; y < 3; y++) {
block(
heater,
[0.39, 0.28, 0.44],
[-0.80 + x * 0.40, 0.27 + y * 0.31, 0],
heaterCase[(x + y) % heaterCase.length]
);
}
}
block(heater, [1.78, 0.60, 0.08], [0, 0.58, 0.24], 0x3f4845);
block(heater, [1.91, 0.09, 0.10], [0, 0.92, 0.27], 0xc3b9a7);
for (let x = 0; x < 7; x++) {
block(
heater,
[0.11, 0.43, 0.08],
[-0.72 + x * 0.24, 0.58, 0.30],
x % 2 ? 0xf19b54 : 0xe87545,
{ emissive: 0x7d2d12, emissiveIntensity: 0.22 }
);
}
block(heater, [0.17, 0.10, 0.10], [0.82, 1.06, 0.15], 0xd95c45);
block(heater, [0.18, 0.35, 0.18], [-0.72, 0.10, 0.02], 0x4c5753);
block(heater, [0.18, 0.35, 0.18], [0.72, 0.10, 0.02], 0x4c5753);
// Rug.
block(scene, [3.75, 0.035, 2.75], [-2.65, 0.025, 0.75], 0x9ebbb1);
block(scene, [3.35, 0.04, 2.35], [-2.65, 0.047, 0.75], 0xb8cec4);
// Sofa against the left wall.
const sofa = new THREE.Group();
sofa.position.set(-4.92, 0, 0.20);
sofa.rotation.y = Math.PI / 2;
scene.add(sofa);
block(sofa, [3.05, 0.43, 1.23], [0, 0.47, 0], 0xb9574d);
block(sofa, [3.08, 1.10, 0.27], [0, 1.12, -0.49], 0xd47763);
for (let x = -1; x <= 1; x++) {
block(sofa, [0.88, 0.27, 0.94], [x, 0.77, 0.12], 0xe58b73);
}
block(sofa, [0.26, 0.90, 1.22], [-1.43, 0.83, 0.02], 0xc86454);
block(sofa, [0.26, 0.90, 1.22], [1.43, 0.83, 0.02], 0xc86454);
block(sofa, [0.62, 0.55, 0.18], [-0.78, 1.13, -0.22], 0xf0c18d);
block(sofa, [0.62, 0.55, 0.18], [0.76, 1.13, -0.22], 0xf0c18d);
for (const x of [-1.18, 1.18]) {
for (const z of [-0.42, 0.42]) {
block(sofa, [0.16, 0.34, 0.16], [x, 0.17, z], 0x5b554a);
}
}
// Coffee table and books.
const table = new THREE.Group();
table.position.set(-2.55, 0, 0.70);
scene.add(table);
for (let x = 0; x < 4; x++) {
for (let z = 0; z < 2; z++) {
block(
table,
[0.43, 0.16, 0.53],
[-0.65 + x * 0.44, 0.78, -0.28 + z * 0.56],
x % 2 ? 0x9a6847 : 0xa87350
);
}
}
for (const x of [-0.65, 0.65]) {
for (const z of [-0.34, 0.34]) {
block(table, [0.14, 0.66, 0.14], [x, 0.38, z], 0x684936);
}
}
block(table, [0.48, 0.08, 0.35], [-0.18, 0.90, 0.05], 0x2f6965);
block(table, [0.39, 0.07, 0.31], [-0.13, 0.98, 0.02], 0xe4b865);
block(table, [0.24, 0.22, 0.24], [0.48, 0.97, -0.12], 0xd5d3c2);
// Armchair.
const chair = new THREE.Group();
chair.position.set(3.40, 0, 1.45);
chair.rotation.y = -2.0;
scene.add(chair);
block(chair, [1.45, 0.40, 1.18], [0, 0.48, 0], 0xd4a849);
block(chair, [1.40, 0.27, 0.94], [0, 0.77, 0.11], 0xe2bd63);
block(chair, [1.46, 1.15, 0.27], [0, 1.13, -0.47], 0xc8993f);
block(chair, [0.25, 0.82, 1.18], [-0.66, 0.82, 0.02], 0xcaa04a);
block(chair, [0.25, 0.82, 1.18], [0.66, 0.82, 0.02], 0xcaa04a);
for (const x of [-0.49, 0.49]) {
for (const z of [-0.38, 0.38]) {
block(chair, [0.14, 0.30, 0.14], [x, 0.15, z], 0x5b554a);
}
}
// Bookcase and small colored book blocks.
const shelf = new THREE.Group();
shelf.position.set(4.28, 0, -3.40);
scene.add(shelf);
block(shelf, [0.16, 3.25, 0.68], [-0.91, 1.63, 0], 0x496b61);
block(shelf, [0.16, 3.25, 0.68], [0.91, 1.63, 0], 0x496b61);
for (const y of [0.20, 1.02, 1.84, 2.66, 3.10]) {
block(shelf, [1.97, 0.12, 0.68], [0, y, 0], 0x648078);
}
const bookColors = [0xd97662, 0xe6b85f, 0x73a8a1, 0x7894b4, 0xc9c3a7];
for (let row = 0; row < 3; row++) {
let x = -0.70;
for (let book = 0; book < 6; book++) {
const height = 0.42 + ((book + row) % 3) * 0.08;
const width = 0.13 + ((book + row) % 2) * 0.04;
block(
shelf,
[width, height, 0.40],
[x + width / 2, 0.26 + row * 0.82 + height / 2, 0.04],
bookColors[(book + row * 2) % bookColors.length]
);
x += width + 0.04;
}
}
// Voxel plant.
const plant = new THREE.Group();
plant.position.set(5.00, 0, 2.72);
scene.add(plant);
block(plant, [0.68, 0.55, 0.68], [0, 0.28, 0], 0xb56f4f);
block(plant, [0.54, 0.10, 0.54], [0, 0.58, 0], 0x5e4435);
block(plant, [0.13, 0.82, 0.13], [0, 0.93, 0], 0x567b4e);
block(plant, [0.43, 0.35, 0.42], [-0.20, 1.20, 0.02], 0x5e9364);
block(plant, [0.39, 0.40, 0.37], [0.24, 1.35, -0.04], 0x78a76d);
block(plant, [0.34, 0.31, 0.36], [0.02, 1.65, 0.03], 0x8db979);
// Conceptual arrows, made entirely from blocks.
const arrowsGroup = new THREE.Group();
scene.add(arrowsGroup);
const arrowColor = 0x219b91;
function makeArrow(position, direction, scale = 1) {
const group = new THREE.Group();
const dir = new THREE.Vector3(...direction).normalize();
const quaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
dir
);
group.quaternion.copy(quaternion);
block(
group,
[0.82, 0.11, 0.11],
[-0.25, 0, 0],
arrowColor,
{ emissive: 0x075b55, emissiveIntensity: 0.38 }
);
const headPoints = [
[0.20, 0.00, 0],
[-0.04, 0.21, 0],
[-0.04, -0.21, 0],
[-0.27, 0.42, 0],
[-0.27, -0.42, 0]
];
headPoints.forEach((point) => {
block(
group,
[0.18, 0.18, 0.18],
point,
arrowColor,
{ emissive: 0x075b55, emissiveIntensity: 0.38 }
);
});
group.position.set(...position);
group.scale.setScalar(scale);
arrowsGroup.add(group);
}
makeArrow([0.35, 1.42, -3.03], [0, 1, 0], 0.95);
makeArrow([0.35, 2.22, -3.03], [0, 1, 0], 0.95);
makeArrow([1.35, 3.30, -2.98], [1, 0, 0], 0.95);
makeArrow([2.70, 3.55, -2.70], [0.75, 0, 0.66], 0.95);
makeArrow([3.70, 3.55, -1.35], [0, 0, 1], 0.95);
makeArrow([4.45, 3.25, 0.12], [0, 0, 1], 0.95);
makeArrow([4.65, 2.28, 1.05], [0, -1, 0], 0.95);
makeArrow([4.65, 1.18, 1.05], [0, -1, 0], 0.95);
makeArrow([3.48, 0.32, 1.92], [-1, 0, 0], 0.90);
makeArrow([2.00, 0.32, 2.48], [-1, 0, 0], 0.90);
makeArrow([0.52, 0.32, 2.73], [-1, 0, 0], 0.90);
makeArrow([-0.98, 0.32, 2.73], [-1, 0, 0], 0.90);
makeArrow([-2.46, 0.40, 2.53], [-1, 0, 0], 0.90);
makeArrow([-3.38, 0.83, 2.28], [0, 1, 0], 0.90);
makeArrow([-3.38, 1.72, 2.28], [0, 1, 0], 0.90);
makeArrow([-3.18, 2.52, 1.86], [0.18, 0, -1], 0.90);
makeArrow([-2.18, 1.03, -2.50], [1, 0, 0], 0.90);
makeArrow([-0.88, 1.03, -2.82], [1, 0, 0], 0.90);
// Small in-scene label reinforces that the arrows are conceptual.
function makeLabelSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 160;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(22, 61, 58, 0.94)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "#5ad0c2";
context.fillRect(0, canvas.height - 14, canvas.width, 14);
context.fillStyle = "#f4faf7";
context.font = "700 42px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 - 4);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(3.15, 0.79, 1);
sprite.position.set(1.55, 4.18, -0.85);
sprite.renderOrder = 10;
arrowsGroup.add(sprite);
}
makeLabelSprite("CONCEPTUAL LOOP");
// Direct camera controls, implemented without addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
theta -= deltaX * 0.006;
phi = THREE.MathUtils.clamp(phi + deltaY * 0.005, 0.22, 1.23);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
9.5,
24
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
let changed = true;
switch (event.key) {
case "ArrowLeft":
theta += 0.12;
break;
case "ArrowRight":
theta -= 0.12;
break;
case "ArrowUp":
phi = THREE.MathUtils.clamp(phi + 0.08, 0.22, 1.23);
break;
case "ArrowDown":
phi = THREE.MathUtils.clamp(phi - 0.08, 0.22, 1.23);
break;
default:
changed = false;
}
if (changed) {
event.preventDefault();
updateCamera();
}
});
const toggleButton = document.getElementById("toggleArrows");
toggleButton.addEventListener("click", () => {
const visible = !arrowsGroup.visible;
arrowsGroup.visible = visible;
toggleButton.textContent = visible ? "Hide arrows" : "Show arrows";
toggleButton.setAttribute("aria-pressed", String(visible));
});
document.getElementById("resetView").addEventListener("click", () => {
theta = 0.72;
phi = 0.57;
radius = 16.5;
updateCamera();
});
function resize() {
const width = host.clientWidth;
const height = host.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(host);
resize();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```