Prompt specification
Build or customize the Three.js 3D scene "Foot-contact geometry explorer" 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: Foot-contact geometry explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/foot-contact-geometry-explorer-x0984
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows the human foot arch. Let viewers change a toy arch shape and load position; visualize support contacts and moment balance without claiming diagnosis, footwear selection, or real tissue stress predictions. Voxel style.
Working Three.js Starter (foot-contact-geometry-explorer-x0984):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Foot Arch — Mechanical Toy</title>
<style>
:root {
color-scheme: dark;
--bg: #07131e;
--panel: rgba(9, 24, 37, 0.88);
--panel-strong: rgba(8, 21, 33, 0.96);
--line: rgba(168, 218, 238, 0.17);
--text: #edf8fb;
--muted: #91aebb;
--cyan: #55e6df;
--blue: #67a8ff;
--yellow: #ffd166;
--coral: #ff7d72;
--green: #9af58a;
--orange: #ffae63;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 22px;
left: 24px;
z-index: 4;
max-width: 470px;
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.45);
}
.eyebrow {
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 3px;
font-size: clamp(28px, 3vw, 44px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 820;
}
.brand p {
margin: 8px 0 0;
max-width: 430px;
color: #b6ccd5;
font-size: 13px;
line-height: 1.5;
}
.disclaimer {
position: fixed;
top: 22px;
right: 22px;
z-index: 5;
width: min(350px, calc(100vw - 44px));
padding: 12px 14px;
border: 1px solid rgba(255, 209, 102, 0.32);
border-radius: 12px;
background: rgba(31, 28, 18, 0.83);
backdrop-filter: blur(14px);
color: #e6ddc1;
font-size: 11.5px;
line-height: 1.45;
box-shadow: 0 14px 45px rgba(0, 0, 0, 0.22);
}
.disclaimer strong {
display: block;
margin-bottom: 3px;
color: var(--yellow);
font-size: 10px;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(18px) saturate(125%);
box-shadow:
0 18px 60px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
}
.controls {
left: 22px;
top: 144px;
width: 300px;
padding: 17px;
max-height: calc(100vh - 185px);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #315166 transparent;
}
.stats {
right: 22px;
top: 144px;
width: 292px;
padding: 17px;
max-height: calc(100vh - 185px);
overflow: auto;
scrollbar-width: thin;
scrollbar-color: #315166 transparent;
}
.panel h2 {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 15px;
font-size: 13px;
letter-spacing: 0.04em;
}
.panel h2 span {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.control {
margin-bottom: 14px;
}
.control label,
.metric-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
color: #c8dbe2;
font-size: 11.5px;
font-weight: 650;
}
.control output {
color: var(--cyan);
font-size: 10.5px;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 4px;
border-radius: 4px;
background: linear-gradient(90deg, #245064, #1c3645);
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
margin-top: -5.5px;
appearance: none;
border: 2px solid #d9ffff;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(85, 230, 223, 0.12);
}
input[type="range"]::-moz-range-track {
height: 4px;
border-radius: 4px;
background: #234657;
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #d9ffff;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(85, 230, 223, 0.12);
}
.separator {
height: 1px;
margin: 17px 0;
background: var(--line);
}
.toggles {
display: grid;
gap: 9px;
margin: 4px 0 15px;
}
.toggle {
display: flex;
align-items: center;
gap: 8px;
color: #b9cdd5;
font-size: 11px;
cursor: pointer;
}
.toggle input {
accent-color: var(--cyan);
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
min-height: 36px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
font-size: 10.5px;
font-weight: 750;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(85, 230, 223, 0.55);
background: rgba(85, 230, 223, 0.09);
}
button:active {
transform: translateY(1px);
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 7px;
width: 100%;
margin-bottom: 14px;
padding: 9px 10px;
border: 1px solid rgba(154, 245, 138, 0.28);
border-radius: 9px;
background: rgba(154, 245, 138, 0.08);
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status-pill::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
content: "";
}
.status-pill.unbalanced {
border-color: rgba(255, 174, 99, 0.32);
background: rgba(255, 174, 99, 0.08);
color: var(--orange);
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 15px;
}
.metric {
min-height: 73px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.metric-label {
margin: 0 0 8px;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.metric-value {
font-size: 19px;
font-weight: 820;
font-variant-numeric: tabular-nums;
}
.metric-state {
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
text-transform: uppercase;
}
.metric.active .metric-value {
color: var(--green);
}
.moment-row {
margin-bottom: 11px;
}
.moment-row .metric-label {
margin-bottom: 5px;
}
.moment-track {
height: 6px;
overflow: hidden;
border-radius: 6px;
background: rgba(255, 255, 255, 0.065);
}
.moment-track i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
transition: width 140ms ease;
}
#loadMomentBar {
background: var(--coral);
}
#supportMomentBar {
background: var(--cyan);
}
#netMomentBar {
background: var(--green);
}
.equation {
min-height: 56px;
margin-top: 13px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(0, 0, 0, 0.16);
color: #c8dce4;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
line-height: 1.55;
}
.fine-print {
margin: 13px 0 0;
color: #829aa5;
font-size: 9.5px;
line-height: 1.5;
}
.footer {
position: fixed;
z-index: 4;
left: 50%;
bottom: 15px;
transform: translateX(-50%);
padding: 8px 13px;
border: 1px solid rgba(168, 218, 238, 0.13);
border-radius: 999px;
background: rgba(7, 19, 30, 0.74);
color: #849ca8;
font-size: 9.5px;
text-align: center;
white-space: nowrap;
pointer-events: none;
}
.legend {
position: fixed;
z-index: 4;
left: 340px;
bottom: 17px;
display: flex;
gap: 12px;
align-items: center;
color: #91a8b3;
font-size: 9.5px;
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.dot {
width: 7px;
height: 7px;
border-radius: 2px;
}
#boot {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 1050px) {
.legend {
display: none;
}
.controls {
width: 278px;
}
.stats {
width: 264px;
}
}
@media (max-width: 760px) {
.brand {
top: 14px;
left: 14px;
}
.brand p {
display: none;
}
.disclaimer {
top: 91px;
right: 12px;
width: calc(100vw - 24px);
}
.controls {
top: auto;
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
max-height: 37vh;
padding: 13px;
}
.stats {
top: auto;
right: 10px;
bottom: calc(37vh + 20px);
width: 235px;
max-height: 33vh;
padding: 13px;
}
.footer {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel foot arch model"></canvas>
<header class="brand">
<div class="eyebrow">Explorable mechanics / 01</div>
<h1>Voxel Foot Arch</h1>
<p>
Change a simplified arch, move a point load, and watch two support
contacts respond in this small rigid-body toy.
</p>
</header>
<div class="disclaimer">
<strong>Mechanical illustration only</strong>
This toy does not diagnose conditions, recommend footwear, assess gait, or
predict real tissue stress.
</div>
<aside class="panel controls" aria-label="Toy model controls">
<h2>Toy setup <span>medial-side view</span></h2>
<div class="control">
<label for="archHeight">
Arch height
<output id="archHeightOut">0.64 u</output>
</label>
<input id="archHeight" type="range" min="0.25" max="0.95" step="0.01" value="0.64" />
</div>
<div class="control">
<label for="archSpan">
Arch span
<output id="archSpanOut">66% of length</output>
</label>
<input id="archSpan" type="range" min="0.50" max="0.72" step="0.01" value="0.66" />
</div>
<div class="control">
<label for="footLength">
Foot length
<output id="footLengthOut">4.40 u</output>
</label>
<input id="footLength" type="range" min="4.00" max="4.80" step="0.05" value="4.40" />
</div>
<div class="separator"></div>
<div class="control">
<label for="loadPosition">
Load position
<output id="loadPositionOut">56% from rear</output>
</label>
<input id="loadPosition" type="range" min="0" max="1" step="0.01" value="0.56" />
</div>
<div class="control">
<label for="loadAmount">
Toy load
<output id="loadAmountOut">1.2 u</output>
</label>
<input id="loadAmount" type="range" min="0.5" max="2.5" step="0.1" value="1.2" />
</div>
<div class="toggles">
<label class="toggle">
<input id="showRail" type="checkbox" checked />
Show moment balance rail
</label>
<label class="toggle">
<input id="showReactions" type="checkbox" checked />
Show reaction arrows
</label>
</div>
<div class="actions">
<button id="resetToy" type="button">Reset toy</button>
<button id="resetView" type="button">Reset view</button>
</div>
<p class="fine-print">
“u” means arbitrary toy units. The geometry and forces are intentionally
simplified and are not anatomical measurements.
</p>
</aside>
<aside class="panel stats" aria-label="Support and moment readouts">
<h2>Support + moment <span>toy calculation</span></h2>
<div id="statusPill" class="status-pill">Toy balanced · ΣM = 0</div>
<div class="metrics">
<div id="rearMetric" class="metric active">
<div class="metric-label">Rear contact</div>
<div id="rearValue" class="metric-value">0.59 u</div>
<div id="rearState" class="metric-state">Active</div>
</div>
<div id="frontMetric" class="metric active">
<div class="metric-label">Forefoot contact</div>
<div id="frontValue" class="metric-value">0.61 u</div>
<div id="frontState" class="metric-state">Active</div>
</div>
</div>
<div class="moment-row">
<div class="metric-label">
<span>Load moment</span>
<span id="loadMomentValue">0.00</span>
</div>
<div class="moment-track"><i id="loadMomentBar"></i></div>
</div>
<div class="moment-row">
<div class="metric-label">
<span>Opposing support moment</span>
<span id="supportMomentValue">0.00</span>
</div>
<div class="moment-track"><i id="supportMomentBar"></i></div>
</div>
<div class="moment-row">
<div class="metric-label">
<span>Net moment</span>
<span id="netMomentValue">0.00</span>
</div>
<div class="moment-track"><i id="netMomentBar"></i></div>
</div>
<div id="equation" class="equation"></div>
<p class="fine-print">
The rail shows the direction of a net moment when the point load lies
outside the two-contact support span. A balanced toy setup can have
opposite moments of equal magnitude.
</p>
</aside>
<div class="legend" aria-hidden="true">
<span><i class="dot" style="background:#ffd166"></i>Point load</span>
<span><i class="dot" style="background:#9af58a"></i>Active contact</span>
<span><i class="dot" style="background:#55e6df"></i>Moment rail</span>
</div>
<div class="footer">
Drag to orbit · Wheel to zoom · Double-click to reset view
</div>
<div id="boot">Loading voxel lab…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07131e);
scene.fog = new THREE.Fog(0x07131e, 10, 22);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 0.9, 0);
const cameraState = {
yaw: 0.10,
elevation: 0.19,
radius: 7.45
};
function applyCamera() {
const horizontal = cameraState.radius * Math.cos(cameraState.elevation);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraState.yaw),
cameraTarget.y + cameraState.radius * Math.sin(cameraState.elevation),
cameraTarget.z + horizontal * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraState.yaw = 0.10;
cameraState.elevation = 0.19;
cameraState.radius = 7.45;
applyCamera();
}
applyCamera();
scene.add(new THREE.HemisphereLight(0xc8f1ff, 0x10202a, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x44dce2, 18, 10, 2);
cyanLight.position.set(-3.2, 2.8, 3.5);
scene.add(cyanLight);
const coralLight = new THREE.PointLight(0xff756c, 11, 9, 2);
coralLight.position.set(3.5, 1.4, 2.7);
scene.add(coralLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(24, 18),
new THREE.MeshStandardMaterial({
color: 0x091923,
roughness: 0.95,
metalness: 0.03
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.014;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x315365, 0x19313f);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// -------------------------------------------------------------------------
// Model state and DOM
// -------------------------------------------------------------------------
const defaults = {
archHeight: 0.64,
archSpan: 0.66,
footLength: 4.40,
loadPosition: 0.56,
loadAmount: 1.2,
showRail: true,
showReactions: true
};
const state = { ...defaults };
const ui = {
archHeight: document.querySelector("#archHeight"),
archSpan: document.querySelector("#archSpan"),
footLength: document.querySelector("#footLength"),
loadPosition: document.querySelector("#loadPosition"),
loadAmount: document.querySelector("#loadAmount"),
showRail: document.querySelector("#showRail"),
showReactions: document.querySelector("#showReactions"),
archHeightOut: document.querySelector("#archHeightOut"),
archSpanOut: document.querySelector("#archSpanOut"),
footLengthOut: document.querySelector("#footLengthOut"),
loadPositionOut: document.querySelector("#loadPositionOut"),
loadAmountOut: document.querySelector("#loadAmountOut"),
statusPill: document.querySelector("#statusPill"),
rearMetric: document.querySelector("#rearMetric"),
frontMetric: document.querySelector("#frontMetric"),
rearValue: document.querySelector("#rearValue"),
frontValue: document.querySelector("#frontValue"),
rearState: document.querySelector("#rearState"),
frontState: document.querySelector("#frontState"),
loadMomentValue: document.querySelector("#loadMomentValue"),
supportMomentValue: document.querySelector("#supportMomentValue"),
netMomentValue: document.querySelector("#netMomentValue"),
loadMomentBar: document.querySelector("#loadMomentBar"),
supportMomentBar: document.querySelector("#supportMomentBar"),
netMomentBar: document.querySelector("#netMomentBar"),
equation: document.querySelector("#equation")
};
const rearT = 0.13;
const voxelSize = 0.18;
const topProfile = [
[0.00, 1.35],
[0.06, 1.78],
[0.18, 1.82],
[0.33, 1.42],
[0.50, 1.26],
[0.70, 1.06],
[0.82, 0.76],
[0.94, 0.50],
[1.00, 0.30]
];
const depthProfile = [
[0.00, 0.22],
[0.14, 0.38],
[0.48, 0.42],
[0.78, 0.37],
[0.92, 0.24],
[1.00, 0.13]
];
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
function sampleProfile(t, profile) {
if (t <= profile[0][0]) return profile[0][1];
for (let i = 0; i < profile.length - 1; i++) {
const a = profile[i];
const b = profile[i + 1];
if (t <= b[0]) {
const local = smoothstep(a[0], b[0], t);
return THREE.MathUtils.lerp(a[1], b[1], local);
}
}
return profile[profile.length - 1][1];
}
function geometry() {
const xMin = -state.footLength / 2;
const frontT = rearT + state.archSpan;
return {
xMin,
xMax: xMin + state.footLength,
frontT,
rearX: xMin + state.footLength * rearT,
frontX: xMin + state.footLength * frontT
};
}
function topAt(x) {
const g = geometry();
const t = clamp((x - g.xMin) / state.footLength, 0, 1);
return sampleProfile(t, topProfile);
}
function bottomAt(x) {
const g = geometry();
const t = clamp((x - g.xMin) / state.footLength, 0, 1);
if (t <= rearT || t >= g.frontT) return 0.12;
const u = (t - rearT) / state.archSpan;
const hump = Math.pow(Math.sin(Math.PI * u), 1.25);
return Math.min(0.12 + state.archHeight * hump, topAt(x) - 0.16);
}
function hash3(x, y, z) {
const value = Math.sin(x * 127.1 + y * 311.7 + z * 74.7) * 43758.5453;
return value - Math.floor(value);
}
// -------------------------------------------------------------------------
// Sprite labels created directly with CanvasTexture
// -------------------------------------------------------------------------
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function createLabel(text, options = {}) {
const canvasLabel = document.createElement("canvas");
canvasLabel.width = 512;
canvasLabel.height = 128;
const context = canvasLabel.getContext("2d");
const texture = new THREE.CanvasTexture(canvasLabel);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const width = options.width ?? 1.7;
sprite.scale.set(width, width / 4, 1);
sprite.renderOrder = 20;
sprite.userData.canvas = canvasLabel;
sprite.userData.context = context;
sprite.userData.texture = texture;
sprite.userData.color = options.color ?? "#eaf7fb";
sprite.userData.background = options.background ?? "rgba(7, 19, 30, 0.88)";
updateLabel(sprite, text);
return sprite;
}
function updateLabel(sprite, text, color) {
const context = sprite.userData.context;
const canvasLabel = sprite.userData.canvas;
if (color) sprite.userData.color = color;
context.clearRect(0, 0, canvasLabel.width, canvasLabel.height);
roundedRect(
context,
7,
9,
canvasLabel.width - 14,
canvasLabel.height - 18,
22
);
context.fillStyle = sprite.userData.background;
context.fill();
context.strokeStyle = "rgba(170, 224, 240, 0.24)";
context.lineWidth = 2;
context.stroke();
context.fillStyle = sprite.userData.color;
context.font = "700 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvasLabel.width / 2, canvasLabel.height / 2 + 1);
sprite.userData.texture.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Voxel foot
// -------------------------------------------------------------------------
const voxelGeometry = new THREE.BoxGeometry(
voxelSize * 0.91,
voxelSize * 0.91,
voxelSize * 0.91
);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.86,
metalness: 0.02
});
let footMesh = null;
function buildFoot() {
if (footMesh) {
scene.remove(footMesh);
if (typeof footMesh.dispose === "function") footMesh.dispose();
}
const g = geometry();
const xCount = Math.ceil(state.footLength / voxelSize);
const yCount = 13;
const zLayers = [-0.27, -0.09, 0.09, 0.27];
const cells = [];
for (let ix = 0; ix < xCount; ix++) {
const x = g.xMin + (ix + 0.5) * voxelSize;
if (x > g.xMax) continue;
const t = (x - g.xMin) / state.footLength;
const top = sampleProfile(t, topProfile);
const bottom = bottomAt(x);
const depth = sampleProfile(t, depthProfile);
for (let iy = 0; iy < yCount; iy++) {
const y = 0.12 + (iy + 0.5) * voxelSize;
if (y > top || y < bottom) continue;
const localRows = Math.max(0, (y - bottom) / voxelSize);
for (let iz = 0; iz < zLayers.length; iz++) {
const z = zLayers[iz];
if (Math.abs(z) > depth) continue;
cells.push({ x, y, z, ix, iy, iz, t, localRows, top, bottom });
}
}
}
footMesh = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
cells.length
);
footMesh.castShadow = true;
footMesh.receiveShadow = true;
footMesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
cells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.updateMatrix();
footMesh.setMatrixAt(index, dummy.matrix);
const variation = hash3(cell.ix, cell.iy, cell.iz);
const inArch =
cell.t > rearT + 0.02 &&
cell.t < g.frontT - 0.02 &&
cell.localRows < 0.9;
const nearTop = cell.top - cell.y < voxelSize * 0.7;
if (inArch) {
color.setHSL(
0.49 + variation * 0.025,
0.68,
0.50 + variation * 0.11
);
} else {
color.setHSL(
0.055 + variation * 0.018,
0.28 + variation * 0.12,
(nearTop ? 0.67 : 0.58) + variation * 0.09
);
}
footMesh.setColorAt(index, color);
});
footMesh.instanceMatrix.needsUpdate = true;
if (footMesh.instanceColor) footMesh.instanceColor.needsUpdate = true;
scene.add(footMesh);
}
// -------------------------------------------------------------------------
// Contact pads, arrows, and labels
// -------------------------------------------------------------------------
function createSupportPad() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0x9af58a,
emissive: 0x4fff72,
emissiveIntensity: 0.36,
roughness: 0.72
});
const geometryPad = new THREE.BoxGeometry(0.115, 0.12, 0.115);
for (let x = -1; x <= 1; x++) {
for (let z = -1; z <= 1; z++) {
const cube = new THREE.Mesh(geometryPad, material);
cube.position.set(x * 0.115, 0.06, z * 0.115);
cube.castShadow = true;
cube.receiveShadow = true;
group.add(cube);
}
}
group.userData.material = material;
return group;
}
const rearPad = createSupportPad();
const frontPad = createSupportPad();
scene.add(rearPad, frontPad);
function setPadActive(pad, active) {
const material = pad.userData.material;
material.color.set(active ? 0x9af58a : 0x344a55);
material.emissive.set(active ? 0x4fff72 : 0x101a20);
material.emissiveIntensity = active ? 0.38 : 0.05;
}
function createArrow(color, direction = "up") {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.35,
roughness: 0.48,
metalness: 0.12
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.027, 1, 10),
material
);
const cone = new THREE.Mesh(
new THREE.ConeGeometry(0.086, 0.16, 10),
material
);
if (direction === "down") cone.rotation.z = Math.PI;
group.add(shaft, cone);
group.userData = { shaft, cone, material };
return group;
}
function sizeArrow(arrow, height) {
const { shaft, cone } = arrow.userData;
const shaftHeight = Math.max(0.08, height - 0.16);
shaft.scale.y = shaftHeight;
if (arrow.userData.direction === "down") {
shaft.position.y = -shaftHeight / 2;
cone.position.y = -(height - 0.08);
} else {
shaft.position.y = shaftHeight / 2;
cone.position.y = height - 0.08;
}
}
createArrow.color = null;
const rearArrow = createArrow(0x9af58a, "up");
const frontArrow = createArrow(0x9af58a, "up");
const loadArrow = createArrow(0xffd166, "down");
loadArrow.userData.direction = "down";
scene.add(rearArrow, frontArrow, loadArrow);
const rearLabel = createLabel("REAR CONTACT", {
width: 1.55,
color: "#b9ffb0"
});
const frontLabel = createLabel("FOREFOOT CONTACT", {
width: 1.85,
color: "#b9ffb0"
});
const loadLabel = createLabel("POINT LOAD · 1.2 u", {
width: 1.85,
color: "#ffe6a0"
});
const statusLabel = createLabel("TOY BALANCED · ΣM = 0", {
width: 2.65,
color: "#aef7a0",
background: "rgba(11, 35, 25, 0.92)"
});
scene.add(rearLabel, frontLabel, loadLabel, statusLabel);
const loadMarker = new THREE.Group();
const loadMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0xffaa32,
emissiveIntensity: 0.45,
roughness: 0.55
});
const markerGeometry = new THREE.BoxGeometry(0.075, 0.075, 0.075);
for (let x = -1; x <= 1; x++) {
for (let z = -1; z <= 1; z++) {
const cube = new THREE.Mesh(markerGeometry, loadMarkerMaterial);
cube.position.set(x * 0.078, 0, z * 0.078);
cube.castShadow = true;
loadMarker.add(cube);
}
}
scene.add(loadMarker);
// -------------------------------------------------------------------------
// Moment balance rail
// -------------------------------------------------------------------------
const balanceGroup = new THREE.Group();
scene.add(balanceGroup);
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x55e6df,
emissive: 0x1fa7a6,
emissiveIntensity: 0.36,
roughness: 0.42,
metalness: 0.25
});
const railBeam = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.055, 0.055),
railMaterial
);
const railPivotA = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.15, 0.15),
railMaterial
);
const railPivotB = railPivotA.clone();
const railMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.13, 0.13),
new THREE.MeshStandardMaterial({
color: 0xff7d72,
emissive: 0xff5e54,
emissiveIntensity: 0.4
})
);
const railStem = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.25, 0.035),
new THREE.MeshStandardMaterial({
color: 0xff7d72,
emissive: 0xff5e54,
emissiveIntensity: 0.28
})
);
railStem.position.y = 0.16;
railMarker.add(railStem);
balanceGroup.add(railBeam, railPivotA, railPivotB, railMarker);
// -------------------------------------------------------------------------
// Toy rigid-body calculation
// -------------------------------------------------------------------------
function updateOutputs() {
ui.archHeightOut.value = `${state.archHeight.toFixed(2)} u`;
ui.archSpanOut.value = `${Math.round(state.archSpan * 100)}% of length`;
ui.footLengthOut.value = `${state.footLength.toFixed(2)} u`;
ui.loadPositionOut.value = `${Math.round(state.loadPosition * 100)}% from rear`;
ui.loadAmountOut.value = `${state.loadAmount.toFixed(1)} u`;
}
function updateDynamics() {
const g = geometry();
const span = g.frontX - g.rearX;
const loadX = g.xMin + state.footLength * state.loadPosition;
const P = state.loadAmount;
let rearReaction = 0;
let frontReaction = 0;
let balanced = false;
let pivotX = g.rearX;
let pivotIsFront = false;
let railAngle = 0;
let loadMoment = 0;
let supportMoment = 0;
let netMoment = 0;
if (loadX < g.rearX) {
rearReaction = P;
frontReaction = 0;
pivotX = g.rearX;
pivotIsFront = false;
loadMoment = P * (g.rearX - loadX);
supportMoment = 0;
netMoment = loadMoment;
railAngle = Math.min(0.27, (netMoment / Math.max(P * span, 0.001)) * 0.9);
} else if (loadX > g.frontX) {
rearReaction = 0;
frontReaction = P;
pivotX = g.frontX;
pivotIsFront = true;
loadMoment = P * (loadX - g.frontX);
supportMoment = 0;
netMoment = -loadMoment;
railAngle = -Math.min(0.27, (netMoment / Math.max(P * span, 0.001)) * 0.9);
} else {
frontReaction = P * ((loadX - g.rearX) / span);
rearReaction = P - frontReaction;
balanced = true;
pivotX = g.rearX;
pivotIsFront = false;
loadMoment = P * (loadX - g.rearX);
supportMoment = frontReaction * span;
netMoment = loadMoment - supportMoment;
railAngle = 0;
}
const rearActive = rearReaction > 0.005;
const frontActive = frontReaction > 0.005;
rearPad.position.x = g.rearX;
frontPad.position.x = g.frontX;
setPadActive(rearPad, rearActive);
setPadActive(frontPad, frontActive);
// Upward support reactions.
rearArrow.visible = ui.showReactions.checked && rearActive;
frontArrow.visible = ui.showReactions.checked && frontActive;
rearArrow.position.set(g.rearX, 0.12, 0.62);
frontArrow.position.set(g.frontX, 0.12, 0.62);
const rearHeight = 0.22 + 0.78 * (rearReaction / P);
const frontHeight = 0.22 + 0.78 * (frontReaction / P);
sizeArrow(rearArrow, rearHeight);
sizeArrow(frontArrow, frontHeight);
rearLabel.position.set(g.rearX, 0.25 + rearHeight, 0.70);
frontLabel.position.set(g.frontX, 0.25 + frontHeight, 0.70);
updateLabel(
rearLabel,
rearActive
? `REAR · ${rearReaction.toFixed(2)} u`
: "REAR · NO CONTACT",
rearActive ? "#b9ffb0" : "#8da1aa"
);
updateLabel(
frontLabel,
frontActive
? `FOREFOOT · ${frontReaction.toFixed(2)} u`
: "FOREFOOT · NO CONTACT",
frontActive ? "#b9ffb0" : "#8da1aa"
);
// Downward point load.
const loadTop = topAt(loadX);
const loadHeight = 0.53 + state.loadAmount * 0.08;
loadArrow.position.set(loadX, loadTop + 0.73, 0);
sizeArrow(loadArrow, loadHeight);
loadMarker.position.set(loadX, loadTop + 0.045, 0);
loadLabel.position.set(loadX, loadTop + 1.12, 0.12);
updateLabel(loadLabel, `POINT LOAD · ${P.toFixed(1)} u`, "#ffe6a0");
// Balance rail.
balanceGroup.visible = ui.showRail.checked;
balanceGroup.position.set(pivotX, 0.27, 1.20);
balanceGroup.rotation.z = railAngle;
if (pivotIsFront) {
railBeam.position.x = -span / 2;
railPivotA.position.x = 0;
railPivotB.position.x = -span;
railMarker.position.x = loadX - pivotX;
} else {
railBeam.position.x = span / 2;
railPivotA.position.x = 0;
railPivotB.position.x = span;
railMarker.position.x = loadX - pivotX;
}
railBeam.scale.x = span;
// Scene status label.
const labelX = g.xMin + state.footLength * 0.49;
statusLabel.position.set(labelX, 2.25, 0.3);
if (balanced) {
updateLabel(statusLabel, "TOY BALANCED · ΣM = 0", "#aef7a0");
} else {
updateLabel(statusLabel, "UNBALANCED TOY LOAD · ΣM ≠ 0", "#ffc38f");
}
// Numeric readouts.
ui.rearValue.textContent = `${rearReaction.toFixed(2)} u`;
ui.frontValue.textContent = `${frontReaction.toFixed(2)} u`;
ui.rearMetric.classList.toggle("active", rearActive);
ui.frontMetric.classList.toggle("active", frontActive);
ui.rearState.textContent = rearActive ? "Active" : "Lifted in toy";
ui.frontState.textContent = frontActive ? "Active" : "Lifted in toy";
ui.loadMomentValue.textContent = loadMoment.toFixed(2);
ui.supportMomentValue.textContent = supportMoment.toFixed(2);
ui.netMomentValue.textContent = Math.abs(netMoment).toFixed(2);
const maxMoment = Math.max(loadMoment, supportMoment, Math.abs(netMoment), 0.001);
ui.loadMomentBar.style.width = `${(loadMoment / maxMoment) * 100}%`;
ui.supportMomentBar.style.width = `${(supportMoment / maxMoment) * 100}%`;
ui.netMomentBar.style.width = `${(Math.abs(netMoment) / maxMoment) * 100}%`;
ui.netMomentBar.style.background = balanced ? "#9af58a" : "#ffae63";
if (balanced) {
const lever = loadX - g.rearX;
ui.equation.innerHTML =
`About the rear contact:<br>` +
`P × d = Rf × L<br>` +
`${P.toFixed(2)} × ${lever.toFixed(2)} = ` +
`${frontReaction.toFixed(2)} × ${span.toFixed(2)}<br>` +
`<span style="color:#9af58a">Equal and opposite moments.</span>`;
ui.statusPill.textContent = "Toy balanced · ΣM = 0";
ui.statusPill.classList.remove("unbalanced");
} else {
const lever = Math.abs(loadX - pivotX);
ui.equation.innerHTML =
`Load outside contact span:<br>` +
`P × d = ${P.toFixed(2)} × ${lever.toFixed(2)}<br>` +
`<span style="color:#ffae63">No opposing contact moment.</span>`;
ui.statusPill.textContent = "Unbalanced toy load · ΣM ≠ 0";
ui.statusPill.classList.add("unbalanced");
}
}
// -------------------------------------------------------------------------
// Controls
// -------------------------------------------------------------------------
function bindRange(input, key, geometryChanged = false) {
input.addEventListener("input", () => {
state[key] = Number(input.value);
if (geometryChanged) buildFoot();
updateOutputs();
updateDynamics();
});
}
bindRange(ui.archHeight, "archHeight", true);
bindRange(ui.archSpan, "archSpan", true);
bindRange(ui.footLength, "footLength", true);
bindRange(ui.loadPosition, "loadPosition", false);
bindRange(ui.loadAmount, "loadAmount", false);
ui.showRail.addEventListener("change", updateDynamics);
ui.showReactions.addEventListener("change", updateDynamics);
document.querySelector("#resetView").addEventListener("click", resetCamera);
document.querySelector("#resetToy").addEventListener("click", () => {
Object.assign(state, defaults);
ui.archHeight.value = state.archHeight;
ui.archSpan.value = state.archSpan;
ui.footLength.value = state.footLength;
ui.loadPosition.value = state.loadPosition;
ui.loadAmount.value = state.loadAmount;
ui.showRail.checked = state.showRail;
ui.showReactions.checked = state.showReactions;
buildFoot();
updateOutputs();
updateDynamics();
resetCamera();
});
// Direct camera controls; no external controls module is used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.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.elevation = clamp(
cameraState.elevation + dy * 0.0045,
0.055,
0.68
);
applyCamera();
});
function stopDragging(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius + event.deltaY * 0.0045,
5.1,
11.5
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
if (window.innerWidth < 760) {
cameraState.radius = Math.max(cameraState.radius, 8.1);
}
applyCamera();
});
// -------------------------------------------------------------------------
// Start
// -------------------------------------------------------------------------
buildFoot();
updateOutputs();
updateDynamics();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
document.querySelector("#boot").remove();
</script>
</body>
</html>
```