Prompt specification
Build or customize the Three.js 3D scene "Dot and cross product comparison" 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: Dot and cross product comparison
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/dot-and-cross-product-comparison-x1754
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Arrange two vector pairs with matching dot products but different cross-product directions; visualize the oriented normal and state the right-hand-rule convention.
Working Three.js Starter (dot-and-cross-product-comparison-x1754):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Matching Dot Products, Opposite Cross Products</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 25, 42, 0.82);
--border: rgba(151, 190, 222, 0.2);
--text: #e8f3ff;
--muted: #91a8bd;
--cyan: #22d3ee;
--amber: #fbbf24;
--pink: #f472b6;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
display: grid;
grid-template-columns: minmax(280px, 1fr) minmax(290px, 380px);
gap: 22px;
align-items: start;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 760px;
font-size: clamp(25px, 3.2vw, 48px);
line-height: 1.03;
letter-spacing: -0.035em;
text-wrap: balance;
}
.subtitle {
max-width: 700px;
margin: 10px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.convention {
padding: 15px 17px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
}
.convention strong {
display: block;
margin-bottom: 6px;
color: var(--pink);
font-size: 11px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.convention p {
margin: 0;
color: #c6d8e8;
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 9px 16px;
margin-top: 12px;
color: var(--muted);
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 18px;
height: 3px;
border-radius: 99px;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.cyan { color: var(--cyan); }
.amber { color: var(--amber); }
.pink { color: var(--pink); }
.arc { color: #c7d8e8; }
.cards {
position: absolute;
left: 24px;
bottom: 22px;
display: flex;
gap: 12px;
max-width: calc(100vw - 190px);
}
.card {
width: 305px;
padding: 14px 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
font-variant-numeric: tabular-nums;
}
.card-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.card-title span:last-child {
color: var(--muted);
font-size: 10px;
}
.formula {
margin: 4px 0;
color: #dceaf7;
font-size: 13px;
line-height: 1.45;
}
.result {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid rgba(151, 190, 222, 0.13);
font-size: 13px;
}
.result b {
color: var(--pink);
}
.controls {
position: absolute;
right: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.hint {
color: var(--muted);
font-size: 11px;
text-align: right;
line-height: 1.45;
}
button {
padding: 10px 13px;
border: 1px solid rgba(34, 211, 238, 0.3);
border-radius: 10px;
background: rgba(8, 25, 42, 0.9);
color: var(--text);
font: inherit;
font-size: 12px;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
border-color: rgba(34, 211, 238, 0.7);
background: rgba(12, 43, 65, 0.95);
}
#error {
position: fixed;
inset: 0;
display: none;
place-items: center;
padding: 30px;
background: var(--bg);
color: #fecaca;
text-align: center;
}
@media (max-width: 850px) {
header {
top: 14px;
left: 14px;
right: 14px;
grid-template-columns: 1fr;
gap: 10px;
}
.convention {
max-width: 560px;
padding: 11px 13px;
}
.subtitle {
display: none;
}
.cards {
left: 12px;
right: 12px;
bottom: 12px;
max-width: none;
}
.card {
width: 50%;
min-width: 0;
padding: 11px 12px;
}
.controls {
right: 12px;
bottom: 158px;
}
.hint {
display: none;
}
}
@media (max-width: 540px) {
h1 {
font-size: 25px;
}
.convention p {
font-size: 11px;
}
.legend {
display: none;
}
.card {
font-size: 11px;
}
.formula,
.result {
font-size: 11px;
}
.card-title {
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional vector diagram"></canvas>
<div class="hud">
<header>
<div>
<div class="eyebrow">Vector Geometry · Right-Handed Coordinates</div>
<h1>Same dot product.<br>Opposite oriented normals.</h1>
<p class="subtitle">
Both vector pairs have dot product 24 and cross-product magnitude 7,
but their cross products point along opposite directions of the Y-axis.
</p>
<div class="legend" aria-label="Scene legend">
<span class="cyan"><i class="swatch"></i>First vector</span>
<span class="amber"><i class="swatch"></i>Second vector</span>
<span class="pink"><i class="swatch"></i>Cross-product normal</span>
<span class="arc"><i class="swatch"></i>Rotation from first to second</span>
</div>
</div>
<aside class="convention">
<strong>Right-hand-rule convention</strong>
<p>
Curl the fingers of your right hand from the first vector toward the
second through the smaller angle. Your thumb points along the
cross product. Three.js uses a right-handed coordinate system.
</p>
</aside>
</header>
<div class="cards">
<section class="card">
<div class="card-title">
<span>Pair I</span>
<span>Cross points +Y</span>
</div>
<div class="formula">A = (3, 0, 4), B = (4, 0, 3)</div>
<div class="formula">A · B = 3(4) + 4(3) = 24</div>
<div class="result">
<span>A × B</span>
<b>(0, 7, 0)</b>
</div>
</section>
<section class="card">
<div class="card-title">
<span>Pair II</span>
<span>Cross points −Y</span>
</div>
<div class="formula">C = (3, 0, −4), D = (4, 0, −3)</div>
<div class="formula">C · D = 3(4) + (−4)(−3) = 24</div>
<div class="result">
<span>C × D</span>
<b>(0, −7, 0)</b>
</div>
</section>
</div>
<div class="controls">
<div class="hint">Drag: orbit<br>Shift-drag: pan · Wheel: zoom</div>
<button id="reset" type="button">Reset view</button>
</div>
</div>
<div id="error">
This scene requires a browser with WebGL support.
</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 errorPanel = document.querySelector("#error");
const resetButton = document.querySelector("#reset");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
console.error(error);
errorPanel.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 19, 43);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom camera controls. No external controls module is used.
const controls = {
target: new THREE.Vector3(0, -0.45, 0),
theta: 0,
phi: 1.02,
radius: 15,
dragging: false,
panning: false,
lastX: 0,
lastY: 0,
interacted: false
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetView() {
const halfFov = THREE.MathUtils.degToRad(camera.fov * 0.5);
const horizontalFit = 12.5 / (2 * Math.tan(halfFov) * camera.aspect);
controls.theta = 0;
controls.phi = 1.02;
controls.radius = Math.max(14.5, horizontalFit);
controls.target.set(0, -0.45, 0);
controls.interacted = false;
updateCamera();
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
if (event.button !== 0 && event.button !== 2) return;
controls.dragging = true;
controls.panning = event.shiftKey || event.button === 2;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.interacted = true;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (controls.panning) {
const right = new THREE.Vector3(1, 0, 0)
.applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0)
.applyQuaternion(camera.quaternion);
const scale = controls.radius * 0.0014;
controls.target
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
} else {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.18,
1.48
);
}
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
controls.panning = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.interacted = true;
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
8,
42
);
updateCamera();
},
{ passive: false }
);
// Lighting.
scene.add(new THREE.HemisphereLight(0xb9ddff, 0x08101b, 1.65));
const keyLight = new THREE.DirectionalLight(0xe7f4ff, 3.2);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4cc9f0, 1.25);
rimLight.position.set(7, 4, -7);
scene.add(rimLight);
// Ground and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 32),
new THREE.MeshStandardMaterial({
color: 0x081421,
roughness: 0.93,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.62;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x1a3b53, 0x10293d);
grid.position.y = -2.595;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const COLORS = {
first: 0x22d3ee,
second: 0xfbbf24,
normal: 0xf472b6,
arc: 0xc7d8e8,
axis: 0x8ca6bb
};
const UP = new THREE.Vector3(0, 1, 0);
const animatedNormalMaterials = [];
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + width - r, y);
context.quadraticCurveTo(x + width, y, x + width, y + r);
context.lineTo(x + width, y + height - r);
context.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
context.lineTo(x + r, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
function makeLabel(text, color = "#c7d8e8", height = 0.30) {
const lines = text.split("\n");
const longest = Math.max(...lines.map(line => line.length));
const canvasWidth = Math.max(150, longest * 37 + 42);
const canvasHeight = lines.length * 72 + 30;
const labelCanvas = document.createElement("canvas");
labelCanvas.width = canvasWidth;
labelCanvas.height = canvasHeight;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, canvasWidth, canvasHeight);
roundedRect(
context,
3,
3,
canvasWidth - 6,
canvasHeight - 6,
18
);
context.fillStyle = "rgba(5, 15, 27, 0.88)";
context.fill();
context.strokeStyle = color;
context.lineWidth = 3;
context.stroke();
context.fillStyle = color;
context.textAlign = "center";
context.textBaseline = "middle";
context.font =
"700 50px Inter, ui-sans-serif, system-ui, sans-serif";
lines.forEach((line, index) => {
const y =
canvasHeight / 2 +
(index - (lines.length - 1) / 2) * 68;
context.fillText(line, canvasWidth / 2, y);
});
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(
height * (canvasWidth / canvasHeight),
height,
1
);
sprite.renderOrder = 20;
return sprite;
}
function makeArrow(parent, vector, color, options = {}) {
const direction = vector.clone().normalize();
const length = vector.length();
const headLength = Math.min(
options.headLength ?? length * 0.22,
length * 0.48
);
const headRadius =
options.headRadius ?? headLength * 0.56;
const shaftRadius =
options.shaftRadius ?? Math.max(0.012, headRadius * 0.36);
const shaftLength = Math.max(0.001, length - headLength);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: options.emissiveIntensity ?? 0.25,
metalness: 0.18,
roughness: 0.32
});
const arrow = new THREE.Group();
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(
shaftRadius,
shaftRadius,
shaftLength,
18
),
material
);
shaft.position.copy(direction.clone().multiplyScalar(shaftLength / 2));
shaft.quaternion.setFromUnitVectors(UP, direction);
shaft.castShadow = true;
arrow.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(headRadius, headLength, 24),
material
);
head.position.copy(
direction.clone().multiplyScalar(shaftLength + headLength / 2)
);
head.quaternion.setFromUnitVectors(UP, direction);
head.castShadow = true;
arrow.add(head);
parent.add(arrow);
return { arrow, material };
}
function makeRotationArc(parent, first, second) {
const firstAngle = Math.atan2(first.z, first.x);
const secondAngle = Math.atan2(second.z, second.x);
let delta = secondAngle - firstAngle;
while (delta > Math.PI) delta -= Math.PI * 2;
while (delta < -Math.PI) delta += Math.PI * 2;
const radius = 0.62;
const points = [];
for (let i = 0; i <= 42; i++) {
const t = i / 42;
const angle = firstAngle + delta * t;
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
0.025,
Math.sin(angle) * radius
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color: COLORS.arc,
dashSize: 0.07,
gapSize: 0.045,
transparent: true,
opacity: 0.9
});
const arc = new THREE.Line(geometry, material);
arc.computeLineDistances();
parent.add(arc);
const tangent = new THREE.Vector3(
-Math.sin(secondAngle),
0,
Math.cos(secondAngle)
)
.multiplyScalar(Math.sign(delta))
.normalize();
const headMaterial = new THREE.MeshStandardMaterial({
color: COLORS.arc,
emissive: COLORS.arc,
emissiveIntensity: 0.18,
roughness: 0.42
});
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.18, 18),
headMaterial
);
arrowHead.position.copy(points[points.length - 1]);
arrowHead.quaternion.setFromUnitVectors(UP, tangent);
parent.add(arrowHead);
}
function addAxisTriad(parent) {
const origin = new THREE.Vector3(-1.85, -1.76, -1.85);
const axisLength = 0.72;
makeArrow(
parent,
new THREE.Vector3(axisLength, 0, 0).add(origin),
0xb86b72,
{
shaftRadius: 0.012,
headLength: 0.14,
headRadius: 0.055
}
);
makeArrow(
parent,
new THREE.Vector3(0, axisLength, 0).add(origin),
0x6fbe8b,
{
shaftRadius: 0.012,
headLength: 0.14,
headRadius: 0.055
}
);
makeArrow(
parent,
new THREE.Vector3(0, 0, axisLength).add(origin),
0x668ed0,
{
shaftRadius: 0.012,
headLength: 0.14,
headRadius: 0.055
}
);
const xLabel = makeLabel("X", "#d98a91", 0.20);
xLabel.position.copy(origin).add(new THREE.Vector3(0.84, 0, 0));
parent.add(xLabel);
const yLabel = makeLabel("Y", "#82d3a0", 0.20);
yLabel.position.copy(origin).add(new THREE.Vector3(0, 0.83, 0));
parent.add(yLabel);
const zLabel = makeLabel("Z", "#83a9e5", 0.20);
zLabel.position.copy(origin).add(new THREE.Vector3(0, 0, 0.84));
parent.add(zLabel);
}
function makePair({
baseX,
title,
first,
second,
firstName,
secondName,
normalText
}) {
const group = new THREE.Group();
group.position.set(baseX, -0.65, 0);
scene.add(group);
// Translucent platform.
const platform = new THREE.Mesh(
new THREE.PlaneGeometry(5.1, 5.2),
new THREE.MeshBasicMaterial({
color: 0x0d2639,
transparent: true,
opacity: 0.58,
side: THREE.DoubleSide,
depthWrite: false
})
);
platform.rotation.x = -Math.PI / 2;
platform.position.y = -1.82;
group.add(platform);
const borderPoints = [
new THREE.Vector3(-2.55, -1.79, -2.6),
new THREE.Vector3(2.55, -1.79, -2.6),
new THREE.Vector3(2.55, -1.79, 2.6),
new THREE.Vector3(-2.55, -1.79, 2.6),
new THREE.Vector3(-2.55, -1.79, -2.6)
];
const border = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(borderPoints),
new THREE.LineBasicMaterial({
color: 0x31546c,
transparent: true,
opacity: 0.75
})
);
group.add(border);
// Shared origin marker.
const origin = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 24, 16),
new THREE.MeshStandardMaterial({
color: 0xe5f4ff,
emissive: 0x7ec8e8,
emissiveIntensity: 0.35,
roughness: 0.25
})
);
origin.castShadow = true;
group.add(origin);
// Display scale keeps the actual vector components readable.
const displayScale = 0.42;
const firstDisplay = first.clone().multiplyScalar(displayScale);
const secondDisplay = second.clone().multiplyScalar(displayScale);
makeArrow(group, firstDisplay, COLORS.first, {
shaftRadius: 0.037,
headLength: 0.25,
headRadius: 0.115
});
makeArrow(group, secondDisplay, COLORS.second, {
shaftRadius: 0.037,
headLength: 0.25,
headRadius: 0.115
});
const firstLabel = makeLabel(firstName, "#22d3ee", 0.28);
firstLabel.position.copy(firstDisplay).add(
new THREE.Vector3(-0.03, 0.27, 0.16)
);
group.add(firstLabel);
const secondLabel = makeLabel(secondName, "#fbbf24", 0.28);
secondLabel.position.copy(secondDisplay).add(
new THREE.Vector3(0.20, 0.27, 0)
);
group.add(secondLabel);
// Oriented normal: first × second.
const cross = first.clone().cross(second);
const normalDirection = cross.clone().normalize();
const normalVector = normalDirection.clone().multiplyScalar(1.65);
const normalArrow = makeArrow(
group,
normalVector,
COLORS.normal,
{
shaftRadius: 0.048,
headLength: 0.29,
headRadius: 0.14,
emissiveIntensity: 0.40
}
);
animatedNormalMaterials.push({
material: normalArrow.material,
phase: baseX > 0 ? Math.PI : 0
});
const normalLabel = makeLabel(normalText, "#f472b6", 0.32);
normalLabel.position.copy(normalVector).add(
new THREE.Vector3(
normalDirection.y > 0 ? 0.70 : -0.70,
normalDirection.y > 0 ? 0.06 : -0.12,
0.12
)
);
group.add(normalLabel);
makeRotationArc(group, first, second);
const titleLabel = makeLabel(title, "#d8ebfa", 0.31);
titleLabel.position.set(-1.42, 0.35, -2.24);
group.add(titleLabel);
addAxisTriad(group);
return group;
}
// Pair I: A × B = (0, 7, 0).
makePair({
baseX: -3.25,
title: "PAIR I / +Y NORMAL",
first: new THREE.Vector3(3, 0, 4),
second: new THREE.Vector3(4, 0, 3),
firstName: "A",
secondName: "B",
normalText: "A × B = +7 ŷ"
});
// Pair II: C × D = (0, -7, 0).
makePair({
baseX: 3.25,
title: "PAIR II / −Y NORMAL",
first: new THREE.Vector3(3, 0, -4),
second: new THREE.Vector3(4, 0, -3),
firstName: "C",
secondName: "D",
normalText: "C × D = −7 ŷ"
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
if (!controls.interacted) {
resetView();
} else {
updateCamera();
}
}
window.addEventListener("resize", resize);
resize();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (!reducedMotion) {
animatedNormalMaterials.forEach(({ material, phase }) => {
material.emissiveIntensity =
0.34 + Math.sin(elapsed * 2.2 + phase) * 0.09;
});
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```