Prompt specification
Build or customize the Three.js 3D scene "Gyroscope museum support scene" 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: Gyroscope museum support scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/gyroscope-museum-support-scene-x1395
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a voxel gyroscope museum exhibit. A spinning wheel sits at the end of a short axle supported at one fixed point above a broad pedestal. Show the axle precessing slowly around that support while the wheel spins about its own axis. Keep the support position stationary. Beside the model, add a compact vector inset for angular momentum and the applied gravitational torque, with directions consistent with the displayed motion. Use a schematic constant-rate precession approximation and identify it briefly. Build the pedestal, support, and wheel rim from readable blocks, leaving clear space around the moving axle.
Working Three.js Starter (gyroscope-museum-support-scene-x1395):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Gyroscope Museum Exhibit</title>
<style>
:root {
color-scheme: dark;
--ink: #e7f2f4;
--muted: #8ea8b0;
--gold: #ffc466;
--cyan: #55e5ee;
--panel: rgba(8, 17, 24, 0.82);
--line: rgba(133, 190, 201, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071018;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 47% 44%, transparent 35%,
rgba(0, 0, 0, 0.18) 70%, rgba(0, 0, 0, 0.55) 100%);
z-index: 2;
}
.title-card {
position: fixed;
top: 26px;
left: 28px;
z-index: 4;
pointer-events: none;
max-width: 390px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.65);
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 3px;
font-size: clamp(28px, 3.2vw, 46px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
letter-spacing: 0.025em;
}
.vector-panel {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
width: 292px;
padding: 15px 15px 13px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.38),
inset 0 1px rgba(255, 255, 255, 0.035);
backdrop-filter: blur(14px);
pointer-events: none;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
}
.panel-heading strong {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live {
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
}
.live::before {
content: "";
display: inline-block;
width: 6px;
height: 6px;
margin-right: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 10px var(--cyan);
}
.vector-panel svg {
width: 100%;
height: auto;
overflow: visible;
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 2px;
font-size: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #c9dadd;
}
.swatch {
width: 22px;
height: 3px;
border-radius: 2px;
background: var(--gold);
box-shadow: 0 0 7px rgba(255, 196, 102, 0.35);
}
.swatch.torque {
background: var(--cyan);
box-shadow: 0 0 7px rgba(85, 229, 238, 0.4);
}
.equation {
margin: 12px 0 5px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #d9e8eb;
font-size: 12px;
line-height: 1.5;
}
.equation b {
color: var(--cyan);
font-weight: 700;
}
.panel-note {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.info-card {
position: fixed;
left: 28px;
bottom: 24px;
z-index: 4;
width: min(440px, calc(100vw - 56px));
padding: 13px 15px;
border-left: 3px solid var(--gold);
background: rgba(7, 16, 24, 0.72);
color: #b8cbd0;
font-size: 11px;
line-height: 1.55;
backdrop-filter: blur(10px);
pointer-events: none;
}
.info-card strong {
color: var(--ink);
}
.controls {
margin-top: 5px;
color: #78929b;
font-size: 10px;
letter-spacing: 0.03em;
}
@media (max-width: 720px) {
.title-card {
top: 17px;
left: 17px;
}
.subtitle {
display: none;
}
.vector-panel {
top: auto;
right: 12px;
bottom: 12px;
width: 255px;
padding: 11px;
}
.vector-panel svg {
max-height: 130px;
}
.equation,
.panel-note {
display: none;
}
.info-card {
left: 12px;
bottom: 12px;
width: calc(100vw - 287px);
min-width: 130px;
padding: 10px;
}
.info-card .controls {
display: none;
}
}
</style>
</head>
<body>
<div class="vignette"></div>
<header class="title-card">
<div class="eyebrow">Museum of Classical Mechanics · Hall 04</div>
<h1>Voxel Gyroscope</h1>
<p class="subtitle">A fixed bearing, a spinning wheel, and slow precession.</p>
</header>
<aside class="vector-panel">
<div class="panel-heading">
<strong>Live vector inset</strong>
<span class="live">TOP VIEW</span>
</div>
<svg id="vector-map" viewBox="0 0 250 170"
role="img"
aria-label="Top-view diagram of angular momentum and gravitational torque">
<defs>
<marker id="arrow-gold"
viewBox="0 0 10 10"
refX="8"
refY="5"
markerWidth="7"
markerHeight="7"
orient="auto">
<path d="M 0 0 L 10 5 L 0 10 Z" fill="#ffc466"></path>
</marker>
<marker id="arrow-cyan"
viewBox="0 0 10 10"
refX="8"
refY="5"
markerWidth="7"
markerHeight="7"
orient="auto">
<path d="M 0 0 L 10 5 L 0 10 Z" fill="#55e5ee"></path>
</marker>
</defs>
<rect x="1" y="1" width="248" height="168" rx="10"
fill="#091720" stroke="#203844"></rect>
<!-- World-axis references: +X right, +Z down. -->
<line x1="24" y1="83" x2="226" y2="83"
stroke="#29414b" stroke-width="1"
stroke-dasharray="3 5"></line>
<line x1="115" y1="17" x2="115" y2="153"
stroke="#29414b" stroke-width="1"
stroke-dasharray="3 5"></line>
<text x="224" y="78" fill="#617983" font-size="8">+X</text>
<text x="120" y="16" fill="#617983" font-size="8">+Z</text>
<!-- Fixed bearing -->
<rect x="109" y="77" width="12" height="12" rx="2"
fill="#f0b85b"></rect>
<circle cx="115" cy="83" r="18"
fill="none" stroke="#d8aa55"
stroke-width="1" stroke-dasharray="2 4"
opacity="0.55"></circle>
<!-- Axle and wheel, angular momentum, and torque are updated in JS. -->
<line id="axle-line"
x1="115" y1="83" x2="170" y2="83"
stroke="#d2dce0" stroke-width="2"></line>
<line id="wheel-line"
x1="170" y1="73" x2="170" y2="93"
stroke="#e4edf0" stroke-width="5"
stroke-linecap="square"></line>
<line id="momentum-line"
x1="115" y1="83" x2="170" y2="83"
stroke="#ffc466" stroke-width="3"
marker-end="url(#arrow-gold)"></line>
<line id="torque-line"
x1="170" y1="83" x2="170" y2="125"
stroke="#55e5ee" stroke-width="3"
marker-end="url(#arrow-cyan)"></line>
<text id="momentum-label"
x="142" y="76" fill="#ffc466"
font-size="12" font-weight="700">L</text>
<text id="torque-label"
x="176" y="111" fill="#55e5ee"
font-size="12" font-weight="700">τg</text>
</svg>
<div class="legend">
<div class="legend-item">
<span class="swatch"></span>
<span>Angular momentum L</span>
</div>
<div class="legend-item">
<span class="swatch torque"></span>
<span>Gravitational torque τg</span>
</div>
</div>
<div class="equation">
<b>τg = r × Mg</b> ∝ <b>Ωp × L</b>
</div>
<p class="panel-note">
The wheel icon lies in the axle’s vertical plane. The cyan torque arrow
is tangent to the wheel center and therefore turns with the axle.
</p>
</aside>
<div class="info-card">
<strong>Schematic constant-rate precession.</strong>
Ωp ≈ 0.16 rad/s; wheel spin ≈ 2.4 rad/s. The support and bearing stay
fixed while the axle precesses around the vertical axis.
<div class="controls">Drag to orbit · mouse wheel to zoom</div>
</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(0x071018);
scene.fog = new THREE.Fog(0x071018, 15, 31);
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
// Direct camera controls, implemented without Three.js addons.
const cameraState = {
azimuth: 0.45,
polar: 1.18,
radius: window.innerWidth < 720 ? 17.5 : 13.4,
target: new THREE.Vector3(-0.55, 2.35, 0)
};
function updateCamera() {
const s = Math.sin(cameraState.polar);
const c = Math.cos(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * s * Math.cos(cameraState.azimuth),
cameraState.target.y + cameraState.radius * c,
cameraState.target.z +
cameraState.radius * s * Math.sin(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
updateCamera();
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.005,
0.48,
1.42
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", (e) => e.preventDefault());
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.01,
9.5,
23
);
updateCamera();
}, { passive: false });
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x0c151d,
roughness: 0.96,
metalness: 0.02
}),
stoneDark: new THREE.MeshStandardMaterial({
color: 0x202d38,
roughness: 0.86,
metalness: 0.08
}),
stoneMid: new THREE.MeshStandardMaterial({
color: 0x31434e,
roughness: 0.78,
metalness: 0.12
}),
stoneTop: new THREE.MeshStandardMaterial({
color: 0x435661,
roughness: 0.7,
metalness: 0.16
}),
steel: new THREE.MeshStandardMaterial({
color: 0x718895,
roughness: 0.36,
metalness: 0.72
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x263946,
roughness: 0.42,
metalness: 0.78
}),
brass: new THREE.MeshStandardMaterial({
color: 0xd7a652,
roughness: 0.28,
metalness: 0.72
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x35dce4,
emissive: 0x087c83,
emissiveIntensity: 1.7,
roughness: 0.28,
metalness: 0.28
}),
amber: new THREE.MeshStandardMaterial({
color: 0xffb54b,
emissive: 0xa54208,
emissiveIntensity: 1.4,
roughness: 0.3,
metalness: 0.25
}),
halo: new THREE.MeshBasicMaterial({
color: 0x49dce5,
transparent: true,
opacity: 0.35,
depthWrite: false
})
};
function addBox(parent, size, position, material, shadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Museum floor
// ------------------------------------------------------------
addBox(
scene,
new THREE.Vector3(32, 0.18, 32),
new THREE.Vector3(0, -0.09, 0),
materials.floor,
false
);
const grid = new THREE.GridHelper(30, 30, 0x25404b, 0x142630);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.45;
scene.add(grid);
// ------------------------------------------------------------
// Broad, block-built pedestal
// ------------------------------------------------------------
const pedestal = new THREE.Group();
scene.add(pedestal);
// Lower 4 × 4 tier.
for (let ix = 0; ix < 4; ix++) {
for (let iz = 0; iz < 4; iz++) {
addBox(
pedestal,
new THREE.Vector3(1.80, 0.50, 1.80),
new THREE.Vector3(
(ix - 1.5) * 1.86,
0.25,
(iz - 1.5) * 1.86
),
(ix + iz) % 3 === 0
? materials.stoneMid
: materials.stoneDark
);
}
}
// Middle 3 × 3 tier.
for (let ix = 0; ix < 3; ix++) {
for (let iz = 0; iz < 3; iz++) {
addBox(
pedestal,
new THREE.Vector3(1.72, 0.42, 1.72),
new THREE.Vector3(
(ix - 1) * 1.78,
0.71,
(iz - 1) * 1.78
),
(ix + iz) % 2 === 0
? materials.stoneTop
: materials.stoneMid
);
}
}
// Upper tiled cap.
for (let ix = 0; ix < 3; ix++) {
for (let iz = 0; iz < 3; iz++) {
addBox(
pedestal,
new THREE.Vector3(1.66, 0.22, 1.66),
new THREE.Vector3(
(ix - 1) * 1.74,
1.03,
(iz - 1) * 1.74
),
materials.stoneTop
);
}
}
// Thin brass perimeter details.
addBox(
pedestal,
new THREE.Vector3(5.32, 0.055, 0.065),
new THREE.Vector3(0, 1.17, 2.66),
materials.brass
);
addBox(
pedestal,
new THREE.Vector3(5.32, 0.055, 0.065),
new THREE.Vector3(0, 1.17, -2.66),
materials.brass
);
addBox(
pedestal,
new THREE.Vector3(0.065, 0.055, 5.32),
new THREE.Vector3(2.66, 1.17, 0),
materials.brass
);
addBox(
pedestal,
new THREE.Vector3(0.065, 0.055, 5.32),
new THREE.Vector3(-2.66, 1.17, 0),
materials.brass
);
// ------------------------------------------------------------
// Stationary support and fixed bearing
// ------------------------------------------------------------
const PIVOT_Y = 3.25;
const WHEEL_ORBIT_RADIUS = 2.45;
const fixedSupport = new THREE.Group();
scene.add(fixedSupport);
addBox(
fixedSupport,
new THREE.Vector3(1.42, 0.34, 1.42),
new THREE.Vector3(0, 1.31, 0),
materials.darkSteel
);
// Readable stacked support blocks.
const supportLevels = [1.72, 2.25, 2.78];
supportLevels.forEach((y, index) => {
addBox(
fixedSupport,
new THREE.Vector3(index === 2 ? 0.58 : 0.67, 0.49, 0.67),
new THREE.Vector3(0, y, 0),
index % 2 === 0 ? materials.steel : materials.darkSteel
);
});
// Fixed cubic bearing housing at the support point.
addBox(
fixedSupport,
new THREE.Vector3(0.74, 0.68, 0.74),
new THREE.Vector3(0, PIVOT_Y, 0),
materials.brass
);
addBox(
fixedSupport,
new THREE.Vector3(0.27, 0.16, 0.05),
new THREE.Vector3(0, PIVOT_Y, 0.39),
materials.cyan,
false
);
// ------------------------------------------------------------
// Precessing axle
// ------------------------------------------------------------
// This group rotates around Y, but its origin stays exactly at
// the fixed bearing position.
const precessionGroup = new THREE.Group();
precessionGroup.position.set(0, PIVOT_Y, 0);
scene.add(precessionGroup);
// Square segmented shaft, built from readable blocks.
for (let i = 0; i < 11; i++) {
addBox(
precessionGroup,
new THREE.Vector3(0.225, 0.225, 0.225),
new THREE.Vector3(0.22 + i * 0.225, 0, 0),
i % 4 === 0 ? materials.brass : materials.steel
);
}
// Shaft collars.
addBox(
precessionGroup,
new THREE.Vector3(0.34, 0.34, 0.34),
new THREE.Vector3(0.56, 0, 0),
materials.brass
);
addBox(
precessionGroup,
new THREE.Vector3(0.30, 0.30, 0.30),
new THREE.Vector3(2.03, 0, 0),
materials.darkSteel
);
// Subtle segmented horizontal halo around the fixed bearing.
const halo = new THREE.Group();
scene.add(halo);
for (let i = 0; i < 36; i++) {
const angle = (i / 36) * Math.PI * 2;
const block = addBox(
halo,
new THREE.Vector3(0.055, 0.035, 0.105),
new THREE.Vector3(
Math.cos(angle) * 1.55,
PIVOT_Y - 0.12,
Math.sin(angle) * 1.55
),
materials.halo,
false
);
block.rotation.y = -angle;
}
// A small tangential arrow on the halo shows the positive
// precession sense. At zero group angle it points toward -Z.
const haloArrow = new THREE.Group();
precessionGroup.add(haloArrow);
for (let i = 0; i < 5; i++) {
addBox(
haloArrow,
new THREE.Vector3(0.065, 0.045, 0.12),
new THREE.Vector3(
1.55,
PIVOT_Y - 0.12 - precessionGroup.position.y,
-0.07 - i * 0.095
),
materials.halo,
false
);
}
// ------------------------------------------------------------
// Spinning voxel wheel
// ------------------------------------------------------------
const wheelSpinner = new THREE.Group();
wheelSpinner.position.set(WHEEL_ORBIT_RADIUS, 0, 0);
precessionGroup.add(wheelSpinner);
// Pixelated rim: a grid-selected annulus made from individual
// readable cuboids. Its plane is YZ, so X is the spin axis.
const rimPositions = [];
const markerPositions = [];
const pixelSize = 0.27;
const blockSize = 0.245;
for (let iy = -5; iy <= 5; iy++) {
for (let iz = -5; iz <= 5; iz++) {
const y = iy * pixelSize;
const z = iz * pixelSize;
const radius = Math.hypot(y, z);
if (radius > 1.00 && radius < 1.47) {
const isMarker =
(iy === -5 && iz === 0) ||
(iy === 0 && iz === 5) ||
(iy === 3 && iz === 3);
if (isMarker) {
markerPositions.push(new THREE.Vector3(0, y, z));
} else {
rimPositions.push(new THREE.Vector3(0, y, z));
}
}
}
}
function createVoxelInstances(positions, material, dimensions) {
if (!positions.length) return;
const geometry = new THREE.BoxGeometry(1, 1, 1);
const mesh = new THREE.InstancedMesh(
geometry,
material,
positions.length
);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3(
dimensions.x,
dimensions.y,
dimensions.z
);
positions.forEach((position, index) => {
matrix.compose(position, quaternion, scale);
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
wheelSpinner.add(mesh);
return mesh;
}
createVoxelInstances(
rimPositions,
materials.darkSteel,
new THREE.Vector3(0.52, blockSize, blockSize)
);
createVoxelInstances(
markerPositions,
materials.amber,
new THREE.Vector3(0.56, blockSize + 0.025, blockSize + 0.025)
);
// Block-built spokes in eight directions.
for (let spoke = 0; spoke < 8; spoke++) {
const angle = spoke * Math.PI / 4;
for (let segment = 0; segment < 5; segment++) {
const radius = 0.43 + segment * 0.19;
const block = addBox(
wheelSpinner,
new THREE.Vector3(0.27, 0.205, 0.18),
new THREE.Vector3(
0,
Math.cos(angle) * radius,
Math.sin(angle) * radius
),
spoke === 0 ? materials.brass : materials.steel
);
block.rotation.x = angle;
}
}
// Central hub, also voxel-like.
addBox(
wheelSpinner,
new THREE.Vector3(0.72, 0.68, 0.68),
new THREE.Vector3(0, 0, 0),
materials.brass
);
addBox(
wheelSpinner,
new THREE.Vector3(0.18, 0.78, 0.78),
new THREE.Vector3(0.40, 0, 0),
materials.cyan
);
addBox(
wheelSpinner,
new THREE.Vector3(0.18, 0.78, 0.78),
new THREE.Vector3(-0.40, 0, 0),
materials.darkSteel
);
// ------------------------------------------------------------
// Exhibit plaque
// ------------------------------------------------------------
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 1024;
plaqueCanvas.height = 256;
const plaqueContext = plaqueCanvas.getContext("2d");
plaqueContext.fillStyle = "#101d25";
plaqueContext.fillRect(0, 0, 1024, 256);
plaqueContext.strokeStyle = "#d2a251";
plaqueContext.lineWidth = 8;
plaqueContext.strokeRect(12, 12, 1000, 232);
plaqueContext.fillStyle = "#f3c76f";
plaqueContext.font = "700 65px sans-serif";
plaqueContext.fillText("VOXEL GYROSCOPE", 56, 104);
plaqueContext.fillStyle = "#91abb3";
plaqueContext.font = "31px sans-serif";
plaqueContext.fillText("FIXED BEARING / PRECESSION STUDY", 59, 170);
plaqueContext.fillStyle = "#55e5ee";
plaqueContext.font = "700 24px sans-serif";
plaqueContext.fillText("SCHEMATIC CONSTANT-RATE MODEL", 59, 215);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
addBox(
pedestal,
new THREE.Vector3(3.65, 0.91, 0.14),
new THREE.Vector3(0, 0.68, 3.70),
materials.darkSteel
);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(3.50, 0.80),
new THREE.MeshBasicMaterial({
map: plaqueTexture,
toneMapped: false
})
);
plaque.position.set(0, 0.68, 3.775);
pedestal.add(plaque);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xa3ddeb,
0x101720,
1.75
);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(
0xffedd0,
3.25
);
key.position.set(6, 11, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -9;
key.shadow.camera.right = 9;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 30;
key.shadow.bias = -0.00025;
scene.add(key);
const cyanSpot = new THREE.SpotLight(
0x5be8f2,
42,
22,
Math.PI / 5,
0.72,
1.7
);
cyanSpot.position.set(-5, 8, 5);
cyanSpot.target.position.set(0, 2.8, 0);
cyanSpot.castShadow = true;
cyanSpot.shadow.mapSize.set(1024, 1024);
scene.add(cyanSpot, cyanSpot.target);
const warmFill = new THREE.PointLight(
0xffb15d,
22,
15,
2
);
warmFill.position.set(5, 4, -3);
scene.add(warmFill);
const axleLight = new THREE.PointLight(
0x9debf2,
7,
7,
2
);
axleLight.position.set(0, PIVOT_Y + 0.2, 0);
scene.add(axleLight);
// ------------------------------------------------------------
// Live vector inset
// ------------------------------------------------------------
const svg = {
axle: document.getElementById("axle-line"),
wheel: document.getElementById("wheel-line"),
momentum: document.getElementById("momentum-line"),
torque: document.getElementById("torque-line"),
momentumLabel: document.getElementById("momentum-label"),
torqueLabel: document.getElementById("torque-label")
};
const insetCenter = { x: 115, y: 83 };
const insetRadius = 55;
function updateVectorInset(precessionAngle) {
/*
* Three.js positive rotation about world +Y maps the local +X
* axle direction to:
*
* L = (cos(theta), 0, -sin(theta)).
*
* The SVG is a top view with +X right and +Z down.
*/
const radial = {
x: Math.cos(precessionAngle),
y: -Math.sin(precessionAngle)
};
/*
* Gravity acts downward. For r pointing along the axle:
*
* tau = r x (-Mg * worldY)
* = (-sin(theta), 0, -cos(theta)).
*
* This is exactly the direction of dL/dt for constant-rate
* precession about +Y.
*/
const tangent = {
x: -Math.sin(precessionAngle),
y: -Math.cos(precessionAngle)
};
const wheelX = insetCenter.x + radial.x * insetRadius;
const wheelY = insetCenter.y + radial.y * insetRadius;
const torqueX = wheelX + tangent.x * 42;
const torqueY = wheelY + tangent.y * 42;
// The wheel lies perpendicular to the radial axle in top view.
const perpendicular = {
x: -radial.y,
y: radial.x
};
const wheelHalfLength = 10;
svg.axle.setAttribute("x1", insetCenter.x);
svg.axle.setAttribute("y1", insetCenter.y);
svg.axle.setAttribute("x2", wheelX);
svg.axle.setAttribute("y2", wheelY);
svg.wheel.setAttribute(
"x1",
wheelX - perpendicular.x * wheelHalfLength
);
svg.wheel.setAttribute(
"y1",
wheelY - perpendicular.y * wheelHalfLength
);
svg.wheel.setAttribute(
"x2",
wheelX + perpendicular.x * wheelHalfLength
);
svg.wheel.setAttribute(
"y2",
wheelY + perpendicular.y * wheelHalfLength
);
svg.momentum.setAttribute("x1", insetCenter.x);
svg.momentum.setAttribute("y1", insetCenter.y);
svg.momentum.setAttribute("x2", wheelX);
svg.momentum.setAttribute("y2", wheelY);
svg.torque.setAttribute("x1", wheelX);
svg.torque.setAttribute("y1", wheelY);
svg.torque.setAttribute("x2", torqueX);
svg.torque.setAttribute("y2", torqueY);
svg.momentumLabel.setAttribute(
"x",
insetCenter.x + radial.x * insetRadius * 0.57 - 4
);
svg.momentumLabel.setAttribute(
"y",
insetCenter.y + radial.y * insetRadius * 0.57 - 7
);
svg.torqueLabel.setAttribute("x", torqueX + 7);
svg.torqueLabel.setAttribute("y", torqueY + 4);
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const PRECESSION_RATE = 0.16;
const WHEEL_SPIN_RATE = 2.4;
const INITIAL_PRECESSION_ANGLE = 0.45;
let elapsed = 0;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
const precessionAngle =
INITIAL_PRECESSION_ANGLE + elapsed * PRECESSION_RATE;
// Only the axle assembly precesses. The stationary support,
// pedestal, and bearing are outside this group.
precessionGroup.rotation.y = precessionAngle;
// Positive spin about the local axle axis gives L along +axle.
wheelSpinner.rotation.x = elapsed * WHEEL_SPIN_RATE;
updateVectorInset(precessionAngle);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateVectorInset(INITIAL_PRECESSION_ANGLE);
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (window.innerWidth < 720 && cameraState.radius < 16) {
cameraState.radius = 17.5;
updateCamera();
}
});
</script>
</body>
</html>
```