Prompt specification
Build or customize the Three.js 3D scene "Infiltration columns with contrasting soils" 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: Infiltration columns with contrasting soils
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/infiltration-columns-with-contrasting-soils-x1186
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts soil horizons. Place coarse and fine material in transparent columns over collection cups; animate qualitative infiltration at different rates and explicitly avoid universal numerical permeability claims. Stylized solid forms.
Working Three.js Starter (infiltration-columns-with-contrasting-soils-x1186):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Soil Horizons — Qualitative Infiltration</title>
<style>
:root{
--ink:#3b2f24; --ink-soft:#7b6647; --paper:rgba(255,252,246,.88);
--line:rgba(59,47,36,.14); --accent:#a9713c;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#f3ecdd;color:var(--ink);
font-family:system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
-webkit-font-smoothing:antialiased}
#scene{position:fixed;inset:0}
canvas{display:block;touch-action:none}
.panel{
position:fixed;background:var(--paper);border:1px solid var(--line);border-radius:14px;
box-shadow:0 10px 26px rgba(70,52,32,.14);padding:14px 16px;
backdrop-filter:blur(7px);-webkit-backdrop-filter:blur(7px);
}
h1{font-size:17px;margin:0 0 6px;letter-spacing:.2px}
h2{font-size:12px;margin:0 0 8px;text-transform:uppercase;letter-spacing:.14em;color:var(--ink-soft)}
h3{font-size:14px;margin:0}
p{margin:0}
.lede{font-size:12.5px;line-height:1.5;color:#4d3f31}
.hint{margin-top:8px;font-size:11px;color:var(--ink-soft)}
#titlePanel{top:16px;left:16px;max-width:340px}
#cardWrap{position:fixed;top:16px;right:16px;width:286px;display:flex;flex-direction:column;gap:10px;
max-height:calc(100vh - 108px);overflow-y:auto;pointer-events:none}
.card{position:relative;pointer-events:auto}
.chead{display:flex;gap:9px;align-items:flex-start}
.swatch{width:16px;height:16px;border-radius:4px;margin-top:3px;flex:none;border:1px solid rgba(0,0,0,.18)}
.sub{font-size:11px;color:var(--ink-soft);margin-top:2px}
.chip{display:inline-block;margin-top:6px;font-size:10.5px;letter-spacing:.09em;text-transform:uppercase;
color:#6b4c2c;background:rgba(169,113,60,.13);border:1px solid rgba(169,113,60,.25);
border-radius:999px;padding:2px 9px}
.desc{font-size:11.5px;line-height:1.45;color:#4d3f31;margin-top:7px}
.bar{height:6px;border-radius:4px;background:rgba(59,47,36,.12);overflow:hidden;margin-top:9px}
.bar i{display:block;height:100%;width:0;border-radius:4px;
background:linear-gradient(90deg,#8fd0ef,#3f92c4);transition:width .12s linear}
.state{font-size:11px;color:var(--ink-soft);margin-top:5px;min-height:15px}
#legendPanel{left:16px;bottom:16px;width:330px}
#legendList{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:1fr;gap:5px}
#legendList li{display:flex;gap:8px;align-items:center;font-size:11.5px;color:#4d3f31}
#legendList b{width:15px;height:15px;flex:none;border-radius:3px;display:grid;place-items:center;
font-size:9px;color:#fff}
.note{font-size:10.5px;color:var(--ink-soft);margin-top:8px;line-height:1.45}
.disclaimer{margin-top:9px;padding-top:8px;border-top:1px dashed var(--line);
font-size:10.5px;line-height:1.5;color:#5d4b38;font-style:italic}
.disclaimer strong{font-style:normal}
#controlPanel{left:50%;transform:translateX(-50%);bottom:16px;display:flex;gap:7px;align-items:center;
flex-wrap:wrap;justify-content:center;padding:9px 12px}
.btn{font:inherit;font-size:11.5px;padding:6px 11px;border-radius:9px;border:1px solid var(--line);
background:rgba(255,255,255,.75);color:var(--ink);cursor:pointer;transition:.15s}
.btn:hover{background:#fff;border-color:rgba(169,113,60,.5)}
.btn.on{background:#a9713c;color:#fff;border-color:#8d5c2e}
.lbl{font-size:11px;color:var(--ink-soft)}
.sep{width:1px;height:20px;background:var(--line)}
@media (max-width:980px){
#legendPanel{display:none}
#cardWrap{width:230px}
#titlePanel{max-width:250px}
}
@media (max-width:620px){
#titlePanel{display:none}
#cardWrap{width:170px;font-size:10px}
.desc{display:none}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="panel" id="titlePanel">
<h1>Soil horizons & qualitative infiltration</h1>
<p class="lede">Three stylized pedons sit in transparent columns above collection cups. Water ponds on the surface, a wetting front descends through each profile, and the cup below fills. Coarser material is shown draining more readily than finer material.</p>
<p class="hint">Drag to orbit · wheel to zoom · shift-drag to pan · click a column to focus</p>
</div>
<div id="cardWrap"></div>
<div class="panel" id="legendPanel">
<h2>Horizons</h2>
<ul id="legendList"></ul>
<p class="note">Colours are stylized. Real horizon colour, thickness and boundary sharpness vary with local soil, parent material, climate and land use.</p>
<p class="disclaimer"><strong>Qualitative illustration only.</strong> The relative speeds shown are illustrative tendencies for the depicted textures — they are not measurements. Infiltration and permeability depend on soil structure, aggregation, pore size and connectivity, antecedent moisture, compaction, depth, temperature and site conditions; <em>no universal numerical permeability values are implied or should be inferred from this scene.</em></p>
</div>
<div class="panel" id="controlPanel">
<button class="btn" id="playBtn">Pause</button>
<button class="btn" id="resetBtn">Reset</button>
<span class="sep"></span>
<span class="lbl">Pour:</span>
<button class="btn pour" data-pour="0.55">Drizzle</button>
<button class="btn pour on" data-pour="1">Steady</button>
<button class="btn pour" data-pour="1.75">Heavy</button>
<span class="sep"></span>
<button class="btn" id="viewBtn">Reset view</button>
<button class="btn" id="labelBtn">Hide labels</button>
</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ------------------------------------------------------------------ utils */
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
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;};}
const rnd = mulberry32(20240917);
/* ------------------------------------------------------------- scene setup */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf3ecdd);
scene.fog = new THREE.Fog(0xf3ecdd, 30, 72);
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
renderer.setSize(innerWidth,innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.getElementById('scene').appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(42, innerWidth/innerHeight, 0.1, 200);
scene.add(new THREE.HemisphereLight(0xfff6e6, 0x6d5c46, 1.05));
const sun = new THREE.DirectionalLight(0xfff3df, 1.7);
sun.position.set(7,13,9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048,2048);
sun.shadow.camera.left=-14; sun.shadow.camera.right=14;
sun.shadow.camera.top=16; sun.shadow.camera.bottom=-8;
sun.shadow.camera.near=1; sun.shadow.camera.far=42;
sun.shadow.bias=-0.0012;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xdfe9ff,0.45);
rim.position.set(-8,6,-7); scene.add(rim);
/* ------------------------------------------------------- geometry constants */
const BASE_Y = 1.00; // top of the collection cup / foot of the column
const COL_H = 6.00; // column height
const TOP_Y = BASE_Y + COL_H;
const R_TOP = 0.86, R_BOT = 0.70; // pedon radius top / bottom
const G_TOP = 1.00, G_BOT = 0.84; // glass radius top / bottom
const radiusAt = y => lerp(R_TOP, R_BOT, clamp((y-BASE_Y)/COL_H,0,1));
/* ------------------------------------------------------------ horizon stacks */
const HORIZONS = [
{key:'O', name:'organic litter & humus', h:0.55},
{key:'A', name:'topsoil / root zone', h:1.15},
{key:'B', name:'subsoil (illuvial)', h:1.70},
{key:'C', name:'parent material', h:1.60},
{key:'R', name:'bedrock / restrictive', h:1.00}
];
/* ------------------------------------------------------- column definitions */
const COLS = [
{
id:'coarse', x:-3.9,
title:'Coarse-textured profile',
sub:'sandy / gravelly pores',
rateWord:'relatively rapid',
css:'#c79a63',
accent:0xb97a42,
speed:0.44, // front descent (units/s) — qualitative only
collect:0.95, // relative volume reaching the cup
grainR:0.085, grainN:44, speck:8, speckN:90,
colors:[0x3a2a1c,0x7a5433,0xc09159,0xdcc59c,0x8e8b86],
desc:'Large, well-connected pores. Water reaches the base of the profile relatively readily and the cup fills comparatively briskly.'
},
{
id:'medium', x:0,
title:'Medium-textured profile',
sub:'silty loam',
rateWord:'intermediate',
css:'#a98256',
accent:0x9c7a48,
speed:0.25,
collect:0.58,
grainR:0.052, grainN:66, speck:4.5, speckN:190,
colors:[0x332619,0x5f412c,0x8e6c46,0xbda884,0x7e7a74],
desc:'Pore size and connectivity are intermediate. The wetting front advances steadily at a moderate rate and the cup fills steadily.'
},
{
id:'fine', x:3.9,
title:'Fine-textured profile',
sub:'clay-rich, densely packed',
rateWord:'relatively slow',
css:'#8d6f5e',
accent:0x8a6b5f,
speed:0.145,
collect:0.32,
grainR:0.031, grainN:96, speck:1.8, speckN:430,
colors:[0x2c2117,0x4e382a,0x7b5a47,0xa8988a,0x5f5c58],
desc:'Small, less connected pores. Water advances more slowly, remains concentrated near the surface longer, and reaches the cup gradually.'
}
];
/* ------------------------------------------------- procedural soil textures */
function soilTexture(baseHex, speckPx, speckCount, seed, gravel){
const S=256, c=document.createElement('canvas'); c.width=c.height=S;
const ctx=c.getContext('2d');
const hex='#'+baseHex.toString(16).padStart(6,'0');
ctx.fillStyle=hex; ctx.fillRect(0,0,S,S);
const r=mulberry32(seed);
// soft mottling
for(let i=0;i<26;i++){
const x=r()*S,y=r()*S,rad=16+r()*46;
const g=ctx.createRadialGradient(x,y,0,x,y,rad);
g.addColorStop(0,'rgba(0,0,0,.07)'); g.addColorStop(1,'rgba(0,0,0,0)');
ctx.fillStyle=g; ctx.beginPath(); ctx.arc(x,y,rad,0,6.2832); ctx.fill();
}
// grain speckles: size encodes texture (coarse -> big, fine -> tiny)
for(let i=0;i<speckCount;i++){
const x=r()*S,y=r()*S,rad=speckPx*(0.45+r()*0.95);
const dark = r()<0.55;
ctx.beginPath(); ctx.arc(x,y,rad,0,6.2832);
ctx.fillStyle = dark ? 'rgba(0,0,0,.20)' : 'rgba(255,255,255,.16)';
ctx.fill();
}
if(gravel){ // pale clasts for coarse parent material
for(let i=0;i<26;i++){
const x=r()*S,y=r()*S,rad=speckPx*(0.9+r()*1.1);
ctx.beginPath(); ctx.ellipse(x,y,rad,rad*0.72,r()*6.2832,0,6.2832);
ctx.fillStyle='rgba(238,230,214,.42)'; ctx.fill();
ctx.strokeStyle='rgba(70,56,40,.22)'; ctx.lineWidth=1.4; ctx.stroke();
}
}
// faint vertical pedogenic streaks
ctx.globalAlpha=.16;
for(let i=0;i<14;i++){
const x=r()*S; ctx.strokeStyle= r()<.5?'#000':'#fff';
ctx.lineWidth=1+r()*2.4; ctx.beginPath();
ctx.moveTo(x,0); ctx.bezierCurveTo(x+12*r(),S*.33,x-12*r(),S*.66,x,S); ctx.stroke();
}
ctx.globalAlpha=1;
const tex=new THREE.CanvasTexture(c);
tex.wrapS=tex.wrapT=THREE.RepeatWrapping;
tex.repeat.set(2.4,1.6);
tex.colorSpace=THREE.SRGBColorSpace;
tex.anisotropy=renderer.capabilities.getMaxAnisotropy();
return tex;
}
/* ---------------------------------------------------------- canvas labels */
function rr(ctx,x,y,w,h,r){ctx.beginPath();ctx.moveTo(x+r,y);
ctx.arcTo(x+w,y,x+w,y+h,r);ctx.arcTo(x+w,y+h,x,y+h,r);
ctx.arcTo(x,y+h,x,y,r);ctx.arcTo(x,y,x+w,y,r);ctx.closePath();}
function makeTagTexture(lines,accentCss){
const W=512;
let H=24; lines.forEach(l=>H+=l.s*1.32+14); H=Math.round(H+14);
const c=document.createElement('canvas'); c.width=W; c.height=H;
const ctx=c.getContext('2d');
rr(ctx,3,3,W-6,H-6,16);
ctx.fillStyle='rgba(255,252,245,.95)'; ctx.fill();
ctx.strokeStyle=accentCss; ctx.lineWidth=4; ctx.stroke();
let y=22;
lines.forEach(l=>{
let s=l.s;
ctx.font=`${l.w||500} ${s}px system-ui,-apple-system,"Segoe UI",Roboto,sans-serif`;
while(ctx.measureText(l.t).width>W-44 && s>14){s-=1;ctx.font=`${l.w||500} ${s}px system-ui,sans-serif`;}
ctx.fillStyle=l.c||'#3b2f24'; ctx.textBaseline='top';
ctx.fillText(l.t,22,y); y+=s*1.32+14;
});
const t=new THREE.CanvasTexture(c); t.colorSpace=THREE.SRGBColorSpace;
t.anisotropy=renderer.capabilities.getMaxAnisotropy(); return t;
}
function makeBadgeTexture(letter,accentCss){
const S=160,c=document.createElement('canvas');c.width=c.height=S;
const ctx=c.getContext('2d');
ctx.beginPath();ctx.arc(S/2,S/2,S/2-6,0,6.2832);
ctx.fillStyle='rgba(255,252,245,.95)';ctx.fill();
ctx.strokeStyle=accentCss;ctx.lineWidth=7;ctx.stroke();
ctx.fillStyle='#3b2f24';ctx.font='700 78px system-ui,sans-serif';
ctx.textAlign='center';ctx.textBaseline='middle';
ctx.fillText(letter,S/2,S/2+4);
const t=new THREE.CanvasTexture(c);t.colorSpace=THREE.SRGBColorSpace;return t;
}
const labelsGroup = new THREE.Group(); scene.add(labelsGroup);
/* --------------------------------------------------------------- the ground */
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(9.2,9.5,0.42,72),
new THREE.MeshStandardMaterial({color:0xe4d5ba,roughness:.95,flatShading:true})
);
platform.position.y=-0.21; platform.receiveShadow=true; scene.add(platform);
const ground = new THREE.Mesh(
new THREE.CircleGeometry(70,64),
new THREE.MeshStandardMaterial({color:0xf0e7d6,roughness:1})
);
ground.rotation.x=-Math.PI/2; ground.position.y=-0.43; ground.receiveShadow=true; scene.add(ground);
// stylised rocks + tufts for scale
const rockMat=new THREE.MeshStandardMaterial({color:0x9d9285,roughness:1,flatShading:true});
const tuftMat=new THREE.MeshStandardMaterial({color:0x8b9c6b,roughness:1,flatShading:true});
for(let i=0;i<26;i++){
const a=rnd()*6.2832, rad=9.8+rnd()*3.6, s=.18+rnd()*.34;
const m=new THREE.Mesh(new THREE.IcosahedronGeometry(s,0),rockMat);
m.position.set(Math.cos(a)*rad,s*.4,Math.sin(a)*rad);
m.rotation.set(rnd()*3,rnd()*3,rnd()*3);
m.castShadow=true;m.receiveShadow=true;scene.add(m);
}
for(let i=0;i<22;i++){
const a=rnd()*6.2832, rad=9.6+rnd()*4.2, h=.25+rnd()*.3;
const m=new THREE.Mesh(new THREE.ConeGeometry(.16+rnd()*.08,h,5),tuftMat);
m.position.set(Math.cos(a)*rad,h/2-0.2,Math.sin(a)*rad);
m.castShadow=true;scene.add(m);
}
/* ------------------------------------------------------------- cup profile */
const cupProfile=[
new THREE.Vector2(0.00,0.00), new THREE.Vector2(0.66,0.00),
new THREE.Vector2(0.76,0.06), new THREE.Vector2(0.80,0.35),
new THREE.Vector2(0.78,0.80), new THREE.Vector2(0.88,0.88),
new THREE.Vector2(0.90,0.98), new THREE.Vector2(0.82,1.00),
new THREE.Vector2(0.72,0.92), new THREE.Vector2(0.70,0.20),
new THREE.Vector2(0.00,0.20)
];
const cupGeo=new THREE.LatheGeometry(cupProfile,36);
const cupMat=new THREE.MeshStandardMaterial({color:0xece3d3,roughness:.85,flatShading:true,
side:THREE.DoubleSide});
/* ------------------------------------------------------- build one pedon */
const dummy=new THREE.Object3D();
const COLORS={}; // temp storage
function buildColumn(def,index){
const g=new THREE.Group(); g.position.x=def.x; scene.add(g);
const S={time:0, front:0, reachedBase:false, collected:0, fill:0, overflow:0};
def.state=S;
/* glass column */
const glass=new THREE.Mesh(
new THREE.CylinderGeometry(G_TOP,G_BOT,COL_H,44,1,true),
new THREE.MeshStandardMaterial({color:0xdceff6,roughness:.12,metalness:.05,
transparent:true,opacity:.20,side:THREE.DoubleSide,depthWrite:false})
);
glass.position.y=BASE_Y+COL_H/2; glass.renderOrder=4; g.add(glass);
const rimMat=new THREE.MeshStandardMaterial({color:0x9fb3bd,roughness:.45,metalness:.25,flatShading:true});
const rimT=new THREE.Mesh(new THREE.TorusGeometry(G_TOP,.055,8,44),rimMat);
rimT.rotation.x=Math.PI/2; rimT.position.y=TOP_Y; rimT.castShadow=true; g.add(rimT);
const rimB=new THREE.Mesh(new THREE.TorusGeometry(G_BOT,.05,8,44),rimMat);
rimB.rotation.x=Math.PI/2; rimB.position.y=BASE_Y; g.add(rimB);
/* pedon horizons */
const layers=[]; let y=BASE_Y;
HORIZONS.forEach((hz,hi)=>{
const yTop=y, yBot=y+hz.h, ym=(yTop+yBot)/2;
const tex=soilTexture(def.colors[hi],def.speck,def.speckN,1000+index*97+hi*13,hi>=3&&def.id==='coarse');
const mat=new THREE.MeshStandardMaterial({map:tex,color:0xffffff,roughness:.95,metalness:0,flatShading:true});
const mesh=new THREE.Mesh(
new THREE.CylinderGeometry(radiusAt(yTop),radiusAt(yBot),hz.h,44,1,false),mat);
mesh.position.y=ym; mesh.castShadow=true; mesh.receiveShadow=true; g.add(mesh);
// crisp horizon boundary
const line=new THREE.Mesh(
new THREE.CylinderGeometry(radiusAt(yTop)+.004,radiusAt(yTop)+.004,.035,44),
new THREE.MeshStandardMaterial({color:def.colors[hi],roughness:1,flatShading:true}));
line.position.y=yTop+.017; g.add(line);
layers.push({hz,mat,base:new THREE.Color(def.colors[hi]),
wet:new THREE.Color(def.colors[hi]).multiplyScalar(.58).lerp(new THREE.Color(0x1d3a48),.2),
yTop,yBot,ym});
y=yBot;
});
def.layers=layers;
/* 3-D surface aggregates (coarse -> chunky clasts, fine -> fine speckle) */
const gGeo=new THREE.IcosahedronGeometry(def.grainR,0);
const gMat=new THREE.MeshStandardMaterial({color:def.colors[1],roughness:1,flatShading:true});
const grains=new THREE.InstancedMesh(gGeo,gMat,def.grainN);
grains.castShadow=true; grains.instanceMatrix.setUsage(THREE.StaticDrawUsage);
for(let i=0;i<def.grainN;i++){
const li=Math.floor(rnd()*HORIZONS.length);
const L=layers[li];
const yy=lerp(L.yTop+0.05,L.yBot-0.05,rnd());
const ang=rnd()*6.2832;
const rr=radiusAt(yy)*lerp(0.86,1.0,rnd());
dummy.position.set(Math.cos(ang)*rr,yy,Math.sin(ang)*rr);
dummy.rotation.set(rnd()*3,rnd()*3,rnd()*3);
const sc=lerp(0.65,1.5,rnd()); dummy.scale.setScalar(sc);
dummy.updateMatrix(); grains.setMatrixAt(i,dummy.matrix);
}
g.add(grains);
/* wetting front shell + front disc */
const wetShell=new THREE.Mesh(new THREE.CylinderGeometry(1,1,1,44),
new THREE.MeshStandardMaterial({color:0x6fc4ef,transparent:true,opacity:.34,
roughness:.15,depthWrite:false,side:THREE.DoubleSide}));
wetShell.visible=false; wetShell.renderOrder=3; g.add(wetShell);
const frontDisc=new THREE.Mesh(new THREE.CylinderGeometry(1,1,.09,44),
new THREE.MeshStandardMaterial({color:0xbfe9ff,emissive:0x2f7fb0,emissiveIntensity:.45,
roughness:.3,transparent:true,opacity:.9,depthWrite:false}));
frontDisc.visible=false; frontDisc.renderOrder=5; g.add(frontDisc);
def.wetShell=wetShell; def.frontDisc=frontDisc; def.lastShell=-1; def.lastDisc=-1;
/* ponded water on the surface */
const pond=new THREE.Mesh(new THREE.CylinderGeometry(R_TOP*.86,R_TOP*.86,.05,40),
new THREE.MeshStandardMaterial({color:0x7ec8ee,transparent:true,opacity:.62,roughness:.1,depthWrite:false}));
pond.position.y=TOP_Y+.02; pond.renderOrder=5; g.add(pond); def.pond=pond;
/* irrigation ring */
const ring=new THREE.Mesh(new THREE.TorusGeometry(.74,.045,8,40),
new THREE.MeshStandardMaterial({color:0x9fb3bd,roughness:.4,metalness:.35,flatShading:true}));
ring.rotation.x=Math.PI/2; ring.position.y=TOP_Y+1.72; ring.castShadow=true; g.add(ring);
for(let i=0;i<4;i++){
const a=i/4*6.2832;
const n=new THREE.Mesh(new THREE.ConeGeometry(.075,.16,8),
new THREE.MeshStandardMaterial({color:0x7f949e,roughness:.4,metalness:.3,flatShading:true}));
n.position.set(Math.cos(a)*.74,TOP_Y+1.58,Math.sin(a)*.74);
n.rotation.x=Math.PI; g.add(n);
}
/* collection cup + water */
const cup=new THREE.Mesh(cupGeo,cupMat);
cup.castShadow=true; cup.receiveShadow=true; g.add(cup);
const collar=new THREE.Mesh(new THREE.CylinderGeometry(.80,.80,.16,36),
new THREE.MeshStandardMaterial({color:0xcbb79b,roughness:.9,flatShading:true}));
collar.position.y=BASE_Y-.04; g.add(collar);
const cupWater=new THREE.Mesh(new THREE.CylinderGeometry(.665,.665,1,32),
new THREE.MeshStandardMaterial({color:0x3f9fd0,roughness:.18,metalness:.05,
transparent:true,opacity:.88}));
cupWater.position.y=.21; cupWater.visible=false; g.add(cupWater); def.cupWater=cupWater;
const ripples=[];
for(let i=0;i<3;i++){
const rp=new THREE.Mesh(new THREE.TorusGeometry(.12,.018,6,28),
new THREE.MeshBasicMaterial({color:0xbfe6fb,transparent:true,opacity:.5,depthWrite:false}));
rp.rotation.x=Math.PI/2; rp.visible=false; g.add(rp);
ripples.push(rp);
}
def.ripples=ripples;
const puddle=new THREE.Mesh(new THREE.CircleGeometry(1,36),
new THREE.MeshStandardMaterial({color:0x9ccfdf,roughness:.25,transparent:true,opacity:.55,depthWrite:false}));
puddle.rotation.x=-Math.PI/2; puddle.position.y=-0.415; puddle.scale.setScalar(0.001);
puddle.visible=false; g.add(puddle); def.puddle=puddle;
/* droplets: from the ring, running down the profile, and into the cup */
const dripGeo=new THREE.SphereGeometry(.045,10,8);
const dripMat=new THREE.MeshStandardMaterial({color:0x9ddcf7,roughness:.05,
metalness:.1,transparent:true,opacity:.92});
const drips=new THREE.InstancedMesh(dripGeo,dripMat,18);
drips.instanceMatrix.setUsage(THREE.DynamicDrawUsage); drips.renderOrder=6; g.add(drips);
def.drips=drips;
def.dripData=[]; for(let i=0;i<18;i++){
const a=rnd()*6.2832,rad=Math.sqrt(rnd())*.7;
def.dripData.push({x:Math.cos(a)*rad,z:Math.sin(a)*rad,y:TOP_Y+1.62,vy:0});
}
const beadGeo=new THREE.SphereGeometry(.05,10,8);
const beads=new THREE.InstancedMesh(beadGeo,dripMat,16);
beads.instanceMatrix.setUsage(THREE.DynamicDrawUsage); beads.renderOrder=6; g.add(beads);
def.beads=beads;
def.beadData=[]; for(let i=0;i<16;i++){
def.beadData.push({a:rnd()*6.2832,depth:rnd()*COL_H,vy:0});
}
const outDrops=new THREE.InstancedMesh(dripGeo,dripMat,10);
outDrops.instanceMatrix.setUsage(THREE.DynamicDrawUsage); outDrops.renderOrder=6; g.add(outDrops);
def.outDrops=outDrops;
def.outData=[]; for(let i=0;i<10;i++) def.outData.push({a:rnd()*6.2832,r:.06+rnd()*.12,y:BASE_Y,vy:0});
const stream=new THREE.Mesh(new THREE.CylinderGeometry(.085,.085,1,16),
new THREE.MeshStandardMaterial({color:0x74c6ee,transparent:true,opacity:.7,roughness:.1,depthWrite:false}));
stream.visible=false; stream.renderOrder=5; g.add(stream); def.stream=stream;
/* pick proxy (invisible) for click-to-focus */
const pick=new THREE.Mesh(new THREE.CylinderGeometry(1.12,1.12,COL_H+2.2,12),
new THREE.MeshBasicMaterial({visible:false}));
pick.position.y=BASE_Y+COL_H/2; pick.userData.colIndex=index; g.add(pick);
/* labels */
const accentCss='#'+def.accent.toString(16).padStart(6,'0');
const titleTex=makeTagTexture([
{t:def.title,s:44,w:700,c:'#3b2f24'},
{t:def.sub,s:30,w:500,c:'#7b6647'}],accentCss);
const titleSprite=new THREE.Sprite(new THREE.SpriteMaterial({map:titleTex,transparent:true,depthWrite:false}));
titleSprite.scale.set(2.05,2.05*titleTex.image.height/titleTex.image.width,1);
titleSprite.position.set(def.x,TOP_Y+2.55,0); titleSprite.renderOrder=10;
labelsGroup.add(titleSprite); def.titleSprite=titleSprite;
const tagX = (index===0)? def.x-1.72 : def.x-1.14;
HORIZONS.forEach(hz=>{
const L=layers.find(l=>l.hz.key===hz.key);
if(index===0){
const tex=makeTagTexture([{t:hz.key+' horizon',s:38,w:700,c:'#3b2f24'},
{t:hz.name,s:26,w:500,c:'#7b6647'}],accentCss);
const sp=new THREE.Sprite(new THREE.SpriteMaterial({map:tex,transparent:true,depthWrite:false}));
sp.scale.set(1.34,1.34*tex.image.height/tex.image.width,1);
sp.position.set(tagX,L.ym,0); sp.renderOrder=10; labelsGroup.add(sp); def.tags.push(sp);
const geo=new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(def.x-0.92,L.ym,0), new THREE.Vector3(tagX+0.70,L.ym,0)]);
const ln=new THREE.Line(geo,new THREE.LineBasicMaterial({color:0xa1907a,transparent:true,opacity:.6}));
labelsGroup.add(ln); def.tags.push(ln);
}else{
const tex=makeBadgeTexture(hz.key,accentCss);
const sp=new THREE.Sprite(new THREE.SpriteMaterial({map:tex,transparent:true,depthWrite:false}));
sp.scale.set(.30,.30,1); sp.position.set(tagX,L.ym,0); sp.renderOrder=10;
labelsGroup.add(sp); def.tags.push(sp);
}
});
return def;
}
COLS.forEach(d=>d.tags=[]);
COLS.forEach(buildColumn);
/* selection ring on the ground */
const selRing=new THREE.Mesh(new THREE.TorusGeometry(1.24,.045,8,48),
new THREE.MeshBasicMaterial({color:0xa9713c,transparent:true,opacity:.85}));
selRing.rotation.x=Math.PI/2; selRing.position.set(COLS[0].x,.02,0); scene.add(selRing);
/* --------------------------------------------------------------- HUD cards */
const cardWrap=document.getElementById('cardWrap');
COLS.forEach(c=>{
const el=document.createElement('div'); el.className='panel card';
el.innerHTML=`<div class="chead"><span class="swatch" style="background:${c.css}"></span>
<div><h3>${c.title}</h3><p class="sub">${c.sub}</p></div></div>
<span class="chip">${c.rateWord}</span>
<p class="desc">${c.desc}</p>
<div class="bar"><i></i></div><p class="state"> </p>`;
cardWrap.appendChild(el);
c.card={bar:el.querySelector('.bar i'),state:el.querySelector('.state')};
});
const legendList=document.getElementById('legendList');
const legendHex={O:'#3a2a1c',A:'#7a5433',B:'#c09159',C:'#dcc59c',R:'#8e8b86'};
HORIZONS.forEach(hz=>{
const li=document.createElement('li');
li.innerHTML=`<b style="background:${legendHex[hz.key]}">${hz.key}</b><span>${hz.name}</span>`;
legendList.appendChild(li);
});
/* ---------------------------------------------------------- state & controls */
const APP={playing:true,pour:1,labels:true};
function setPour(v){
APP.pour=v;
document.querySelectorAll('.pour').forEach(b=>b.classList.toggle('on',parseFloat(b.dataset.pour)===v));
}
document.querySelectorAll('.pour').forEach(b=>b.addEventListener('click',()=>setPour(parseFloat(b.dataset.pour))));
const playBtn=document.getElementById('playBtn');
playBtn.addEventListener('click',()=>{APP.playing=!APP.playing;playBtn.textContent=APP.playing?'Pause':'Play';});
document.getElementById('resetBtn').addEventListener('click',resetSim);
document.getElementById('labelBtn').addEventListener('click',e=>{
APP.labels=!APP.labels; labelsGroup.visible=APP.labels;
e.target.textContent=APP.labels?'Hide labels':'Show labels';
});
function resetSim(){
COLS.forEach(c=>{const S=c.state;S.time=0;S.front=0;S.reachedBase=false;S.collected=0;S.fill=0;S.overflow=0;
c.dripData.forEach(d=>{d.y=TOP_Y+1.62;d.vy=0;});
c.beadData.forEach(d=>{d.depth=rnd()*COL_H;d.vy=0;});
c.outData.forEach(d=>{d.y=BASE_Y;d.vy=0;});});
}
document.getElementById('viewBtn').addEventListener('click',resetView);
/* ------------------------------------------------------- camera (hand-rolled) */
const cam={theta:0.42,phi:1.22,radius:15.5,tx:-0.35,ty:3.6,tz:0,
dTheta:0.42,dPhi:1.22,dRadius:15.5,dTx:-0.35,dTy:3.6,dTz:0};
function resetView(){cam.dTheta=0.42;cam.dPhi=1.22;cam.dRadius=15.5;cam.dTx=-0.35;cam.dTy=3.6;cam.dTz=0;}
const cTarget=new THREE.Vector3(), cPos=new THREE.Vector3();
function updateCamera(){
cam.theta=lerp(cam.theta,cam.dTheta,.12);
cam.phi=lerp(cam.phi,cam.dPhi,.12);
cam.radius=lerp(cam.radius,cam.dRadius,.12);
cam.tx=lerp(cam.tx,cam.dTx,.12); cam.ty=lerp(cam.ty,cam.dTy,.12); cam.tz=lerp(cam.tz,cam.dTz,.12);
cTarget.set(cam.tx,cam.ty,cam.tz);
const sp=Math.sin(cam.phi);
cPos.set(cTarget.x+cam.radius*sp*Math.sin(cam.theta),
cTarget.y+cam.radius*Math.cos(cam.phi),
cTarget.z+cam.radius*sp*Math.cos(cam.theta));
camera.position.copy(cPos); camera.lookAt(cTarget);
}
const el=renderer.domElement;
let dragging=false,px=0,py=0,panning=false,moved=0;
el.addEventListener('pointerdown',e=>{dragging=true;moved=0;px=e.clientX;py=e.clientY;
panning=e.shiftKey||e.button===2; el.setPointerCapture(e.pointerId);});
window.addEventListener('pointermove',e=>{
if(!dragging)return;
const dx=e.clientX-px,dy=e.clientY-py; px=e.clientX;py=e.clientY; moved+=Math.abs(dx)+Math.abs(dy);
if(panning){
const right=new THREE.Vector3().setFromMatrixColumn(camera.matrix,0);
const up=new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
const k=cam.radius*0.0016;
cam.dTx-=right.x*dx*k+up.x*dy*k;
cam.dTy-=right.y*dx*k+up.y*dy*k;
cam.dTz-=right.z*dx*k+up.z*dy*k;
}else{
cam.dTheta-=dx*0.0055;
cam.dPhi=clamp(cam.dPhi-dy*0.0045,0.28,1.52);
}
});
window.addEventListener('pointerup',e=>{
if(dragging&&moved<7)pickColumn(e.clientX,e.clientY);
dragging=false;
});
el.addEventListener('contextmenu',e=>e.preventDefault());
el.addEventListener('wheel',e=>{e.preventDefault();
cam.dRadius=clamp(cam.dRadius*(1+Math.sign(e.deltaY)*0.09),7,34);},{passive:false});
/* pinch zoom */
let pinchDist=null;
el.addEventListener('touchstart',e=>{if(e.touches.length===2)pinchDist=Math.hypot(
e.touches[0].clientX-e.touches[1].clientX,e.touches[0].clientY-e.touches[1].clientY);},{passive:true});
el.addEventListener('touchmove',e=>{if(e.touches.length===2&&pinchDist){
const d=Math.hypot(e.touches[0].clientX-e.touches[1].clientX,e.touches[0].clientY-e.touches[1].clientY);
cam.dRadius=clamp(cam.dRadius*(pinchDist/d),7,34); pinchDist=d;}},{passive:true});
/* click-to-focus */
const ray=new THREE.Raycaster(), ndc=new THREE.Vector2();
let selected=0;
function pickColumn(cx,cy){
const rect=el.getBoundingClientRect();
ndc.set(((cx-rect.left)/rect.width)*2-1,-((cy-rect.top)/rect.height)*2+1);
ray.setFromCamera(ndc,camera);
const hits=ray.intersectObjects(scene.children,true);
for(const h of hits){
let o=h.object;
while(o&&o.userData.colIndex===undefined)o=o.parent;
if(o){selected=o.userData.colIndex;const c=COLS[selected];
cam.dTx=c.x;cam.dTy=3.6;cam.dTz=0;cam.dRadius=11.5;break;}
}
}
window.addEventListener('keydown',e=>{
if(e.code==='Space'){e.preventDefault();playBtn.click();}
if(e.key==='r'||e.key==='R')resetView();
});
/* ------------------------------------------------------------- simulation */
const FILL_CAP=7.0;
function updateColumn(c,dt){
const S=c.state;
if(APP.playing){
S.time+=dt;
if(!S.reachedBase){
S.front=Math.min(COL_H,S.front+c.speed*APP.pour*dt);
if(S.front>=COL_H) S.reachedBase=true;
}
if(S.reachedBase){
S.collected+=c.collect*APP.pour*dt;
S.fill=Math.min(1,S.collected/FILL_CAP);
if(S.fill>=1) S.overflow+=dt;
}
}
/* wetting shell (rebuilt only when the front has moved appreciably) */
if(Math.abs(S.front-c.lastShell)>0.045){
c.lastShell=S.front;
const yBot=TOP_Y-S.front, h=Math.max(0.001,S.front);
const g=new THREE.CylinderGeometry(radiusAt(TOP_Y)+.015,radiusAt(yBot)+.015,h,44);
c.wetShell.geometry.dispose(); c.wetShell.geometry=g;
c.wetShell.position.set(0,(TOP_Y+yBot)/2,0);
}
c.wetShell.visible=S.front>0.03;
if(Math.abs(S.front-c.lastDisc)>0.045){
c.lastDisc=S.front;
const yb=TOP_Y-S.front, r=radiusAt(yb)+.022;
const g=new THREE.CylinderGeometry(r,r,.09,44);
c.frontDisc.geometry.dispose(); c.frontDisc.geometry=g;
c.frontDisc.position.set(0,yb,0);
}
c.frontDisc.visible=S.front>0.03&&S.front<COL_H-0.02;
/* horizon wetness tint + sheen */
c.layers.forEach(L=>{
const d0=TOP_Y-L.yTop,d1=TOP_Y-L.yBot;
const f=clamp((S.front-d0)/Math.max(.001,d1-d0),0,1);
L.mat.color.copy(L.base).lerp(L.wet,f);
L.mat.roughness=lerp(.95,.42,f);
});
/* ponding depth on the surface */
const pondScale=0.55+APP.pour*0.32;
c.pond.scale.set(pondScale,1,pondScale);
c.pond.material.opacity=0.30+APP.pour*0.16;
/* droplets falling from the ring */
const fall=1.5+APP.pour*1.1;
c.dripData.forEach((d,i)=>{
if(APP.playing){d.vy+=fall*dt*3.4; d.y-=d.vy*dt;}
if(d.y<TOP_Y+0.02){d.y=TOP_Y+1.62;d.vy=0;}
const on=APP.pour>0.8||i%2===0;
dummy.position.set(d.x,d.y,d.z);
dummy.rotation.set(0,0,0);
dummy.scale.setScalar(on&&d.y>TOP_Y+0.03?1:0);
dummy.updateMatrix(); c.drips.setMatrixAt(i,dummy.matrix);
});
c.drips.instanceMatrix.needsUpdate=true;
/* beads running down the profile surface */
const bSpeed=c.speed*1.7+0.06;
c.beadData.forEach((b,i)=>{
if(APP.playing&&S.front>0.15){b.depth+=bSpeed*dt; if(b.depth>S.front) b.depth=0;}
const y=TOP_Y-b.depth, rr=radiusAt(y)+0.055;
dummy.position.set(Math.cos(b.a)*rr,y,Math.sin(b.a)*rr);
dummy.rotation.set(0,0,0);
dummy.scale.setScalar(S.front>0.15?1:0);
dummy.updateMatrix(); c.beads.setMatrixAt(i,dummy.matrix);
});
c.beads.instanceMatrix.needsUpdate=true;
/* outflow into the cup */
const surfY=0.21+0.72*S.fill;
c.cupWater.visible=S.fill>0.012;
c.cupWater.scale.y=Math.max(.002,0.72*S.fill);
c.cupWater.position.y=0.21+0.36*S.fill;
c.stream.visible=S.reachedBase&&S.fill<1;
if(c.stream.visible){
const h=BASE_Y-surfY;
c.stream.scale.y=h; c.stream.position.y=(BASE_Y+surfY)/2;
}
c.outData.forEach((d,i)=>{
if(APP.playing&&S.reachedBase){d.vy+=9*dt;d.y-=d.vy*dt;}
if(d.y<surfY+0.02){d.y=BASE_Y;d.vy=0;}
dummy.position.set(Math.cos(d.a)*d.r,d.y,Math.sin(d.a)*d.r);
dummy.rotation.set(0,0,0);
dummy.scale.setScalar(S.reachedBase&&S.fill<1?1:0);
dummy.updateMatrix(); c.outDrops.setMatrixAt(i,dummy.matrix);
});
c.outDrops.instanceMatrix.needsUpdate=true;
/* ripples on the collected water */
c.ripples.forEach((rp,i)=>{
const ph=((S.time*0.7+i/3)%1);
const on=S.reachedBase&&S.fill>0.05;
rp.visible=on;
if(on){
rp.position.set(0,surfY+0.01,0);
rp.scale.setScalar(0.6+ph*3.4);
rp.material.opacity=0.45*(1-ph);
}
});
/* overflow puddle */
c.puddle.visible=S.overflow>0.05;
if(c.puddle.visible){
const s=0.5+Math.min(1.6,S.overflow*0.5);
c.puddle.scale.set(s,s,1);
c.puddle.material.opacity=Math.min(.6,0.2+S.overflow*0.2);
}
}
/* --------------------------------------------------------------- HUD update */
let hudT=0;
function updateHUD(dt){
hudT+=dt; if(hudT<0.1)return; hudT=0;
COLS.forEach(c=>{
const S=c.state;
const pct=clamp(S.front/COL_H,0,1)*100;
c.card.bar.style.width=pct.toFixed(1)+'%';
let txt;
if(S.front<0.35) txt='Surface ponding — only the uppermost horizon is wetting.';
else if(S.front<COL_H*0.55) txt='Wetting front descending through the upper horizons.';
else if(S.front<COL_H-0.25) txt='Front approaching the base of the profile.';
else if(S.fill>=1) txt='Cup full — water is overflowing from the collection cup.';
else txt='Percolating into the collection cup below.';
c.card.state.textContent=txt;
});
}
/* --------------------------------------------------------------- main loop */
const clock=new THREE.Clock();
function animate(){
const dt=Math.min(.05,clock.getDelta());
updateCamera();
COLS.forEach(c=>updateColumn(c,dt));
selRing.position.x=lerp(selRing.position.x,COLS[selected].x,.12);
selRing.material.opacity=0.45+0.35*Math.sin(clock.elapsedTime*1.8)*0.5+0.2;
updateHUD(dt);
renderer.render(scene,camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener('resize',()=>{
camera.aspect=innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
</script>
</body>
</html>
```