Prompt specification
Build or customize the Three.js 3D scene "Bowling Lane Roll Transition Exhibit" 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: Bowling Lane Roll Transition Exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/bowling-lane-roll-transition-exhibit-x3639
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a voxel educational bowling lane with a marked ball and a short motion timeline. Divide the demonstration into a schematic sliding phase followed by a rolling phase. Track both the ball center and a contrasting mark on its surface, so translation and rotation can be inspected separately. In the pure-rolling phase, couple angular speed to forward speed using the ball's radius. Clearly identify the changeover as an illustrative transition rather than a calibrated bowling model.
Working Three.js Starter (bowling-lane-roll-transition-exhibit-x3639):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Bowling Motion Study</title>
<style>
:root {
color-scheme: dark;
--bg: #07131b;
--panel: rgba(8, 24, 34, 0.88);
--border: rgba(154, 211, 224, 0.18);
--text: #e9f7f8;
--muted: #91aeb7;
--cyan: #54e6ff;
--orange: #ffad42;
--green: #78e6a4;
--transition: #ffd166;
}
* { 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;
}
button, input { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.header {
position: fixed;
top: 20px;
left: 22px;
z-index: 5;
max-width: 570px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3.1vw, 42px);
line-height: 1.02;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.45;
}
.disclaimer {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 12px;
padding: 7px 10px;
border: 1px solid rgba(255, 209, 102, 0.35);
border-radius: 7px;
background: rgba(62, 46, 13, 0.48);
color: #ffe3a0;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.035em;
}
.disclaimer::before {
content: "!";
display: grid;
place-items: center;
width: 17px;
height: 17px;
border-radius: 50%;
background: var(--transition);
color: #251b04;
font-weight: 900;
}
.panel {
position: fixed;
z-index: 6;
top: 22px;
right: 22px;
width: min(340px, calc(100vw - 44px));
padding: 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
.panel-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 12px;
}
.phase-badge {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.phase-badge::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
#status {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
#phaseTitle {
margin: 0 0 6px;
font-size: 22px;
letter-spacing: -0.025em;
}
#phaseCopy {
min-height: 66px;
margin: 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.52;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 14px 0 11px;
}
.metric {
min-height: 66px;
padding: 10px;
border: 1px solid rgba(255, 255, 255, 0.065);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
}
.metric-label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 9.5px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-variant-numeric: tabular-nums;
font-size: 19px;
font-weight: 780;
line-height: 1;
}
.metric-value.cyan { color: var(--cyan); }
.metric-value.orange { color: var(--orange); }
.metric-value.green { color: var(--green); }
.relation {
padding: 10px 11px;
border-left: 3px solid var(--cyan);
border-radius: 4px;
background: rgba(84, 230, 255, 0.055);
color: #c9e9ee;
font-size: 11.5px;
line-height: 1.45;
}
.relation strong {
color: white;
font-variant-numeric: tabular-nums;
}
.legend {
display: grid;
gap: 8px;
margin-top: 13px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.legend-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
color: #d7ebef;
font-size: 11.5px;
}
.legend-label {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 22px;
height: 3px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 8px rgba(84, 230, 255, 0.6);
}
.swatch.mark {
width: 10px;
height: 10px;
border-radius: 2px;
background: var(--orange);
box-shadow: 0 0 8px rgba(255, 173, 66, 0.55);
}
.toggle {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 10.5px;
cursor: pointer;
user-select: none;
}
.toggle input {
accent-color: var(--cyan);
cursor: pointer;
}
.view-buttons {
display: flex;
gap: 7px;
margin-top: 12px;
}
.small-button,
.control-button,
.phase-button {
border: 1px solid rgba(154, 211, 224, 0.18);
border-radius: 8px;
background: rgba(255, 255, 255, 0.045);
color: #d9edf0;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease;
}
.small-button {
flex: 1;
padding: 7px 8px;
font-size: 10.5px;
font-weight: 700;
}
.small-button:hover,
.control-button:hover,
.phase-button:hover {
border-color: rgba(84, 230, 255, 0.45);
background: rgba(84, 230, 255, 0.09);
}
.timeline-panel {
position: fixed;
z-index: 8;
left: 50%;
bottom: 20px;
width: min(760px, calc(100vw - 32px));
transform: translateX(-50%);
padding: 13px 15px 12px;
border: 1px solid var(--border);
border-radius: 14px;
background: rgba(7, 20, 29, 0.92);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.36);
backdrop-filter: blur(14px);
}
.timeline-header {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
}
.control-button {
min-width: 82px;
padding: 8px 12px;
font-size: 11px;
font-weight: 800;
}
#playButton {
border-color: rgba(84, 230, 255, 0.35);
color: var(--cyan);
}
.time-readout {
margin-left: auto;
color: var(--muted);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.timeline-track {
position: relative;
height: 42px;
border-radius: 7px;
background: #102b36;
overflow: hidden;
}
.segments {
position: absolute;
inset: 0;
display: flex;
}
.segment {
position: relative;
display: grid;
place-items: center;
overflow: hidden;
border-right: 1px solid rgba(7, 20, 29, 0.9);
color: rgba(255, 255, 255, 0.84);
font-size: 9.5px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.segment.slide {
width: 36%;
background: rgba(84, 230, 255, 0.21);
}
.segment.transition {
width: 12%;
background: rgba(255, 209, 102, 0.27);
}
.segment.roll {
width: 52%;
background: rgba(120, 230, 164, 0.20);
}
#playhead {
position: absolute;
z-index: 4;
top: 0;
bottom: 0;
left: 0;
width: 3px;
transform: translateX(-1.5px);
background: white;
box-shadow: 0 0 10px white;
pointer-events: none;
}
#scrub {
position: absolute;
z-index: 5;
inset: 0;
width: 100%;
height: 100%;
margin: 0;
opacity: 0;
cursor: pointer;
}
.timeline-panel:focus-within {
outline: 2px solid rgba(84, 230, 255, 0.65);
outline-offset: 2px;
}
.timeline-footer {
display: flex;
align-items: center;
gap: 7px;
margin-top: 9px;
}
.phase-button {
padding: 5px 9px;
color: var(--muted);
font-size: 9.5px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.timeline-note {
margin-left: auto;
color: #78949d;
font-size: 9.5px;
}
.camera-help {
position: fixed;
z-index: 4;
left: 22px;
bottom: 151px;
color: rgba(194, 220, 226, 0.62);
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
@media (max-width: 800px) {
.header {
top: 13px;
left: 14px;
max-width: calc(100vw - 28px);
}
.subtitle { display: none; }
.disclaimer { margin-top: 8px; font-size: 9.5px; }
.panel {
top: auto;
right: 12px;
bottom: 149px;
width: min(320px, calc(100vw - 24px));
padding: 11px;
}
#phaseCopy { min-height: 0; font-size: 11px; }
.metrics { margin: 9px 0; gap: 6px; }
.metric { min-height: 54px; padding: 8px; }
.metric-value { font-size: 16px; }
.legend, .view-buttons { display: none; }
.timeline-panel { bottom: 10px; width: calc(100vw - 20px); }
.timeline-note { display: none; }
.camera-help { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional voxel bowling lane"></canvas>
<header class="header">
<p class="eyebrow">Voxel Motion Lab · Translation + Rotation</p>
<h1>Bowling, in two ideas</h1>
<p class="subtitle">
A schematic sliding phase followed by a rolling phase. The cyan probe follows
the ball center; the orange surface mark reveals rotation independently.
</p>
<div class="disclaimer">
ILLUSTRATIVE TRANSITION — NOT A CALIBRATED BOWLING MODEL
</div>
</header>
<aside class="panel" aria-label="Motion measurements">
<div class="panel-top">
<div id="phaseBadge" class="phase-badge">Schematic sliding</div>
<div id="status">PLAYING</div>
</div>
<h2 id="phaseTitle">Sliding</h2>
<p id="phaseCopy"></p>
<div class="metrics">
<div class="metric">
<span class="metric-label">Center speed v</span>
<span id="speedValue" class="metric-value cyan">—</span>
</div>
<div class="metric">
<span class="metric-label">Angular speed |ω|</span>
<span id="omegaValue" class="metric-value orange">—</span>
</div>
<div class="metric">
<span class="metric-label">No-slip check Rω/v</span>
<span id="ratioValue" class="metric-value green">—</span>
</div>
<div class="metric">
<span class="metric-label">Center position x</span>
<span id="positionValue" class="metric-value cyan">—</span>
</div>
<div class="metric">
<span class="metric-label">Mark rotation θ</span>
<span id="angleValue" class="metric-value orange">—</span>
</div>
<div class="metric">
<span class="metric-label">Ball radius R</span>
<span class="metric-value">0.68 u</span>
</div>
</div>
<div id="relation" class="relation"></div>
<div class="legend">
<div class="legend-row">
<span class="legend-label"><i class="swatch"></i>Ball center: translation</span>
<label class="toggle"><input id="centerToggle" type="checkbox" checked> show</label>
</div>
<div class="legend-row">
<span class="legend-label"><i class="swatch mark"></i>Surface mark: rotation</span>
<label class="toggle"><input id="markToggle" type="checkbox" checked> show</label>
</div>
<div class="legend-row">
<span class="legend-label">Velocity / spin arrows</span>
<label class="toggle"><input id="vectorToggle" type="checkbox" checked> show</label>
</div>
</div>
<div class="view-buttons">
<button id="resetView" class="small-button" type="button">Reset view</button>
<button id="topView" class="small-button" type="button">Top view</button>
</div>
</aside>
<div class="camera-help">Drag to orbit · wheel/pinch to zoom · space to play/pause</div>
<section class="timeline-panel" aria-label="Motion timeline">
<div class="timeline-header">
<button id="playButton" class="control-button" type="button">Pause</button>
<button id="restartButton" class="control-button" type="button">Restart</button>
<div id="timeReadout" class="time-readout">0.00 / 10.00 s</div>
</div>
<div class="timeline-track">
<div class="segments" aria-hidden="true">
<div class="segment slide">Sliding</div>
<div class="segment transition">Transition</div>
<div class="segment roll">Pure rolling</div>
</div>
<div id="playhead"></div>
<input
id="scrub"
type="range"
min="0"
max="10"
step="0.001"
value="0"
aria-label="Animation time"
>
</div>
<div class="timeline-footer">
<button class="phase-button" data-time="0.15" type="button">Sliding</button>
<button class="phase-button" data-time="3.70" type="button">Transition</button>
<button class="phase-button" data-time="4.95" type="button">Rolling</button>
<span class="timeline-note">Illustrative easing between the two regimes</span>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and deterministic motion model
// -------------------------------------------------------------------------
const DURATION = 10.0;
const SLIDE_END = 3.6;
const ROLL_START = 4.8;
const START_X = -13.5;
const BALL_RADIUS = 0.68;
const LANE_TOP = 0.11;
const BALL_CENTER_Y = LANE_TOP + BALL_RADIUS;
const SLIDE_SPEED = 3.0;
const ROLL_SPEED = 2.4;
const SLIDE_OMEGA = 1.8;
const SAMPLE_DT = 1 / 120;
const SAMPLE_COUNT = Math.round(DURATION / SAMPLE_DT) + 1;
const frameX = new Float32Array(SAMPLE_COUNT);
const frameAngle = new Float32Array(SAMPLE_COUNT);
const Z_AXIS = new THREE.Vector3(0, 0, 1);
const MARK_LOCAL = new THREE.Vector3(0.0, -BALL_RADIUS + 0.055, 0.20);
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(u) {
u = clamp(u, 0, 1);
return u * u * (3 - 2 * u);
}
function speedAt(t) {
if (t < SLIDE_END) return SLIDE_SPEED;
if (t >= ROLL_START) return ROLL_SPEED;
const u = (t - SLIDE_END) / (ROLL_START - SLIDE_END);
const blend = smoothstep(u);
return lerp(SLIDE_SPEED, ROLL_SPEED, blend);
}
function omegaAt(t) {
if (t < SLIDE_END) return SLIDE_OMEGA;
if (t < ROLL_START) {
const u = (t - SLIDE_END) / (ROLL_START - SLIDE_END);
const blend = smoothstep(u);
const noSlipOmega = speedAt(t) / BALL_RADIUS;
// Deliberately illustrative: the rates are eased together rather than
// solved from a friction/contact model.
return lerp(SLIDE_OMEGA, noSlipOmega, blend);
}
// Exact pure-rolling constraint.
return speedAt(t) / BALL_RADIUS;
}
// Integrate once so scrubbing and playback produce identical results.
frameX[0] = START_X;
frameAngle[0] = 0;
for (let i = 1; i < SAMPLE_COUNT; i++) {
const t0 = (i - 1) * SAMPLE_DT;
const t1 = i * SAMPLE_DT;
frameX[i] = frameX[i - 1]
+ 0.5 * (speedAt(t0) + speedAt(t1)) * SAMPLE_DT;
frameAngle[i] = frameAngle[i - 1]
+ 0.5 * (omegaAt(t0) + omegaAt(t1)) * SAMPLE_DT;
}
function stateAt(t) {
t = clamp(t, 0, DURATION);
const exact = t / SAMPLE_DT;
const i = Math.min(SAMPLE_COUNT - 2, Math.floor(exact));
const f = exact - i;
return {
x: lerp(frameX[i], frameX[i + 1], f),
angle: lerp(frameAngle[i], frameAngle[i + 1], f),
speed: speedAt(t),
omega: omegaAt(t)
};
}
function markerWorldAt(t) {
const s = stateAt(t);
return MARK_LOCAL.clone()
.applyAxisAngle(Z_AXIS, -s.angle)
.add(new THREE.Vector3(s.x, BALL_CENTER_Y, 0));
}
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lights
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131b);
scene.fog = new THREE.Fog(0x07131b, 27, 62);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 0.58,
phi: 0.73,
radius: 26,
target: new THREE.Vector3(0, 1.0, 0)
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
const c = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * s * Math.cos(cameraState.theta),
cameraState.target.y + cameraState.radius * c,
cameraState.target.z + cameraState.radius * s * Math.sin(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xbcefff, 0x172029, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.3);
keyLight.position.set(-8, 18, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -23;
keyLight.shadow.camera.right = 23;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 55;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x54e6ff, 1.3);
rimLight.position.set(12, 8, -14);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffad42, 12, 13, 2);
warmLight.position.set(12, 4, 3);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Voxel lane
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 70),
new THREE.MeshStandardMaterial({
color: 0x081820,
roughness: 0.95,
metalness: 0.03
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.34;
ground.receiveShadow = true;
scene.add(ground);
function addBox(size, position, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const laneBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x102733,
roughness: 0.86
});
addBox(
new THREE.Vector3(35.4, 0.38, 9.1),
new THREE.Vector3(0, -0.24, 0),
laneBaseMaterial
);
const gutterMaterial = new THREE.MeshStandardMaterial({
color: 0x1a4654,
roughness: 0.5,
metalness: 0.18
});
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x16313c,
roughness: 0.72
});
for (const side of [-1, 1]) {
addBox(
new THREE.Vector3(35.4, 0.22, 0.72),
new THREE.Vector3(0, -0.09, side * 3.85),
gutterMaterial
);
addBox(
new THREE.Vector3(35.4, 0.48, 0.30),
new THREE.Vector3(0, -0.02, side * 4.38),
railMaterial
);
}
const tileGeometry = new THREE.BoxGeometry(0.98, 0.22, 0.98);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.72,
metalness: 0.04
});
const xCount = 34;
const zCount = 7;
const tileCount = xCount * zCount;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
tiles.castShadow = false;
const tileMatrix = new THREE.Matrix4();
let tileIndex = 0;
for (let ix = 0; ix < xCount; ix++) {
for (let iz = 0; iz < zCount; iz++) {
const x = -16.5 + ix;
const z = -3 + iz;
tileMatrix.makeTranslation(x, 0, z);
tiles.setMatrixAt(tileIndex, tileMatrix);
const checker = (ix + iz) % 2 === 0;
const edge = iz === 0 || iz === zCount - 1;
const color = new THREE.Color();
if (edge) color.set(0x28586a);
else if (checker) color.set(0x9d8062);
else color.set(0xb09270);
const variation = 0.94 + 0.06 * Math.sin(ix * 2.17 + iz * 0.91);
color.multiplyScalar(variation);
tiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
const foulMaterial = new THREE.MeshStandardMaterial({
color: 0xff754c,
emissive: 0x4a1207,
emissiveIntensity: 0.5,
roughness: 0.5
});
for (let iz = 0; iz < 7; iz++) {
addBox(
new THREE.Vector3(0.13, 0.045, 0.78),
new THREE.Vector3(-12.2, LANE_TOP + 0.024, -3 + iz),
foulMaterial
);
}
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0xe5f6ed,
roughness: 0.55
});
function addArrow(x, z) {
addBox(
new THREE.Vector3(0.64, 0.035, 0.11),
new THREE.Vector3(x, LANE_TOP + 0.02, z),
arrowMaterial
);
const wingGeometry = new THREE.BoxGeometry(0.40, 0.035, 0.11);
for (const side of [-1, 1]) {
const wing = new THREE.Mesh(wingGeometry, arrowMaterial);
wing.position.set(
x + 0.28,
LANE_TOP + 0.02,
z + side * 0.105
);
wing.rotation.y = side * 0.62;
scene.add(wing);
}
}
addArrow(-9.1, 0);
addArrow(-6.1, 0);
addArrow(-3.1, 0);
// -------------------------------------------------------------------------
// Voxel pin rack
// -------------------------------------------------------------------------
const pinMaterial = new THREE.MeshStandardMaterial({
color: 0xf4f1df,
roughness: 0.44
});
const pinStripeMaterial = new THREE.MeshStandardMaterial({
color: 0xe54c43,
roughness: 0.5
});
function createVoxelPin(x, z) {
const group = new THREE.Group();
group.position.set(x, LANE_TOP, z);
const pieces = [
[0.55, 0.22, 0.55, 0.11, pinMaterial],
[0.46, 0.36, 0.46, 0.39, pinMaterial],
[0.35, 0.34, 0.35, 0.74, pinMaterial],
[0.24, 0.25, 0.24, 1.03, pinStripeMaterial],
[0.30, 0.30, 0.30, 1.30, pinMaterial]
];
for (const [w, h, d, y, material] of pieces) {
addBox(
new THREE.Vector3(w, h, d),
new THREE.Vector3(0, y, 0),
material,
group
);
}
scene.add(group);
}
const pinPositions = [
[14.55, 0],
[15.27, -0.38], [15.27, 0.38],
[15.99, -0.76], [15.99, 0], [15.99, 0.76],
[16.71, -1.14], [16.71, -0.38],
[16.71, 0.38], [16.71, 1.14]
];
for (const [x, z] of pinPositions) createVoxelPin(x, z);
// -------------------------------------------------------------------------
// Voxel ball and contrasting surface mark
// -------------------------------------------------------------------------
const ballRoot = new THREE.Group();
const ballSpin = new THREE.Group();
ballRoot.add(ballSpin);
scene.add(ballRoot);
const voxelPositions = [];
const step = 0.15;
const cubeSize = 0.145;
for (let ix = -4; ix <= 4; ix++) {
for (let iy = -4; iy <= 4; iy++) {
for (let iz = -4; iz <= 4; iz++) {
const x = ix * step;
const y = iy * step;
const z = iz * step;
const limit = BALL_RADIUS - cubeSize * 0.5;
if (x * x + y * y + z * z <= limit * limit) {
voxelPositions.push(new THREE.Vector3(x, y, z));
}
}
}
}
const ballGeometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
const ballMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.3,
metalness: 0.14
});
const ballVoxels = new THREE.InstancedMesh(
ballGeometry,
ballMaterial,
voxelPositions.length
);
ballVoxels.castShadow = true;
ballVoxels.receiveShadow = true;
const voxelMatrix = new THREE.Matrix4();
const voxelColor = new THREE.Color();
voxelPositions.forEach((position, i) => {
voxelMatrix.makeTranslation(position.x, position.y, position.z);
ballVoxels.setMatrixAt(i, voxelMatrix);
const stripe = Math.abs(position.x) < 0.18;
const variation = 0.9 + 0.12 * Math.sin(position.x * 19 + position.y * 13);
if (stripe) voxelColor.set(0x184e73);
else voxelColor.set(0x126a9c);
voxelColor.multiplyScalar(variation);
ballVoxels.setColorAt(i, voxelColor);
});
ballVoxels.instanceMatrix.needsUpdate = true;
ballVoxels.instanceColor.needsUpdate = true;
ballSpin.add(ballVoxels);
const markerRoot = new THREE.Group();
markerRoot.position.copy(MARK_LOCAL);
ballSpin.add(markerRoot);
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0xffa62b,
depthTest: false,
depthWrite: false
});
const markerGeometry = new THREE.BoxGeometry(0.12, 0.12, 0.12);
const markerOffsets = [
[0, 0, 0],
[-0.07, 0, 0],
[0.07, 0, 0],
[0, -0.07, 0],
[0, 0.07, 0]
];
for (const [x, y, z] of markerOffsets) {
const cube = new THREE.Mesh(markerGeometry, markerMaterial);
cube.position.set(x, y, z);
cube.renderOrder = 30;
markerRoot.add(cube);
}
// A cyan center probe remains non-rotating, separating translation from spin.
const probeGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.40, 0, 0),
new THREE.Vector3(0.40, 0, 0),
new THREE.Vector3(0, -0.40, 0),
new THREE.Vector3(0, 0.40, 0),
new THREE.Vector3(0, 0, -0.40),
new THREE.Vector3(0, 0, 0.40)
]);
const probe = new THREE.LineSegments(
probeGeometry,
new THREE.LineBasicMaterial({
color: 0x54e6ff,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
})
);
probe.renderOrder = 28;
ballRoot.add(probe);
const centerDot = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 12, 8),
new THREE.MeshBasicMaterial({
color: 0x54e6ff,
depthTest: false,
depthWrite: false
})
);
centerDot.renderOrder = 29;
ballRoot.add(centerDot);
// -------------------------------------------------------------------------
// Translation path, surface-mark path, and vectors
// -------------------------------------------------------------------------
const finalX = frameX[SAMPLE_COUNT - 1];
const centerFull = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(START_X, BALL_CENTER_Y, 0),
new THREE.Vector3(finalX, BALL_CENTER_Y, 0)
]),
new THREE.LineDashedMaterial({
color: 0x54e6ff,
dashSize: 0.22,
gapSize: 0.15,
transparent: true,
opacity: 0.38,
depthTest: false,
depthWrite: false
})
);
centerFull.computeLineDistances();
centerFull.renderOrder = 10;
scene.add(centerFull);
const centerTravelGeometry = new THREE.BufferGeometry();
centerTravelGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const centerTravel = new THREE.Line(
centerTravelGeometry,
new THREE.LineBasicMaterial({
color: 0x54e6ff,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
centerTravel.renderOrder = 12;
scene.add(centerTravel);
const markSampleTimes = [];
const markSamplePositions = [];
for (let i = 0; i < SAMPLE_COUNT; i += 2) {
const t = i * SAMPLE_DT;
markSampleTimes.push(t);
markSamplePositions.push(markerWorldAt(t));
}
const markFull = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(markSamplePositions),
new THREE.LineBasicMaterial({
color: 0xffad42,
transparent: true,
opacity: 0.24,
depthTest: false,
depthWrite: false
})
);
markFull.renderOrder = 11;
scene.add(markFull);
const markTravelGeometry = new THREE.BufferGeometry().setFromPoints(
markSamplePositions
);
const markTravel = new THREE.Line(
markTravelGeometry,
new THREE.LineBasicMaterial({
color: 0xffad42,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
})
);
markTravel.renderOrder = 13;
scene.add(markTravel);
const velocityArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
1.3,
0x54e6ff,
0.28,
0.16
);
velocityArrow.line.material.depthTest = false;
velocityArrow.line.material.depthWrite = false;
velocityArrow.cone.material.depthTest = false;
velocityArrow.cone.material.depthWrite = false;
velocityArrow.line.renderOrder = 25;
velocityArrow.cone.renderOrder = 25;
scene.add(velocityArrow);
const angularArrow = new THREE.Group();
const arcRadius = BALL_RADIUS * 1.28;
const arcPoints = [];
for (let i = 0; i <= 72; i++) {
const a = -4.35 * (i / 72);
arcPoints.push(
new THREE.Vector3(
Math.cos(a) * arcRadius,
Math.sin(a) * arcRadius,
0
)
);
}
const angularArc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
new THREE.LineBasicMaterial({
color: 0xffad42,
transparent: true,
opacity: 0.82,
depthTest: false,
depthWrite: false
})
);
angularArc.renderOrder = 24;
angularArrow.add(angularArc);
const endAngle = -4.35;
const angularDirection = new THREE.Vector3(
Math.sin(endAngle),
-Math.cos(endAngle),
0
).normalize();
const angularTip = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.30, 12),
new THREE.MeshBasicMaterial({
color: 0xffad42,
depthTest: false,
depthWrite: false
})
);
angularTip.position.copy(
new THREE.Vector3(
Math.cos(endAngle) * arcRadius,
Math.sin(endAngle) * arcRadius,
0
).addScaledVector(angularDirection, 0.13)
);
angularTip.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
angularDirection
);
angularTip.renderOrder = 25;
angularArrow.add(angularTip);
scene.add(angularArrow);
// -------------------------------------------------------------------------
// Direct camera controls: no addons or example imports
// -------------------------------------------------------------------------
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 dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi + dy * 0.005, 0.10, 1.46);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
12,
43
);
updateCamera();
}, { passive: false });
document.querySelector("#resetView").addEventListener("click", () => {
cameraState.theta = 0.58;
cameraState.phi = 0.73;
cameraState.radius = 26;
cameraState.target.set(0, 1, 0);
updateCamera();
});
document.querySelector("#topView").addEventListener("click", () => {
cameraState.theta = 0.58;
cameraState.phi = 0.10;
cameraState.radius = 28;
cameraState.target.set(0, 0.8, 0);
updateCamera();
});
// -------------------------------------------------------------------------
// Timeline and interface
// -------------------------------------------------------------------------
const playButton = document.querySelector("#playButton");
const restartButton = document.querySelector("#restartButton");
const scrub = document.querySelector("#scrub");
const playhead = document.querySelector("#playhead");
const timeReadout = document.querySelector("#timeReadout");
const statusElement = document.querySelector("#status");
const phaseBadge = document.querySelector("#phaseBadge");
const phaseTitle = document.querySelector("#phaseTitle");
const phaseCopy = document.querySelector("#phaseCopy");
const speedValue = document.querySelector("#speedValue");
const omegaValue = document.querySelector("#omegaValue");
const ratioValue = document.querySelector("#ratioValue");
const positionValue = document.querySelector("#positionValue");
const angleValue = document.querySelector("#angleValue");
const relation = document.querySelector("#relation");
let currentTime = 0;
let playing = true;
let previousFrameTime = performance.now();
function togglePlayback() {
if (!playing && currentTime >= DURATION) currentTime = 0;
playing = !playing;
updateInterface(stateAt(currentTime));
}
playButton.addEventListener("click", togglePlayback);
restartButton.addEventListener("click", () => {
currentTime = 0;
playing = true;
updateInterface(stateAt(currentTime));
});
scrub.addEventListener("input", () => {
currentTime = Number(scrub.value);
updateInterface(stateAt(currentTime));
});
document.querySelectorAll(".phase-button").forEach((button) => {
button.addEventListener("click", () => {
currentTime = Number(button.dataset.time);
playing = false;
updateInterface(stateAt(currentTime));
});
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
togglePlayback();
}
if (event.key.toLowerCase() === "r" && event.target === document.body) {
currentTime = 0;
playing = true;
updateInterface(stateAt(currentTime));
}
});
document.querySelector("#centerToggle").addEventListener("change", (event) => {
centerFull.visible = event.target.checked;
centerTravel.visible = event.target.checked;
});
document.querySelector("#markToggle").addEventListener("change", (event) => {
markFull.visible = event.target.checked;
markTravel.visible = event.target.checked;
});
document.querySelector("#vectorToggle").addEventListener("change", (event) => {
velocityArrow.visible = event.target.checked;
angularArrow.visible = event.target.checked;
});
function updateInterface(state) {
const ratio = state.omega * BALL_RADIUS / state.speed;
const angleDegrees = ((state.angle * 180 / Math.PI) % 360 + 360) % 360;
speedValue.textContent = `${state.speed.toFixed(2)} u/s`;
omegaValue.textContent = `${state.omega.toFixed(2)} rad/s`;
ratioValue.textContent = ratio.toFixed(2);
positionValue.textContent = `${state.x.toFixed(2)} u`;
angleValue.textContent = `${angleDegrees.toFixed(0)}°`;
const progress = currentTime / DURATION;
scrub.value = currentTime;
playhead.style.left = `${progress * 100}%`;
timeReadout.textContent = `${currentTime.toFixed(2)} / ${DURATION.toFixed(2)} s`;
playButton.textContent = playing ? "Pause" : "Play";
statusElement.textContent = playing ? "PLAYING" : "PAUSED";
if (currentTime < SLIDE_END) {
phaseBadge.textContent = "Schematic sliding";
phaseBadge.style.color = "var(--cyan)";
phaseTitle.textContent = "Sliding";
phaseCopy.textContent =
"The ball center advances independently of the surface spin. Here Rω is below v, so the idealized contact point would slip.";
relation.innerHTML =
`<strong>Rω/v = ${ratio.toFixed(2)}</strong> — below 1, so translation and rotation are not no-slip coupled.`;
} else if (currentTime < ROLL_START) {
phaseBadge.textContent = "Illustrative transition";
phaseBadge.style.color = "var(--transition)";
phaseTitle.textContent = "Transition";
phaseCopy.textContent =
"The linear and angular rates are eased toward a no-slip relationship. This is a teaching transition, not a friction or contact simulation.";
relation.innerHTML =
`The rates ease toward <strong>ω = v/R</strong>; the ratio is now <strong>${ratio.toFixed(2)}</strong>.`;
} else {
phaseBadge.textContent = "Pure rolling";
phaseBadge.style.color = "var(--green)";
phaseTitle.textContent = "Rolling";
phaseCopy.textContent =
"Angular speed is coupled to forward speed: ω = v/R. The cyan center path stays straight while the orange surface mark shows the rotation.";
relation.innerHTML =
`<strong>Rω/v = ${ratio.toFixed(2)}</strong> — exactly 1, enforcing <strong>v = Rω</strong> during this phase.`;
}
}
function updateScene(state) {
ballRoot.position.set(state.x, BALL_CENTER_Y, 0);
ballSpin.rotation.z = -state.angle;
const centerPositions = centerTravel.geometry.attributes.position;
centerPositions.setXYZ(0, START_X, BALL_CENTER_Y, 0);
centerPositions.setXYZ(1, state.x, BALL_CENTER_Y, 0);
centerPositions.needsUpdate = true;
let markCount = 0;
for (const sampleTime of markSampleTimes) {
if (sampleTime <= currentTime + 0.0001) markCount++;
else break;
}
markTravel.geometry.setDrawRange(0, markCount);
velocityArrow.position.set(state.x, BALL_CENTER_Y, 0);
velocityArrow.setLength(
Math.max(0.85, state.speed * 0.43),
0.28,
0.16
);
angularArrow.position.set(state.x, BALL_CENTER_Y, 0);
}
function animate(now) {
const delta = Math.min((now - previousFrameTime) / 1000, 0.05);
previousFrameTime = now;
if (playing) {
currentTime += delta;
if (currentTime >= DURATION) {
currentTime = DURATION;
playing = false;
}
}
const state = stateAt(currentTime);
updateScene(state);
updateInterface(state);
renderer.render(scene, camera);
requestAnimationFrame(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);
});
const initialState = stateAt(0);
updateScene(initialState);
updateInterface(initialState);
requestAnimationFrame(animate);
renderer.render(scene, camera);
</script>
</body>
</html>
```