Prompt specification
Build or customize the Three.js 3D scene "Two Tank Cells and a Gate Slot" 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: Two Tank Cells and a Gate Slot
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-tank-cells-and-a-gate-slot-x3517
Scene Description Prompt:
A cutaway pair of tanks with unequal water levels, a closed connecting gate, and labeled initial volumes. Three.js from cdnjs, one HTML file.
Working Three.js Starter (two-tank-cells-and-a-gate-slot-x3517):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connected Tanks — Initial Condition</title>
<style>
:root {
color-scheme: dark;
--accent: #55d8f4;
--warning: #ff7166;
--panel: rgba(7, 18, 31, 0.78);
--border: rgba(132, 205, 229, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111d;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 42%, rgba(2, 7, 13, 0.36) 100%),
linear-gradient(180deg, rgba(3, 10, 18, 0.16), transparent 30%);
z-index: 2;
}
header {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
margin-bottom: 8px;
color: var(--accent);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #f1f8fb;
font-size: clamp(26px, 3vw, 42px);
font-weight: 650;
letter-spacing: -0.035em;
}
header p {
margin: 8px 0 0;
color: rgba(216, 235, 244, 0.68);
font-size: 13px;
letter-spacing: 0.02em;
}
.reset {
position: fixed;
top: 28px;
right: 28px;
z-index: 6;
padding: 10px 14px;
border: 1px solid var(--border);
border-radius: 10px;
color: #d9edf5;
background: var(--panel);
backdrop-filter: blur(12px);
cursor: pointer;
font: 600 11px/1 Inter, ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.11em;
text-transform: uppercase;
transition: border-color 160ms, background 160ms, transform 160ms;
}
.reset:hover {
border-color: rgba(85, 216, 244, 0.65);
background: rgba(12, 31, 46, 0.9);
transform: translateY(-1px);
}
.legend {
position: fixed;
left: 28px;
bottom: 26px;
z-index: 5;
display: flex;
gap: 18px;
align-items: center;
padding: 11px 14px;
border: 1px solid var(--border);
border-radius: 10px;
color: rgba(221, 239, 246, 0.76);
background: var(--panel);
backdrop-filter: blur(12px);
font-size: 11px;
letter-spacing: 0.04em;
pointer-events: none;
}
.legend-item {
display: flex;
gap: 7px;
align-items: center;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px rgba(85, 216, 244, 0.55);
}
.swatch.gate {
background: var(--warning);
box-shadow: 0 0 12px rgba(255, 113, 102, 0.55);
}
.controls {
position: fixed;
right: 28px;
bottom: 26px;
z-index: 5;
color: rgba(210, 232, 241, 0.55);
font-size: 11px;
letter-spacing: 0.055em;
pointer-events: none;
}
@media (max-width: 700px) {
header {
top: 18px;
left: 18px;
}
header p {
max-width: 230px;
line-height: 1.5;
}
.reset {
top: 18px;
right: 18px;
}
.legend {
left: 18px;
bottom: 18px;
gap: 12px;
}
.controls {
display: none;
}
}
</style>
</head>
<body>
<div class="vignette"></div>
<header>
<div class="eyebrow">Hydrostatics / Initial Condition</div>
<h1>Connected Tanks</h1>
<p>Closed connecting gate · unequal free-surface elevations</p>
</header>
<button class="reset" id="resetView" type="button">Reset view</button>
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
<span>Water</span>
</div>
<div class="legend-item">
<span class="swatch gate"></span>
<span>Closed gate</span>
</div>
</div>
<div class="controls">Drag to orbit · Scroll to zoom · Double-click to reset</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(0x07111d);
scene.fog = new THREE.FogExp2(0x07111d, 0.027);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D cutaway of two connected water tanks with a closed gate"
);
document.body.prepend(renderer.domElement);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa9ddff, 0x13202c, 2.25));
const keyLight = new THREE.DirectionalLight(0xf2fbff, 3.1);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3bc8ff, 2.0);
rimLight.position.set(7, 6, -7);
scene.add(rimLight);
const gateLight = new THREE.PointLight(0xff554a, 12, 6, 2);
gateLight.position.set(0, 2.0, 0.6);
scene.add(gateLight);
// -------------------------------------------------------------------------
// Ground and base
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0x081521,
roughness: 0.88,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(
36,
36,
0x28536a,
0x132b3b
);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(11.8, 0.18, 3.65),
new THREE.MeshStandardMaterial({
color: 0x142535,
roughness: 0.52,
metalness: 0.42
})
);
plinth.position.y = 0.14;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const plinthEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(plinth.geometry),
new THREE.LineBasicMaterial({
color: 0x416b82,
transparent: true,
opacity: 0.65
})
);
plinthEdge.position.copy(plinth.position);
scene.add(plinthEdge);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x8aa4b5,
metalness: 0.78,
roughness: 0.26
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x233a49,
metalness: 0.72,
roughness: 0.3
});
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0x718b9c,
metalness: 0.82,
roughness: 0.23
});
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8edcf4,
transparent: true,
opacity: 0.12,
roughness: 0.08,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const waterMaterial = new THREE.MeshPhysicalMaterial({
color: 0x20b9e6,
emissive: 0x063c57,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.7,
roughness: 0.16,
metalness: 0.04,
clearcoat: 0.65,
clearcoatRoughness: 0.18,
depthWrite: false
});
const waterTopMaterial = new THREE.MeshPhysicalMaterial({
color: 0x75e5fa,
emissive: 0x0a6c88,
emissiveIntensity: 0.25,
transparent: true,
opacity: 0.78,
roughness: 0.12,
metalness: 0.02,
side: THREE.DoubleSide,
depthWrite: false
});
const gateMaterial = new THREE.MeshStandardMaterial({
color: 0xff665b,
emissive: 0x6c100d,
emissiveIntensity: 0.35,
metalness: 0.46,
roughness: 0.3
});
const levelLineMaterial = new THREE.LineBasicMaterial({
color: 0x8cecff,
transparent: true,
opacity: 0.9
});
// -------------------------------------------------------------------------
// Canvas-backed 3D labels
// -------------------------------------------------------------------------
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 makeVolumeLabel(kicker, value) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 280;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 1008, 264, 28);
ctx.fillStyle = "rgba(5, 16, 28, 0.91)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = "rgba(85, 216, 244, 0.68)";
ctx.stroke();
ctx.fillStyle = "#55d8f4";
ctx.font = "700 34px system-ui, sans-serif";
ctx.letterSpacing = "3px";
ctx.fillText(kicker, 48, 72);
ctx.fillStyle = "#f2fbff";
ctx.font = "720 76px system-ui, sans-serif";
ctx.fillText(value, 48, 178);
ctx.fillStyle = "rgba(185, 222, 235, 0.65)";
ctx.font = "500 25px system-ui, sans-serif";
ctx.fillText("INITIAL WATER VOLUME", 50, 232);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(3.15, 0.862, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeTextLabel(text, accent = "#55d8f4", width = 1.8) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 170;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 758, 160, 70);
ctx.fillStyle = "rgba(4, 13, 23, 0.90)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.font = "700 53px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 384, 87);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 170 / 768, 1);
sprite.renderOrder = 21;
return sprite;
}
// -------------------------------------------------------------------------
// Tank construction
// -------------------------------------------------------------------------
const TANK_WIDTH = 3.5;
const TANK_DEPTH = 2.5;
const TANK_HEIGHT = 4.2;
const TANK_BASE = 0.57;
const TANK_CENTER_Y = TANK_BASE + TANK_HEIGHT / 2;
function addBox(group, width, height, depth, x, y, z, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function createTank(centerX, waterHeight, accent, volumeText, heightText) {
const group = new THREE.Group();
group.position.x = centerX;
const halfW = TANK_WIDTH / 2;
const halfD = TANK_DEPTH / 2;
// Bottom pan.
addBox(
group,
TANK_WIDTH + 0.12,
0.18,
TANK_DEPTH + 0.12,
0,
0.47,
0,
darkMetalMaterial
);
// Transparent rear and side panels; the front wall is intentionally absent.
const rear = addBox(
group,
TANK_WIDTH,
TANK_HEIGHT,
0.055,
0,
TANK_CENTER_Y,
-halfD,
glassMaterial
);
rear.castShadow = false;
rear.renderOrder = 4;
const leftSide = addBox(
group,
0.055,
TANK_HEIGHT,
TANK_DEPTH,
-halfW,
TANK_CENTER_Y,
0,
glassMaterial
);
leftSide.castShadow = false;
leftSide.renderOrder = 4;
const rightSide = addBox(
group,
0.055,
TANK_HEIGHT,
TANK_DEPTH,
halfW,
TANK_CENTER_Y,
0,
glassMaterial
);
rightSide.castShadow = false;
rightSide.renderOrder = 4;
// Structural frame.
const frame = 0.065;
// Four vertical corner posts.
for (const x of [-halfW, halfW]) {
for (const z of [-halfD, halfD]) {
addBox(
group,
frame,
TANK_HEIGHT,
frame,
x,
TANK_CENTER_Y,
z,
frameMaterial
);
}
}
// Top rim.
for (const z of [-halfD, halfD]) {
addBox(
group,
TANK_WIDTH + frame,
frame,
frame,
0,
TANK_BASE + TANK_HEIGHT,
z,
frameMaterial
);
}
for (const x of [-halfW, halfW]) {
addBox(
group,
frame,
frame,
TANK_DEPTH + frame,
x,
TANK_BASE + TANK_HEIGHT,
0,
frameMaterial
);
}
// Narrow lower front lip makes the cutaway edge clear.
addBox(
group,
TANK_WIDTH + frame,
0.055,
0.065,
0,
TANK_BASE + 0.025,
halfD,
frameMaterial
);
// Feet.
for (const x of [-halfW + 0.25, halfW - 0.25]) {
for (const z of [-halfD + 0.25, halfD - 0.25]) {
addBox(
group,
0.16,
0.28,
0.16,
x,
0.23,
z,
darkMetalMaterial
);
}
}
// Water body.
const waterWidth = TANK_WIDTH - 0.16;
const waterDepth = TANK_DEPTH - 0.16;
const water = addBox(
group,
waterWidth,
waterHeight,
waterDepth,
0,
TANK_BASE + waterHeight / 2,
0,
waterMaterial
);
water.castShadow = false;
water.renderOrder = 2;
// Visible free surface.
const surface = new THREE.Mesh(
new THREE.PlaneGeometry(waterWidth, waterDepth),
waterTopMaterial
);
surface.rotation.x = -Math.PI / 2;
surface.position.set(0, TANK_BASE + waterHeight + 0.006, 0);
surface.renderOrder = 3;
group.add(surface);
// Bright line marking the free-surface elevation.
const levelY = TANK_BASE + waterHeight;
const levelGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-halfW + 0.08, levelY, halfD + 0.008),
new THREE.Vector3(halfW - 0.08, levelY, halfD + 0.008)
]);
group.add(new THREE.Line(levelGeometry, levelLineMaterial));
// Vertical height dimension outside the tank.
const gaugeX = centerX < 0 ? -halfW - 0.26 : halfW + 0.26;
const gaugeZ = halfD + 0.05;
const gaugePoints = [
new THREE.Vector3(gaugeX, TANK_BASE, gaugeZ),
new THREE.Vector3(gaugeX, levelY, gaugeZ),
new THREE.Vector3(gaugeX - 0.12, TANK_BASE, gaugeZ),
new THREE.Vector3(gaugeX + 0.12, TANK_BASE, gaugeZ),
new THREE.Vector3(gaugeX - 0.12, levelY, gaugeZ),
new THREE.Vector3(gaugeX + 0.12, levelY, gaugeZ)
];
group.add(
new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(gaugePoints),
levelLineMaterial
)
);
const heightLabel = makeTextLabel(heightText, accent, 1.72);
heightLabel.position.set(gaugeX, levelY + 0.32, gaugeZ + 0.08);
group.add(heightLabel);
const volumeLabel = makeVolumeLabel(
`TANK ${centerX < 0 ? "A" : "B"} · INITIAL VOLUME`,
volumeText
);
volumeLabel.position.set(0, TANK_BASE + waterHeight * 0.53, halfD + 0.72);
group.add(volumeLabel);
scene.add(group);
return group;
}
createTank(
-3,
3.25,
"#55d8f4",
"V₁ = 42.0 L",
"h₁ = 0.68 m"
);
createTank(
3,
2.05,
"#67e8d4",
"V₂ = 26.5 L",
"h₂ = 0.43 m"
);
// -------------------------------------------------------------------------
// Connecting pipe and closed gate
// -------------------------------------------------------------------------
const PIPE_Y = 1.08;
const PIPE_LENGTH = 2.5;
const pipe = new THREE.Mesh(
new THREE.CylinderGeometry(0.285, 0.285, PIPE_LENGTH, 36),
pipeMaterial
);
pipe.rotation.z = Math.PI / 2;
pipe.position.set(0, PIPE_Y, 0);
pipe.castShadow = true;
scene.add(pipe);
// Pipe flanges at both tank walls.
for (const x of [-1.24, 1.24]) {
const flange = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.43, 0.16, 36),
darkMetalMaterial
);
flange.rotation.z = Math.PI / 2;
flange.position.set(x, PIPE_Y, 0);
flange.castShadow = true;
scene.add(flange);
}
// Closed gate disc, perpendicular to the pipe.
const gateDisc = new THREE.Mesh(
new THREE.CylinderGeometry(0.405, 0.405, 0.14, 40),
gateMaterial
);
gateDisc.rotation.z = Math.PI / 2;
gateDisc.position.set(0, PIPE_Y, 0);
gateDisc.castShadow = true;
scene.add(gateDisc);
// Central stem.
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.76, 18),
pipeMaterial
);
stem.position.set(0, 1.72, 0);
stem.castShadow = true;
scene.add(stem);
// Handwheel in the horizontal plane.
const wheel = new THREE.Mesh(
new THREE.TorusGeometry(0.39, 0.055, 12, 40),
gateMaterial
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(0, 2.12, 0);
wheel.castShadow = true;
scene.add(wheel);
function cylinderBetween(a, b, radius, material) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 12),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
// Wheel spokes.
for (let i = 0; i < 4; i++) {
const angle = i * Math.PI / 2;
cylinderBetween(
new THREE.Vector3(0, 2.12, 0),
new THREE.Vector3(
Math.cos(angle) * 0.37,
2.12,
Math.sin(angle) * 0.37
),
0.026,
gateMaterial
);
}
const gateLabel = makeTextLabel("CLOSED GATE", "#ff7166", 2.08);
gateLabel.position.set(0, 2.86, 0.28);
scene.add(gateLabel);
// Small direction marks indicating that the gate blocks the pipe.
const blockMaterial = new THREE.MeshBasicMaterial({
color: 0xff7166,
transparent: true,
opacity: 0.9
});
for (const x of [-0.11, 0.11]) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.64, 0.045),
blockMaterial
);
bar.position.set(x, PIPE_Y, 0.29);
scene.add(bar);
}
// -------------------------------------------------------------------------
// Custom camera controls — no external control modules
// -------------------------------------------------------------------------
const view = {
theta: 0.38,
phi: 1.08,
radius: 13.4,
target: new THREE.Vector3(0, 2.25, 0)
};
const desired = {
theta: view.theta,
phi: view.phi,
radius: view.radius
};
function fittedRadius() {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 1 ? 17.8 : 13.4;
}
function resetView() {
desired.theta = 0.38;
desired.phi = 1.08;
desired.radius = fittedRadius();
}
function updateCamera() {
view.theta += (desired.theta - view.theta) * 0.14;
view.phi += (desired.phi - view.phi) * 0.14;
view.radius += (desired.radius - view.radius) * 0.14;
const spherical = new THREE.Spherical(
view.radius,
THREE.MathUtils.clamp(view.phi, 0.28, 1.48),
view.theta
);
camera.position.setFromSpherical(spherical).add(view.target);
camera.lookAt(view.target);
}
const canvas = renderer.domElement;
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
desired.theta -= deltaX * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - deltaY * 0.006,
0.28,
1.48
);
previousX = event.clientX;
previousY = event.clientY;
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
8.5,
24
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
document.getElementById("resetView").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") desired.theta += step;
if (event.key === "ArrowRight") desired.theta -= step;
if (event.key === "ArrowUp") desired.phi -= step;
if (event.key === "ArrowDown") desired.phi += step;
if (event.key === "+" || event.key === "=") {
desired.radius = Math.max(8.5, desired.radius - 0.7);
}
if (event.key === "-" || event.key === "_") {
desired.radius = Math.min(24, desired.radius + 0.7);
}
if (event.key.toLowerCase() === "r") resetView();
desired.phi = THREE.MathUtils.clamp(desired.phi, 0.28, 1.48);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetView();
view.radius = desired.radius;
updateCamera();
renderer.setAnimationLoop(() => {
updateCamera();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```