Prompt specification
Build or customize the Three.js 3D scene "Discrete components beside a chip outline" 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: Discrete components beside a chip outline
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/discrete-components-beside-a-chip-outline-x2493
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts integrated circuits and electronic miniaturization. Place several separate electronic components beside a simplified integrated-circuit package. Use equal functional labels to distinguish packaging differences from changes in the represented logic. Stylized solid forms.
Working Three.js Starter (discrete-components-beside-a-chip-outline-x2493):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Logic, Packaged — Three.js Scene</title>
<style>
:root {
color-scheme: dark;
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: #07111f;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
header {
position: absolute;
top: 24px;
left: 28px;
max-width: 480px;
color: #eef6ff;
text-shadow: 0 2px 14px #000;
}
.eyebrow {
margin: 0 0 8px;
color: #55dac8;
font-size: 11px;
font-weight: 800;
letter-spacing: .22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(26px, 4vw, 48px);
line-height: .98;
letter-spacing: -.04em;
}
header p {
max-width: 430px;
margin: 13px 0 0;
color: #aebed0;
font-size: 13px;
line-height: 1.55;
}
.legend {
position: absolute;
right: 24px;
bottom: 24px;
width: min(420px, calc(100vw - 48px));
padding: 15px 17px;
border: 1px solid #334155;
border-radius: 12px;
background: rgba(7, 17, 31, .86);
box-shadow: 0 16px 50px rgba(0, 0, 0, .3);
color: #dce8f5;
backdrop-filter: blur(12px);
}
.legend-title {
margin-bottom: 10px;
color: #7f93a8;
font-size: 10px;
font-weight: 800;
letter-spacing: .16em;
text-transform: uppercase;
}
.legend-items {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 14px;
font-size: 11px;
font-weight: 700;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
}
.dot {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: 0 0 12px currentColor;
}
.legend-note {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid #263548;
color: #8fa1b5;
font-size: 10px;
line-height: 1.45;
}
.help {
position: absolute;
left: 28px;
bottom: 26px;
color: #72869c;
font-size: 11px;
line-height: 1.6;
}
button {
position: absolute;
right: 24px;
top: 24px;
padding: 9px 13px;
border: 1px solid #3b4b60;
border-radius: 8px;
background: #101c2c;
color: #dbe7f3;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
pointer-events: auto;
transition: border-color .2s, background .2s;
}
button:hover {
border-color: #55dac8;
background: #152638;
}
@media (max-width: 700px) {
header {
top: 17px;
left: 18px;
max-width: calc(100vw - 110px);
}
header p {
display: none;
}
.legend {
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 12px;
}
.legend-items {
grid-template-columns: 1fr;
gap: 6px;
}
.legend-note {
display: none;
}
.help {
display: none;
}
button {
right: 14px;
top: 14px;
}
}
</style>
</head>
<body>
<div class="overlay">
<header>
<p class="eyebrow">Electronic miniaturization</p>
<h1>Logic, Packaged</h1>
<p>
Four separate implementations sit beside one integrated package.
Matching labels identify equivalent functions; the enclosure and
footprint show the packaging difference.
</p>
</header>
<div class="help">
Drag to orbit · Scroll to zoom · Arrow keys to rotate<br />
+ / − to zoom
</div>
<div class="legend">
<div class="legend-title">Matching functional labels</div>
<div class="legend-items">
<div class="legend-item">
<span class="dot" style="background:#38d9c4;color:#38d9c4"></span>
NOT · 1 IN / 1 OUT
</div>
<div class="legend-item">
<span class="dot" style="background:#ff6b61;color:#ff6b61"></span>
AND · 2 IN / 1 OUT
</div>
<div class="legend-item">
<span class="dot" style="background:#ffbd59;color:#ffbd59"></span>
OR · 2 IN / 1 OUT
</div>
<div class="legend-item">
<span class="dot" style="background:#b58cff;color:#b58cff"></span>
NAND · 2 IN / 1 OUT
</div>
</div>
<div class="legend-note">
The same colored logic symbols appear inside both the discrete
packages and the die of the monolithic IC.
</div>
</div>
<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";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
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;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 19, 36);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(-1.45, 0.55, 0);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9ed7ff, 0x172033, 2.0));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-4, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x3be0d0, 1.7);
rimLight.position.set(9, 6, -7);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb85c, 18, 16, 2);
warmLight.position.set(4, 4, 5);
scene.add(warmLight);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x08111d,
roughness: 0.96,
metalness: 0.02
}),
board: new THREE.MeshStandardMaterial({
color: 0x111d2c,
roughness: 0.76,
metalness: 0.12
}),
package: new THREE.MeshStandardMaterial({
color: 0x202b3a,
roughness: 0.48,
metalness: 0.38
}),
packageEdge: new THREE.MeshStandardMaterial({
color: 0x344358,
roughness: 0.38,
metalness: 0.52
}),
inset: new THREE.MeshStandardMaterial({
color: 0x080e17,
roughness: 0.42,
metalness: 0.55
}),
gold: new THREE.MeshStandardMaterial({
color: 0xd5a548,
roughness: 0.3,
metalness: 0.8
}),
trace: new THREE.MeshStandardMaterial({
color: 0x28616b,
roughness: 0.5,
metalness: 0.5
}),
traceGold: new THREE.MeshStandardMaterial({
color: 0x8c6a31,
roughness: 0.52,
metalness: 0.55
})
};
const functionColors = {
NOT: 0x38d9c4,
AND: 0xff6b61,
OR: 0xffbd59,
NAND: 0xb58cff
};
const functionLabels = {
NOT: "NOT · 1 IN / 1 OUT",
AND: "AND · 2 IN / 1 OUT",
OR: "OR · 2 IN / 1 OUT",
NAND: "NAND · 2 IN / 1 OUT"
};
// ------------------------------------------------------------
// Text as canvas textures
// ------------------------------------------------------------
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 makeTextPlane(
text,
accent = 0x55dac8,
width = 2,
height = 0.4,
background = "#0b1422"
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const accentHex = `#${accent.toString(16).padStart(6, "0")}`;
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accentHex;
ctx.fillRect(0, 0, 18, canvas.height);
ctx.strokeStyle = "#334155";
ctx.lineWidth = 5;
roundedRect(ctx, 7, 7, 1010, 242, 24);
ctx.stroke();
const lines = text.split("\n");
let fontSize = lines.length > 1 ? 54 : 62;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#eef6ff";
const fit = () => {
const maxWidth = 930;
ctx.font = `800 ${fontSize}px system-ui, sans-serif`;
const widest = Math.max(
...lines.map(line => ctx.measureText(line).width)
);
if (widest > maxWidth && fontSize > 26) {
fontSize = Math.max(26, Math.floor(fontSize * maxWidth / widest));
}
};
fit();
if (lines.length === 1) {
ctx.fillText(lines[0], 522, 132);
} else {
const lineHeight = fontSize * 1.2;
const start = 128 - (lines.length - 1) * lineHeight / 2;
lines.forEach((line, index) => {
ctx.fillText(line, 522, start + index * lineHeight);
});
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
});
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
}
// ------------------------------------------------------------
// Solid board and floor
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(48, 32),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.22;
floor.receiveShadow = true;
scene.add(floor);
const board = new THREE.Mesh(
new THREE.BoxGeometry(19, 0.24, 7.6),
materials.board
);
board.position.set(-1.5, -0.05, 0);
board.receiveShadow = true;
board.castShadow = true;
scene.add(board);
const grid = new THREE.GridHelper(19, 38, 0x20334a, 0x18283a);
grid.position.set(-1.5, 0.075, 0);
grid.scale.z = 7.6 / 19;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const leftHeading = makeTextPlane(
"A · DISCRETE PACKAGES",
0x7f93a8,
5.1,
0.58
);
leftHeading.rotation.x = -Math.PI / 2;
leftHeading.position.set(-4.45, 0.085, -2.8);
scene.add(leftHeading);
const rightHeading = makeTextPlane(
"B · MONOLITHIC IC",
0x55dac8,
4.8,
0.58
);
rightHeading.rotation.x = -Math.PI / 2;
rightHeading.position.set(2.4, 0.085, -2.8);
scene.add(rightHeading);
// ------------------------------------------------------------
// Logic gate geometry
// ------------------------------------------------------------
function gateShape(type) {
const shape = new THREE.Shape();
if (type === "AND" || type === "NAND") {
shape.moveTo(-0.55, -0.5);
shape.lineTo(0, -0.5);
shape.absarc(0, 0, 0.5, -Math.PI / 2, Math.PI / 2, false);
shape.lineTo(-0.55, 0.5);
shape.closePath();
} else if (type === "OR") {
shape.moveTo(-0.55, 0.5);
shape.bezierCurveTo(-0.2, 0.42, 0.05, 0.25, 0.5, 0);
shape.bezierCurveTo(0.05, -0.25, -0.2, -0.42, -0.55, -0.5);
shape.bezierCurveTo(-0.28, -0.24, -0.28, 0.24, -0.55, 0.5);
shape.closePath();
} else {
shape.moveTo(-0.5, -0.5);
shape.lineTo(0.5, 0);
shape.lineTo(-0.5, 0.5);
shape.closePath();
}
return shape;
}
function makeGate(type, color, scale = 1) {
const group = new THREE.Group();
const geometry = new THREE.ExtrudeGeometry(
gateShape(type),
{
depth: 0.11,
bevelEnabled: true,
bevelThickness: 0.035,
bevelSize: 0.025,
bevelSegments: 2,
curveSegments: 28
}
);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.36,
metalness: 0.25,
emissive: new THREE.Color(color).multiplyScalar(0.08)
});
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
if (type === "NAND") {
const bubble = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 24, 16),
material
);
bubble.position.set(0.59, 0, 0.075);
bubble.castShadow = true;
group.add(bubble);
}
group.rotation.x = -Math.PI / 2;
group.scale.setScalar(scale);
return group;
}
// ------------------------------------------------------------
// Discrete component packages
// ------------------------------------------------------------
function makePin(sizeX, sizeZ) {
const pin = new THREE.Mesh(
new THREE.BoxGeometry(sizeX, 0.11, sizeZ),
materials.gold
);
pin.castShadow = true;
return pin;
}
function makeDiscrete(type, x) {
const group = new THREE.Group();
group.position.x = x;
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.48, 0.5, 1.64),
materials.package
);
body.position.y = 0.32;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const topPlate = new THREE.Mesh(
new THREE.BoxGeometry(1.34, 0.055, 1.49),
materials.inset
);
topPlate.position.y = 0.59;
topPlate.receiveShadow = true;
group.add(topPlate);
const accent = makeTextPlane(
functionLabels[type],
functionColors[type],
1.39,
0.28
);
accent.position.set(0, 0.315, 0.826);
group.add(accent);
const gate = makeGate(type, functionColors[type], 0.82);
gate.position.set(0, 0.635, -0.08);
group.add(gate);
// Small pads communicate the number of inputs and one output.
const padGeometry = new THREE.BoxGeometry(0.17, 0.035, 0.095);
const inputZ = type === "NOT" ? [0] : [-0.27, 0.27];
inputZ.forEach(z => {
const input = new THREE.Mesh(padGeometry, materials.gold);
input.position.set(-0.65, 0.635, z);
group.add(input);
});
const output = new THREE.Mesh(
new THREE.BoxGeometry(0.17, 0.035, 0.095),
materials.gold
);
output.position.set(type === "NAND" ? 0.69 : 0.65, 0.635, -0.08);
group.add(output);
// Pins on both sides of the separate enclosure.
[-0.51, 0, 0.51].forEach(z => {
const leftPin = makePin(0.18, 0.26);
leftPin.position.set(-0.79, 0.25, z);
group.add(leftPin);
const rightPin = makePin(0.18, 0.26);
rightPin.position.set(0.79, 0.25, z);
group.add(rightPin);
});
return group;
}
const discreteTypes = ["NOT", "AND", "OR", "NAND"];
const discreteX = [-7.0, -5.25, -3.5, -1.75];
discreteTypes.forEach((type, index) => {
scene.add(makeDiscrete(type, discreteX[index]));
});
// ------------------------------------------------------------
// Integrated-circuit package
// ------------------------------------------------------------
const ic = new THREE.Group();
ic.position.x = 2.4;
const icBody = new THREE.Mesh(
new THREE.BoxGeometry(4.8, 0.62, 4.0),
materials.package
);
icBody.position.y = 0.39;
icBody.castShadow = true;
icBody.receiveShadow = true;
ic.add(icBody);
const lowerBand = new THREE.Mesh(
new THREE.BoxGeometry(4.82, 0.09, 4.02),
materials.packageEdge
);
lowerBand.position.y = 0.12;
ic.add(lowerBand);
const dieBed = new THREE.Mesh(
new THREE.BoxGeometry(4.36, 0.055, 3.53),
materials.inset
);
dieBed.position.y = 0.715;
dieBed.receiveShadow = true;
ic.add(dieBed);
const icFrontLabel = makeTextPlane(
"ONE IC · FOUR FUNCTIONS · SAME LOGIC",
0x55dac8,
3.78,
0.34
);
icFrontLabel.position.set(0, 0.39, 2.006);
ic.add(icFrontLabel);
// Die cells use the same row-major order as the discrete modules.
const cellPositions = [
{ type: "NOT", x: -1.08, z: -0.78 },
{ type: "AND", x: 1.08, z: -0.78 },
{ type: "OR", x: -1.08, z: 0.78 },
{ type: "NAND", x: 1.08, z: 0.78 }
];
cellPositions.forEach(({ type, x, z }) => {
const tint = new THREE.Color(functionColors[type])
.lerp(new THREE.Color(0x111b29), 0.58);
const cellMaterial = new THREE.MeshStandardMaterial({
color: tint,
roughness: 0.52,
metalness: 0.22,
emissive: new THREE.Color(functionColors[type])
.multiplyScalar(0.025)
});
const cell = new THREE.Mesh(
new THREE.BoxGeometry(1.92, 0.08, 1.39),
cellMaterial
);
cell.position.set(x, 0.782, z);
cell.castShadow = true;
cell.receiveShadow = true;
ic.add(cell);
const gate = makeGate(type, functionColors[type], 0.52);
gate.position.set(x, 0.845, z - 0.12);
ic.add(gate);
const label = makeTextPlane(
functionLabels[type],
functionColors[type],
1.78,
0.25,
"#0a121e"
);
label.rotation.x = -Math.PI / 2;
label.position.set(x, 0.845, z + 0.49);
ic.add(label);
});
// Dense gold pins around the monolithic package.
const sidePinGeometry = new THREE.BoxGeometry(0.28, 0.12, 0.34);
const endPinGeometry = new THREE.BoxGeometry(0.34, 0.12, 0.28);
[-1.42, -0.95, -0.48, 0, 0.48, 0.95, 1.42].forEach(z => {
const left = new THREE.Mesh(sidePinGeometry, materials.gold);
left.position.set(-2.52, 0.29, z);
left.castShadow = true;
ic.add(left);
const right = new THREE.Mesh(sidePinGeometry, materials.gold);
right.position.set(2.52, 0.29, z);
right.castShadow = true;
ic.add(right);
});
[-1.85, -1.25, -0.65, 0, 0.65, 1.25, 1.85].forEach(x => {
const back = new THREE.Mesh(endPinGeometry, materials.gold);
back.position.set(x, 0.29, -2.12);
back.castShadow = true;
ic.add(back);
const front = new THREE.Mesh(endPinGeometry, materials.gold);
front.position.set(x, 0.29, 2.12);
front.castShadow = true;
ic.add(front);
});
scene.add(ic);
// ------------------------------------------------------------
// Flat arrow: separate packages become one integrated package
// ------------------------------------------------------------
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.48, -0.10);
arrowShape.lineTo(0.08, -0.10);
arrowShape.lineTo(0.08, -0.25);
arrowShape.lineTo(0.48, 0);
arrowShape.lineTo(0.08, 0.25);
arrowShape.lineTo(0.08, 0.10);
arrowShape.lineTo(-0.48, 0.10);
arrowShape.closePath();
const arrow = new THREE.Mesh(
new THREE.ShapeGeometry(arrowShape),
new THREE.MeshStandardMaterial({
color: 0x55dac8,
roughness: 0.5,
metalness: 0.25,
emissive: 0x123d3b
})
);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(-0.43, 0.088, 0);
scene.add(arrow);
// ------------------------------------------------------------
// Stylized PCB traces
// ------------------------------------------------------------
function traceSegment(x1, z1, x2, z2, material, width = 0.035) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const segment = new THREE.Mesh(
new THREE.BoxGeometry(length, 0.018, width),
material
);
segment.position.set(
(x1 + x2) / 2,
0.082,
(z1 + z2) / 2
);
segment.rotation.y = -Math.atan2(dz, dx);
segment.receiveShadow = true;
scene.add(segment);
}
for (let i = 0; i < 7; i++) {
const x = 0.65 + i * 0.58;
const bendX = x + (i % 2 === 0 ? 0.18 : -0.16);
traceSegment(x, 2.1, bendX, 2.72, materials.trace);
traceSegment(bendX, 2.72, bendX + 0.18, 3.28, materials.traceGold);
}
for (let i = 0; i < 4; i++) {
const x = discreteX[i];
traceSegment(x, 0.84, x, 2.3, materials.traceGold, 0.028);
traceSegment(x, 2.3, x + (i - 1.5) * 0.12, 3.12, materials.trace, 0.028);
}
// ------------------------------------------------------------
// Custom camera controls — no addons required
// ------------------------------------------------------------
const controls = {
yaw: 0.035,
pitch: 0.97,
radius: window.innerWidth < 700 ? 21.5 : 17.2
};
function updateCamera() {
const sinPitch = Math.sin(controls.pitch);
camera.position.set(
target.x + controls.radius * sinPitch * Math.sin(controls.yaw),
target.y + controls.radius * Math.cos(controls.pitch),
target.z + controls.radius * sinPitch * Math.cos(controls.yaw)
);
camera.lookAt(target);
}
function resetView() {
controls.yaw = 0.035;
controls.pitch = 0.97;
controls.radius = window.innerWidth < 700 ? 21.5 : 17.2;
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.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.005,
0.48,
1.34
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
10,
28
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", event => {
let changed = true;
switch (event.key) {
case "ArrowLeft":
controls.yaw += 0.08;
break;
case "ArrowRight":
controls.yaw -= 0.08;
break;
case "ArrowUp":
controls.pitch = Math.max(0.48, controls.pitch - 0.06);
break;
case "ArrowDown":
controls.pitch = Math.min(1.34, controls.pitch + 0.06);
break;
case "+":
case "=":
controls.radius = Math.max(10, controls.radius - 0.8);
break;
case "-":
case "_":
controls.radius = Math.min(28, controls.radius + 0.8);
break;
default:
changed = false;
}
if (changed) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```