Prompt specification
Build or customize the Three.js 3D scene "Rolling Ball Competing Explanations" 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: Rolling Ball Competing Explanations
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/rolling-ball-competing-explanations-x3378
Scene Description Prompt:
Reveal a slope or push behind a voxel ball's motion piece by piece; update the supported explanation. Three.js from cdnjs in standalone HTML.
Working Three.js Starter (rolling-ball-competing-explanations-x3378):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Motion Lab — Revealing the Cause</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(9, 20, 29, 0.91);
--line: rgba(154, 202, 218, 0.16);
--text: #eef8fa;
--muted: #92aab4;
--cyan: #62e6d1;
--amber: #ffbd66;
--blue: #72b8ff;
}
* {
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 {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.topbar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 22px 26px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
letter-spacing: 0.04em;
text-transform: uppercase;
font-size: 12px;
font-weight: 750;
}
.brand-mark {
position: relative;
width: 34px;
height: 34px;
border: 1px solid rgba(98, 230, 209, 0.5);
border-radius: 10px;
background: rgba(98, 230, 209, 0.07);
box-shadow: 0 0 30px rgba(98, 230, 209, 0.08);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 2px;
background: var(--cyan);
}
.brand-mark::before {
width: 8px;
height: 8px;
left: 8px;
top: 8px;
box-shadow: 9px 0 0 rgba(98, 230, 209, 0.38);
}
.brand-mark::after {
width: 17px;
height: 2px;
left: 8px;
bottom: 8px;
transform: rotate(-25deg);
transform-origin: left center;
}
.mode-switch {
display: flex;
padding: 4px;
gap: 4px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(7, 16, 24, 0.78);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.mode-switch button {
border: 0;
border-radius: 8px;
padding: 9px 15px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.04em;
transition:
color 160ms ease,
background 160ms ease;
}
.mode-switch button:hover {
color: var(--text);
}
.mode-switch button.active {
color: #05110f;
background: var(--cyan);
}
.panel {
position: fixed;
z-index: 10;
left: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
padding: 21px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--panel);
backdrop-filter: blur(20px);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.36),
inset 0 1px rgba(255, 255, 255, 0.025);
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.step-count {
color: var(--muted);
letter-spacing: 0.08em;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.2vw, 29px);
line-height: 1.12;
letter-spacing: -0.035em;
}
#explanation {
min-height: 82px;
margin: 12px 0 16px;
color: #b7c8cf;
font-size: 14px;
line-height: 1.58;
}
.evidence {
display: flex;
flex-wrap: wrap;
gap: 7px;
min-height: 28px;
margin-bottom: 18px;
}
.chip {
padding: 6px 9px;
border: 1px solid rgba(98, 230, 209, 0.18);
border-radius: 999px;
color: #b9e9e2;
background: rgba(98, 230, 209, 0.055);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.035em;
}
.timeline {
position: relative;
display: flex;
justify-content: space-between;
margin: 2px 0 19px;
}
.timeline::before {
content: "";
position: absolute;
top: 11px;
left: 9px;
right: 9px;
height: 1px;
background: var(--line);
}
.timeline-step {
position: relative;
z-index: 1;
width: 24px;
height: 24px;
padding: 0;
border: 1px solid #29414d;
border-radius: 50%;
color: #718894;
background: #0a1720;
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition:
border-color 160ms ease,
color 160ms ease,
background 160ms ease;
}
.timeline-step:hover {
border-color: #6e919f;
color: white;
}
.timeline-step.done {
border-color: rgba(98, 230, 209, 0.6);
color: var(--cyan);
}
.timeline-step.current {
border-color: var(--cyan);
color: #071018;
background: var(--cyan);
box-shadow: 0 0 18px rgba(98, 230, 209, 0.25);
}
.controls {
display: grid;
grid-template-columns: 88px 1fr;
gap: 9px;
}
.control {
min-height: 43px;
border: 1px solid var(--line);
border-radius: 11px;
color: var(--text);
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
font-size: 12px;
font-weight: 750;
transition:
transform 140ms ease,
border-color 140ms ease,
background 140ms ease;
}
.control:hover:not(:disabled) {
transform: translateY(-1px);
border-color: rgba(98, 230, 209, 0.45);
background: rgba(98, 230, 209, 0.07);
}
.control:disabled {
opacity: 0.36;
cursor: default;
}
.control.primary {
border-color: var(--cyan);
color: #06110f;
background: var(--cyan);
}
.control.primary:hover:not(:disabled) {
background: #83f0df;
}
.secondary-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 12px;
}
.replay {
padding: 0;
border: 0;
color: var(--muted);
background: none;
cursor: pointer;
font-size: 11px;
font-weight: 700;
}
.replay:hover {
color: var(--text);
}
.model-note {
color: #607984;
font-size: 10px;
line-height: 1.4;
text-align: right;
}
.hud {
position: fixed;
z-index: 5;
top: 86px;
right: 26px;
width: 190px;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(7, 16, 24, 0.62);
backdrop-filter: blur(12px);
pointer-events: none;
}
.hud-label {
margin-bottom: 7px;
color: #647d88;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.hud-value {
color: #d9eaee;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 12px;
}
.hint {
position: fixed;
z-index: 5;
right: 27px;
bottom: 27px;
color: rgba(171, 195, 203, 0.58);
font-size: 11px;
pointer-events: none;
}
@media (max-width: 720px) {
.topbar {
align-items: flex-start;
padding: 15px;
}
.brand span:last-child {
display: none;
}
.mode-switch button {
padding: 8px 10px;
font-size: 10px;
}
.panel {
left: 12px;
right: 12px;
bottom: 12px;
width: auto;
padding: 16px;
border-radius: 16px;
}
#explanation {
min-height: 0;
margin: 9px 0 12px;
font-size: 12px;
line-height: 1.45;
}
.evidence {
margin-bottom: 12px;
}
.timeline {
margin-bottom: 12px;
}
.hud,
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel ball motion demonstration"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<span>Motion Lab / Causal Reveal</span>
</div>
<nav class="mode-switch" aria-label="Motion cause">
<button type="button" data-mode="slope" class="active">Slope</button>
<button type="button" data-mode="push">Push</button>
</nav>
</header>
<aside class="hud">
<div class="hud-label">Simplified model</div>
<div class="hud-value" id="model-value">Ramp + gravity</div>
</aside>
<main class="panel">
<div class="eyebrow">
<span>Supported explanation</span>
<span class="step-count" id="step-count">01 / 05</span>
</div>
<h1 id="explanation-title">What is observed?</h1>
<p id="explanation" aria-live="polite">
The voxel ball changes position while the cause is hidden. The scene
supports an observation of motion, but not yet its cause.
</p>
<div class="evidence" id="evidence"></div>
<div class="timeline" id="timeline" aria-label="Reveal steps"></div>
<div class="controls">
<button class="control" id="back-button" type="button" disabled>Back</button>
<button class="control primary" id="next-button" type="button">
Reveal next piece
</button>
</div>
<div class="secondary-row">
<button class="replay" id="replay-button" type="button" hidden>
↻ Replay motion
</button>
<div class="model-note" id="model-note">
Rolling resistance and air drag omitted
</div>
</div>
</main>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</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 renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 17, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
theta: 0.64,
phi: 1.02,
radius: 16.5,
target: new THREE.Vector3(0.35, 1.25, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0x9ed8e7, 0x071018, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58d8d0, 2.1);
rimLight.position.set(7, 5, -7);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffae63, 8, 13, 2);
warmLight.position.set(-4, 3, 4);
scene.add(warmLight);
// Ground
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0x09151d,
roughness: 0.98,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(32, 32, 0x1c3b46, 0x102630);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
// Constants shared by both models
const BALL_RADIUS = 0.75;
const VOXEL_SPACING = 0.31;
// Voxel ball
function createVoxelBall() {
const group = new THREE.Group();
const voxels = [];
const extent = 2;
for (let x = -extent; x <= extent; x++) {
for (let y = -extent; y <= extent; y++) {
for (let z = -extent; z <= extent; z++) {
if (x * x + y * y + z * z <= 6.2) {
voxels.push({ x, y, z });
}
}
}
}
const geometry = new THREE.BoxGeometry(0.285, 0.285, 0.285);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.48,
metalness: 0.08,
vertexColors: true
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
voxels.length
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
voxels.forEach((voxel, index) => {
dummy.position.set(
voxel.x * VOXEL_SPACING,
voxel.y * VOXEL_SPACING,
voxel.z * VOXEL_SPACING
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const light = 1 - voxel.y * 0.045;
color.setHSL(
0.47 + voxel.z * 0.008,
0.61,
Math.min(0.69, 0.48 * light)
);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
scene.add(group);
return group;
}
const ball = createVoxelBall();
// Canvas-texture labels, implemented without renderer addons.
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(text, color = "#62e6d1", width = 2.0) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
roundedRect(ctx, 12, 22, 488, 84, 22);
ctx.fillStyle = "rgba(6, 16, 23, 0.91)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "700 40px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 64);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function makeArrow(color, labelText, labelWidth = 1.85) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(),
1.4,
color,
0.28,
0.17
);
arrow.line.material.depthTest = false;
arrow.cone.material.depthTest = false;
arrow.line.renderOrder = 15;
arrow.cone.renderOrder = 15;
const label = makeLabel(labelText, color, labelWidth);
label.visible = false;
return { arrow, label };
}
function placeArrow(item, origin, direction, length, labelOffset = 0.16) {
item.arrow.position.copy(origin);
item.arrow.setDirection(direction.clone().normalize());
item.arrow.setLength(
length,
Math.min(0.32, length * 0.28),
Math.min(0.19, length * 0.17)
);
item.label.position.copy(origin).addScaledVector(
direction.clone().normalize(),
length + labelOffset
);
}
// Slope model geometry
const slopeTheta = Math.atan2(2.9, 11.8);
const slopeLength = 12.3;
const slopeThickness = 0.36;
const slopeTop = new THREE.Vector3(-5.8, 3.2, 0);
const slopeDirection = new THREE.Vector3(
Math.cos(slopeTheta),
-Math.sin(slopeTheta),
0
);
const slopeNormal = new THREE.Vector3(
Math.sin(slopeTheta),
Math.cos(slopeTheta),
0
);
const rampGroup = new THREE.Group();
const rampCenter = slopeTop
.clone()
.addScaledVector(slopeDirection, -slopeLength * 0.5)
.addScaledVector(slopeNormal, -slopeThickness * 0.5);
rampGroup.position.copy(rampCenter);
rampGroup.rotation.z = -slopeTheta;
const rampBase = new THREE.Mesh(
new THREE.BoxGeometry(slopeLength, slopeThickness, 4.7),
new THREE.MeshStandardMaterial({
color: 0x132b36,
roughness: 0.8,
metalness: 0.12
})
);
rampBase.castShadow = true;
rampBase.receiveShadow = true;
rampGroup.add(rampBase);
const rampTileMaterials = [
new THREE.MeshStandardMaterial({
color: 0x1e4750,
roughness: 0.72,
metalness: 0.13
}),
new THREE.MeshStandardMaterial({
color: 0x24535a,
roughness: 0.72,
metalness: 0.13
})
];
const tileCount = 24;
const tileLength = slopeLength / tileCount;
for (let i = 0; i < tileCount; i++) {
const tile = new THREE.Mesh(
new THREE.BoxGeometry(tileLength - 0.035, 0.075, 4.52),
rampTileMaterials[i % 2]
);
tile.position.set(
-slopeLength * 0.5 + tileLength * (i + 0.5),
slopeThickness * 0.5 + 0.037,
0
);
tile.castShadow = true;
tile.receiveShadow = true;
rampGroup.add(tile);
}
scene.add(rampGroup);
// Height guide beside the ramp
const heightGuide = new THREE.Group();
const verticalGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(slopeTop.x, 0.02, 2.55),
new THREE.Vector3(slopeTop.x, slopeTop.y, 2.55)
]),
new THREE.LineDashedMaterial({
color: 0x75a5b5,
dashSize: 0.17,
gapSize: 0.12,
transparent: true,
opacity: 0.75,
depthTest: false
})
);
verticalGuide.computeLineDistances();
heightGuide.add(verticalGuide);
const horizontalGuide = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(slopeTop.x, slopeTop.y, 2.55),
new THREE.Vector3(
slopeTop.x + slopeDirection.x * slopeLength,
slopeTop.y + slopeDirection.y * slopeLength,
2.55
)
]),
new THREE.LineDashedMaterial({
color: 0x75a5b5,
dashSize: 0.17,
gapSize: 0.12,
transparent: true,
opacity: 0.75,
depthTest: false
})
);
horizontalGuide.computeLineDistances();
heightGuide.add(horizontalGuide);
const heightLabel = makeLabel("height difference", "#9ac0cc", 2.4);
heightLabel.position.set(
slopeTop.x + 0.15,
slopeTop.y * 0.55,
2.62
);
heightGuide.add(heightLabel);
scene.add(heightGuide);
// Push model geometry
const pushPlatform = new THREE.Mesh(
new THREE.BoxGeometry(16, 0.25, 4.4),
new THREE.MeshStandardMaterial({
color: 0x20353d,
roughness: 0.78,
metalness: 0.12
})
);
pushPlatform.position.set(2.6, 0.125, 0);
pushPlatform.receiveShadow = true;
pushPlatform.castShadow = true;
scene.add(pushPlatform);
const platformEdge = new THREE.Mesh(
new THREE.BoxGeometry(16, 0.055, 0.07),
new THREE.MeshStandardMaterial({
color: 0x4d6a70,
roughness: 0.55,
metalness: 0.18
})
);
platformEdge.position.set(2.6, 0.277, 2.2);
scene.add(platformEdge);
const pusher = new THREE.Group();
const pusherBody = new THREE.Mesh(
new THREE.BoxGeometry(1.3, 1.5, 1.65),
new THREE.MeshStandardMaterial({
color: 0xb86f35,
roughness: 0.58,
metalness: 0.12
})
);
pusherBody.castShadow = true;
pusherBody.receiveShadow = true;
pusher.add(pusherBody);
const pusherFace = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 1.52, 1.68),
new THREE.MeshStandardMaterial({
color: 0xffbd66,
emissive: 0x4b2505,
emissiveIntensity: 0.45,
roughness: 0.5,
metalness: 0.08
})
);
pusherFace.position.x = 0.68;
pusherFace.castShadow = true;
pusher.add(pusherFace);
const pusherStem = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 2.6, 0.3),
new THREE.MeshStandardMaterial({
color: 0x314850,
roughness: 0.7,
metalness: 0.25
})
);
pusherStem.position.set(-0.34, 1.92, 0);
pusherStem.castShadow = true;
pusher.add(pusherStem);
const pusherBase = new THREE.Mesh(
new THREE.BoxGeometry(1.75, 0.18, 2.2),
new THREE.MeshStandardMaterial({
color: 0x263a42,
roughness: 0.76,
metalness: 0.2
})
);
pusherBase.position.y = -0.84;
pusherBase.castShadow = true;
pusher.add(pusherBase);
scene.add(pusher);
// Force arrows
const slopeGravity = makeArrow(0xffbd66, "mg", 1.3);
const slopeComponent = makeArrow(0x62e6d1, "mg sin θ", 2.0);
const slopeNormalArrow = makeArrow(0x72b8ff, "N", 1.25);
const slopeVelocity = makeArrow(0xffffff, "v", 1.15);
const pushApplied = makeArrow(0xffbd66, "F push", 1.85);
const pushFriction = makeArrow(0xff7e79, "friction", 2.0);
const pushNormal = makeArrow(0x72b8ff, "N", 1.25);
const pushWeight = makeArrow(0x62e6d1, "mg", 1.25);
const pushVelocity = makeArrow(0xffffff, "v", 1.15);
const allArrows = [
slopeGravity,
slopeComponent,
slopeNormalArrow,
slopeVelocity,
pushApplied,
pushFriction,
pushNormal,
pushWeight,
pushVelocity
];
function setArrowVisible(item, visible) {
item.arrow.visible = visible;
item.label.visible = visible;
}
// Trails
function createTrail(color) {
const positions = new Float32Array(160 * 3);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setDrawRange(0, 0);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.8,
depthTest: false,
depthWrite: false
})
);
line.frustumCulled = false;
line.renderOrder = 8;
scene.add(line);
return line;
}
const slopeTrail = createTrail(0x62e6d1);
const pushTrail = createTrail(0xffbd66);
function fillTrail(line, pathFunction, count = 160) {
const attribute = line.geometry.getAttribute("position");
for (let i = 0; i < count; i++) {
const point = pathFunction(i / (count - 1));
attribute.setXYZ(i, point.x, point.y, point.z);
}
attribute.needsUpdate = true;
line.geometry.computeBoundingSphere();
}
const slopeStart = slopeTop
.clone()
.addScaledVector(slopeNormal, 0.075 + BALL_RADIUS);
const slopeTravel = slopeLength * 0.91;
fillTrail(
slopeTrail,
t => slopeStart.clone().addScaledVector(slopeDirection, t * slopeTravel)
);
const pushStart = new THREE.Vector3(-0.45, 0.25 + BALL_RADIUS, 0);
const pushTravel = 7.2;
fillTrail(
pushTrail,
t => pushStart.clone().add(new THREE.Vector3(t * pushTravel, 0, 0))
);
// State and copy
const state = {
mode: "slope",
stage: 0,
motionStart: performance.now(),
motionProgress: 0
};
const copy = {
slope: [
{
title: "What is observed?",
text:
"The voxel ball changes position while the cause is hidden. The scene supports an observation of motion, but not yet its cause.",
evidence: ["ball position", "motion observed"]
},
{
title: "An inclined route appears",
text:
"The inclined voxel ramp is now visible beneath the ball. Its upper and lower ends differ in height, so the available route descends.",
evidence: ["inclined surface", "height difference"]
},
{
title: "Gravity points down the slope",
text:
"Gravity points vertically downward. The highlighted component lies along the ramp toward the lower end; that component points in the direction of travel.",
evidence: ["gravity arrow", "along-slope component"]
},
{
title: "The trail confirms downhill motion",
text:
"Successive position samples form the ball’s trail, and the velocity arrow points down the incline. The trail confirms downhill motion rather than merely showing a tilted scene.",
evidence: ["position trail", "velocity direction"]
},
{
title: "The force account is complete",
text:
"The support force is shown perpendicular to the ramp. With rolling resistance omitted, the along-ramp gravity component accelerates the rolling ball; the perpendicular components balance.",
evidence: ["support force", "gravity component", "rolling motion"]
}
],
push: [
{
title: "What is observed?",
text:
"The voxel ball changes position while the cause is hidden. The scene supports an observation of motion, but not yet its cause.",
evidence: ["ball position", "motion observed"]
},
{
title: "A pusher is placed behind the ball",
text:
"A level runway and pusher are now visible behind the ball. Their alignment shows that the pusher can act horizontally through the ball’s center.",
evidence: ["level surface", "rear pusher"]
},
{
title: "The applied force is revealed",
text:
"The amber arrow begins at the contact face and points through the ball’s center. It identifies the applied forward force produced by the pusher.",
evidence: ["contact face", "applied-force arrow"]
},
{
title: "The trail confirms the direction",
text:
"Position samples and the velocity arrow show the ball moving away from the pusher. The contact-side arrow establishes which way the push acts.",
evidence: ["position trail", "velocity direction"]
},
{
title: "The force account is complete",
text:
"Weight and normal force balance vertically. Friction opposes the applied push, so the net horizontal force changes the ball’s speed. The simplified model treats the push and friction as steady.",
evidence: ["normal force", "weight", "friction", "net force"]
}
]
};
const explanationTitle = document.querySelector("#explanation-title");
const explanationText = document.querySelector("#explanation");
const evidenceContainer = document.querySelector("#evidence");
const stepCount = document.querySelector("#step-count");
const nextButton = document.querySelector("#next-button");
const backButton = document.querySelector("#back-button");
const replayButton = document.querySelector("#replay-button");
const modelValue = document.querySelector("#model-value");
const modelNote = document.querySelector("#model-note");
const timeline = document.querySelector("#timeline");
for (let i = 0; i < 5; i++) {
const button = document.createElement("button");
button.type = "button";
button.className = "timeline-step";
button.textContent = String(i + 1);
button.setAttribute(
"aria-label",
`Go to reveal step ${i + 1}`
);
button.addEventListener("click", () => setStage(i));
timeline.appendChild(button);
}
const timelineSteps = [...timeline.querySelectorAll(".timeline-step")];
function updateExplanation() {
const item = copy[state.mode][state.stage];
explanationTitle.textContent = item.title;
explanationText.textContent = item.text;
stepCount.textContent = `${String(state.stage + 1).padStart(2, "0")} / 05`;
evidenceContainer.replaceChildren(
...item.evidence.map(text => {
const chip = document.createElement("span");
chip.className = "chip";
chip.textContent = text;
return chip;
})
);
timelineSteps.forEach((button, index) => {
button.classList.toggle("done", index < state.stage);
button.classList.toggle("current", index === state.stage);
button.setAttribute(
"aria-current",
index === state.stage ? "step" : "false"
);
});
backButton.disabled = state.stage === 0;
nextButton.disabled = state.stage === 4;
nextButton.textContent =
state.stage === 4
? "All pieces revealed"
: "Reveal next piece";
replayButton.hidden = state.stage < 2;
}
function updateVisibility() {
const stage = state.stage;
const slope = state.mode === "slope";
rampGroup.visible = slope && stage >= 1;
heightGuide.visible = slope && stage >= 1;
pushPlatform.visible = !slope && stage >= 1;
platformEdge.visible = !slope && stage >= 1;
pusher.visible = !slope && stage >= 1;
setArrowVisible(slopeGravity, slope && stage >= 2);
setArrowVisible(slopeComponent, slope && stage >= 2);
setArrowVisible(slopeNormalArrow, slope && stage >= 4);
setArrowVisible(slopeVelocity, slope && stage >= 3);
setArrowVisible(pushApplied, !slope && stage >= 2);
setArrowVisible(pushFriction, !slope && stage >= 4);
setArrowVisible(pushNormal, !slope && stage >= 4);
setArrowVisible(pushWeight, !slope && stage >= 4);
setArrowVisible(pushVelocity, !slope && stage >= 3);
slopeTrail.visible = slope && stage >= 3;
pushTrail.visible = !slope && stage >= 3;
if (slope) {
modelValue.textContent = "Ramp + gravity";
modelNote.textContent = "Rolling resistance and air drag omitted";
} else {
modelValue.textContent = "Horizontal push + friction";
modelNote.textContent = "Steady push and friction assumed";
}
}
function setStage(nextStage) {
const bounded = THREE.MathUtils.clamp(nextStage, 0, 4);
const previousStage = state.stage;
state.stage = bounded;
if (bounded >= 2 && previousStage < 2) {
state.motionStart =
performance.now() - (bounded - 2) * 550;
}
updateVisibility();
updateExplanation();
}
function setMode(mode) {
state.mode = mode;
state.stage = 0;
state.motionProgress = 0;
state.motionStart = performance.now();
document.querySelectorAll("[data-mode]").forEach(button => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
updateVisibility();
updateExplanation();
}
document.querySelectorAll("[data-mode]").forEach(button => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
nextButton.addEventListener("click", () => setStage(state.stage + 1));
backButton.addEventListener("click", () => setStage(state.stage - 1));
replayButton.addEventListener("click", () => {
state.motionStart = performance.now();
state.motionProgress = 0;
});
function setTrailProgress(line, progress) {
const count = Math.max(2, Math.round(progress * 159));
line.geometry.setDrawRange(0, count);
}
function updateMotion(now) {
const stage = state.stage;
if (state.mode === "slope") {
if (stage === 0) {
ball.position.set(0, BALL_RADIUS, 0);
ball.rotation.z = 0;
state.motionProgress = 0;
setTrailProgress(slopeTrail, 0);
return;
}
const elapsed = Math.max(0, (now - state.motionStart) / 1000);
if (stage < 2) {
ball.position.copy(slopeStart);
ball.rotation.z = 0;
state.motionProgress = 0;
setTrailProgress(slopeTrail, 0);
return;
}
const progress = Math.min(elapsed / 5.8, 1);
const distance = progress * slopeTravel;
state.motionProgress = progress;
ball.position
.copy(slopeStart)
.addScaledVector(slopeDirection, distance);
ball.rotation.z = -distance / BALL_RADIUS;
setTrailProgress(slopeTrail, progress);
const center = ball.position;
placeArrow(
slopeGravity,
center.clone().add(new THREE.Vector3(0, 0.15, 0)),
new THREE.Vector3(0, -1, 0),
1.85
);
placeArrow(
slopeComponent,
center.clone().add(new THREE.Vector3(0, 0.28, 0)),
slopeDirection,
1.85
);
placeArrow(
slopeNormalArrow,
center.clone().add(new THREE.Vector3(0, 0.02, 0)),
slopeNormal,
1.5
);
placeArrow(
slopeVelocity,
center.clone().add(new THREE.Vector3(0, -0.15, 0)),
slopeDirection,
1.05 + progress * 0.65
);
} else {
if (stage === 0) {
ball.position.copy(pushStart);
ball.rotation.z = 0;
state.motionProgress = 0;
setTrailProgress(pushTrail, 0);
return;
}
const elapsed = Math.max(0, (now - state.motionStart) / 1000);
if (stage < 2) {
ball.position.copy(pushStart);
ball.rotation.z = 0;
state.motionProgress = 0;
pusher.position.set(-1.93, 1.03, 0);
setTrailProgress(pushTrail, 0);
return;
}
const acceleration = 0.55;
const travel = 0.5 * acceleration * elapsed * elapsed;
const clampedTravel = Math.min(travel, pushTravel);
const progress = clampedTravel / pushTravel;
state.motionProgress = progress;
ball.position.copy(pushStart).add(
new THREE.Vector3(clampedTravel, 0, 0)
);
ball.rotation.z = -clampedTravel / BALL_RADIUS;
// The pusher remains in contact, acting like a steady-force actuator.
pusher.position.set(
ball.position.x - BALL_RADIUS - 0.73,
1.03,
0
);
setTrailProgress(pushTrail, progress);
const contact = new THREE.Vector3(
ball.position.x - BALL_RADIUS - 0.06,
ball.position.y,
0
);
placeArrow(
pushApplied,
contact,
new THREE.Vector3(1, 0, 0),
1.55
);
placeArrow(
pushFriction,
ball.position.clone(),
new THREE.Vector3(-1, 0, 0),
1.05
);
placeArrow(
pushNormal,
ball.position.clone(),
new THREE.Vector3(0, 1, 0),
1.35
);
placeArrow(
pushWeight,
ball.position.clone(),
new THREE.Vector3(0, -1, 0),
1.35
);
placeArrow(
pushVelocity,
ball.position.clone().add(new THREE.Vector3(0, -0.08, 0)),
new THREE.Vector3(1, 0, 0),
1.05 + progress * 0.6
);
}
}
// Direct camera controls: no OrbitControls or other addons.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
const activePointers = new Map();
let previousPinchDistance = 0;
canvas.addEventListener("pointerdown", event => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", event => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (previousPinchDistance / distance),
9,
27
);
previousPinchDistance = distance;
return;
}
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.45,
1.45
);
pointerX = event.clientX;
pointerY = event.clientY;
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 0) {
dragging = false;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9,
27
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.theta = 0.64;
cameraState.phi = 1.02;
cameraState.radius = 16.5;
cameraState.target.set(0.35, 1.25, 0);
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
setMode("slope");
function animate(now) {
requestAnimationFrame(animate);
updateCamera();
updateMotion(now);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```