Prompt specification
Build or customize the Three.js 3D scene "Mobile cart brake test" 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: Mobile cart brake test
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mobile-cart-brake-test-x0198
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows locking caster wheels. Place a small cart on a level surface and apply a symbolic push; unlocked wheels roll, while engaged brakes stop rotation in a labeled simplified demonstration. Low-poly.
Working Three.js Starter (mobile-cart-brake-test-x0198):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Locking Caster Wheels — Simplified Motion Demonstration</title>
<style>
:root {
--ink: #17312f;
--muted: #627774;
--panel: rgba(250, 253, 252, 0.9);
--line: rgba(28, 67, 62, 0.14);
--green: #13a886;
--green-soft: #dff5ee;
--blue: #168bd2;
--blue-soft: #e2f2fc;
--red: #e34f47;
--red-soft: #fde9e7;
--amber: #d88b24;
--shadow: 0 18px 50px rgba(38, 67, 63, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eaf1ef;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#stage canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 28px;
left: 32px;
max-width: 540px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #3f6862;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--green);
box-shadow: 0 0 0 5px rgba(19, 168, 134, 0.12);
content: "";
}
h1 {
margin: 0;
font-size: clamp(31px, 3.4vw, 51px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
max-width: 460px;
margin: 14px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.controls {
position: fixed;
z-index: 12;
top: 28px;
right: 28px;
width: 310px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.status-row {
display: flex;
align-items: center;
gap: 11px;
padding-bottom: 15px;
border-bottom: 1px solid var(--line);
}
.status-dot {
position: relative;
flex: 0 0 auto;
width: 11px;
height: 11px;
border-radius: 50%;
background: #8da09d;
box-shadow: 0 0 0 5px rgba(141, 160, 157, 0.13);
transition: 180ms ease;
}
.status-dot.rolling {
background: var(--blue);
box-shadow: 0 0 0 5px rgba(22, 139, 210, 0.13);
}
.status-dot.braking,
.status-dot.stopped {
background: var(--red);
box-shadow: 0 0 0 5px rgba(227, 79, 71, 0.13);
}
.status-dot.pushing {
background: var(--amber);
box-shadow: 0 0 0 5px rgba(216, 139, 36, 0.13);
}
.status-title {
margin: 0;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status-copy {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin: 15px 0;
}
.readout {
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.56);
}
.readout-label {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.readout-value {
font-size: 17px;
font-weight: 780;
letter-spacing: -0.025em;
}
.readout-value small {
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
.progress {
height: 4px;
overflow: hidden;
margin-bottom: 14px;
border-radius: 999px;
background: #e1e9e7;
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--blue), var(--green), var(--red));
transition: width 100ms linear;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
button {
min-height: 43px;
padding: 0 12px;
border: 0;
border-radius: 11px;
color: var(--ink);
background: #e7efed;
font-size: 11px;
font-weight: 820;
letter-spacing: 0.025em;
cursor: pointer;
transition: transform 130ms ease, background 130ms ease,
box-shadow 130ms ease;
}
button:hover {
transform: translateY(-1px);
background: #dce8e5;
}
button:active {
transform: translateY(0);
}
button.primary {
width: 100%;
margin-bottom: 9px;
color: white;
background: var(--ink);
box-shadow: 0 8px 20px rgba(23, 49, 47, 0.17);
}
button.primary:hover {
background: #244744;
}
button.danger {
color: #b82f2a;
background: var(--red-soft);
}
button.danger:hover {
background: #fbdad7;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
line-height: 1.35;
cursor: pointer;
}
.switch-row input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 39px;
height: 22px;
border-radius: 999px;
background: #c9d5d2;
transition: 160ms ease;
}
.switch::after {
position: absolute;
top: 3px;
left: 3px;
width: 16px;
height: 16px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
content: "";
transition: 160ms ease;
}
.switch-row input:checked + .switch {
background: var(--green);
}
.switch-row input:checked + .switch::after {
transform: translateX(17px);
}
.timeline {
position: fixed;
z-index: 10;
bottom: 27px;
left: 50%;
display: flex;
align-items: stretch;
width: min(620px, calc(100vw - 460px));
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.84);
border-radius: 16px;
background: rgba(250, 253, 252, 0.84);
box-shadow: 0 13px 35px rgba(38, 67, 63, 0.1);
backdrop-filter: blur(14px);
transform: translateX(-50%);
pointer-events: none;
}
.step {
position: relative;
display: flex;
flex: 1;
align-items: center;
justify-content: center;
gap: 8px;
min-width: 0;
padding: 9px 7px;
border-radius: 10px;
color: #839390;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.step + .step::before {
position: absolute;
left: -1px;
width: 1px;
height: 20px;
background: var(--line);
content: "";
}
.step-number {
display: grid;
width: 21px;
height: 21px;
flex: 0 0 auto;
place-items: center;
border: 1px solid #cbd6d3;
border-radius: 50%;
font-size: 9px;
}
.step.active {
color: var(--ink);
background: white;
}
.step.active .step-number {
border-color: var(--blue);
color: white;
background: var(--blue);
}
.step.completed {
color: #3e776c;
}
.step.completed .step-number {
border-color: var(--green);
color: white;
background: var(--green);
}
.legend {
position: fixed;
z-index: 10;
bottom: 34px;
left: 32px;
display: grid;
gap: 9px;
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.legend-swatch {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--green);
}
.legend-swatch.blue {
background: var(--blue);
}
.legend-swatch.red {
background: var(--red);
}
.camera-help {
position: fixed;
z-index: 10;
right: 32px;
bottom: 34px;
color: #728582;
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
#annotations {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: 118px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 10px;
background: rgba(255, 255, 255, 0.87);
box-shadow: 0 9px 24px rgba(34, 66, 61, 0.12);
backdrop-filter: blur(9px);
transform: translate(-50%, -100%);
transition: border-color 180ms ease, background 180ms ease;
}
.scene-label::after {
position: absolute;
bottom: -18px;
left: 50%;
width: 1px;
height: 18px;
background: rgba(36, 72, 67, 0.35);
content: "";
}
.scene-label b {
display: block;
color: var(--ink);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.scene-label span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
white-space: nowrap;
}
.scene-label.push {
border-left: 3px solid var(--blue);
}
.scene-label.wheel {
border-left: 3px solid var(--green);
}
.scene-label.brake {
border-left: 3px solid var(--red);
}
.scene-label.locked {
background: rgba(255, 245, 243, 0.91);
border-left-color: var(--red);
}
.note {
margin-top: 13px;
color: #80908d;
font-size: 9px;
line-height: 1.45;
}
@media (max-width: 900px) {
.topbar {
top: 16px;
left: 17px;
max-width: calc(100vw - 34px);
}
h1 {
font-size: 32px;
}
.subtitle {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 14px;
width: min(310px, calc(100vw - 28px));
padding: 14px;
}
.timeline,
.legend,
.camera-help {
display: none;
}
.scene-label {
transform: translate(-50%, -100%) scale(0.88);
}
}
@media (max-height: 650px) {
.controls {
padding: 12px;
}
.readouts,
.note {
display: none;
}
.subtitle {
display: none;
}
}
</style>
</head>
<body>
<div id="stage" role="img"
aria-label="Interactive low-poly cart with four locking caster wheels"></div>
<div id="annotations" aria-hidden="true">
<div id="labelPush" class="scene-label push">
<b>Symbolic push</b>
<span>force applied in +X</span>
</div>
<div id="labelWheel" class="scene-label wheel">
<b id="wheelLabelTitle">Unlocked wheel</b>
<span id="wheelLabelText">free to rotate</span>
</div>
<div id="labelBrake" class="scene-label brake">
<b id="brakeLabelTitle">Brake released</b>
<span id="brakeLabelText">caster remains mobile</span>
</div>
</div>
<header class="topbar">
<div class="eyebrow">Mechanism study 01</div>
<h1>Locking caster wheels</h1>
<p class="subtitle">
A simplified straight-line demonstration: apply a symbolic push to roll
the cart, then engage the caster brakes to lock wheel rotation.
</p>
</header>
<section class="controls" aria-label="Demonstration controls">
<div class="status-row">
<div id="statusDot" class="status-dot"></div>
<div>
<p id="statusTitle" class="status-title">Ready</p>
<p id="statusCopy" class="status-copy">Brakes released · casters free to roll</p>
</div>
</div>
<div class="readouts">
<div class="readout">
<span class="readout-label">Cart travel</span>
<span class="readout-value"><span id="travelValue">0.00</span> <small>m</small></span>
</div>
<div class="readout">
<span class="readout-label">Wheel speed</span>
<span class="readout-value"><span id="wheelValue">0</span> <small>°/s</small></span>
</div>
</div>
<div class="progress" aria-hidden="true">
<div id="progressFill"></div>
</div>
<button id="runButton" class="primary" type="button">
▶ Apply symbolic push
</button>
<div class="button-row">
<button id="brakeButton" class="danger" type="button">
Engage brakes
</button>
<button id="resetButton" type="button">Reset</button>
</div>
<label class="switch-row">
<span>Automatic brake after the unlocked roll</span>
<input id="autoBrake" type="checkbox" checked>
<span class="switch" aria-hidden="true"></span>
</label>
<p class="note">
Simplified model: straight travel, rigid wheel braking, and short coast
distance. Real caster swivel and stopping behavior vary by load.
</p>
</section>
<nav class="timeline" aria-label="Demonstration stages">
<div id="stepPush" class="step">
<span class="step-number">1</span><span>Push</span>
</div>
<div id="stepRoll" class="step">
<span class="step-number">2</span><span>Roll</span>
</div>
<div id="stepBrake" class="step">
<span class="step-number">3</span><span>Brake</span>
</div>
<div id="stepStop" class="step">
<span class="step-number">4</span><span>Stop</span>
</div>
</nav>
<div class="legend">
<div class="legend-item">
<span class="legend-swatch blue"></span> Applied force
</div>
<div class="legend-item">
<span class="legend-swatch"></span> Free wheel rotation
</div>
<div class="legend-item">
<span class="legend-swatch red"></span> Engaged brake
</div>
</div>
<div class="camera-help">Drag to orbit · Scroll to zoom · Double-click to reset view</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 stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.12;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeaf1ef);
scene.fog = new THREE.Fog(0xeaf1ef, 13, 27);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0.05, 0.82, 0);
const cameraState = {
yaw: 0.69,
pitch: 0.96,
radius: 8.7
};
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
cameraTarget.x + Math.sin(yaw) * horizontal,
cameraTarget.y + Math.sin(pitch) * radius,
cameraTarget.z + Math.cos(yaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xffffff, 0x78908a, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff2dd, 3.6);
keyLight.position.set(4.5, 8.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9e8ff, 1.05);
fillLight.position.set(-5, 4, -4);
scene.add(fillLight);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0,
flatShading: true,
...extra
});
}
const materials = {
ground: standard(0xdfe9e6, { roughness: 1 }),
deck: standard(0x315b5b, { roughness: 0.68 }),
top: standard(0xd8c8a8),
frame: standard(0x244744),
handle: standard(0x274d4a),
tire: standard(0x263331, { roughness: 0.92 }),
hub: standard(0x98aaa5, { metalness: 0.25, roughness: 0.48 }),
spoke: standard(0xe8eee9),
brake: standard(0xe34f47, {
emissive: 0x4c0805,
emissiveIntensity: 0.16
}),
crate: standard(0xc79a62),
crateDark: standard(0x9d7044),
tape: standard(0xf0d38f),
smallCrate: standard(0x4c8c86),
blue: standard(0x168bd2, {
emissive: 0x073d60,
emissiveIntensity: 0.35
})
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radius,
length,
position,
material,
radialSegments = 10
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Level surface
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(24, 18),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(18, 36, 0xa9bfba, 0xc4d3cf);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
const laneMaterial = standard(0xb7cbc6, { roughness: 1 });
for (const z of [-0.57, 0.57]) {
const lane = addBox(
scene,
[8.4, 0.012, 0.026],
[0, 0.012, z],
laneMaterial,
false
);
lane.receiveShadow = false;
}
// ------------------------------------------------------------
// Cart
// ------------------------------------------------------------
const cart = new THREE.Group();
cart.position.x = -1.35;
scene.add(cart);
addBox(cart, [2.9, 0.13, 1.55], [0, 0.86, 0], materials.deck);
addBox(cart, [2.78, 0.065, 1.43], [0, 0.955, 0], materials.top);
for (const z of [-0.69, 0.69]) {
addBox(cart, [2.9, 0.13, 0.09], [0, 0.765, z], materials.frame);
}
for (const x of [-1.39, 1.39]) {
addBox(cart, [0.09, 0.13, 1.4], [x, 0.765, 0], materials.frame);
}
// Rear handle.
for (const z of [-0.6, 0.6]) {
addCylinder(cart, 0.038, 0.86, [-1.26, 1.37, z], materials.handle, 8);
}
const grip = addCylinder(
cart,
0.046,
1.25,
[-1.26, 1.81, 0],
materials.handle,
8
);
grip.rotation.x = Math.PI / 2;
// Cargo.
addBox(cart, [1.18, 0.78, 1.02], [0.28, 1.37, 0.02], materials.crate);
addBox(cart, [0.18, 0.79, 0.026], [0.28, 1.37, 0.541], materials.tape);
addBox(cart, [0.18, 0.026, 1.03], [0.28, 1.771, 0.02], materials.tape);
addBox(cart, [0.56, 0.49, 0.72], [-0.71, 1.235, -0.12], materials.smallCrate);
addBox(cart, [0.08, 0.50, 0.735], [-0.71, 1.235, -0.12], materials.tape);
// ------------------------------------------------------------
// Four locking caster assemblies
// ------------------------------------------------------------
const wheelRadius = 0.27;
const wheelPivots = [];
const brakeLevers = [];
const statusRingMaterial = new THREE.MeshStandardMaterial({
color: 0x18b58f,
emissive: 0x073d31,
emissiveIntensity: 0.45,
roughness: 0.45,
metalness: 0,
flatShading: true
});
function createCaster(x, z) {
const root = new THREE.Group();
root.position.set(x, 0, z);
cart.add(root);
// Swivel stem and mounting plate.
addCylinder(root, 0.055, 0.28, [0, 0.68, 0], materials.hub, 8);
addBox(root, [0.29, 0.07, 0.29], [0, 0.805, 0], materials.frame);
// Fork plates.
for (const side of [-1, 1]) {
addBox(
root,
[0.065, 0.43, 0.045],
[0, 0.46, side * 0.15],
materials.frame
);
}
// The wheel axle runs along Z, so rolling occurs around Z.
const wheelPivot = new THREE.Group();
wheelPivot.position.set(0, wheelRadius, 0);
root.add(wheelPivot);
wheelPivots.push(wheelPivot);
const tireGeometry = new THREE.CylinderGeometry(
wheelRadius,
wheelRadius,
0.18,
12
);
tireGeometry.rotateX(Math.PI / 2);
const tire = new THREE.Mesh(tireGeometry, materials.tire);
tire.castShadow = true;
tire.receiveShadow = true;
wheelPivot.add(tire);
const hubGeometry = new THREE.CylinderGeometry(0.105, 0.105, 0.205, 10);
hubGeometry.rotateX(Math.PI / 2);
const hub = new THREE.Mesh(hubGeometry, materials.hub);
hub.castShadow = true;
wheelPivot.add(hub);
// Contrasting spokes make the angular motion easy to read.
for (const side of [-1, 1]) {
for (let i = 0; i < 3; i++) {
const spoke = new THREE.Mesh(
new THREE.BoxGeometry(0.36, 0.035, 0.028),
materials.spoke
);
spoke.position.z = side * 0.109;
spoke.rotation.z = (i * Math.PI * 2) / 3;
spoke.castShadow = true;
wheelPivot.add(spoke);
}
}
// Colored status ring around the wheel face.
const statusRing = new THREE.Mesh(
new THREE.TorusGeometry(0.305, 0.015, 6, 28),
statusRingMaterial
);
statusRing.position.set(0, wheelRadius, 0.113);
root.add(statusRing);
// Red brake lever pivots over the tire when engaged.
const leverPivot = new THREE.Group();
leverPivot.position.set(0, 0.54, 0.205);
leverPivot.rotation.z = 0.62;
root.add(leverPivot);
const lever = addBox(
leverPivot,
[0.075, 0.29, 0.055],
[0, 0.135, 0],
materials.brake
);
addBox(
leverPivot,
[0.13, 0.075, 0.075],
[0, 0.275, -0.015],
materials.brake
);
brakeLevers.push(leverPivot);
}
createCaster(-1.05, -0.54);
createCaster(-1.05, 0.54);
createCaster(1.05, -0.54);
createCaster(1.05, 0.54);
// ------------------------------------------------------------
// Symbolic push arrow
// ------------------------------------------------------------
const pushArrow = new THREE.Group();
pushArrow.position.set(-1.66, 0.16, 1.14);
cart.add(pushArrow);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0x168bd2,
emissive: 0x07527b,
emissiveIntensity: 0.65,
roughness: 0.45,
flatShading: true
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.95, 8),
arrowMaterial
);
shaft.rotation.z = -Math.PI / 2;
shaft.position.x = 0.42;
pushArrow.add(shaft);
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.3, 10),
arrowMaterial
);
arrowHead.rotation.z = -Math.PI / 2;
arrowHead.position.x = 1.04;
pushArrow.add(arrowHead);
// ------------------------------------------------------------
// Demonstration state
// ------------------------------------------------------------
const START_X = -1.35;
const END_X = 1.8;
const MAX_SPEED = 1.45;
const BRAKE_DECELERATION = 3.65;
let phase = "ready";
let cartX = START_X;
let speed = 0;
let wheelAngle = 0;
let phaseTime = 0;
let brakeEngaged = false;
let brakeTargetAngle = 0.62;
let currentBrakeAngle = 0.62;
const runButton = document.getElementById("runButton");
const brakeButton = document.getElementById("brakeButton");
const resetButton = document.getElementById("resetButton");
const autoBrake = document.getElementById("autoBrake");
const statusDot = document.getElementById("statusDot");
const statusTitle = document.getElementById("statusTitle");
const statusCopy = document.getElementById("statusCopy");
const travelValue = document.getElementById("travelValue");
const wheelValue = document.getElementById("wheelValue");
const progressFill = document.getElementById("progressFill");
const stepPush = document.getElementById("stepPush");
const stepRoll = document.getElementById("stepRoll");
const stepBrake = document.getElementById("stepBrake");
const stepStop = document.getElementById("stepStop");
const labelPush = document.getElementById("labelPush");
const labelWheel = document.getElementById("labelWheel");
const labelBrake = document.getElementById("labelBrake");
const wheelLabelTitle = document.getElementById("wheelLabelTitle");
const wheelLabelText = document.getElementById("wheelLabelText");
const brakeLabelTitle = document.getElementById("brakeLabelTitle");
const brakeLabelText = document.getElementById("brakeLabelText");
function resetBrakeVisual() {
brakeEngaged = false;
brakeTargetAngle = 0.62;
}
function startDemonstration() {
cartX = START_X;
speed = 0;
wheelAngle = 0;
phaseTime = 0;
phase = "pushing";
resetBrakeVisual();
cart.position.x = cartX;
updateUI();
}
function engageBrakes() {
if (brakeEngaged) return;
brakeEngaged = true;
brakeTargetAngle = -0.3;
if (speed > 0.025) {
phase = "braking";
} else {
speed = 0;
phase = "stopped";
}
phaseTime = 0;
updateUI();
}
function releaseBrakes() {
brakeEngaged = false;
brakeTargetAngle = 0.62;
if (phase === "stopped") {
phase = "ready";
speed = 0;
} else if (phase === "braking") {
phase = "rolling";
speed = Math.max(speed, 0.65);
phaseTime = 0;
}
updateUI();
}
runButton.addEventListener("click", startDemonstration);
brakeButton.addEventListener("click", () => {
if (brakeEngaged) {
releaseBrakes();
} else {
engageBrakes();
}
});
resetButton.addEventListener("click", () => {
phase = "ready";
cartX = START_X;
speed = 0;
wheelAngle = 0;
phaseTime = 0;
resetBrakeVisual();
cart.position.x = cartX;
updateUI();
});
function setStep(element, state) {
element.classList.remove("active", "completed");
if (state) element.classList.add(state);
}
function updateUI() {
const statusMap = {
ready: {
title: "Ready",
copy: "Brakes released · casters free to roll",
dot: ""
},
pushing: {
title: "Push applied",
copy: "Symbolic force accelerates the cart",
dot: "pushing"
},
rolling: {
title: "Unlocked · rolling",
copy: "Wheel angle changes with cart travel",
dot: "rolling"
},
braking: {
title: "Brake engaged",
copy: "Wheel rotation locked at 0°/s",
dot: "braking"
},
stopped: {
title: "Stopped",
copy: "Locked caster holds the cart",
dot: "stopped"
},
limit: {
title: "Travel limit",
copy: "Auto-brake off · reset to run again",
dot: ""
}
};
const status = statusMap[phase] || statusMap.ready;
statusTitle.textContent = status.title;
statusCopy.textContent = status.copy;
statusDot.className = `status-dot ${status.dot}`;
runButton.textContent =
phase === "ready" ? "▶ Apply symbolic push" : "↻ Replay demonstration";
brakeButton.textContent = brakeEngaged ? "Release brakes" : "Engage brakes";
const pushDone = ["rolling", "braking", "stopped", "limit"].includes(phase);
const rollDone = ["braking", "stopped"].includes(phase);
const brakeDone = phase === "stopped";
setStep(stepPush, phase === "pushing" ? "active" : pushDone ? "completed" : "");
setStep(stepRoll, phase === "rolling" ? "active" : rollDone ? "completed" : "");
setStep(stepBrake, phase === "braking" ? "active" : brakeDone ? "completed" : "");
setStep(stepStop, phase === "stopped" ? "active" : "");
if (brakeEngaged) {
wheelLabelTitle.textContent = "Locked wheel";
wheelLabelText.textContent = "rotation = 0°/s";
brakeLabelTitle.textContent = "Brake engaged";
brakeLabelText.textContent = "mechanical lock";
labelWheel.classList.add("locked");
labelBrake.classList.add("locked");
} else {
wheelLabelTitle.textContent = "Unlocked wheel";
wheelLabelText.textContent = "free to rotate";
brakeLabelTitle.textContent = "Brake released";
brakeLabelText.textContent = "caster remains mobile";
labelWheel.classList.remove("locked");
labelBrake.classList.remove("locked");
}
}
updateUI();
// ------------------------------------------------------------
// Simulation update
// ------------------------------------------------------------
function updateSimulation(dt) {
if (phase === "pushing") {
phaseTime += dt;
if (phaseTime >= 0.38) {
phase = "rolling";
phaseTime = 0;
}
} else if (phase === "rolling") {
phaseTime += dt;
speed = Math.min(MAX_SPEED, speed + 3.8 * dt);
const distance = speed * dt;
cartX += distance;
// Negative rotation around Z matches +X travel.
wheelAngle -= distance / wheelRadius;
if (autoBrake.checked && phaseTime >= 1.8) {
engageBrakes();
} else if (cartX >= END_X) {
speed = 0;
phase = "limit";
}
} else if (phase === "braking") {
phaseTime += dt;
speed = Math.max(0, speed - BRAKE_DECELERATION * dt);
// The brake prevents wheel rotation, so the wheel angle is frozen
// while the cart completes a short simplified coasting distance.
cartX += speed * dt;
if (speed <= 0.01) {
speed = 0;
phase = "stopped";
}
}
cart.position.x = cartX;
for (const pivot of wheelPivots) {
pivot.rotation.z = wheelAngle;
}
currentBrakeAngle = THREE.MathUtils.lerp(
currentBrakeAngle,
brakeTargetAngle,
1 - Math.exp(-dt * 15)
);
for (const lever of brakeLevers) {
lever.rotation.z = currentBrakeAngle;
}
if (brakeEngaged) {
statusRingMaterial.color.setHex(0xe34f47);
statusRingMaterial.emissive.setHex(0x5a0905);
} else {
statusRingMaterial.color.setHex(0x18b58f);
statusRingMaterial.emissive.setHex(0x073d31);
}
const arrowPulse =
phase === "pushing" || phase === "rolling"
? 1 + Math.sin(performance.now() * 0.009) * 0.055
: 1;
pushArrow.scale.set(arrowPulse, arrowPulse, arrowPulse);
const angularSpeed = brakeEngaged ? 0 : (speed / wheelRadius) * 180 / Math.PI;
travelValue.textContent = Math.max(0, cartX - START_X).toFixed(2);
wheelValue.textContent = angularSpeed.toFixed(0);
let progress = 0;
if (phase === "pushing") progress = 0.08;
else if (phase === "rolling") progress = 0.08 + Math.min(phaseTime / 1.8, 1) * 0.62;
else if (phase === "braking") progress = 0.7 + Math.min(phaseTime / 0.5, 1) * 0.2;
else if (phase === "stopped") progress = 1;
progressFill.style.width = `${progress * 100}%`;
}
// ------------------------------------------------------------
// Screen-space annotations
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, offsetX, offsetY) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x + offsetX}px`;
element.style.top = `${y + offsetY}px`;
element.style.visibility =
projected.z > -1 && projected.z < 1 ? "visible" : "hidden";
}
const pushAnchor = new THREE.Vector3();
const wheelAnchor = new THREE.Vector3();
const brakeAnchor = new THREE.Vector3();
function updateAnnotations() {
pushArrow.getWorldPosition(pushAnchor);
pushAnchor.y += 0.48;
wheelAnchor.set(1.05, wheelRadius, 0.68);
cart.localToWorld(wheelAnchor);
brakeAnchor.set(1.05, 0.72, 0.69);
cart.localToWorld(brakeAnchor);
placeLabel(labelPush, pushAnchor, -12, -7);
placeLabel(labelWheel, wheelAnchor, 77, 29);
placeLabel(labelBrake, brakeAnchor, 86, -28);
}
// ------------------------------------------------------------
// Direct camera controls — no external control add-ons
// ------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.48,
1.3
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.006,
5.4,
13.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.69;
cameraState.pitch = 0.96;
cameraState.radius = 8.7;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.04);
updateSimulation(dt);
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```