Prompt specification
Build or customize the Three.js 3D scene "Moving furniture force vignette" 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: Moving furniture force vignette
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/moving-furniture-force-vignette-x1383
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: moving furniture force vignette. Compose a box, floor, push arrow, and optional wheeled platform; separate sliding-friction assumptions from rolling-resistance assumptions rather than treating them as interchangeable.
Working Three.js Starter (moving-furniture-force-vignette-x1383):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Furniture Force Lab</title>
<style>
:root {
color-scheme: dark;
--ink: #f4f7f9;
--muted: #b8c4cc;
--panel: rgba(18, 27, 34, 0.9);
--line: rgba(255, 255, 255, 0.12);
--orange: #ff9e3d;
--red: #ff6464;
--cyan: #60d9e8;
--green: #82e09a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e5eb;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#viewport,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
ellipse at 48% 45%,
transparent 34%,
rgba(10, 18, 24, 0.06) 63%,
rgba(10, 18, 24, 0.34) 100%
);
z-index: 2;
}
.title-card {
position: fixed;
top: 20px;
left: 22px;
z-index: 4;
max-width: min(430px, calc(100vw - 390px));
padding: 15px 18px;
border: 1px solid rgba(255, 255, 255, 0.28);
border-radius: 14px;
background: rgba(18, 27, 34, 0.82);
box-shadow: 0 12px 32px rgba(12, 24, 32, 0.2);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 5px;
color: #9bdce5;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(19px, 2.3vw, 28px);
line-height: 1.05;
}
.subtitle {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.panel {
position: fixed;
top: 20px;
right: 20px;
z-index: 5;
width: 342px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 17px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(8, 18, 24, 0.28);
backdrop-filter: blur(16px);
scrollbar-width: thin;
scrollbar-color: #536570 transparent;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
font-size: 14px;
font-weight: 800;
}
.live-dot {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-dot::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 10px rgba(130, 224, 154, 0.7);
content: "";
}
.segment {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
padding: 4px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(0, 0, 0, 0.15);
}
.segment button {
min-height: 38px;
border: 0;
border-radius: 8px;
color: var(--muted);
background: transparent;
cursor: pointer;
font-size: 12px;
font-weight: 800;
transition: 140ms ease;
}
.segment button.active {
color: #172127;
background: #dce8ed;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
.control {
margin-top: 15px;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
font-size: 12px;
}
.control-row label {
font-weight: 700;
}
output {
color: #aeeaf1;
font-variant-numeric: tabular-nums;
font-weight: 800;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
accent-color: #71d4df;
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: #81919b;
font-size: 9px;
}
.divider {
height: 1px;
margin: 15px 0;
background: var(--line);
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.metric {
min-height: 57px;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
}
.metric span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric strong {
font-size: 16px;
font-variant-numeric: tabular-nums;
}
.metric.orange strong {
color: var(--orange);
}
.metric.red strong {
color: var(--red);
}
.metric.green strong {
color: var(--green);
}
.status {
margin-top: 9px;
padding: 9px 10px;
border-left: 3px solid var(--cyan);
border-radius: 4px;
color: #dce8ed;
background: rgba(96, 217, 232, 0.08);
font-size: 11px;
font-weight: 800;
line-height: 1.4;
}
.model-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.model-note strong {
color: #eaf2f5;
}
.formula {
margin-top: 8px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 8px;
color: #c9d5db;
background: rgba(0, 0, 0, 0.15);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.55;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.actions button {
min-height: 40px;
border: 1px solid var(--line);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 255, 255, 0.07);
cursor: pointer;
font-size: 12px;
font-weight: 800;
}
.actions button:hover {
background: rgba(255, 255, 255, 0.12);
}
.actions .primary {
border-color: transparent;
color: #162228;
background: #8adce5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 11px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.swatch {
width: 13px;
height: 4px;
border-radius: 2px;
background: var(--orange);
}
.swatch.red {
background: var(--red);
}
.hint {
position: fixed;
bottom: 18px;
left: 22px;
z-index: 4;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 8px;
color: #263842;
background: rgba(241, 247, 249, 0.78);
box-shadow: 0 6px 20px rgba(15, 30, 40, 0.12);
font-size: 10px;
font-weight: 700;
backdrop-filter: blur(8px);
}
[hidden] {
display: none !important;
}
@media (max-width: 760px) {
.title-card {
top: 10px;
left: 10px;
max-width: calc(100vw - 20px);
padding: 11px 13px;
}
.subtitle {
display: none;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 46vh;
padding: 13px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport">
<canvas id="scene" aria-label="Interactive voxel furniture physics scene"></canvas>
<div class="vignette"></div>
</div>
<header class="title-card">
<div class="eyebrow">Voxel Mechanics Lab</div>
<h1>Moving Furniture: Force & Resistance</h1>
<p class="subtitle">
Compare direct sliding with a wheeled platform. Each mode uses a distinct
resistance model rather than treating friction and rolling resistance as interchangeable.
</p>
</header>
<aside class="panel" aria-label="Simulation controls">
<div class="panel-title">
<span>Force controls</span>
<span class="live-dot" id="liveStatus">Running</span>
</div>
<div class="segment" role="group" aria-label="Contact model">
<button id="slidingMode" class="active" type="button">Sliding on floor</button>
<button id="rollingMode" type="button">Rolling platform</button>
</div>
<div class="control">
<div class="control-row">
<label for="push">Applied push</label>
<output id="pushOut" for="push">320 N</output>
</div>
<input id="push" type="range" min="20" max="600" step="5" value="320">
<div class="range-ends"><span>20 N</span><span>600 N</span></div>
</div>
<div class="control">
<div class="control-row">
<label for="mass" id="massLabel">Furniture mass</label>
<output id="massOut" for="mass">60 kg</output>
</div>
<input id="mass" type="range" min="20" max="180" step="5" value="60">
<div class="range-ends"><span>20 kg</span><span>180 kg</span></div>
</div>
<div id="slidingControls">
<div class="control">
<div class="control-row">
<label for="muStatic">Static coefficient, μₛ</label>
<output id="muStaticOut" for="muStatic">0.48</output>
</div>
<input id="muStatic" type="range" min="0.20" max="0.80" step="0.01" value="0.48">
</div>
<div class="control">
<div class="control-row">
<label for="muKinetic">Kinetic coefficient, μₖ</label>
<output id="muKineticOut" for="muKinetic">0.36</output>
</div>
<input id="muKinetic" type="range" min="0.05" max="0.75" step="0.01" value="0.36">
</div>
</div>
<div id="rollingControls" hidden>
<div class="control">
<div class="control-row">
<label for="crr">Rolling-resistance coefficient, Cᵣᵣ</label>
<output id="crrOut" for="crr">0.025</output>
</div>
<input id="crr" type="range" min="0.005" max="0.080" step="0.001" value="0.025">
<div class="range-ends"><span>Easy rolling</span><span>High resistance</span></div>
</div>
</div>
<div class="divider"></div>
<div class="metrics">
<div class="metric orange">
<span>Applied force</span>
<strong id="metricForce">320 N</strong>
</div>
<div class="metric red">
<span id="resistanceTitle">Kinetic resistance</span>
<strong id="metricResistance">212 N</strong>
</div>
<div class="metric green">
<span>Net force</span>
<strong id="metricNet">108 N</strong>
</div>
<div class="metric">
<span>Speed</span>
<strong id="metricSpeed">0.00 m/s</strong>
</div>
</div>
<div class="status" id="statusText">Sliding</div>
<p class="model-note" id="modelNote"></p>
<div class="formula" id="formula"></div>
<div class="actions">
<button id="playPause" class="primary" type="button">Pause</button>
<button id="reset" type="button">Reset motion</button>
</div>
<div class="legend" aria-label="Force colors">
<span><i class="swatch"></i> Push</span>
<span><i class="swatch red"></i> Resistance</span>
</div>
</aside>
<div class="hint">Drag to orbit · Mouse wheel to zoom · Space to pause · R to reset</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, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e5eb);
scene.fog = new THREE.Fog(0xd9e5eb, 22, 40);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls: no OrbitControls or addons are imported.
const orbit = {
target: new THREE.Vector3(0, 0.55, 0),
radius: 16.5,
theta: 0.72,
phi: 0.94,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
orbit.dragging = true;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.pointerX;
const dy = event.clientY - orbit.pointerY;
orbit.pointerX = event.clientX;
orbit.pointerY = event.clientY;
orbit.theta -= dx * 0.007;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.006, 0.34, 1.38);
updateCamera();
});
function endDrag(event) {
orbit.dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("pointerleave", (event) => {
if (orbit.dragging && event.buttons === 0) endDrag(event);
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
9,
27
);
updateCamera();
},
{ passive: false }
);
canvas.style.cursor = "grab";
// Lighting.
scene.add(new THREE.HemisphereLight(0xeaf7ff, 0x64716a, 2.1));
const sun = new THREE.DirectionalLight(0xfff3df, 3.2);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xaadfff, 0.8);
fill.position.set(8, 5, -7);
scene.add(fill);
// Voxel floor.
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.93,
metalness: 0
});
const floorGeometry = new THREE.BoxGeometry(0.775, 0.16, 0.775);
const columns = 15;
const rows = 11;
const floorTiles = new THREE.InstancedMesh(
floorGeometry,
floorMaterial,
columns * rows
);
floorTiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
dummy.position.set(
(col - (columns - 1) / 2) * 0.8,
-0.08,
(row - (rows - 1) / 2) * 0.8
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
floorTiles.setMatrixAt(tileIndex, dummy.matrix);
const shade = 0.5 + ((col + row * 3) % 5) * 0.018;
color.setHSL(0.54, 0.12, shade);
floorTiles.setColorAt(tileIndex, color);
tileIndex++;
}
}
scene.add(floorTiles);
const floorBase = new THREE.Mesh(
new THREE.BoxGeometry(12.35, 0.34, 9.15),
new THREE.MeshStandardMaterial({
color: 0x81949d,
roughness: 0.95
})
);
floorBase.position.y = -0.29;
floorBase.receiveShadow = true;
scene.add(floorBase);
// Voxel rear wall for depth.
const wallGeometry = new THREE.BoxGeometry(0.77, 0.77, 0.25);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9
});
const wall = new THREE.InstancedMesh(
wallGeometry,
wallMaterial,
columns * 3
);
wall.receiveShadow = true;
let wallIndex = 0;
for (let level = 0; level < 3; level++) {
for (let col = 0; col < columns; col++) {
dummy.position.set(
(col - (columns - 1) / 2) * 0.8,
0.385 + level * 0.8,
-4.52
);
dummy.updateMatrix();
wall.setMatrixAt(wallIndex, dummy.matrix);
color.setHSL(0.55, 0.16, 0.79 + ((col + level) % 4) * 0.018);
wall.setColorAt(wallIndex, color);
wallIndex++;
}
}
scene.add(wall);
// Moving assembly.
const mover = new THREE.Group();
mover.position.x = -3.65;
scene.add(mover);
const crateGroup = new THREE.Group();
mover.add(crateGroup);
const cell = 0.42;
const nx = 5;
const ny = 4;
const nz = 4;
const crateGeometry = new THREE.BoxGeometry(cell * 0.95, cell * 0.95, cell * 0.95);
const crateMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82
});
const crateCells = new THREE.InstancedMesh(
crateGeometry,
crateMaterial,
nx * ny * nz
);
crateCells.castShadow = true;
crateCells.receiveShadow = true;
let crateIndex = 0;
for (let z = 0; z < nz; z++) {
for (let y = 0; y < ny; y++) {
for (let x = 0; x < nx; x++) {
dummy.position.set(
(x - (nx - 1) / 2) * cell,
(y + 0.5) * cell,
(z - (nz - 1) / 2) * cell
);
dummy.updateMatrix();
crateCells.setMatrixAt(crateIndex, dummy.matrix);
const edge = x === 0 || x === nx - 1 || z === 0 || z === nz - 1;
const plank = x % 2 === 0;
color.setHSL(
0.085,
edge ? 0.43 : 0.35,
plank ? 0.54 : 0.48
);
crateCells.setColorAt(crateIndex, color);
crateIndex++;
}
}
}
crateGroup.add(crateCells);
const strapMaterial = new THREE.MeshStandardMaterial({
color: 0x35444a,
roughness: 0.62,
metalness: 0.18
});
for (const x of [-0.63, 0.63]) {
const strap = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 1.63, 0.07),
strapMaterial
);
strap.position.set(x, 0.82, 0.865);
strap.castShadow = true;
crateGroup.add(strap);
}
const handleMaterial = new THREE.MeshStandardMaterial({
color: 0x202a2e,
roughness: 0.55
});
for (const x of [-0.27, 0.27]) {
const handle = new THREE.Mesh(
new THREE.BoxGeometry(0.32, 0.11, 0.09),
handleMaterial
);
handle.position.set(x, 0.82, 0.91);
handle.castShadow = true;
crateGroup.add(handle);
}
// Optional wheeled platform.
const platform = new THREE.Group();
mover.add(platform);
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0x667983,
roughness: 0.48,
metalness: 0.52
});
const deck = new THREE.Mesh(
new THREE.BoxGeometry(2.95, 0.18, 2.28),
metalMaterial
);
deck.position.y = 0.73;
deck.castShadow = true;
deck.receiveShadow = true;
platform.add(deck);
const deckTop = new THREE.Mesh(
new THREE.BoxGeometry(2.78, 0.07, 2.1),
new THREE.MeshStandardMaterial({
color: 0xa8bac1,
roughness: 0.7,
metalness: 0.25
})
);
deckTop.position.y = 0.855;
deckTop.castShadow = true;
platform.add(deckTop);
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0x263238,
roughness: 0.82
});
const hubMaterial = new THREE.MeshStandardMaterial({
color: 0xe5a43d,
roughness: 0.44,
metalness: 0.4
});
const wheelGroups = [];
const wheelRadius = 0.32;
for (const x of [-1.04, 1.04]) {
for (const z of [-0.91, 0.91]) {
const wheelGroup = new THREE.Group();
wheelGroup.position.set(x, 0.34, z);
wheelGroup.rotation.order = "YXZ";
const tire = new THREE.Mesh(
new THREE.BoxGeometry(0.64, 0.64, 0.24),
wheelMaterial
);
tire.castShadow = true;
wheelGroup.add(tire);
const hub = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.25, 0.29),
hubMaterial
);
hub.castShadow = true;
wheelGroup.add(hub);
platform.add(wheelGroup);
wheelGroups.push(wheelGroup);
}
}
// Voxel arrow helper. Its pivot is at the arrow tip.
function createVoxelArrow(hexColor) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: hexColor,
emissive: hexColor,
emissiveIntensity: 0.18,
roughness: 0.55
});
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(1.05, 0.14, 0.14),
material
);
shaft.position.x = -0.76;
shaft.castShadow = true;
group.add(shaft);
const headSizes = [0.2, 0.18, 0.16];
const headPositions = [-0.14, -0.30, -0.44];
for (let i = 0; i < headSizes.length; i++) {
const cube = new THREE.Mesh(
new THREE.BoxGeometry(headSizes[i], headSizes[i], 0.15),
material
);
cube.position.x = headPositions[i];
cube.castShadow = true;
group.add(cube);
}
return group;
}
const pushArrow = createVoxelArrow(0xff922f);
mover.add(pushArrow);
const resistanceArrow = createVoxelArrow(0xff5555);
resistanceArrow.rotation.y = Math.PI;
mover.add(resistanceArrow);
// Canvas-texture labels.
function makeLabel() {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.65, 0.66, 1);
sprite.renderOrder = 20;
let lastText = "";
function setText(text, accent = "#ffffff") {
if (text === lastText) return;
lastText = text;
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(18, 27, 34, 0.88)";
context.strokeStyle = accent;
context.lineWidth = 4;
context.beginPath();
context.roundRect(4, 8, 504, 112, 22);
context.fill();
context.stroke();
context.fillStyle = accent;
context.font = "800 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
texture.needsUpdate = true;
}
return { sprite, setText };
}
const pushLabel = makeLabel();
const resistanceLabel = makeLabel();
mover.add(pushLabel.sprite, resistanceLabel.sprite);
// Simulation state.
const G = 9.81;
const state = {
mode: "sliding",
running: true,
x: -3.65,
velocity: 0,
wheelAngle: 0,
push: 320,
mass: 60,
muStatic: 0.48,
muKinetic: 0.36,
crr: 0.025,
netForce: 0,
resistance: 0,
staticLimit: 0,
acceleration: 0,
status: "Sliding"
};
const ui = {
push: document.querySelector("#push"),
mass: document.querySelector("#mass"),
massLabel: document.querySelector("#massLabel"),
muStatic: document.querySelector("#muStatic"),
muKinetic: document.querySelector("#muKinetic"),
crr: document.querySelector("#crr"),
pushOut: document.querySelector("#pushOut"),
massOut: document.querySelector("#massOut"),
muStaticOut: document.querySelector("#muStaticOut"),
muKineticOut: document.querySelector("#muKineticOut"),
crrOut: document.querySelector("#crrOut"),
slidingMode: document.querySelector("#slidingMode"),
rollingMode: document.querySelector("#rollingMode"),
slidingControls: document.querySelector("#slidingControls"),
rollingControls: document.querySelector("#rollingControls"),
playPause: document.querySelector("#playPause"),
reset: document.querySelector("#reset"),
liveStatus: document.querySelector("#liveStatus"),
metricForce: document.querySelector("#metricForce"),
metricResistance: document.querySelector("#metricResistance"),
metricNet: document.querySelector("#metricNet"),
metricSpeed: document.querySelector("#metricSpeed"),
resistanceTitle: document.querySelector("#resistanceTitle"),
statusText: document.querySelector("#statusText"),
modelNote: document.querySelector("#modelNote"),
formula: document.querySelector("#formula")
};
function updateModelText() {
if (state.mode === "sliding") {
ui.resistanceTitle.textContent = "Sliding resistance";
ui.modelNote.innerHTML =
"<strong>Direct sliding model:</strong> the crate contacts the floor. " +
"Static friction can hold it up to <strong>μₛN</strong>; after breakaway, " +
"kinetic friction <strong>μₖN</strong> opposes motion. These are sliding-friction " +
"assumptions, not rolling resistance.";
ui.formula.innerHTML =
"N = mg<br>" +
"Fstatic,max = μₛN<br>" +
"Fkinetic = μₖN<br>" +
"Fnet = Fpush − Fkinetic while sliding";
} else {
ui.resistanceTitle.textContent = "Rolling resistance";
ui.modelNote.innerHTML =
"<strong>Ideal wheeled model:</strong> wheel slip and bearing drag are neglected. " +
"A rolling-resistance coefficient <strong>Cᵣᵣ</strong> creates an equivalent " +
"opposing force <strong>CᵣᵣN</strong>. No sliding-friction coefficient is used; " +
"the platform and cargo are treated as one combined mass.";
ui.formula.innerHTML =
"N = mg<br>" +
"Frolling = CᵣᵣN<br>" +
"Fnet = Fpush − Frolling<br>" +
"a = Fnet / m";
}
}
function resetMotion() {
state.x = -3.65;
state.velocity = 0;
state.wheelAngle = 0;
state.netForce = 0;
state.acceleration = 0;
state.status = state.mode === "sliding" ? "Ready to slide" : "Ready to roll";
}
function setMode(mode) {
state.mode = mode;
ui.slidingMode.classList.toggle("active", mode === "sliding");
ui.rollingMode.classList.toggle("active", mode === "rolling");
ui.slidingControls.hidden = mode !== "sliding";
ui.rollingControls.hidden = mode !== "rolling";
platform.visible = mode === "rolling";
crateGroup.position.y = mode === "rolling" ? 0.9 : 0.02;
resetMotion();
updateModelText();
}
ui.slidingMode.addEventListener("click", () => setMode("sliding"));
ui.rollingMode.addEventListener("click", () => setMode("rolling"));
ui.push.addEventListener("input", () => {
state.push = Number(ui.push.value);
ui.pushOut.textContent = `${state.push} N`;
});
ui.mass.addEventListener("input", () => {
state.mass = Number(ui.mass.value);
ui.massOut.textContent = `${state.mass} kg`;
ui.massLabel.textContent =
state.mode === "rolling" ? "Combined cargo + platform mass" : "Furniture mass";
});
ui.muStatic.addEventListener("input", () => {
state.muStatic = Number(ui.muStatic.value);
ui.muStaticOut.textContent = state.muStatic.toFixed(2);
if (state.muKinetic > state.muStatic) {
state.muKinetic = state.muStatic;
ui.muKinetic.value = state.muStatic;
ui.muKineticOut.textContent = state.muKinetic.toFixed(2);
}
});
ui.muKinetic.addEventListener("input", () => {
state.muKinetic = Number(ui.muKinetic.value);
ui.muKineticOut.textContent = state.muKinetic.toFixed(2);
});
ui.crr.addEventListener("input", () => {
state.crr = Number(ui.crr.value);
ui.crrOut.textContent = state.crr.toFixed(3);
});
ui.playPause.addEventListener("click", () => {
state.running = !state.running;
ui.playPause.textContent = state.running ? "Pause" : "Run";
ui.liveStatus.textContent = state.running ? "Running" : "Paused";
});
ui.reset.addEventListener("click", resetMotion);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
ui.playPause.click();
}
if (event.key.toLowerCase() === "r") {
resetMotion();
}
});
function simulate(dt) {
const normal = state.mass * G;
const push = state.push;
if (state.mode === "sliding") {
const staticLimit = state.muStatic * normal;
const kinetic = state.muKinetic * normal;
state.staticLimit = staticLimit;
if (state.velocity <= 0.0001) {
if (push <= staticLimit) {
state.velocity = 0;
state.acceleration = 0;
state.netForce = 0;
state.resistance = push;
state.status = "Held by static friction";
return;
}
state.resistance = kinetic;
state.netForce = push - kinetic;
state.acceleration = state.netForce / state.mass;
state.status = "Sliding";
} else {
state.resistance = kinetic;
state.netForce = push - kinetic;
state.acceleration = state.netForce / state.mass;
state.status = "Sliding";
}
} else {
const rollingResistance = state.crr * normal;
state.staticLimit = rollingResistance;
state.resistance = rollingResistance;
if (state.velocity <= 0.0001 && push <= rollingResistance) {
state.velocity = 0;
state.acceleration = 0;
state.netForce = 0;
state.status = "Held by rolling resistance";
return;
}
state.netForce = push - rollingResistance;
state.acceleration = state.netForce / state.mass;
state.status = "Rolling";
}
state.velocity += state.acceleration * dt;
if (state.velocity < 0) {
state.velocity = 0;
state.acceleration = 0;
}
const previousX = state.x;
state.x += state.velocity * dt;
if (state.x >= 4.05) {
state.x = 4.05;
state.velocity = 0;
state.acceleration = 0;
state.netForce = 0;
state.status = "Destination reached";
}
state.wheelAngle -= (state.x - previousX) / wheelRadius;
}
function updateVisuals() {
mover.position.x = state.x;
for (const wheel of wheelGroups) {
wheel.rotation.z = state.wheelAngle;
}
const pushLength = THREE.MathUtils.clamp(
0.85 + state.push / 600 * 1.65,
0.9,
2.5
);
const resistanceLength = THREE.MathUtils.clamp(
0.35 + state.resistance / 400 * 1.25,
0.4,
1.6
);
const rolling = state.mode === "rolling";
const tipX = rolling ? -1.52 : -1.08;
const arrowY = rolling ? 1.38 : 0.87;
pushArrow.position.set(tipX, arrowY, 0);
pushArrow.scale.x = pushLength;
pushLabel.sprite.position.set(
tipX - pushLength * 0.56,
arrowY + 0.55,
0.02
);
pushLabel.setText(`PUSH ${Math.round(state.push)} N`, "#ffad59");
const resistanceTip = rolling ? 1.5 : 1.08;
resistanceArrow.position.set(resistanceTip, 0.28, 1.34);
resistanceArrow.scale.x = resistanceLength;
resistanceLabel.sprite.position.set(
resistanceTip + resistanceLength * 0.58,
0.47,
1.45
);
const resistanceName =
state.mode === "sliding"
? state.velocity > 0.001
? "SLIDE"
: "STATIC"
: "ROLL";
resistanceLabel.setText(
`${resistanceName} ${Math.round(state.resistance)} N`,
"#ff7777"
);
}
function updateUI() {
ui.metricForce.textContent = `${Math.round(state.push)} N`;
ui.metricResistance.textContent = `${Math.round(state.resistance)} N`;
ui.metricNet.textContent = `${Math.round(state.netForce)} N`;
ui.metricSpeed.textContent = `${state.velocity.toFixed(2)} m/s`;
ui.statusText.textContent = state.status;
}
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
setMode(state.mode);
ui.massLabel.textContent = "Furniture mass";
const clock = new THREE.Clock();
let uiAccumulator = 0;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.033);
if (state.running) {
simulate(dt);
}
updateVisuals();
uiAccumulator += dt;
if (uiAccumulator > 0.06) {
updateUI();
uiAccumulator = 0;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```