Prompt specification
Build or customize the Three.js 3D scene "Foot outline and shoe last" 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 outline and shoe last
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/foot-outline-and-shoe-last-x0537
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Display a simple foot-shaped solid beside a translucent shoe form with length and width guides; reveal that matching one dimension alone does not guarantee overall fit.
Working Three.js Starter (foot-outline-and-shoe-last-x0537):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Fit Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 23, 40, 0.86);
--border: rgba(166, 216, 255, 0.16);
--text: #eef8ff;
--muted: #94abc0;
--cyan: #65d7ff;
--amber: #ffb45c;
--good: #54e1a5;
--bad: #ff657d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#scene canvas {
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.dimension-label {
position: absolute;
padding: 5px 8px;
border: 1px solid currentColor;
border-radius: 7px;
background: rgba(5, 14, 26, 0.88);
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: color 180ms ease, border-color 180ms ease;
}
.topbar {
position: fixed;
top: 24px;
left: 28px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.topbar h1 {
margin: 6px 0 4px;
font-size: clamp(23px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.04em;
}
.topbar p {
margin: 0;
color: var(--muted);
font-size: 13px;
}
.legend {
position: fixed;
top: 26px;
right: 28px;
z-index: 5;
display: flex;
gap: 15px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(7, 17, 31, 0.72);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 11px;
font-weight: 700;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
.swatch.foot {
background: var(--amber);
}
.swatch.shoe {
background: var(--cyan);
}
.panel {
position: fixed;
z-index: 10;
top: 92px;
right: 24px;
width: min(350px, calc(100vw - 48px));
max-height: calc(100vh - 116px);
overflow: auto;
padding: 20px;
border: 1px solid var(--border);
border-radius: 20px;
background:
linear-gradient(145deg, rgba(18, 38, 61, 0.92), rgba(7, 18, 33, 0.9));
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(18px);
}
.panel h2 {
margin: 6px 0 8px;
font-size: 25px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 0 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.measurement-table {
width: 100%;
margin: 0 0 18px;
border-collapse: collapse;
overflow: hidden;
border: 1px solid var(--border);
border-radius: 12px;
font-size: 12px;
}
.measurement-table th,
.measurement-table td {
padding: 10px 11px;
border-bottom: 1px solid rgba(166, 216, 255, 0.09);
text-align: right;
}
.measurement-table tr:last-child td {
border-bottom: 0;
}
.measurement-table th:first-child,
.measurement-table td:first-child {
text-align: left;
}
.measurement-table thead {
color: var(--muted);
background: rgba(255, 255, 255, 0.025);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.measurement-table td {
font-weight: 800;
}
.match {
color: var(--good);
}
.mismatch {
color: var(--bad);
}
.control {
margin: 0 0 15px;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
output {
color: var(--text);
font-size: 12px;
letter-spacing: 0;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 18px 0 14px;
}
button {
min-height: 42px;
padding: 9px 10px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
cursor: pointer;
font-size: 11px;
font-weight: 850;
transition:
transform 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(101, 215, 255, 0.55);
background: rgba(101, 215, 255, 0.09);
}
button.primary {
border-color: rgba(84, 225, 165, 0.45);
background: rgba(84, 225, 165, 0.13);
color: #b8ffe0;
}
.status {
position: relative;
padding: 14px 46px 14px 14px;
border: 1px solid var(--border);
border-radius: 13px;
background: rgba(0, 0, 0, 0.18);
}
.status.warn {
border-color: rgba(255, 101, 125, 0.35);
background: rgba(255, 101, 125, 0.07);
}
.status.good {
border-color: rgba(84, 225, 165, 0.38);
background: rgba(84, 225, 165, 0.08);
}
.status.bad {
border-color: rgba(255, 180, 92, 0.35);
background: rgba(255, 180, 92, 0.07);
}
.status-title {
margin-bottom: 4px;
font-size: 13px;
font-weight: 900;
}
.status-detail {
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.verdict {
position: absolute;
top: 13px;
right: 12px;
display: grid;
place-items: center;
width: 30px;
height: 30px;
border-radius: 50%;
background: rgba(255, 101, 125, 0.15);
color: var(--bad);
font-size: 12px;
font-weight: 950;
}
.status.good .verdict {
background: rgba(84, 225, 165, 0.15);
color: var(--good);
}
.scene-message {
position: fixed;
z-index: 6;
top: 18%;
left: calc(50% - 175px);
transform: translateX(-50%);
min-width: 290px;
padding: 11px 15px;
border: 1px solid rgba(255, 101, 125, 0.38);
border-radius: 12px;
background: rgba(8, 18, 32, 0.84);
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(12px);
text-align: center;
pointer-events: none;
}
.scene-message.good {
border-color: rgba(84, 225, 165, 0.4);
}
#messageTitle {
color: var(--bad);
font-size: 9px;
font-weight: 950;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scene-message.good #messageTitle {
color: var(--good);
}
#messageMath {
margin-top: 5px;
font-size: 13px;
font-weight: 800;
}
#messageMath b {
color: var(--muted);
font-weight: 600;
}
.controls-hint {
position: fixed;
z-index: 5;
bottom: 24px;
left: 28px;
color: rgba(190, 213, 231, 0.65);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 760px) {
.topbar {
top: 16px;
left: 18px;
}
.topbar h1 {
font-size: 25px;
}
.topbar p,
.legend {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 47vh;
padding: 15px;
border-radius: 16px;
}
.panel h2 {
font-size: 20px;
}
.intro {
display: none;
}
.measurement-table {
margin-bottom: 12px;
}
.scene-message {
top: 88px;
left: 50%;
min-width: 250px;
}
.controls-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel foot and shoe fit demonstration"></main>
<div id="labels" aria-hidden="true"></div>
<header class="topbar">
<div class="eyebrow">Voxel Fit Lab</div>
<h1>One match is not enough.</h1>
<p>Compare length and width before calling the fit complete.</p>
</header>
<div class="legend">
<span><i class="swatch foot"></i> Solid foot</span>
<span><i class="swatch shoe"></i> Translucent shoe</span>
</div>
<section class="scene-message" id="sceneMessage" aria-live="polite">
<div id="messageTitle">One dimension matched — overall fit not confirmed</div>
<div id="messageMath"></div>
</section>
<aside class="panel">
<div class="eyebrow">Dimensional test</div>
<h2>Match the whole footprint.</h2>
<p class="intro">
The solid foot can match the shoe in length while still failing the
overall fit because its width does not align.
</p>
<table class="measurement-table">
<thead>
<tr>
<th>Dimension</th>
<th>Foot</th>
<th>Shoe</th>
</tr>
</thead>
<tbody>
<tr>
<td>Length</td>
<td id="footLengthCell">22 vx</td>
<td>22 vx</td>
</tr>
<tr>
<td>Width</td>
<td id="footWidthCell">8 vx</td>
<td>9 vx</td>
</tr>
</tbody>
</table>
<div class="control">
<div class="control-head">
<label for="lengthSlider">Foot length</label>
<output id="lengthOutput" for="lengthSlider">22 voxels</output>
</div>
<input
id="lengthSlider"
type="range"
min="16"
max="24"
step="1"
value="22"
aria-label="Foot length"
/>
</div>
<div class="control">
<div class="control-head">
<label for="widthSlider">Foot width</label>
<output id="widthOutput" for="widthSlider">8 voxels</output>
</div>
<input
id="widthSlider"
type="range"
min="6"
max="11"
step="1"
value="8"
aria-label="Foot width"
/>
</div>
<div class="buttons">
<button id="oneMatchButton" type="button">Show one-dimension match</button>
<button id="bothMatchButton" class="primary" type="button">
Match both dimensions
</button>
</div>
<div class="status warn" id="statusPanel" aria-live="polite">
<div class="status-title" id="statusTitle">Length matches — fit still incomplete</div>
<div class="status-detail" id="statusDetail">
Width is still different. Matching one dimension alone does not
guarantee overall fit.
</div>
<div class="verdict" id="verdict">NO</div>
</div>
</aside>
<div class="controls-hint">Drag to orbit · Scroll to zoom · Double-click 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";
// -------------------------------------------------------------------------
// Constants and scene setup
// -------------------------------------------------------------------------
const VOXEL = 0.20;
const SHOE_LENGTH = 22;
const SHOE_WIDTH = 9;
const COLORS = {
good: 0x54e1a5,
bad: 0xff657d,
cyan: 0x65d7ff,
amber: 0xffb45c,
muted: 0x8da8bd
};
let footLength = 22;
let footWidth = 8;
const host = document.getElementById("scene");
const labelHost = document.getElementById("labels");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 17, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom camera controls implemented here; no Three.js addons are used.
class SimpleOrbit {
constructor(cameraObject, element) {
this.camera = cameraObject;
this.element = element;
this.target = new THREE.Vector3(0, 0.65, 0);
this.theta = 0.58;
this.phi = 1.02;
this.radius = 14.2;
this.dragging = false;
this.previousX = 0;
this.previousY = 0;
element.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
this.dragging = true;
this.previousX = event.clientX;
this.previousY = event.clientY;
element.setPointerCapture(event.pointerId);
});
element.addEventListener("pointermove", (event) => {
if (!this.dragging) return;
const deltaX = event.clientX - this.previousX;
const deltaY = event.clientY - this.previousY;
this.theta -= deltaX * 0.006;
this.phi -= deltaY * 0.005;
this.phi = THREE.MathUtils.clamp(this.phi, 0.28, 1.46);
this.previousX = event.clientX;
this.previousY = event.clientY;
});
const stopDragging = (event) => {
this.dragging = false;
if (element.hasPointerCapture(event.pointerId)) {
element.releasePointerCapture(event.pointerId);
}
};
element.addEventListener("pointerup", stopDragging);
element.addEventListener("pointercancel", stopDragging);
element.addEventListener(
"wheel",
(event) => {
event.preventDefault();
this.radius *= Math.exp(event.deltaY * 0.001);
this.radius = THREE.MathUtils.clamp(this.radius, 8, 22);
},
{ passive: false }
);
element.addEventListener("dblclick", () => this.reset());
window.addEventListener("keydown", (event) => {
if (["INPUT", "BUTTON"].includes(document.activeElement?.tagName)) return;
if (event.key === "ArrowLeft") this.theta += 0.08;
if (event.key === "ArrowRight") this.theta -= 0.08;
if (event.key === "ArrowUp") this.phi -= 0.06;
if (event.key === "ArrowDown") this.phi += 0.06;
if (event.key === "+" || event.key === "=") this.radius -= 0.5;
if (event.key === "-") this.radius += 0.5;
this.phi = THREE.MathUtils.clamp(this.phi, 0.28, 1.46);
this.radius = THREE.MathUtils.clamp(this.radius, 8, 22);
});
this.update();
}
reset() {
this.theta = 0.58;
this.phi = 1.02;
this.radius = 14.2;
this.target.set(0, 0.65, 0);
}
update() {
const sinPhi = Math.sin(this.phi);
this.camera.position.set(
this.target.x + this.radius * sinPhi * Math.sin(this.theta),
this.target.y + this.radius * Math.cos(this.phi),
this.target.z + this.radius * sinPhi * Math.cos(this.theta)
);
this.camera.lookAt(this.target);
}
}
const orbit = new SimpleOrbit(camera, renderer.domElement);
scene.add(new THREE.HemisphereLight(0xc8ecff, 0x111827, 2.35));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x28bfff, 22, 18, 2);
cyanLight.position.set(5, 3, 4);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xff9b3f, 18, 16, 2);
amberLight.position.set(-5, 2.5, 3);
scene.add(amberLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(44, 44),
new THREE.MeshStandardMaterial({
color: 0x091525,
roughness: 0.95,
metalness: 0.03
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.018;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
34,
34,
0x25516a,
0x193249
);
grid.position.y = 0.004;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const footRoot = new THREE.Group();
const shoeRoot = new THREE.Group();
footRoot.position.set(-3.1, 0, 0);
shoeRoot.position.set(3.15, 0, 0);
scene.add(footRoot, shoeRoot);
// -------------------------------------------------------------------------
// Shape helpers
// -------------------------------------------------------------------------
function sampleProfile(points, t) {
for (let i = 0; i < points.length - 1; i++) {
const [x0, y0] = points[i];
const [x1, y1] = points[i + 1];
if (t >= x0 && t <= x1) {
const blend = (t - x0) / (x1 - x0);
return THREE.MathUtils.lerp(y0, y1, blend);
}
}
return points[points.length - 1][1];
}
const footProfile = [
[0.00, 0.52],
[0.08, 0.70],
[0.25, 0.76],
[0.46, 0.80],
[0.62, 0.94],
[0.76, 1.00],
[0.88, 0.94],
[0.96, 0.72],
[1.00, 0.48]
];
const shoeProfile = [
[0.00, 0.70],
[0.10, 0.82],
[0.28, 0.82],
[0.49, 0.88],
[0.69, 1.00],
[0.82, 0.96],
[0.93, 0.76],
[1.00, 0.46]
];
function baseLayers(t) {
if (t < 0.09) return 4;
if (t < 0.27) return 3;
if (t < 0.64) return 2;
return 1;
}
function ankleHeight(t) {
if (t < 0.13) return 8;
if (t < 0.25) return 6;
return 0;
}
function shoeHeight(t) {
if (t < 0.10) return 7;
if (t < 0.25) return 8;
if (t < 0.40) return 6;
if (t < 0.58) return 5;
if (t < 0.75) return 4;
if (t < 0.90) return 3;
return 2;
}
function deterministicNoise(a, b, c) {
const value = Math.sin(a * 12.9898 + b * 78.233 + c * 37.719) * 43758.5453;
return value - Math.floor(value);
}
// -------------------------------------------------------------------------
// Foot model
// -------------------------------------------------------------------------
const footMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.74,
metalness: 0.02,
flatShading: true
});
let footMesh = null;
function buildFoot() {
if (footMesh) {
footRoot.remove(footMesh);
footMesh.geometry.dispose();
footMesh.dispose?.();
}
const cells = [];
const length = footLength;
const width = footWidth;
for (let ix = 0; ix < length; ix++) {
const t = (ix + 0.5) / length;
const profile = sampleProfile(footProfile, t);
const rowWidth = Math.max(2, Math.round(width * profile));
const layers = baseLayers(t);
for (let iz = 0; iz < rowWidth; iz++) {
const z = (iz - (rowWidth - 1) / 2) * VOXEL;
for (let iy = 0; iy < layers; iy++) {
cells.push({
x: (ix - (length - 1) / 2) * VOXEL,
y: (iy + 0.5) * VOXEL,
z,
ix,
iy,
iz
});
}
}
// Raised ankle section makes the silhouette read as a foot.
const ankle = ankleHeight(t);
if (ankle > 0) {
const ankleWidth = Math.max(2, Math.round(width * 0.42));
for (let iz = 0; iz < ankleWidth; iz++) {
const z = (iz - (ankleWidth - 1) / 2) * VOXEL;
for (let iy = layers; iy < ankle; iy++) {
cells.push({
x: (ix - (length - 1) / 2) * VOXEL,
y: (iy + 0.5) * VOXEL,
z,
ix,
iy,
iz
});
}
}
}
}
footMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
footMaterial,
cells.length
);
const dummy = new THREE.Object3D();
const baseColor = new THREE.Color(COLORS.amber);
cells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.scale.set(VOXEL * 0.92, VOXEL * 0.92, VOXEL * 0.92);
dummy.updateMatrix();
footMesh.setMatrixAt(index, dummy.matrix);
const noise = deterministicNoise(cell.ix, cell.iz, cell.iy);
const color = baseColor.clone();
color.offsetHSL(
(noise - 0.5) * 0.025,
(noise - 0.5) * 0.07,
(noise - 0.5) * 0.09
);
footMesh.setColorAt(index, color);
});
footMesh.instanceMatrix.needsUpdate = true;
footMesh.instanceColor.needsUpdate = true;
footMesh.castShadow = true;
footMesh.receiveShadow = true;
footMesh.computeBoundingSphere();
footRoot.add(footMesh);
}
// -------------------------------------------------------------------------
// Translucent voxel shoe
// -------------------------------------------------------------------------
const shoeUpperMaterial = new THREE.MeshStandardMaterial({
color: 0x68d8ff,
emissive: 0x0b3954,
emissiveIntensity: 0.45,
transparent: true,
opacity: 0.16,
depthWrite: false,
side: THREE.DoubleSide,
roughness: 0.3,
metalness: 0.08
});
const shoeSoleMaterial = new THREE.MeshStandardMaterial({
color: 0x167b9f,
emissive: 0x06293a,
emissiveIntensity: 0.35,
roughness: 0.46,
metalness: 0.18
});
function buildShoe() {
const soleCells = [];
const upperCells = [];
for (let ix = 0; ix < SHOE_LENGTH; ix++) {
const t = (ix + 0.5) / SHOE_LENGTH;
const rowWidth = Math.max(
3,
Math.round(SHOE_WIDTH * sampleProfile(shoeProfile, t))
);
const height = shoeHeight(t);
const x = (ix - (SHOE_LENGTH - 1) / 2) * VOXEL;
for (let iz = 0; iz < rowWidth; iz++) {
const z = (iz - (rowWidth - 1) / 2) * VOXEL;
soleCells.push({ x, y: VOXEL * 0.5, z });
for (let iy = 1; iy < height; iy++) {
const taper = Math.max(0.56, 1 - iy * 0.065);
const upperWidth = Math.max(2, Math.round(rowWidth * taper));
const upperZ = (iz - (upperWidth - 1) / 2) * VOXEL;
// A small opening at the top of the heel suggests the collar.
const collarOpening =
t > 0.1 &&
t < 0.3 &&
iy >= height - 2 &&
Math.abs(upperZ) < VOXEL * 0.55;
if (!collarOpening) {
upperCells.push({
x,
y: (iy + 0.5) * VOXEL,
z: upperZ
});
}
}
}
}
const dummy = new THREE.Object3D();
const sole = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
shoeSoleMaterial,
soleCells.length
);
soleCells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.scale.set(VOXEL * 0.97, VOXEL * 0.86, VOXEL * 0.97);
dummy.updateMatrix();
sole.setMatrixAt(index, dummy.matrix);
});
sole.instanceMatrix.needsUpdate = true;
sole.castShadow = true;
sole.receiveShadow = true;
shoeRoot.add(sole);
const upper = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
shoeUpperMaterial,
upperCells.length
);
upperCells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.scale.set(VOXEL * 0.91, VOXEL * 0.91, VOXEL * 0.91);
dummy.updateMatrix();
upper.setMatrixAt(index, dummy.matrix);
});
upper.instanceMatrix.needsUpdate = true;
upper.renderOrder = 4;
shoeRoot.add(upper);
// Five pale laces across the instep.
const laceMaterial = new THREE.MeshBasicMaterial({
color: 0xdff8ff,
transparent: true,
opacity: 0.82
});
[0.37, 0.43, 0.49, 0.55, 0.61].forEach((t, index) => {
const x = (t - 0.5) * SHOE_LENGTH * VOXEL;
const height = shoeHeight(t);
const lace = new THREE.Mesh(
new THREE.BoxGeometry(
VOXEL * 0.16,
VOXEL * 0.15,
SHOE_WIDTH * VOXEL * 0.56
),
laceMaterial
);
lace.position.set(x, height * VOXEL + 0.025, 0);
lace.rotation.y = index % 2 === 0 ? 0.07 : -0.07;
shoeRoot.add(lace);
});
// Bright floor contour emphasizes the translucent shoe's footprint.
const contourPoints = [];
for (let ix = 0; ix < SHOE_LENGTH; ix++) {
const t = (ix + 0.5) / SHOE_LENGTH;
const width = SHOE_WIDTH * sampleProfile(shoeProfile, t) * VOXEL;
contourPoints.push(
new THREE.Vector3(
(ix - (SHOE_LENGTH - 1) / 2) * VOXEL,
0.025,
width / 2
)
);
}
for (let ix = SHOE_LENGTH - 1; ix >= 0; ix--) {
const t = (ix + 0.5) / SHOE_LENGTH;
const width = SHOE_WIDTH * sampleProfile(shoeProfile, t) * VOXEL;
contourPoints.push(
new THREE.Vector3(
(ix - (SHOE_LENGTH - 1) / 2) * VOXEL,
0.025,
-width / 2
)
);
}
const contour = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(contourPoints),
new THREE.LineBasicMaterial({
color: COLORS.cyan,
transparent: true,
opacity: 0.5,
depthTest: false
})
);
contour.renderOrder = 5;
shoeRoot.add(contour);
}
// -------------------------------------------------------------------------
// Dimension guides
// -------------------------------------------------------------------------
function createLabel(text) {
const element = document.createElement("div");
element.className = "dimension-label";
element.textContent = text;
labelHost.appendChild(element);
return element;
}
function createDimensionGuides(root, length, width, prefix) {
const group = new THREE.Group();
root.add(group);
const halfLength = (length * VOXEL) / 2;
const halfWidth = (width * VOXEL) / 2;
const lengthZ = halfWidth + 0.62;
const widthX = halfLength + 0.58;
const lengthPositions = [
-halfLength, 0.06, lengthZ,
halfLength, 0.06, lengthZ,
-halfLength, 0.06, lengthZ - 0.12,
-halfLength + 0.13, 0.06, lengthZ,
-halfLength, 0.06, lengthZ + 0.12,
-halfLength + 0.13, 0.06, lengthZ,
halfLength, 0.06, lengthZ - 0.12,
halfLength - 0.13, 0.06, lengthZ,
halfLength, 0.06, lengthZ + 0.12,
halfLength - 0.13, 0.06, lengthZ
];
const widthPositions = [
widthX, 0.06, -halfWidth,
widthX, 0.06, halfWidth,
widthX - 0.12, 0.06, -halfWidth,
widthX, 0.06, -halfWidth + 0.13,
widthX + 0.12, 0.06, -halfWidth,
widthX, 0.06, -halfWidth + 0.13,
widthX - 0.12, 0.06, halfWidth,
widthX, 0.06, halfWidth - 0.13,
widthX + 0.12, 0.06, halfWidth,
widthX, 0.06, halfWidth - 0.13
];
const lengthLine = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(lengthPositions, 3)
),
new THREE.LineBasicMaterial({
color: COLORS.muted,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
const widthLine = new THREE.LineSegments(
new THREE.BufferGeometry().setAttribute(
"position",
new THREE.Float32BufferAttribute(widthPositions, 3)
),
new THREE.LineBasicMaterial({
color: COLORS.muted,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
lengthLine.renderOrder = 8;
widthLine.renderOrder = 8;
group.add(lengthLine, widthLine);
return {
group,
length: {
line: lengthLine,
label: createLabel(`${prefix} · L ${length}`),
anchor: new THREE.Vector3(0, 0.13, lengthZ)
},
width: {
line: widthLine,
label: createLabel(`${prefix} · W ${width}`),
anchor: new THREE.Vector3(widthX, 0.13, 0)
}
};
}
function disposeDimensionGuides(guides) {
if (!guides) return;
guides.group.removeFromParent();
guides.group.traverse((object) => {
object.geometry?.dispose();
object.material?.dispose();
});
guides.length.label.remove();
guides.width.label.remove();
}
let footGuides = null;
const shoeGuides = createDimensionGuides(
shoeRoot,
SHOE_LENGTH,
SHOE_WIDTH,
"SHOE"
);
// -------------------------------------------------------------------------
// UI state and fit explanation
// -------------------------------------------------------------------------
const lengthSlider = document.getElementById("lengthSlider");
const widthSlider = document.getElementById("widthSlider");
const lengthOutput = document.getElementById("lengthOutput");
const widthOutput = document.getElementById("widthOutput");
const footLengthCell = document.getElementById("footLengthCell");
const footWidthCell = document.getElementById("footWidthCell");
const statusPanel = document.getElementById("statusPanel");
const statusTitle = document.getElementById("statusTitle");
const statusDetail = document.getElementById("statusDetail");
const verdict = document.getElementById("verdict");
const sceneMessage = document.getElementById("sceneMessage");
const messageTitle = document.getElementById("messageTitle");
const messageMath = document.getElementById("messageMath");
function refreshFoot() {
buildFoot();
disposeDimensionGuides(footGuides);
footGuides = createDimensionGuides(
footRoot,
footLength,
footWidth,
"FOOT"
);
updateFitState();
}
function updateFitState() {
const lengthMatches = footLength === SHOE_LENGTH;
const widthMatches = footWidth === SHOE_WIDTH;
const bothMatch = lengthMatches && widthMatches;
const oneMatches = lengthMatches !== widthMatches;
lengthOutput.textContent = `${footLength} voxels`;
widthOutput.textContent = `${footWidth} voxels`;
footLengthCell.textContent = `${footLength} vx`;
footWidthCell.textContent = `${footWidth} vx`;
footLengthCell.className = lengthMatches ? "match" : "mismatch";
footWidthCell.className = widthMatches ? "match" : "mismatch";
const lengthColor = lengthMatches ? COLORS.good : COLORS.bad;
const widthColor = widthMatches ? COLORS.good : COLORS.bad;
footGuides.length.line.material.color.setHex(lengthColor);
footGuides.width.line.material.color.setHex(widthColor);
shoeGuides.length.line.material.color.setHex(lengthColor);
shoeGuides.width.line.material.color.setHex(widthColor);
footGuides.length.label.style.color = `#${lengthColor.toString(16).padStart(6, "0")}`;
footGuides.width.label.style.color = `#${widthColor.toString(16).padStart(6, "0")}`;
shoeGuides.length.label.style.color = `#${lengthColor.toString(16).padStart(6, "0")}`;
shoeGuides.width.label.style.color = `#${widthColor.toString(16).padStart(6, "0")}`;
footGuides.length.label.textContent = `FOOT · L ${footLength}${lengthMatches ? " ✓" : " ×"}`;
footGuides.width.label.textContent = `FOOT · W ${footWidth}${widthMatches ? " ✓" : " ×"}`;
shoeGuides.length.label.textContent = `SHOE · L ${SHOE_LENGTH}${lengthMatches ? " ✓" : " ×"}`;
shoeGuides.width.label.textContent = `SHOE · W ${SHOE_WIDTH}${widthMatches ? " ✓" : " ×"}`;
statusPanel.className = `status ${bothMatch ? "good" : oneMatches ? "warn" : "bad"}`;
verdict.textContent = bothMatch ? "YES" : "NO";
sceneMessage.classList.toggle("good", bothMatch);
if (bothMatch) {
statusTitle.textContent = "Overall dimensional fit confirmed";
statusDetail.textContent =
"Both length and width align with the shoe form. In this simplified model, the complete fit check passes.";
messageTitle.textContent = "Both dimensions align — overall fit confirmed";
messageMath.innerHTML =
`Length ${footLength} = ${SHOE_LENGTH} <b>and</b> width ${footWidth} = ${SHOE_WIDTH}`;
} else if (lengthMatches) {
const difference = Math.abs(footWidth - SHOE_WIDTH);
statusTitle.textContent = "Length matches — fit still incomplete";
statusDetail.textContent =
`Width is still different by ${difference} voxel${difference === 1 ? "" : "s"}. Matching one dimension alone does not guarantee overall fit.`;
messageTitle.textContent = "One dimension matched — overall fit not confirmed";
messageMath.innerHTML =
`Length ${footLength} = ${SHOE_LENGTH} <b>but</b> width ${footWidth} ≠ ${SHOE_WIDTH}`;
} else if (widthMatches) {
const difference = Math.abs(footLength - SHOE_LENGTH);
statusTitle.textContent = "Width matches — fit still incomplete";
statusDetail.textContent =
`Length is still different by ${difference} voxel${difference === 1 ? "" : "s"}. A width match alone cannot establish the whole fit.`;
messageTitle.textContent = "One dimension matched — overall fit not confirmed";
messageMath.innerHTML =
`Width ${footWidth} = ${SHOE_WIDTH} <b>but</b> length ${footLength} ≠ ${SHOE_LENGTH}`;
} else {
statusTitle.textContent = "Neither dimension matches";
statusDetail.textContent =
"Adjust the foot or use the example buttons to compare one-dimensional and complete dimensional alignment.";
messageTitle.textContent = "No complete fit yet";
messageMath.innerHTML =
`Length ${footLength} ≠ ${SHOE_LENGTH} <b>and</b> width ${footWidth} ≠ ${SHOE_WIDTH}`;
}
}
lengthSlider.addEventListener("input", () => {
footLength = Number(lengthSlider.value);
refreshFoot();
});
widthSlider.addEventListener("input", () => {
footWidth = Number(widthSlider.value);
refreshFoot();
});
document
.getElementById("oneMatchButton")
.addEventListener("click", () => {
footLength = SHOE_LENGTH;
footWidth = SHOE_WIDTH - 1;
lengthSlider.value = footLength;
widthSlider.value = footWidth;
refreshFoot();
});
document
.getElementById("bothMatchButton")
.addEventListener("click", () => {
footLength = SHOE_LENGTH;
footWidth = SHOE_WIDTH;
lengthSlider.value = footLength;
widthSlider.value = footWidth;
refreshFoot();
});
// -------------------------------------------------------------------------
// Projected HTML dimension labels
// -------------------------------------------------------------------------
const projectedPoint = new THREE.Vector3();
function projectLabel(root, guide) {
projectedPoint.copy(guide.anchor);
root.localToWorld(projectedPoint);
projectedPoint.project(camera);
const visible =
projectedPoint.z > -1 &&
projectedPoint.z < 1 &&
Math.abs(projectedPoint.x) < 1.15 &&
Math.abs(projectedPoint.y) < 1.15;
guide.label.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projectedPoint.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projectedPoint.y * 0.5 + 0.5) * window.innerHeight;
guide.label.style.left = `${x}px`;
guide.label.style.top = `${y}px`;
}
function updateLabels() {
if (footGuides) {
projectLabel(footRoot, footGuides.length);
projectLabel(footRoot, footGuides.width);
}
projectLabel(shoeRoot, shoeGuides.length);
projectLabel(shoeRoot, shoeGuides.width);
}
// -------------------------------------------------------------------------
// Initialize and animate
// -------------------------------------------------------------------------
buildShoe();
refreshFoot();
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 760 ? 49 : 42;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
function animate() {
requestAnimationFrame(animate);
orbit.update();
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```