Prompt specification
Build or customize the Three.js 3D scene "Sole tread and contact patch" 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: Sole tread and contact patch
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sole-tread-and-contact-patch-x0617
Scene Description Prompt:
Compare stylized treaded and flat shoe soles, highlighting their different contact patches on one plane. Build standalone HTML using Three.js from cdnjs.
Working Three.js Starter (sole-tread-and-contact-patch-x0617):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sole Contact Comparison</title>
<style>
:root {
color-scheme: dark;
--bg: #071116;
--panel: rgba(9, 23, 30, 0.76);
--line: rgba(179, 225, 231, 0.14);
--text: #eef8f8;
--muted: #8ca5aa;
--tread: #ff7043;
--flat: #42e2d6;
}
* {
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;
}
body {
min-width: 320px;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: clamp(22px, 4vw, 52px);
left: clamp(22px, 4vw, 56px);
width: min(410px, calc(100vw - 44px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 18px;
color: #aac0c4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: var(--tread);
box-shadow: 0 0 12px rgba(255, 112, 67, 0.7);
}
h1 {
margin: 0;
font-size: clamp(34px, 5vw, 66px);
font-weight: 530;
line-height: 0.98;
letter-spacing: -0.055em;
}
h1 em {
color: #91a8ad;
font-style: normal;
font-weight: 400;
}
.intro p {
max-width: 355px;
margin: 20px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.panel {
position: absolute;
top: clamp(20px, 3vw, 38px);
right: clamp(20px, 3vw, 38px);
width: 232px;
padding: 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.panel-title {
margin-bottom: 14px;
color: #7f999f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.toggle {
display: grid;
grid-template-columns: 10px 1fr auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
color: var(--text);
font: inherit;
font-size: 11px;
text-align: left;
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease;
}
.toggle:hover {
border-color: rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.06);
}
.toggle-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: linear-gradient(135deg, var(--tread), var(--flat));
box-shadow: 0 0 10px rgba(66, 226, 214, 0.5);
}
.toggle b {
color: #89a4a9;
font-size: 9px;
letter-spacing: 0.12em;
}
.range-header {
display: flex;
justify-content: space-between;
margin: 17px 1px 8px;
color: #a6b9bd;
font-size: 10px;
letter-spacing: 0.04em;
}
.range-header output {
color: var(--flat);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 3px;
margin: 7px 0 17px;
appearance: none;
border-radius: 99px;
background: rgba(255, 255, 255, 0.12);
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
border: 3px solid #0d2229;
border-radius: 50%;
background: var(--flat);
box-shadow: 0 0 0 1px var(--flat);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid #0d2229;
border-radius: 50%;
background: var(--flat);
box-shadow: 0 0 0 1px var(--flat);
}
.reset {
width: 100%;
padding: 10px;
border: 0;
border-top: 1px solid var(--line);
background: transparent;
color: #839da2;
font: inherit;
font-size: 10px;
cursor: pointer;
transition: color 150ms ease;
}
.reset:hover {
color: var(--text);
}
.legend {
position: absolute;
bottom: clamp(22px, 4vw, 46px);
left: clamp(22px, 4vw, 56px);
display: flex;
flex-wrap: wrap;
gap: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 99px;
background: rgba(7, 17, 22, 0.64);
color: #9db1b5;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.swatch {
width: 8px;
height: 8px;
border-radius: 2px;
}
.swatch.tread {
background: var(--tread);
box-shadow: 0 0 10px rgba(255, 112, 67, 0.8);
}
.swatch.flat {
border-radius: 50%;
background: var(--flat);
box-shadow: 0 0 10px rgba(66, 226, 214, 0.8);
}
.hint {
position: absolute;
right: clamp(22px, 4vw, 48px);
bottom: clamp(25px, 4vw, 48px);
color: #617b81;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.object-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 10px;
min-width: 150px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(7, 17, 22, 0.76);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
will-change: transform;
}
.object-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 25px;
content: "";
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.26), transparent);
}
.object-label .number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border-radius: 7px;
color: #071116;
font-size: 9px;
font-weight: 900;
}
#treadLabel .number {
background: var(--tread);
}
#flatLabel .number {
background: var(--flat);
}
.object-label strong {
display: block;
font-size: 9px;
letter-spacing: 0.12em;
}
.object-label small {
display: block;
margin-top: 3px;
color: #70898e;
font-size: 8px;
letter-spacing: 0.04em;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #071116;
color: #8ba4a9;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 20px;
left: 20px;
}
.intro p {
display: none;
}
h1 {
font-size: 37px;
}
.eyebrow {
margin-bottom: 13px;
}
.panel {
top: auto;
right: 16px;
bottom: 16px;
width: 195px;
padding: 13px;
}
.legend {
bottom: 18px;
left: 16px;
max-width: calc(100vw - 235px);
}
.legend-item {
padding: 8px 10px;
font-size: 8px;
}
.hint,
.object-label {
display: none;
}
}
@media (max-width: 480px) {
.intro p,
.legend {
display: none;
}
.panel {
width: calc(100vw - 32px);
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive comparison of treaded and flat shoe soles"></canvas>
<div class="ui">
<header class="intro">
<div class="eyebrow">Footwear mechanics / comparison 01</div>
<h1>Same floor.<br /><em>Different contact.</em></h1>
<p>
A treaded sole divides its load across isolated contact islands.
A flat sole creates one continuous contact region. Both footprints
are projected onto the same shared plane.
</p>
</header>
<section class="panel" aria-label="Display controls">
<div class="panel-title">Display controls</div>
<button class="toggle" id="patchToggle" type="button" aria-pressed="true">
<span class="toggle-dot"></span>
<span>Contact patches</span>
<b id="patchState">ON</b>
</button>
<div class="range-header">
<span>Sole separation</span>
<output id="liftValue" for="lift">58%</output>
</div>
<input
id="lift"
type="range"
min="25"
max="80"
value="58"
aria-label="Sole separation"
/>
<button class="reset" id="resetView" type="button">Reset camera view ↺</button>
</section>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="swatch tread"></span>
Segmented contact
</div>
<div class="legend-item">
<span class="swatch flat"></span>
Continuous contact
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="object-label" id="treadLabel">
<span class="number">01</span>
<div>
<strong>TREADED</strong>
<small>Isolated contact islands</small>
</div>
</div>
<div class="object-label" id="flatLabel">
<span class="number">02</span>
<div>
<strong>FLAT</strong>
<small>Continuous contact area</small>
</div>
</div>
</div>
<div id="loading">Building contact study…</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 loading = document.querySelector("#loading");
const liftInput = document.querySelector("#lift");
const liftValue = document.querySelector("#liftValue");
const patchToggle = document.querySelector("#patchToggle");
const patchState = document.querySelector("#patchState");
const resetView = document.querySelector("#resetView");
const treadLabel = document.querySelector("#treadLabel");
const flatLabel = document.querySelector("#flatLabel");
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071116);
scene.fog = new THREE.Fog(0x071116, 14, 30);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
// Shared contact plane.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 22),
new THREE.MeshStandardMaterial({
color: 0x0a1a21,
roughness: 0.9,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(26, 52, 0x315f68, 0x17313a);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.27;
scene.add(grid);
// Lighting.
scene.add(
new THREE.HemisphereLight(0xc5ebff, 0x101418, 1.45)
);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4.5, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x48dfe4, 24, 20, 2);
cyanLight.position.set(-7, 4, -4);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xff6d42, 22, 18, 2);
warmLight.position.set(5, 4, 2);
scene.add(warmLight);
// A stylized asymmetric footprint outline in local XY.
function createSoleShape() {
const shape = new THREE.Shape();
shape.moveTo(-0.64, -2.35);
shape.bezierCurveTo(-1.0, -2.35, -1.05, -1.86, -0.95, -1.45);
shape.bezierCurveTo(-0.86, -0.96, -0.64, -0.25, -0.7, 0.3);
shape.bezierCurveTo(-0.78, 0.88, -1.05, 1.45, -1.02, 2.02);
shape.bezierCurveTo(-1.0, 2.48, -0.55, 2.65, 0.0, 2.68);
shape.bezierCurveTo(0.62, 2.66, 1.02, 2.42, 0.98, 1.98);
shape.bezierCurveTo(0.94, 1.46, 0.69, 0.92, 0.64, 0.34);
shape.bezierCurveTo(0.6, -0.25, 0.79, -0.96, 0.87, -1.45);
shape.bezierCurveTo(0.98, -1.92, 0.94, -2.34, 0.58, -2.38);
shape.bezierCurveTo(0.18, -2.42, -0.18, -2.4, -0.64, -2.35);
return shape;
}
const soleShape = createSoleShape();
function createRoundedRectangle(width, depth, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -depth / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + depth - radius);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - radius,
y + depth
);
shape.lineTo(x + radius, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function outlineGeometry(shape, y = 0) {
const points = shape.getPoints(100).map(
(point) => new THREE.Vector3(point.x, y, -point.y)
);
return new THREE.BufferGeometry().setFromPoints(points);
}
function createSoleBase(shape, depth, material) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: 0.055,
bevelThickness: 0.04
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function createTopInsert(shape, y, material, scaleX = 0.88, scaleZ = 0.9) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.045,
steps: 1,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.025,
bevelThickness: 0.018
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = y;
mesh.scale.set(scaleX, 1, scaleZ);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
const treadRoot = new THREE.Group();
const flatRoot = new THREE.Group();
treadRoot.position.x = -2.28;
flatRoot.position.x = 2.28;
scene.add(treadRoot, flatRoot);
// Treaded sole.
const treadBase = createSoleBase(
soleShape,
0.18,
new THREE.MeshStandardMaterial({
color: 0xe95635,
roughness: 0.48,
metalness: 0.08
})
);
const treadTop = createTopInsert(
soleShape,
0.202,
new THREE.MeshStandardMaterial({
color: 0x202b31,
roughness: 0.72,
metalness: 0.02
}),
0.88,
0.9
);
treadRoot.add(treadBase, treadTop);
const treadOutline = new THREE.LineLoop(
outlineGeometry(soleShape, 0.248),
new THREE.LineBasicMaterial({
color: 0xff9a75,
transparent: true,
opacity: 0.48
})
);
treadOutline.scale.set(0.88, 1, 0.9);
treadRoot.add(treadOutline);
// Flat sole.
const flatBase = createSoleBase(
soleShape,
0.13,
new THREE.MeshStandardMaterial({
color: 0x2b9fad,
roughness: 0.42,
metalness: 0.12
})
);
const flatTop = createTopInsert(
soleShape,
0.152,
new THREE.MeshStandardMaterial({
color: 0xb8d0d1,
roughness: 0.68,
metalness: 0.02
}),
0.88,
0.9
);
flatRoot.add(flatBase, flatTop);
const flatOutline = new THREE.LineLoop(
outlineGeometry(soleShape, 0.198),
new THREE.LineBasicMaterial({
color: 0x7ff5eb,
transparent: true,
opacity: 0.55
})
);
flatOutline.scale.set(0.88, 1, 0.9);
flatRoot.add(flatOutline);
// Actual underside tread blocks and their matching projected patches.
const treadLugs = [
{ x: -0.45, z: 1.62, w: 0.28, d: 0.58, a: -0.05 },
{ x: 0.05, z: 1.62, w: 0.28, d: 0.58, a: 0.02 },
{ x: 0.55, z: 1.62, w: 0.28, d: 0.58, a: 0.08 },
{ x: -0.55, z: 1.05, w: 0.32, d: 0.36, a: -0.18 },
{ x: -0.05, z: 1.05, w: 0.30, d: 0.36, a: 0.0 },
{ x: 0.48, z: 1.05, w: 0.28, d: 0.36, a: 0.18 },
{ x: -0.42, z: 0.42, w: 0.38, d: 0.32, a: -0.25 },
{ x: 0.12, z: 0.42, w: 0.36, d: 0.32, a: 0.05 },
{ x: 0.58, z: 0.42, w: 0.28, d: 0.32, a: 0.25 },
{ x: -0.72, z: -0.35, w: 0.34, d: 0.48, a: -0.22 },
{ x: -0.18, z: -0.35, w: 0.34, d: 0.48, a: 0.0 },
{ x: 0.38, z: -0.35, w: 0.30, d: 0.48, a: 0.22 },
{ x: -0.58, z: -1.05, w: 0.38, d: 0.62, a: -0.16 },
{ x: 0.03, z: -1.05, w: 0.38, d: 0.62, a: 0.0 },
{ x: 0.60, z: -1.05, w: 0.32, d: 0.62, a: 0.16 },
{ x: -0.42, z: -1.72, w: 0.30, d: 0.46, a: -0.24 },
{ x: 0.08, z: -1.72, w: 0.30, d: 0.46, a: -0.05 },
{ x: 0.52, z: -1.72, w: 0.26, d: 0.46, a: 0.2 },
{ x: -0.78, z: 0.55, w: 0.18, d: 0.72, a: -0.12 },
{ x: 0.78, z: -0.75, w: 0.18, d: 0.75, a: 0.1 }
];
const lugMaterial = new THREE.MeshStandardMaterial({
color: 0x151d22,
roughness: 0.68,
metalness: 0.05
});
const treadPatchMaterial = new THREE.MeshBasicMaterial({
color: 0xff7043,
transparent: true,
opacity: 0.86,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const flatPatchMaterial = new THREE.MeshBasicMaterial({
color: 0x42e2d6,
transparent: true,
opacity: 0.68,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const treadGhostMaterial = new THREE.MeshBasicMaterial({
color: 0xff7043,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
});
const treadContact = new THREE.Group();
const flatContact = new THREE.Group();
treadContact.position.x = -2.28;
flatContact.position.x = 2.28;
scene.add(treadContact, flatContact);
// Ghost footprint indicates the total available tread area.
const treadGhostGeometry = new THREE.ShapeGeometry(soleShape, 80);
treadGhostGeometry.rotateX(-Math.PI / 2);
const treadGhost = new THREE.Mesh(
treadGhostGeometry,
treadGhostMaterial
);
treadGhost.position.y = 0.018;
treadGhost.scale.set(0.93, 1, 0.93);
treadContact.add(treadGhost);
for (const lug of treadLugs) {
const roundedShape = createRoundedRectangle(
lug.w,
lug.d,
Math.min(lug.w, lug.d) * 0.22
);
const lugGeometry = new THREE.ExtrudeGeometry(roundedShape, {
depth: 0.16,
steps: 1,
bevelEnabled: true,
bevelSegments: 2,
bevelSize: 0.018,
bevelThickness: 0.012
});
lugGeometry.rotateX(-Math.PI / 2);
lugGeometry.translate(0, -0.08, 0);
lugGeometry.computeVertexNormals();
const lugMesh = new THREE.Mesh(lugGeometry, lugMaterial);
lugMesh.position.set(lug.x, 0, lug.z);
lugMesh.rotation.y = lug.a;
lugMesh.castShadow = true;
lugMesh.receiveShadow = true;
treadRoot.add(lugMesh);
// Matching contact island on the shared plane.
const patchShape = createRoundedRectangle(
lug.w * 1.02,
lug.d * 1.02,
Math.min(lug.w, lug.d) * 0.22
);
const patchGeometry = new THREE.ShapeGeometry(patchShape, 10);
patchGeometry.rotateX(-Math.PI / 2);
const patchPivot = new THREE.Group();
patchPivot.position.set(lug.x, 0.027, lug.z);
patchPivot.rotation.y = lug.a;
const patch = new THREE.Mesh(patchGeometry, treadPatchMaterial);
patchPivot.add(patch);
treadContact.add(patchPivot);
}
// The flat sole produces one uninterrupted footprint.
const flatPatchGeometry = new THREE.ShapeGeometry(soleShape, 100);
flatPatchGeometry.rotateX(-Math.PI / 2);
const flatPatch = new THREE.Mesh(flatPatchGeometry, flatPatchMaterial);
flatPatch.position.y = 0.022;
flatPatch.scale.set(0.92, 1, 0.92);
flatContact.add(flatPatch);
const flatPatchOutline = new THREE.LineLoop(
outlineGeometry(soleShape, 0.028),
new THREE.LineBasicMaterial({
color: 0x8bfff5,
transparent: true,
opacity: 0.9
})
);
flatPatchOutline.scale.set(0.92, 1, 0.92);
flatContact.add(flatPatchOutline);
// Thin vertical guides connect the elevated soles to the contact plane.
const projectionDefinitions = [];
const projectionObjects = [];
function addProjection(group, x, z, color, topOffset) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[x, 0.025, z, x, 0.6, z],
3
)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.22,
depthWrite: false
})
);
group.add(line);
projectionDefinitions.push({ line, topOffset });
projectionObjects.push(line);
}
for (const index of [0, 5, 9, 13, 16]) {
const lug = treadLugs[index];
addProjection(treadContact, lug.x, lug.z, 0xff7043, -0.16);
}
for (const point of [
[-0.45, 1.5],
[0, 0.1],
[0.42, -1.5]
]) {
addProjection(flatContact, point[0], point[1], 0x42e2d6, 0);
}
function applySeparation() {
const separation = Number(liftInput.value) / 100;
// The tread lugs and flat sole both terminate at the same conceptual height.
treadRoot.position.y = separation + 0.16;
flatRoot.position.y = separation;
for (const projection of projectionDefinitions) {
const attribute = projection.line.geometry.getAttribute("position");
attribute.setY(1, separation);
attribute.needsUpdate = true;
}
liftValue.value = `${liftInput.value}%`;
}
liftInput.addEventListener("input", applySeparation);
applySeparation();
// Direct camera controls: no addon imports.
const defaultView = {
theta: 0.3,
phi: 1.02,
radius: 14.6
};
const currentView = { ...defaultView };
const targetView = { ...defaultView };
const cameraTarget = new THREE.Vector3(0, 0.55, 0);
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
function updateCamera() {
currentView.theta +=
(targetView.theta - currentView.theta) * 0.1;
currentView.phi +=
(targetView.phi - currentView.phi) * 0.1;
currentView.radius +=
(targetView.radius - currentView.radius) * 0.1;
spherical.set(
currentView.radius,
currentView.phi,
currentView.theta
);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
const activePointers = new Map();
let previousPinchDistance = 0;
function pointerDistance() {
const points = [...activePointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
targetView.radius = THREE.MathUtils.clamp(
targetView.radius *
(previousPinchDistance / distance),
8.5,
22
);
}
previousPinchDistance = distance;
return;
}
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
targetView.theta -= deltaX * 0.006;
targetView.phi = THREE.MathUtils.clamp(
targetView.phi - deltaY * 0.005,
0.28,
1.43
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
function endPointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) {
previousPinchDistance = 0;
}
if (activePointers.size === 0) {
dragging = false;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetView.radius = THREE.MathUtils.clamp(
targetView.radius * Math.exp(event.deltaY * 0.001),
8.5,
22
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
targetView.theta = defaultView.theta;
targetView.phi = defaultView.phi;
targetView.radius = defaultView.radius;
});
resetView.addEventListener("click", () => {
targetView.theta = defaultView.theta;
targetView.phi = defaultView.phi;
targetView.radius = defaultView.radius;
});
let patchesVisible = true;
patchToggle.addEventListener("click", () => {
patchesVisible = !patchesVisible;
treadContact.visible = patchesVisible;
flatContact.visible = patchesVisible;
for (const projection of projectionObjects) {
projection.visible = patchesVisible;
}
patchState.textContent = patchesVisible ? "ON" : "OFF";
patchToggle.setAttribute("aria-pressed", String(patchesVisible));
});
// Project DOM labels from world-space anchor points.
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -100%)`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
const treadAnchor = new THREE.Vector3();
const flatAnchor = new THREE.Vector3();
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
function animate(time) {
requestAnimationFrame(animate);
updateCamera();
const pulse = reducedMotion
? 1
: 0.9 + Math.sin(time * 0.0022) * 0.1;
treadPatchMaterial.opacity = 0.8 * pulse;
flatPatchMaterial.opacity = 0.66 * pulse;
camera.updateMatrixWorld();
treadAnchor.set(
-2.28,
treadRoot.position.y + 0.88,
1.0
);
flatAnchor.set(
2.28,
flatRoot.position.y + 0.66,
-1.1
);
positionLabel(treadLabel, treadAnchor);
positionLabel(flatLabel, flatAnchor);
renderer.render(scene, camera);
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```