Prompt specification
Build or customize the Three.js 3D scene "Terrain-and-footwear museum exhibit" 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: Terrain-and-footwear museum exhibit
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/terrain-and-footwear-museum-exhibit-x0620
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts soil, rock, and smooth-floor tiles with several abstract sole patterns; users compare contact geometry and groove visibility through labeled qualitative diagrams rather than product recommendations. Low-poly.
Working Three.js Starter (terrain-and-footwear-museum-exhibit-x0620):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact & Groove Geometry — Qualitative Study</title>
<style>
:root{
--bg:#12161a; --panel:#171c22; --card:#1e242c; --line:#2b333d;
--ink:#dfe6ee; --muted:#94a2b1; --accent:#ffc857;
--soil:#8a6544; --rock:#8d949c; --floor:#cfd4d8;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{
background:var(--bg); color:var(--ink);
font:13px/1.45 system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
display:flex; overflow:hidden;
}
#view{position:relative;flex:1 1 auto;min-width:0}
#view canvas{display:block;width:100%;height:100%}
#hud{
position:absolute;left:14px;bottom:12px;color:#6d7a88;font-size:11px;
letter-spacing:.02em;pointer-events:none;text-shadow:0 1px 2px rgba(0,0,0,.5)
}
#hud b{color:#9fb0c0;font-weight:600}
#panel{
flex:0 0 384px;width:384px;background:var(--panel);border-left:1px solid var(--line);
overflow-y:auto;padding:16px 16px 26px;
}
#panel h1{font-size:16px;margin:0 0 4px;letter-spacing:.01em}
#panel h3{margin:0;font-size:13.5px;letter-spacing:.02em}
.sub{color:var(--muted);font-size:11.5px;margin:0}
.disclaimer{
margin:10px 0 14px;padding:8px 10px;border:1px solid #4a3f22;background:#2a2413;
color:#e6c98a;border-radius:7px;font-size:11px
}
.sect-label{
font-size:10px;text-transform:uppercase;letter-spacing:.14em;color:#6f7e8d;margin:16px 0 7px
}
.chips{display:flex;flex-wrap:wrap;gap:6px}
.chip{
display:flex;align-items:center;gap:7px;cursor:pointer;user-select:none;
padding:6px 9px;border-radius:7px;border:1px solid var(--line);background:#1b2129;
color:var(--muted);font-size:11.5px;transition:.15s
}
.chip:hover{border-color:#46525f;color:var(--ink)}
.chip.on{background:#253039;border-color:#5d6b79;color:#fff}
.swatch{width:11px;height:11px;border-radius:3px;flex:0 0 auto}
.toggles{display:flex;flex-wrap:wrap;gap:12px;margin-top:11px;color:var(--muted);font-size:11.5px}
.toggles label{display:flex;align-items:center;gap:5px;cursor:pointer}
.toggles input{accent-color:#7ea3c4}
.card{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:11px;margin-top:12px}
.card-head{display:flex;align-items:baseline;gap:8px;margin-bottom:9px}
.card-head span{color:var(--muted);font-size:11px}
.card canvas{display:block;border-radius:6px;margin:0 auto 8px}
dl{margin:2px 0 0;display:grid;grid-template-columns:104px 1fr;gap:5px 9px}
dt{color:#7f8d9c;font-size:10.5px;text-transform:uppercase;letter-spacing:.07em;padding-top:1px}
dd{margin:0;font-size:11.7px;color:#d4dde6}
.foot{margin-top:9px;font-size:10px;color:#63707e;letter-spacing:.04em;text-transform:uppercase}
#foot-note{margin-top:16px;font-size:10.5px;color:#63707e;line-height:1.5}
@media (max-width:900px){
body{flex-direction:column}
#panel{flex:0 0 auto;width:100%;max-height:46vh;border-left:0;border-top:1px solid var(--line)}
#view{min-height:54vh}
}
</style>
</head>
<body>
<div id="view">
<div id="hud"><b>drag</b> orbit · <b>scroll</b> zoom · <b>shift-drag</b> pan · <b>click a sole</b> to select a pattern · <b>R</b> reset view</div>
</div>
<aside id="panel">
<h1>Contact & groove geometry</h1>
<p class="sub">Qualitative side-by-side study of three abstract sole patterns over soil, rock and a smooth floor.</p>
<div class="disclaimer">
Everything below is a <b>schematic, qualitative diagram</b> of geometry — contact area and groove legibility.
It is <b>not</b> a product evaluation, ranking, or recommendation, and no tread is endorsed.
</div>
<div class="sect-label">Pattern in view</div>
<div class="chips" id="chips"></div>
<div class="toggles">
<label><input type="checkbox" id="t-cards" checked> contact cards</label>
<label><input type="checkbox" id="t-boards" checked> section boards</label>
<label><input type="checkbox" id="t-dim" checked> dim unselected</label>
</div>
<div class="sect-label">Qualitative diagrams</div>
<div id="cards"></div>
<div id="foot-note">
Diagrams are not to scale. Depth, gap and contact terms are qualitative descriptors of the drawn geometry only.
</div>
</aside>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ *
* data
* ------------------------------------------------------------------ */
const PAL = { A:'#3b6ea5', B:'#b8653f', C:'#4f7d5a' };
const FOOTPRINT = [
[-0.42,-1.25],[ 0.42,-1.25],[ 0.55,-0.55],[ 0.52, 0.32],
[ 0.30, 1.22],[-0.30, 1.22],[-0.52, 0.32],[-0.55,-0.55]
];
function chevron(y,w,t){ return [[-w,y],[0,y+0.20],[w,y],[w,y-t],[0,y+0.20-t],[-w,y-t]]; }
function rect(x,y,w,h){ return [[x-w,y-h],[x+w,y-h],[x+w,y+h],[x-w,y+h]]; }
const PATTERNS = [
{ id:'A', name:'Split chevron', color:PAL.A, depth:0.20, gap:'narrow', depthWord:'deep',
note:'V-bands meet the outline only at their ends; the middle of the sole stays open.',
lugs:[
chevron(-0.95,0.40,0.20), chevron(-0.48,0.46,0.20), chevron(0.00,0.50,0.20),
chevron( 0.48,0.46,0.20), chevron( 0.95,0.34,0.20)
]},
{ id:'B', name:'Isolated blocks', color:PAL.B, depth:0.15, gap:'medium', depthWord:'medium',
note:'Nine separate pads leave a wide unbridged interior between them.',
lugs:(()=>{const out=[];for(const x of [-0.33,0,0.33])for(const y of [-0.72,0,0.72])out.push(rect(x,y,0.12,0.17));return out;})()},
{ id:'C', name:'Broad rails', color:PAL.C, depth:0.085, gap:'wide', depthWord:'shallow',
note:'Transverse bars cross the outline, so reach runs from edge to edge.',
lugs:[ rect(0,-0.92,0.44,0.17), rect(0,0.00,0.52,0.17), rect(0,0.92,0.33,0.17) ]}
];
const SURFACES = [
{ id:'soil', name:'Soil', sub:'granular · yielding', fill:'#7a5a3c', line:'#4d3926', word:'broad but interrupted' },
{ id:'rock', name:'Rock', sub:'angular · rigid', fill:'#6f7479', line:'#454a50', word:'sparse and edge-biased' },
{ id:'floor', name:'Smooth floor', sub:'planar · rigid', fill:'#cfd4d8', line:'#9aa2a8', word:'continuous and even' }
];
/* qualitative descriptors ------------------------------------------------ */
function describe(s,p){
const contact = {
soil : 'Broad but interrupted — pads settle into the grain and spread into soft-edged patches.',
rock : 'Edge-biased — pads bridge depressions and touch only on facet ridges and corners.',
floor: 'Continuous — the whole pad outline lands on the plane at once.'
}[s.id];
const gapWord = { narrow:'thin lines', medium:'open channels', wide:'broad separations' }[p.gap];
const groove = {
soil : `Gaps read as ${gapWord}, but loose material softens their edges and partly fills them.`,
rock : `Gaps read as ${gapWord}, their edges broken by facet steps and short cast shadows.`,
floor: `Gaps read as ${gapWord}, their edges staying crisp against the plane.`
}[s.id];
const edge = {
soil : 'Pad borders dissolve into the surface as grains ride up the edge.',
rock : 'Pad borders stay sharp; the surrounding facets make them read harder still.',
floor:'Pad borders stay sharp and evenly lit.'
}[s.id];
const response = {
soil : 'Lugs settle unevenly; the imprint shifts with how the grain packs.',
rock : 'Lugs stay rigid; load lands on the highest ridge beneath each pad.',
floor:'Lugs land flat; the imprint is a direct copy of the layout.'
}[s.id];
return { contact, groove, edge, response };
}
/* ------------------------------------------------------------------ *
* diagram drawing (canvas 2d)
* ------------------------------------------------------------------ */
const TOP_W = 160, TOP_H = 260, SEC_W = 340, SEC_H = 126;
function drawTopView(ctx, surface, pattern){
ctx.fillStyle = '#f4f2ed'; ctx.fillRect(0,0,TOP_W,TOP_H);
ctx.fillStyle = '#3b4753'; ctx.font = '600 10px system-ui,sans-serif';
ctx.textAlign = 'left';
ctx.fillText('apparent contact · top view', 10, 15);
const s = 72, ox = TOP_W/2, oy = TOP_H - 26;
const PX = lx => ox + lx*s, PY = ly => oy - ly*s;
// footprint outline
ctx.save();
ctx.setLineDash([4,3]); ctx.strokeStyle = '#8b95a0'; ctx.lineWidth = 1.2;
ctx.beginPath();
FOOTPRINT.forEach((p,i)=> i ? ctx.lineTo(PX(p[0]),PY(p[1])) : ctx.moveTo(PX(p[0]),PY(p[1])));
ctx.closePath(); ctx.stroke(); ctx.restore();
const rnd = mulberry32(1337 + surface.id.length*31 + pattern.id.charCodeAt(0));
const ink = 'rgba(31,42,53,0.92)';
pattern.lugs.forEach(lug=>{
if(surface.id === 'floor'){
ctx.beginPath();
lug.forEach((p,i)=> i ? ctx.lineTo(PX(p[0]),PY(p[1])) : ctx.moveTo(PX(p[0]),PY(p[1])));
ctx.closePath(); ctx.fillStyle = ink; ctx.fill();
} else if(surface.id === 'soil'){
const cx = lug.reduce((a,p)=>a+p[0],0)/lug.length;
const cy = lug.reduce((a,p)=>a+p[1],0)/lug.length;
let minX=1e9,maxX=-1e9,minY=1e9,maxY=-1e9;
lug.forEach(p=>{minX=Math.min(minX,p[0]);maxX=Math.max(maxX,p[0]);minY=Math.min(minY,p[1]);maxY=Math.max(maxY,p[1]);});
const rx = (maxX-minX)*0.55*s, ry=(maxY-minY)*0.55*s;
const jx = (rnd()-0.5)*7, jy=(rnd()-0.5)*7;
const g = ctx.createRadialGradient(PX(cx)+jx,PY(cy)+jy,1,PX(cx)+jx,PY(cy)+jy,Math.max(rx,ry));
g.addColorStop(0,'rgba(31,42,53,0.85)'); g.addColorStop(0.65,'rgba(31,42,53,0.45)');
g.addColorStop(1,'rgba(31,42,53,0)');
ctx.fillStyle = g;
ctx.beginPath(); ctx.ellipse(PX(cx)+jx,PY(cy)+jy,rx,ry,0,0,Math.PI*2); ctx.fill();
for(let k=0;k<3;k++){
ctx.fillStyle='rgba(31,42,53,0.35)';
ctx.beginPath();
ctx.arc(PX(cx)+(rnd()-0.5)*rx*2.2, PY(cy)+(rnd()-0.5)*ry*2.2, 1+rnd()*1.6,0,Math.PI*2);
ctx.fill();
}
} else { // rock
const ext = [...lug].sort((a,b)=>a[0]-b[0]);
const picks = [ext[0], ext[ext.length-1]];
const vert = [...lug].sort((a,b)=>a[1]-b[1]);
picks.push(vert[0]);
ctx.fillStyle = ink;
picks.forEach(p=>{
const x=PX(p[0]), y=PY(p[1]), r=4.2;
ctx.beginPath(); ctx.moveTo(x-r,y); ctx.lineTo(x,y-r*0.9); ctx.lineTo(x+r,y); ctx.closePath(); ctx.fill();
});
}
});
ctx.fillStyle = '#6a7684'; ctx.font = '10px system-ui,sans-serif';
ctx.fillText('coverage — ' + surface.word, 10, TOP_H - 10);
}
function drawSection(ctx, surface, pattern){
ctx.fillStyle = '#f4f2ed'; ctx.fillRect(0,0,SEC_W,SEC_H);
const L = 58, R = 300, plateTop = 18, plateBot = 32, baseY = 96;
// --- surface profile
const prof = [];
const rnd = mulberry32(77 + pattern.id.charCodeAt(0)*13 + surface.id.length*7);
if(surface.id === 'floor'){
for(let x=10;x<=SEC_W-10;x+=10) prof.push([x, baseY]);
} else if(surface.id === 'rock'){
for(let x=10;x<=SEC_W-10;x+=34) prof.push([x, baseY + (rnd()-0.5)*13]);
prof.push([SEC_W-10, baseY]);
} else {
for(let x=10;x<=SEC_W-10;x+=22){
const y = baseY + Math.sin(x*0.10)*3.2 + (rnd()-0.5)*2.4;
prof.push([x,y]);
}
prof.push([SEC_W-10, baseY]);
}
const yAt = x => { for(let i=1;i<prof.length;i++){ if(x>=prof[i-1][0]&&x<=prof[i][0]){
const t=(x-prof[i-1][0])/(prof[i][0]-prof[i-1][0]); return prof[i-1][1]+(prof[i][1]-prof[i-1][1])*t; } }
return baseY; };
ctx.beginPath(); ctx.moveTo(prof[0][0],prof[0][1]);
prof.forEach(p=>ctx.lineTo(p[0],p[1]));
ctx.lineTo(SEC_W, SEC_H); ctx.lineTo(0, SEC_H); ctx.closePath();
ctx.fillStyle = surface.fill; ctx.fill();
ctx.beginPath(); ctx.moveTo(prof[0][0],prof[0][1]);
prof.forEach(p=>ctx.lineTo(p[0],p[1]));
ctx.strokeStyle = surface.line; ctx.lineWidth = 1.4; ctx.stroke();
// --- lug schematic
const spec = { A:{n:5,w:34,depth:18}, B:{n:4,w:38,depth:12}, C:{n:3,w:50,depth:6} }[pattern.id];
const gap = (R - L - spec.n*spec.w) / (spec.n - 1);
const lugs = [];
for(let i=0;i<spec.n;i++){
const x = L + i*(spec.w+gap);
lugs.push({x0:x, x1:x+spec.w, bottom: plateBot + spec.depth});
ctx.fillStyle = pattern.color;
ctx.fillRect(x, plateBot, spec.w, spec.depth);
}
// plate
ctx.fillStyle = '#e4eaf0'; ctx.strokeStyle='#9aa6b2'; ctx.lineWidth=1;
ctx.fillRect(L, plateTop, R-L, plateBot-plateTop);
ctx.strokeRect(L, plateTop, R-L, plateBot-plateTop);
// --- contact marks
lugs.forEach(l=>{
const yy = yAt((l.x0+l.x1)/2);
if(surface.id==='floor'){
ctx.strokeStyle='rgba(31,42,53,0.9)'; ctx.lineWidth=3;
ctx.beginPath(); ctx.moveTo(l.x0+1,yy+1); ctx.lineTo(l.x1-1,yy+1); ctx.stroke();
} else if(surface.id==='rock'){
ctx.fillStyle='rgba(31,42,53,0.9)';
[l.x0+3, l.x1-3].forEach(x=>{
ctx.beginPath(); ctx.moveTo(x-5,yy-6); ctx.lineTo(x+5,yy-6); ctx.lineTo(x,yy+2); ctx.closePath(); ctx.fill();
});
} else {
ctx.fillStyle='rgba(31,42,53,0.55)';
ctx.beginPath(); ctx.ellipse((l.x0+l.x1)/2, yy+1, (l.x1-l.x0)*0.36, 5, 0,0,Math.PI*2); ctx.fill();
}
});
// --- labels
ctx.fillStyle = '#3b4753'; ctx.font='10px system-ui,sans-serif';
ctx.textAlign='left';
ctx.fillText('groove gap — ' + pattern.gap, 8, 11);
ctx.textAlign='right';
ctx.fillText('lug depth — ' + pattern.depthWord, SEC_W-8, 11);
ctx.textAlign='left';
ctx.fillText('sole pad', 8, 24);
ctx.strokeStyle='#9aa6b2'; ctx.lineWidth=0.8;
ctx.beginPath(); ctx.moveTo(44,21); ctx.lineTo(L-2,24); ctx.stroke();
ctx.fillText('contact patches', 8, SEC_H-12);
ctx.beginPath(); ctx.moveTo(72, SEC_H-15); ctx.lineTo(lugs[1].x0+8, yAt(lugs[1].x0+8)+4); ctx.stroke();
ctx.textAlign='right';
ctx.fillStyle='#6a7684';
ctx.fillText(surface.name.toLowerCase() + ' profile', SEC_W-8, SEC_H-12);
ctx.textAlign='left';
}
function paint(canvas, W, H, fn){
const dpr = Math.min(window.devicePixelRatio || 1, 2);
canvas.width = W*dpr; canvas.height = H*dpr;
canvas.style.width = W+'px'; canvas.style.height = H+'px';
const ctx = canvas.getContext('2d');
ctx.setTransform(dpr,0,0,dpr,0,0);
ctx.clearRect(0,0,W,H);
fn(ctx);
}
/* ------------------------------------------------------------------ *
* three.js scene
* ------------------------------------------------------------------ */
const view = document.getElementById('view');
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(window.devicePixelRatio,2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
view.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9d1d8);
scene.fog = new THREE.Fog(0xc9d1d8, 34, 78);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 200);
camera.position.set(0, 15.5, 22);
scene.add(new THREE.HemisphereLight(0xe4edf5, 0x6d6252, 0.85));
const sun = new THREE.DirectionalLight(0xffffff, 1.15);
sun.position.set(11,17,9); sun.castShadow = true;
sun.shadow.mapSize.set(2048,2048);
Object.assign(sun.shadow.camera,{left:-20,right:20,top:14,bottom:-14,near:1,far:60});
sun.shadow.bias = -0.0012;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xbfd4e6, 0.35); rim.position.set(-12,7,-10); scene.add(rim);
/* ---------- custom orbit controls (no addons) ---------- */
const ctrl = {
target: new THREE.Vector3(0,1.1,0),
r: 27, phi: 0.98, theta: 0,
rT: 27, phiT: 0.98, thetaT: 0,
dragging:false, panning:false, lx:0, ly:0, moved:0
};
function applyCamera(){
const sp = Math.sin(ctrl.phi), cp = Math.cos(ctrl.phi);
camera.position.set(
ctrl.target.x + ctrl.r*sp*Math.sin(ctrl.theta),
ctrl.target.y + ctrl.r*cp,
ctrl.target.z + ctrl.r*sp*Math.cos(ctrl.theta)
);
camera.lookAt(ctrl.target);
}
function resetView(){ ctrl.rT=27; ctrl.phiT=0.98; ctrl.thetaT=0; ctrl.target.set(0,1.1,0); }
const el = renderer.domElement;
el.addEventListener('pointerdown', e=>{
ctrl.dragging = true; ctrl.panning = e.shiftKey || e.button===2;
ctrl.lx = e.clientX; ctrl.ly = e.clientY; ctrl.moved = 0;
el.setPointerCapture(e.pointerId);
});
el.addEventListener('pointermove', e=>{
if(!ctrl.dragging) return;
const dx = e.clientX-ctrl.lx, dy = e.clientY-ctrl.ly;
ctrl.lx = e.clientX; ctrl.ly = e.clientY; ctrl.moved += Math.abs(dx)+Math.abs(dy);
if(ctrl.panning){
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix,0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
const k = ctrl.r*0.0016;
ctrl.target.addScaledVector(right,-dx*k).addScaledVector(up, dy*k);
ctrl.target.x = THREE.MathUtils.clamp(ctrl.target.x,-16,16);
ctrl.target.z = THREE.MathUtils.clamp(ctrl.target.z,-10,10);
} else {
ctrl.thetaT -= dx*0.0055;
ctrl.phiT = THREE.MathUtils.clamp(ctrl.phiT - dy*0.0045, 0.18, 1.45);
}
});
el.addEventListener('pointerup', e=>{
ctrl.dragging = false;
if(ctrl.moved < 6) pick(e);
});
el.addEventListener('pointercancel', ()=> ctrl.dragging=false);
el.addEventListener('contextmenu', e=> e.preventDefault());
el.addEventListener('wheel', e=>{
e.preventDefault();
ctrl.rT = THREE.MathUtils.clamp(ctrl.rT * (1 + Math.sign(e.deltaY)*0.09), 7, 52);
}, {passive:false});
window.addEventListener('keydown', e=>{ if(e.key==='r'||e.key==='R') resetView(); });
/* ---------- helpers ---------- */
function mulberry32(a){ return function(){ a|=0; a=a+0x6D2B79F5|0; let t=Math.imul(a^a>>>15,1|a);
t=t+Math.imul(t^t>>>7,61|t)^t; return ((t^t>>>14)>>>0)/4294967296; }; }
function flatMat(color, extra={}){ return new THREE.MeshLambertMaterial({color, flatShading:true, ...extra}); }
function facetedTop(w,d,segs,color,jitter,seed){
const geo = new THREE.PlaneGeometry(w,d,segs,segs);
geo.rotateX(-Math.PI/2);
const pos = geo.attributes.position, rnd = mulberry32(seed);
for(let i=0;i<pos.count;i++) pos.setY(i,(rnd()-0.5)*jitter*2);
const g = geo.toNonIndexed();
const n = g.attributes.position.count, colors = new Float32Array(n*3);
const base = new THREE.Color(color);
for(let i=0;i<n;i+=3){
const c = base.clone().multiplyScalar(0.84 + rnd()*0.3);
for(let k=0;k<3;k++){ colors[(i+k)*3]=c.r; colors[(i+k)*3+1]=c.g; colors[(i+k)*3+2]=c.b; }
}
g.setAttribute('color', new THREE.BufferAttribute(colors,3));
const m = new THREE.Mesh(g, new THREE.MeshLambertMaterial({vertexColors:true, flatShading:true}));
m.receiveShadow = true; return m;
}
function makeLabelSprite(title, sub, accent){
const c = document.createElement('canvas'); c.width=512; c.height=128;
const x = c.getContext('2d');
x.fillStyle='rgba(16,21,26,0.82)';
x.beginPath(); x.roundRect(4,4,504,120,18); x.fill();
x.fillStyle = accent || '#e6edf4'; x.font='600 44px system-ui,sans-serif'; x.textAlign='center';
x.fillText(title, 256, sub ? 62 : 80);
if(sub){ x.fillStyle='#9fb0c0'; x.font='26px system-ui,sans-serif'; x.fillText(sub, 256, 100); }
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace;
const s = new THREE.Sprite(new THREE.SpriteMaterial({map:t, transparent:true, depthTest:false}));
s.renderOrder = 12;
return s;
}
/* ---------- platform ---------- */
const ground = new THREE.Mesh(new THREE.PlaneGeometry(220,220), flatMat(0xc2c9d0));
ground.rotation.x = -Math.PI/2; ground.position.y = -1.02; ground.receiveShadow = true; scene.add(ground);
const platform = new THREE.Mesh(new THREE.BoxGeometry(31.5,0.45,13), flatMat(0x3f454d));
platform.position.set(0,-0.78,0); platform.receiveShadow = true; platform.castShadow = true; scene.add(platform);
/* ---------- tiles ---------- */
const TILE_X = [-9.4, 0, 9.4];
const SOLE_Z = [-2.35, 0, 2.35];
const HOVER_Y = 1.35;
const picks = [];
function buildTile(surf, si){
const x = TILE_X[si], grp = new THREE.Group(); grp.position.x = x; scene.add(grp);
const slab = new THREE.Mesh(new THREE.BoxGeometry(7.6,0.5,7.6), flatMat(0x4b525a));
slab.position.y = -0.27; slab.castShadow = true; slab.receiveShadow = true; grp.add(slab);
if(surf.id === 'soil'){
const top = facetedTop(7.5,7.5,7,0x6d4f36,0.085,101+si); grp.add(top);
const rnd = mulberry32(500+si);
for(let i=0;i<46;i++){
const a = rnd()*Math.PI*2, rad = 1.5 + rnd()*2.1;
const px = Math.cos(a)*rad, pz = Math.sin(a)*rad;
const s = 0.05 + rnd()*0.075;
const peb = new THREE.Mesh(new THREE.IcosahedronGeometry(s,0), flatMat(rnd()>0.5?0x5a4128:0x84603f));
peb.position.set(px, s*0.45, pz);
peb.rotation.set(rnd()*3,rnd()*3,rnd()*3);
peb.castShadow = true; peb.receiveShadow = true; grp.add(peb);
}
} else if(surf.id === 'rock'){
const top = facetedTop(7.5,7.5,6,0x7b8087,0.13,202+si); grp.add(top);
const rnd = mulberry32(900+si);
for(let i=0;i<11;i++){
const a = rnd()*Math.PI*2, rad = 1.7 + rnd()*2.0;
const s = 0.16 + rnd()*0.3;
const rock = new THREE.Mesh(new THREE.IcosahedronGeometry(s,0), flatMat(rnd()>0.5?0x6d737a:0x8b9199));
rock.position.set(Math.cos(a)*rad, s*0.42, Math.sin(a)*rad);
rock.scale.set(1+rnd()*0.5, 0.55+rnd()*0.5, 1+rnd()*0.4);
rock.rotation.set(rnd()*3,rnd()*3,rnd()*3);
rock.castShadow = true; rock.receiveShadow = true; grp.add(rock);
}
} else {
const t = 2.44;
for(let i=0;i<3;i++) for(let j=0;j<3;j++){
const shade = 0xd3d8dc + (i+j)%3*0x012;
const m = new THREE.Mesh(new THREE.PlaneGeometry(t,t), flatMat(shade));
m.rotation.x = -Math.PI/2;
m.position.set(-t + i*(t+0.04), 0.012, -t + j*(t+0.04));
m.receiveShadow = true; grp.add(m);
}
}
return grp;
}
/* ---------- soles ---------- */
function buildSole(pattern, surf){
const g = new THREE.Group();
const plateMat = flatMat(0xe6ebf1, {transparent:true});
const lugMat = flatMat(new THREE.Color(pattern.color), {transparent:true});
const shape = new THREE.Shape(FOOTPRINT.map(p=>new THREE.Vector2(p[0],p[1])));
const plateGeo = new THREE.ExtrudeGeometry(shape,{depth:0.13,bevelEnabled:false,curveSegments:1});
plateGeo.rotateX(-Math.PI/2);
const plate = new THREE.Mesh(plateGeo, plateMat);
plate.castShadow = true; g.add(plate);
pattern.lugs.forEach(lug=>{
const ls = new THREE.Shape(lug.map(p=>new THREE.Vector2(p[0],p[1])));
const geo = new THREE.ExtrudeGeometry(ls,{depth:pattern.depth,bevelEnabled:false,curveSegments:1});
geo.rotateX(Math.PI/2);
const m = new THREE.Mesh(geo, lugMat);
m.castShadow = true; g.add(m);
});
const tag = makeLabelSprite(pattern.id+' · '+pattern.name, null, pattern.color);
tag.scale.set(1.9,0.48,1); tag.position.set(0,0.52,0); g.add(tag);
g.userData = {pattern:pattern.id, surface:surf.id};
g.traverse(o=>{ if(o.isMesh){ o.userData = {pattern:pattern.id, surface:surf.id}; picks.push(o); } });
return {group:g, plateMat, lugMat};
}
/* ---------- contact cards + drop lines ---------- */
function contactTexture(surf, pattern){
const c = document.createElement('canvas'); c.width = TOP_W*3; c.height = TOP_H*3;
const ctx = c.getContext('2d'); ctx.setTransform(3,0,0,3,0,0);
drawTopView(ctx, surf, pattern);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; t.anisotropy = 4;
return t;
}
function sectionTexture(surf, pattern){
const c = document.createElement('canvas'); c.width = SEC_W*3; c.height = SEC_H*3;
const ctx = c.getContext('2d'); ctx.setTransform(3,0,0,3,0,0);
drawSection(ctx, surf, pattern);
const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; t.anisotropy = 4;
return t;
}
/* ---------- build everything ---------- */
const items = [];
const boardItems = [];
SURFACES.forEach((surf,si)=>{
const tile = buildTile(surf, si);
const x = TILE_X[si];
// standing section board at the back of the tile
const boardHolder = new THREE.Group(); boardHolder.position.set(x,0,-4.55); scene.add(boardHolder);
const post = new THREE.Mesh(new THREE.CylinderGeometry(0.045,0.055,1.5,6), flatMat(0x525a63));
post.position.y = 0.35; post.castShadow = true; boardHolder.add(post);
const frame = new THREE.Mesh(new THREE.BoxGeometry(4.62,1.80,0.07), flatMat(0x2c333b));
frame.position.y = 1.55; frame.castShadow = true; boardHolder.add(frame);
const board = new THREE.Mesh(new THREE.PlaneGeometry(4.42,1.64), new THREE.MeshBasicMaterial({transparent:true}));
board.position.set(0,1.55,0.045); boardHolder.add(board);
boardItems.push({holder:boardHolder, board, surf});
const nameTag = makeLabelSprite(surf.name.toUpperCase(), surf.sub, '#f0f5fa');
nameTag.scale.set(2.5,0.62,1); nameTag.position.set(x,2.85,-4.55); scene.add(nameTag);
PATTERNS.forEach((pat,pi)=>{
const z = SOLE_Z[pi];
const sole = buildSole(pat, surf);
sole.group.position.set(x, HOVER_Y, z);
sole.group.rotation.y = Math.PI/2;
sole.group.rotation.x = 0.055;
scene.add(sole.group);
// contact card (projected imprint) lying on / just above the surface
const cardHolder = new THREE.Group();
cardHolder.position.set(x, surf.id === 'floor' ? 0.035 : 0.24, z);
cardHolder.rotation.y = Math.PI/2;
const cardMat = new THREE.MeshBasicMaterial({map: contactTexture(surf,pat), transparent:true, opacity:0.96, depthWrite:false});
const card = new THREE.Mesh(new THREE.PlaneGeometry(1.6,2.6), cardMat);
card.rotation.x = -Math.PI/2;
card.renderOrder = 3;
cardHolder.add(card);
scene.add(cardHolder);
// dashed drop line from the sole to its imprint
const lg = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, HOVER_Y - pat.depth - 0.02, z),
new THREE.Vector3(x, cardHolder.position.y + 0.02, z)
]);
const line = new THREE.Line(lg, new THREE.LineDashedMaterial({color:0x8e99a5, dashSize:0.12, gapSize:0.11, transparent:true, opacity:0.6}));
line.computeLineDistances(); scene.add(line);
items.push({surf, pat, pi, sole, card, cardMat, line});
});
});
/* ---------- selection state ---------- */
let selected = 'A';
const chipsEl = document.getElementById('chips');
const cardsEl = document.getElementById('cards');
PATTERNS.forEach(p=>{
const b = document.createElement('div');
b.className = 'chip'; b.dataset.p = p.id;
b.innerHTML = `<span class="swatch" style="background:${p.color}"></span><b>${p.id}</b> ${p.name}`;
b.addEventListener('click', ()=> select(p.id));
b.addEventListener('mouseenter', ()=> hover(p.id));
b.addEventListener('mouseleave', ()=> hover(null));
chipsEl.appendChild(b);
});
let hovered = null;
function hover(id){ hovered = id; refresh(); }
function select(id){ selected = id; refresh(); }
function refresh(){
const dim = document.getElementById('t-dim').checked;
const showCards = document.getElementById('t-cards').checked;
const showBoards = document.getElementById('t-boards').checked;
[...chipsEl.children].forEach(c=> c.classList.toggle('on', c.dataset.p === selected));
items.forEach(it=>{
const on = it.pat.id === selected;
const hot = hovered && it.pat.id === hovered;
const op = dim ? (on ? 1 : 0.3) : 1;
it.sole.plateMat.opacity = op; it.sole.lugMat.opacity = op;
it.sole.plateMat.emissive.set(hot ? 0x334455 : 0x000000);
it.sole.lugMat.emissive.set(hot ? 0x223344 : 0x000000);
it.card.visible = showCards;
it.cardMat.opacity = dim ? (on ? 0.96 : 0.3) : 0.96;
it.line.visible = showCards;
it.line.material.opacity = dim ? (on ? 0.6 : 0.22) : 0.6;
// refresh card texture for the current pattern of this item
const tex = contactTexture(it.surf, it.pat);
if(it.cardMat.map) it.cardMat.map.dispose();
it.cardMat.map = tex; it.cardMat.needsUpdate = true;
});
boardItems.forEach(b=>{
b.holder.visible = showBoards;
const pat = PATTERNS.find(p=>p.id === selected);
const tex = sectionTexture(b.surf, pat);
if(b.board.material.map) b.board.material.map.dispose();
b.board.material.map = tex; b.board.material.needsUpdate = true;
});
// panel cards
SURFACES.forEach((surf,si)=>{
const card = cardsEl.querySelector(`.card[data-surface="${surf.id}"]`);
if(!card) return;
const pat = PATTERNS.find(p=>p.id === selected);
const d = describe(surf, pat);
paint(card.querySelector('.topview'), TOP_W, TOP_H, ctx=>drawTopView(ctx, surf, pat));
paint(card.querySelector('.section'), SEC_W, SEC_H, ctx=>drawSection(ctx, surf, pat));
card.querySelector('dd.contact').textContent = d.contact;
card.querySelector('dd.groove').textContent = d.groove;
card.querySelector('dd.edge').textContent = d.edge;
card.querySelector('dd.response').textContent = d.response;
card.querySelector('.pnote').textContent = pat.note;
card.classList.toggle('active', selected);
});
}
/* ---------- panel cards markup ---------- */
SURFACES.forEach(s=>{
const d = document.createElement('div');
d.className = 'card'; d.dataset.surface = s.id;
d.innerHTML = `
<div class="card-head"><h3>${s.name}</h3><span>${s.sub}</span></div>
<canvas class="topview"></canvas>
<canvas class="section"></canvas>
<dl>
<dt>Contact geom.</dt><dd class="contact"></dd>
<dt>Groove visib.</dt><dd class="groove"></dd>
<dt>Edge</dt><dd class="edge"></dd>
<dt>Response</dt><dd class="response"></dd>
</dl>
<div class="foot">layout note — <span class="pnote"></span></div>`;
cardsEl.appendChild(d);
});
['t-cards','t-boards','t-dim'].forEach(id=> document.getElementById(id).addEventListener('change', refresh));
/* ---------- picking ---------- */
const ray = new THREE.Raycaster(), ndc = new THREE.Vector2();
function pick(e){
const r = el.getBoundingClientRect();
ndc.x = ((e.clientX-r.left)/r.width)*2-1;
ndc.y = -((e.clientY-r.top)/r.height)*2+1;
ray.setFromCamera(ndc, camera);
const hit = ray.intersectObjects(picks,false)[0];
if(hit && hit.object.userData.pattern) select(hit.object.userData.pattern);
}
/* ---------- resize + loop ---------- */
function resize(){
const w = view.clientWidth, h = view.clientHeight;
renderer.setSize(w,h,false);
camera.aspect = w/h; camera.updateProjectionMatrix();
}
window.addEventListener('resize', resize);
resize();
const clock = new THREE.Clock();
function tick(){
requestAnimationFrame(tick);
const k = 0.12;
ctrl.r += (ctrl.rT-ctrl.r)*k;
ctrl.phi += (ctrl.phiT-ctrl.phi)*k;
ctrl.theta += (ctrl.thetaT-ctrl.theta)*k;
applyCamera();
// boards stay upright and face the camera
boardItems.forEach(b=>{
const p = new THREE.Vector3(); b.holder.getWorldPosition(p);
b.holder.rotation.y = Math.atan2(camera.position.x-p.x, camera.position.z-p.z);
});
const t = clock.getElapsedTime();
items.forEach((it,i)=>{
it.sole.group.position.y = HOVER_Y + Math.sin(t*0.6 + i*1.1)*0.035;
});
renderer.render(scene,camera);
}
refresh();
tick();
</script>
</body>
</html>
```