Prompt specification
Build or customize the Three.js 3D scene "Plastered reservoir edge and catchment slope" 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: Plastered reservoir edge and catchment slope
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/plastered-reservoir-edge-and-catchment-slope-x2289
Scene Description Prompt:
A stylized Maya reservoir edge receives runoff from a sloping catchment. Show basin and collection surface distinctly. HTML scene with Three.js from cdnjs.
Working Three.js Starter (plastered-reservoir-edge-and-catchment-slope-x2289):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Maya Reservoir Edge — Catchment & Basin</title>
<style>
:root{
--ink:#f3ead8; --dim:#c9bfa9; --panel:rgba(18,26,29,.74);
--edge:rgba(233,196,131,.28); --catch:#9fbd57; --basin:#43b6d6; --arch:#e2a44a;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#0d1417;
font-family:"Trebuchet MS","Segoe UI",system-ui,sans-serif;color:var(--ink)}
#app{position:fixed;inset:0}
canvas{display:block;touch-action:none}
#leaders{position:fixed;inset:0;pointer-events:none}
#labels{position:fixed;inset:0;pointer-events:none}
.panel{position:fixed;background:var(--panel);border:1px solid var(--edge);
border-radius:12px;backdrop-filter:blur(7px);box-shadow:0 10px 30px rgba(0,0,0,.35)}
#title{top:16px;left:16px;padding:12px 16px 13px;max-width:330px}
#title h1{margin:0;font-size:19px;letter-spacing:.14em;text-transform:uppercase}
#title h1 em{font-style:normal;color:var(--arch)}
#title p{margin:6px 0 0;font-size:12.5px;line-height:1.45;color:var(--dim)}
#legend{bottom:16px;left:16px;padding:12px 14px 11px;width:296px}
#legend h2{margin:0 0 8px;font-size:10.5px;letter-spacing:.2em;color:var(--dim);text-transform:uppercase}
#legend svg{display:block;margin:0 auto 8px;border-radius:8px;background:rgba(255,255,255,.05)}
.key{display:flex;gap:9px;align-items:flex-start;margin:7px 0;font-size:12px;line-height:1.4}
.sw{width:13px;height:13px;border-radius:3px;margin-top:2px;flex:none;box-shadow:0 0 0 1px rgba(0,0,0,.4)}
.key b{font-weight:600}
.key span{color:var(--dim);display:block;font-size:11px}
#controls{top:16px;right:16px;padding:12px 14px;width:212px}
#controls h2{margin:0 0 7px;font-size:10.5px;letter-spacing:.2em;color:var(--dim);text-transform:uppercase}
.row{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:10px}
button{font:inherit;font-size:11.5px;color:var(--ink);background:rgba(255,255,255,.06);
border:1px solid var(--edge);border-radius:7px;padding:6px 9px;cursor:pointer;transition:.18s}
button:hover{background:rgba(226,164,74,.18)}
button.on{background:rgba(226,164,74,.28);border-color:var(--arch);color:#fff}
.swbtn.on[data-zone="catchment"]{background:rgba(159,189,87,.3);border-color:var(--catch)}
.swbtn.on[data-zone="basin"]{background:rgba(67,182,214,.3);border-color:var(--basin)}
#hint{bottom:16px;left:50%;transform:translateX(-50%);padding:7px 14px;font-size:11px;
color:var(--dim);letter-spacing:.05em}
.label{position:absolute;padding:5px 9px 6px;border-radius:8px;white-space:nowrap;
background:rgba(12,18,20,.78);border:1px solid rgba(255,255,255,.16);
box-shadow:0 6px 18px rgba(0,0,0,.4);transform-origin:0 0;will-change:transform}
.label i{display:block;font-style:normal;font-size:9px;letter-spacing:.18em;text-transform:uppercase;color:#9fb0b6;margin-bottom:1px}
.label b{font-size:12px;font-weight:600;letter-spacing:.02em}
.label.catch{border-left:3px solid var(--catch)}
.label.basin{border-left:3px solid var(--basin)}
.label.arch{border-left:3px solid var(--arch)}
</style>
</head>
<body>
<div id="app"></div>
<svg id="leaders"></svg>
<div id="labels"></div>
<div id="title" class="panel">
<h1>Maya <em>Reservoir</em> Edge</h1>
<p>Runoff from a terraced upland catchment is carried by a stone acequia into a
cut limestone basin. The two surfaces are rendered and annotated separately.</p>
</div>
<div id="legend" class="panel">
<h2>Section through the reservoir</h2>
<svg width="268" height="84" viewBox="0 0 268 84">
<path d="M2 14 L118 50 L118 62 L2 62 Z" fill="#6d8f47"/>
<path d="M26 24 h26 v7 h-26 z M56 36 h26 v7 h-26 z M88 46 h26 v7 h-26 z" fill="#5c7c3c"/>
<path d="M118 54 L152 60" stroke="#8fd8e6" stroke-width="4" fill="none" stroke-linecap="round"/>
<path d="M148 62 Q177 82 206 62 L206 78 L148 78 Z" fill="#2b6f8c"/>
<path d="M152 63 Q177 78 202 63" stroke="#59c9e6" stroke-width="4" fill="none"/>
<path d="M148 62 Q177 82 206 62" stroke="#f0e6cd" stroke-width="2" fill="none"/>
<text x="8" y="76" fill="#9fbd57" font-size="9" font-family="sans-serif" letter-spacing="1">COLLECTION SURFACE</text>
<text x="176" y="76" fill="#43b6d6" font-size="9" font-family="sans-serif" letter-spacing="1">BASIN</text>
</svg>
<div class="key"><span class="sw" style="background:#9fbd57"></span>
<div><b>Collection surface</b><span>Sloping catchment, 12 ha · terraced milpas, ~7.4 m fall</span></div></div>
<div class="key"><span class="sw" style="background:#43b6d6"></span>
<div><b>Basin</b><span>Excavated limestone bowl, 0.9 ha · water surface at −0.1 m</span></div></div>
<div class="key"><span class="sw" style="background:#e2a44a"></span>
<div><b>Built edge</b><span>Masonry revetment, aqueduct spout, temple platform</span></div></div>
</div>
<div id="controls" class="panel">
<h2>View</h2>
<div class="row">
<button id="v-all" class="on">Whole edge</button>
<button id="v-catch">Catchment</button>
<button id="v-basin">Basin</button>
</div>
<h2>Highlight</h2>
<div class="row">
<button class="swbtn on" data-zone="all">Both</button>
<button class="swbtn" data-zone="catchment">Collection</button>
<button class="swbtn" data-zone="basin">Basin</button>
</div>
<h2>Layers</h2>
<div class="row">
<button id="l-flow" class="on">Runoff</button>
<button id="l-rain">Rain</button>
<button id="l-lab" class="on">Labels</button>
</div>
</div>
<div id="hint" class="panel">drag to orbit · scroll to zoom</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ───────────────────────────── utilities ───────────────────────────── */
const clamp=(v,a,b)=>v<a?a:v>b?b:v;
const lerp=(a,b,t)=>a+(b-a)*t;
const smooth=t=>{t=clamp(t,0,1);return t*t*(3-2*t);};
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(20240);
const rndR=(a,b)=>a+(b-a)*rnd();
/* ───────────────────────────── renderer ────────────────────────────── */
const app=document.getElementById('app');
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;
renderer.toneMapping=THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure=1.06;
app.appendChild(renderer.domElement);
const scene=new THREE.Scene();
scene.fog=new THREE.Fog(0xc4d8dd,52,135);
const camera=new THREE.PerspectiveCamera(42,innerWidth/innerHeight,0.1,400);
/* sky dome */
const sky=new THREE.Mesh(new THREE.SphereGeometry(220,32,20),
new THREE.ShaderMaterial({side:THREE.BackSide,depthWrite:false,
uniforms:{uSun:{value:new THREE.Vector3(-0.45,0.72,0.35).normalize()}},
vertexShader:`varying vec3 vD; void main(){vD=normalize(position);gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}`,
fragmentShader:`uniform vec3 uSun; varying vec3 vD;
void main(){
float h=clamp(vD.y*0.5+0.5,0.0,1.0);
vec3 zen=vec3(0.16,0.42,0.62), hor=vec3(0.93,0.84,0.70);
vec3 c=mix(hor,zen,pow(h,0.75));
float s=pow(max(dot(normalize(vD),normalize(uSun)),0.0),42.0);
c+=vec3(1.0,0.86,0.62)*s*0.85;
c+=vec3(0.98,0.78,0.5)*pow(max(1.0-abs(vD.y),0.0),6.0)*0.12;
gl_FragColor=vec4(c,1.0);}`}));
scene.add(sky);
/* lights */
scene.add(new THREE.HemisphereLight(0xbfe3f2,0x6b5a3a,0.72));
const sun=new THREE.DirectionalLight(0xfff0d0,2.15);
sun.position.set(-22,30,16);
sun.castShadow=true;
sun.shadow.mapSize.set(2048,2048);
sun.shadow.camera.left=-34;sun.shadow.camera.right=34;
sun.shadow.camera.top=34;sun.shadow.camera.bottom=-34;
sun.shadow.camera.near=1;sun.shadow.camera.far=110;
sun.shadow.bias=-0.0008;
scene.add(sun);
const fill=new THREE.DirectionalLight(0x9fc6d8,0.42);
fill.position.set(18,12,-22);scene.add(fill);
/* ─────────────────── terrain: catchment + basin ───────────────────── */
const BASIN={cx:0,cz:1.0,R:5.6};
const WATER_Y=-0.12;
const Z_CATCH=0,Z_PLAZA=1,Z_BASIN=2;
function basinTerrace(r){
if(r<3.0) return -3.60;
if(r<3.9) return -2.40;
if(r<4.8) return -1.20;
if(r<5.6) return -0.15;
return 0;
}
function baseHeight(x,z){
const r=Math.hypot(x,z-BASIN.cz);
let h=(r<BASIN.R)?basinTerrace(r):0;
if(z<-5.0){
const t=clamp((-z-5.0)/21,0,1);
let hh=smooth(t)*7.4;
const terr=smooth(clamp((t-0.28)/0.42,0,1));
hh=lerp(hh,Math.floor(hh/0.95)*0.95,terr*0.8);
hh*=1-0.55*smooth(clamp((Math.abs(x)-10)/11,0,1));
hh+=(Math.sin(x*0.45)*0.32+Math.cos(z*0.36+x*0.18)*0.34)*t;
h=Math.max(h,hh);
}
return h;
}
function slopeAt(x,z){const e=0.6;const gx=(baseHeight(x+e,z)-baseHeight(x-e,z))/(2*e);
const gz=(baseHeight(x,z+e)-baseHeight(x,z-e))/(2*e);return Math.hypot(gx,gz);}
const SIZE=72,SEG=300;
const tGeo=new THREE.PlaneGeometry(SIZE,SIZE,SEG,SEG);
tGeo.rotateX(-Math.PI/2);
const tPos=tGeo.attributes.position;
const baseCol=new Float32Array(tPos.count*3);
const zoneArr=new Uint8Array(tPos.count);
for(let i=0;i<tPos.count;i++){
const x=tPos.getX(i),z=tPos.getZ(i);
tPos.setY(i,baseHeight(x,z));
}
tGeo.computeVertexNormals();
function vertexColor(x,z){
const r=Math.hypot(x,z-BASIN.cz), s=slopeAt(x,z);
let col,zone;
if(r<BASIN.R){
if(r<3.05){col=new THREE.Color(0x74877f);zone=Z_BASIN;} // wet basin floor
else{col=new THREE.Color(0xc8bda0);zone=Z_BASIN;} // cut limestone steps
}else if(z<-5.2){
zone=Z_CATCH;
col=new THREE.Color(s>0.62?0x8d8a63:0x7d9a4c);
}else{zone=Z_PLAZA;col=new THREE.Color(0xd5c8a5);}
const j=0.90+rnd()*0.20;
col.multiplyScalar(j);
if(zone===Z_BASIN&&r<3.05) col.lerp(new THREE.Color(0x3d6b6b),0.25);
return {col,zone};
}
for(let i=0;i<tPos.count;i++){
const x=tPos.getX(i),z=tPos.getZ(i);
const {col,zone}=vertexColor(x,z);
baseCol[i*3]=col.r;baseCol[i*3+1]=col.g;baseCol[i*3+2]=col.b;
zoneArr[i]=zone;
}
tGeo.setAttribute('color',new THREE.BufferAttribute(baseCol.slice(),3));
const terrain=new THREE.Mesh(tGeo,new THREE.MeshStandardMaterial({vertexColors:true,roughness:0.97}));
terrain.receiveShadow=true;terrain.castShadow=true;
scene.add(terrain);
/* ───────────── acequia (stone runoff channel) path ─────────────── */
const chXZ=[[-8.6,-26.5],[-7.0,-22.5],[-5.2,-18.5],[-3.6,-14.5],[-2.2,-11.0],[-0.6,-8.2],[0.8,-6.2],[1.3,-4.75]];
const chPts=chXZ.map(([x,z],i)=>new THREE.Vector3(x,i===chXZ.length-1?0.30:baseHeight(x,z)-0.20,z));
const channel=new THREE.CatmullRomCurve3(chPts,false,'catmullrom',0.35);
/* carve a shallow groove for the channel into the terrain */
{
const samples=channel.getSpacedPoints(360);
for(let i=0;i<tPos.count;i++){
const x=tPos.getX(i),z=tPos.getZ(i);
let best=1e9,by=0;
for(let k=0;k<samples.length;k++){
const dx=x-samples[k].x,dz=z-samples[k].z,d=dx*dx+dz*dz;
if(d<best){best=d;by=samples[k].y;}
}
const d=Math.sqrt(best);
if(d<1.15){
const w=smooth(1-d/1.15);
const y=tPos.getY(i);
tPos.setY(i,y-(0.30*w));
}
}
tGeo.computeVertexNormals();
}
/* ─────────────── masonry: revetment, channel stones, terraces ─────────────── */
const regMeshes=[];
function register(mesh,zone,baseColor,baseOpacity){
mesh.userData.zone=zone;
regMeshes.push({mesh,zone,
baseColor:baseColor?baseColor.clone():null,
baseOpacity:baseOpacity!==undefined?baseOpacity:mesh.material.opacity,
baseTransparent:mesh.material.transparent});
return mesh;
}
function instanced(geo,mat,items,zone,cast=true){
const m=new THREE.InstancedMesh(geo,mat,items.length);
const d=new THREE.Object3D();
items.forEach((it,i)=>{
d.position.copy(it.p);
if(it.q)d.quaternion.copy(it.q);else d.rotation.set(it.rx||0,it.ry||0,it.rz||0);
const s=it.s||[1,1,1];d.scale.set(s[0],s[1],s[2]);
d.updateMatrix();m.setMatrixAt(i,d.matrix);
});
m.castShadow=cast;m.receiveShadow=true;m.instanceMatrix.needsUpdate=true;
scene.add(m);register(m,zone,mat.color,mat.opacity);
return m;
}
const stoneMat=new THREE.MeshStandardMaterial({color:0xb9ad8d,roughness:0.92});
const stoneMat2=new THREE.MeshStandardMaterial({color:0x9d9377,roughness:0.95});
/* basin rim revetment (gap where the spout enters) */
{
const items=[];
const N=76;
for(let i=0;i<N;i++){
const a=i/N*Math.PI*2;
const dx=Math.cos(a),dz=Math.sin(a);
const inflowA=Math.atan2(-5.75,1.3);
let da=Math.abs(((a-inflowA+Math.PI)%(Math.PI*2))-Math.PI);
if(da<0.22)continue;
const r=5.72;
items.push({p:new THREE.Vector3(BASIN.cx+dx*r,0.16,BASIN.cz+dz*r),
ry:a,s:[1,1,1],rx:0,rz:rndR(-0.05,0.05)});
}
instanced(new THREE.BoxGeometry(0.62,0.52,0.34),stoneMat2,items,Z_BASIN);
}
/* channel side stones */
{
const items=[];
const N=150;
for(let i=0;i<N;i++){
const t=i/(N-1),p=channel.getPointAt(t),tan=channel.getTangentAt(t);
const nx=-tan.z,nz=tan.x;const len=Math.hypot(nx,nz);const ux=nx/len,uz=nz/len;
const ang=Math.atan2(tan.x,tan.z);
for(const side of [-1,1]){
const off=0.52*side+rndR(-0.05,0.05);
items.push({p:new THREE.Vector3(p.x+ux*off,p.y-0.11+rndR(-0.03,0.03),p.z+uz*off),
ry:ang+rndR(-0.09,0.09),s:[1,1,1]});
}
}
instanced(new THREE.BoxGeometry(0.3,0.44,0.9),stoneMat,items,Z_CATCH);
}
/* terrace retaining walls on the catchment */
{
const items=[];
for(const [lvl,zz] of [[1.9,-12.0],[3.8,-16.0],[5.6,-20.5],[7.0,-25.0]]){
for(let x=-13;x<=13;x+=0.85){
const z=zz+Math.sin(x*0.14)*0.9;
const y=baseHeight(x,z);
items.push({p:new THREE.Vector3(x,y-0.18,z),ry:rndR(-0.08,0.08),s:[1,1,1]});
}
}
instanced(new THREE.BoxGeometry(0.8,0.85,0.42),stoneMat2,items,Z_CATCH);
}
/* ─────────────────────── channel + waterfall water ─────────────────────── */
function ribbon(curve,width,seg){
const pos=[],uv=[],idx=[];
for(let i=0;i<=seg;i++){
const t=i/seg,p=curve.getPointAt(t),tan=curve.getTangentAt(t);
const nx=-tan.z,nz=tan.x,L=Math.hypot(nx,nz);
pos.push(p.x+nx/L*width/2,p.y,p.z+nz/L*width/2,
p.x-nx/L*width/2,p.y,p.z-nz/L*width/2);
uv.push(0,t,1,t);
}
for(let i=0;i<seg;i++){const a=i*2,b=i*2+1,c=(i+1)*2,d=(i+1)*2+1;idx.push(a,c,b,b,c,d);}
const g=new THREE.BufferGeometry();
g.setAttribute('position',new THREE.Float32BufferAttribute(pos,3));
g.setAttribute('uv',new THREE.Float32BufferAttribute(uv,2));
g.setIndex(idx);g.computeVertexNormals();return g;
}
const flowUniforms={uTime:{value:0},uOpacity:{value:1}};
const flowMat=new THREE.ShaderMaterial({transparent:true,side:THREE.DoubleSide,depthWrite:false,
uniforms:flowUniforms,
vertexShader:`varying vec2 vUv; varying vec3 vW;
void main(){vUv=uv;vW=(modelMatrix*vec4(position,1.0)).xyz;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}`,
fragmentShader:`uniform float uTime;uniform float uOpacity;varying vec2 vUv;varying vec3 vW;
void main(){
float s=fract(vUv.y*9.0-uTime*1.35);
float streak=smoothstep(0.0,0.25,s)*smoothstep(0.75,0.45,s);
float edge=smoothstep(0.0,0.18,vUv.x)*smoothstep(1.0,0.82,vUv.x);
vec3 c=mix(vec3(0.42,0.78,0.86),vec3(0.93,0.99,1.0),streak);
gl_FragColor=vec4(c,(0.42+0.5*streak)*edge*uOpacity);}`});
const chanWater=new THREE.Mesh(ribbon(channel,0.52,180),flowMat);
scene.add(chanWater);register(chanWater,Z_CATCH,null,1);
/* waterfall from spout into basin */
const fallCurve=new THREE.CatmullRomCurve3([
new THREE.Vector3(1.30,0.26,-4.74),
new THREE.Vector3(1.36,0.02,-4.40),
new THREE.Vector3(1.42,-0.12,-3.95),
new THREE.Vector3(1.46,-0.13,-3.60)]);
const fallMesh=new THREE.Mesh(ribbon(fallCurve,0.5,26),flowMat);
scene.add(fallMesh);register(fallMesh,Z_BASIN,null,1);
/* spout / aqueduct head */
{
const g=new THREE.Group();
const lip=new THREE.Mesh(new THREE.BoxGeometry(1.15,0.28,0.55),stoneMat);
lip.position.set(1.30,0.16,-4.78);lip.castShadow=true;g.add(lip);
for(const s of [-1,1]){
const b=new THREE.Mesh(new THREE.BoxGeometry(0.34,0.62,0.6),stoneMat);
b.position.set(1.30+s*0.52,0.06,-4.80);b.castShadow=true;g.add(b);
}
scene.add(g);
}
/* ───────────────────────── reservoir water plane ───────────────────────── */
const waterUni={uTime:{value:0},uDeep:{value:new THREE.Color(0x0b4f63)},
uShallow:{value:new THREE.Color(0x36b3c9)},uInflow:{value:new THREE.Vector2(1.44,-4.9)},
uRadius:{value:5.42},uDim:{value:0}};
const waterMat=new THREE.ShaderMaterial({transparent:true,depthWrite:false,
uniforms:waterUni,side:THREE.DoubleSide,
vertexShader:`varying vec3 vP;varying vec3 vW;
void main(){vP=position;vW=(modelMatrix*vec4(position,1.0)).xyz;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}`,
fragmentShader:`uniform float uTime;uniform vec3 uDeep,uShallow;uniform vec2 uInflow;
uniform float uRadius,uDim;varying vec3 vP;varying vec3 vW;
void main(){
float r=length(vP.xz);
float ring=sin(r*5.2-uTime*1.35);
float ring2=sin(r*10.4-uTime*2.05);
float dI=length(vP.xz-uInflow);
float splash=sin(dI*7.5-uTime*5.5)*exp(-dI*0.5);
float glint=sin(vP.x*7.0+uTime*0.9)*sin(vP.z*5.0-uTime*0.7);
float h=ring*0.5+ring2*0.22+splash*0.95+glint*0.1;
vec3 c=mix(uDeep,uShallow,clamp(0.52+h*0.34,0.0,1.0));
c=mix(c,uShallow*1.12,smoothstep(uRadius*0.68,uRadius,r));
vec3 V=normalize(cameraPosition-vW);
vec3 L=normalize(vec3(-0.45,0.78,0.36));
float spec=pow(max(dot(normalize(vec3(0.0,1.0,0.0)),normalize(L+V)),0.0),55.0);
c+=vec3(1.0,0.95,0.82)*spec*0.65;
c=mix(c,vec3(0.78,0.80,0.78),uDim*0.8);
float a=(0.84-smoothstep(uRadius*0.88,uRadius,r)*0.3)*(1.0-uDim*0.55);
gl_FragColor=vec4(c,a);}`});
const water=new THREE.Mesh(new THREE.CircleGeometry(5.42,120),waterMat);
water.rotation.x=-Math.PI/2;water.position.set(BASIN.cx,WATER_Y,BASIN.cz);
water.renderOrder=3;scene.add(water);register(water,Z_BASIN,null,1);
/* splash rings at the inflow */
const splashRings=[];
for(let i=0;i<4;i++){
const m=new THREE.Mesh(new THREE.RingGeometry(0.26,0.34,40),
new THREE.MeshBasicMaterial({color:0xdff6ff,transparent:true,opacity:0,side:THREE.DoubleSide,depthWrite:false}));
m.rotation.x=-Math.PI/2;m.position.set(1.44,WATER_Y+0.03,-3.95);m.renderOrder=4;
scene.add(m);splashRings.push({m,ph:i*0.42});
}
/* ───────────────────────── vegetation & crops ───────────────────────── */
const leafMat=new THREE.MeshStandardMaterial({color:0x4e7a3c,roughness:0.9});
const trunkMat=new THREE.MeshStandardMaterial({color:0x6b5238,roughness:0.95});
const cropM=new THREE.MeshStandardMaterial({color:0x9fc25a,roughness:0.92});
const reedMat=new THREE.MeshStandardMaterial({color:0x8fae58,roughness:0.9});
const rockMat=new THREE.MeshStandardMaterial({color:0x9a9384,roughness:0.95});
/* trees */
{
const trunks=[],canopy=[];
let tries=0;
while(trunks.length<58&&tries<6000){
tries++;
const x=rndR(-24,24),z=rndR(-29,-6.2);
if(Math.abs(x)<3.4&&z>-14)continue;
const y=baseHeight(x,z);
if(y<0.5||slopeAt(x,z)>0.95)continue;
const h=rndR(1.4,2.6);
trunks.push({p:new THREE.Vector3(x,y+h*0.35,z),s:[0.16,h*0.7,0.16],ry:rndR(0,6.28)});
canopy.push({p:new THREE.Vector3(x,y+h*0.95,z),s:[rndR(0.9,1.6),rndR(0.7,1.2),rndR(0.9,1.6)],
rx:rndR(-0.2,0.2),ry:rndR(0,6.28),rz:rndR(-0.2,0.2)});
}
instanced(new THREE.CylinderGeometry(0.55,0.85,1,6),trunkMat,trunks,Z_CATCH);
instanced(new THREE.IcosahedronGeometry(1,0),leafMat,canopy,Z_CATCH);
}
/* milpa crops on the flat treads */
{
const items=[];
for(let x=-16;x<=16;x+=0.75){
for(let z=-27;z<=-7;z+=0.75){
if(Math.abs(x)<1.6&&z>-15)continue;
const y=baseHeight(x,z);
if(y<0.8||slopeAt(x,z)>0.22)continue;
if(rnd()<0.42)continue;
items.push({p:new THREE.Vector3(x,y+0.42,z),s:[1,1,1],ry:rndR(0,6.28)});
if(items.length>620)break;
}
if(items.length>620)break;
}
instanced(new THREE.ConeGeometry(0.16,0.85,4),cropM,items,Z_CATCH);
}
/* reeds at the waterline */
{
const items=[];
for(let i=0;i<190;i++){
const a=rndR(0,Math.PI*2),r=rndR(5.0,5.55);
const x=BASIN.cx+Math.cos(a)*r,z=BASIN.cz+Math.sin(a)*r;
items.push({p:new THREE.Vector3(x,-0.05,z),s:[1,rndR(0.6,1.3),1],ry:rndR(0,6.28),
rx:rndR(-0.12,0.12),rz:rndR(-0.12,0.12)});
}
instanced(new THREE.ConeGeometry(0.06,1,3),reedMat,items,Z_BASIN,false);
}
/* rocks */
{
const items=[];
for(let i=0;i<70;i++){
const x=rndR(-22,22),z=rndR(-26,13);
const y=baseHeight(x,z);
items.push({p:new THREE.Vector3(x,y+0.12,z),s:[rndR(0.2,0.6),rndR(0.15,0.4),rndR(0.2,0.6)],
rx:rndR(0,3),ry:rndR(0,6.28),rz:rndR(0,3)});
}
instanced(new THREE.IcosahedronGeometry(1,0),rockMat,items,Z_PLAZA);
}
/* lily pads */
{
const items=[];
for(let i=0;i<18;i++){
const a=rndR(0,Math.PI*2),r=rndR(0.6,4.3);
items.push({p:new THREE.Vector3(BASIN.cx+Math.cos(a)*r,WATER_Y+0.03,BASIN.cz+Math.sin(a)*r),
s:[rndR(0.7,1.2),1,rndR(0.7,1.2)],ry:rndR(0,6.28)});
}
instanced(new THREE.CylinderGeometry(0.34,0.34,0.05,12),
new THREE.MeshStandardMaterial({color:0x3f7a3c,roughness:0.85}),items,Z_BASIN,false);
}
/* ─────────────────────── Maya built environment ─────────────────────── */
const lime=new THREE.MeshStandardMaterial({color:0xe4d4b0,roughness:0.9});
const terra=new THREE.MeshStandardMaterial({color:0xb45a34,roughness:0.88});
const dark=new THREE.MeshStandardMaterial({color:0x2a2018,roughness:1});
/* stepped temple platform east of the basin */
{
const g=new THREE.Group();g.position.set(8.6,0,2.2);
const tiers=[[5.4,1.15],[4.1,1.05],[2.9,0.95]];
let y=0;
tiers.forEach(([w,h],i)=>{
const b=new THREE.Mesh(new THREE.BoxGeometry(w,h,w),i===1?lime:lime);
b.position.y=y+h/2;b.castShadow=true;b.receiveShadow=true;g.add(b);
y+=h;
});
const shrine=new THREE.Mesh(new THREE.BoxGeometry(1.9,1.25,1.5),terra);
shrine.position.y=y+0.62;shrine.castShadow=true;g.add(shrine);
const door=new THREE.Mesh(new THREE.BoxGeometry(0.6,0.85,0.08),dark);
door.position.set(0,y+0.42,0.78);g.add(door);
/* roof comb */
const comb=new THREE.Mesh(new THREE.BoxGeometry(1.5,0.55,0.3),lime);
comb.position.set(0,y+1.5,0.05);comb.castShadow=true;g.add(comb);
const comb2=new THREE.Mesh(new THREE.BoxGeometry(1.0,0.35,0.28),lime);
comb2.position.set(0,y+1.85,0.05);comb2.castShadow=true;g.add(comb2);
/* stair */
for(let i=0;i<6;i++){
const s=new THREE.Mesh(new THREE.BoxGeometry(2.0,0.2,0.5),lime);
s.position.set(0,0.1+i*0.19,2.9-i*0.5);s.castShadow=true;s.receiveShadow=true;g.add(s);
}
scene.add(g);g.traverse(child=>{if(child.isMesh) register(child,Z_PLAZA);});
}
/* palapa (thatched shelter) */
{
const g=new THREE.Group();g.position.set(-7.4,0,2.6);
const wood=new THREE.MeshStandardMaterial({color:0x8a6a45,roughness:0.95});
const thatch=new THREE.MeshStandardMaterial({color:0xc9a45c,roughness:1});
for(const [dx,dz] of [[-1.3,-1.3],[1.3,-1.3],[-1.3,1.3],[1.3,1.3]]){
const p=new THREE.Mesh(new THREE.CylinderGeometry(0.1,0.12,2.4,6),wood);
p.position.set(dx,1.2,dz);p.castShadow=true;g.add(p);
}
const roof=new THREE.Mesh(new THREE.ConeGeometry(2.5,1.35,10),thatch);
roof.position.y=3.0;roof.castShadow=true;g.add(roof);
const bench=new THREE.Mesh(new THREE.BoxGeometry(2.2,0.18,0.5),wood);
bench.position.set(0,0.55,-1.0);bench.castShadow=true;g.add(bench);
scene.add(g);g.traverse(child=>{if(child.isMesh) register(child,Z_PLAZA);});
}
/* carved stela */
{
const g=new THREE.Group();g.position.set(-5.4,0,-2.6);g.rotation.y=0.5;
const slab=new THREE.Mesh(new THREE.BoxGeometry(0.3,1.9,1.0),stoneMat2);
slab.position.y=0.9;slab.castShadow=true;g.add(slab);
const cv=document.createElement('canvas');cv.width=128;cv.height=256;
const cx2=cv.getContext('2d');
cx2.fillStyle='#b9ac8d';cx2.fillRect(0,0,128,256);
cx2.fillStyle='#4a4034';
for(let i=0;i<9;i++){
cx2.fillRect(30,16+i*26,68,4);
cx2.fillRect(52,22+i*26,20,16);
cx2.beginPath();cx2.arc(60,30+i*26,9,0,Math.PI*2);cx2.strokeStyle='#4a4034';cx2.lineWidth=3;cx2.stroke();
}
const tex=new THREE.CanvasTexture(cv);tex.colorSpace=THREE.SRGBColorSpace;
const face=new THREE.Mesh(new THREE.PlaneGeometry(0.85,1.7),
new THREE.MeshStandardMaterial({map:tex,roughness:1}));
face.position.set(0.16,0.9,0);g.add(face);
scene.add(g);g.traverse(child=>{if(child.isMesh) register(child,Z_PLAZA);});
}
/* pottery jars */
{
const pts=[];
for(let i=0;i<=10;i++){const t=i/10;
pts.push(new THREE.Vector2(Math.sin(t*Math.PI)*0.34+0.06,t*0.8));}
const prof=[];
for(let i=0;i<=14;i++){const t=i/14;
prof.push(new THREE.Vector2(0.34*Math.sin(t*Math.PI*0.92)+0.04, t*0.8));}
const jar=new THREE.Mesh(new THREE.LatheGeometry(prof,12),
new THREE.MeshStandardMaterial({color:0xa85c36,roughness:0.9}));
jar.position.set(-6.2,0,3.6);jar.castShadow=true;scene.add(jar);register(jar,Z_PLAZA);
const jar2=jar.clone();jar2.position.set(-6.9,0,3.9);jar2.scale.setScalar(0.75);scene.add(jar2);
}
/* ───────────────── downhill flow arrows on the catchment ───────────────── */
{
const items=[];
const up=new THREE.Vector3(0,1,0);
for(const z of [-11,-14.5,-18,-21.5,-25]){
for(const x of [-11,-6.5,-2,2,6.5,11]){
const y=baseHeight(x,z);
if(y<0.6)continue;
const e=1.0;
const gx=(baseHeight(x+e,z)-baseHeight(x-e,z))/(2*e);
const gz=(baseHeight(x,z+e)-baseHeight(x,z-e))/(2*e);
const dir=new THREE.Vector3(-gx,0,-gz);
if(dir.length()<0.05)continue;dir.normalize();
const q=new THREE.Quaternion().setFromUnitVectors(up,dir);
items.push({p:new THREE.Vector3(x,y+0.55,z),q,q0:null,s:[0.5,1.15,0.5]});
}
}
const m=new THREE.InstancedMesh(new THREE.ConeGeometry(0.3,1.0,6),
new THREE.MeshStandardMaterial({color:0x2fa8c6,emissive:0x0d5f74,emissiveIntensity:0.5,
transparent:true,opacity:0.92,roughness:0.5}),items.length);
const d=new THREE.Object3D();
items.forEach((it,i)=>{d.position.copy(it.p);d.quaternion.copy(it.q);d.scale.set(...it.s);d.updateMatrix();m.setMatrixAt(i,d.matrix);});
m.instanceMatrix.needsUpdate=true;m.castShadow=false;scene.add(m);register(m,Z_CATCH);
}
/* ─────────────────────── runoff particles & rain ─────────────────────── */
const chanSamples=channel.getSpacedPoints(420);
const NP=520;
const runPos=new Float32Array(NP*3);
const runState=[];
for(let i=0;i<NP;i++)runState.push({s:rnd(),v:rndR(0.055,0.115),o:rndR(-0.2,0.2),w:rndR(-0.12,0.12)});
const runGeo=new THREE.BufferGeometry();
runGeo.setAttribute('position',new THREE.BufferAttribute(runPos,3));
const runoff=new THREE.Points(runGeo,new THREE.PointsMaterial({color:0xe6fbff,size:0.16,
transparent:true,opacity:0.95,depthWrite:false,sizeAttenuation:true}));
runoff.frustumCulled=false;scene.add(runoff);register(runoff,Z_CATCH);
const fallPts=[];for(let i=0;i<160;i++)fallPts.push({p:rnd(),ox:rndR(-0.22,0.22),oz:rndR(-0.2,0.2)});
const fallPos=new Float32Array(fallPts.length*3);
const fallGeo=new THREE.BufferGeometry();
fallGeo.setAttribute('position',new THREE.BufferAttribute(fallPos,3));
const fallDrops=new THREE.Points(fallGeo,new THREE.PointsMaterial({color:0xd8f4ff,size:0.13,
transparent:true,opacity:0.9,depthWrite:false}));
fallDrops.frustumCulled=false;scene.add(fallDrops);register(fallDrops,Z_BASIN);
/* rain */
const RAIN=520;
const rainPos=new Float32Array(RAIN*6);
const rainState=[];
for(let i=0;i<RAIN;i++)rainState.push({x:rndR(-24,24),z:rndR(-30,-4),y:rndR(2,26),v:rndR(11,17)});
const rainGeo=new THREE.BufferGeometry();
rainGeo.setAttribute('position',new THREE.BufferAttribute(rainPos,3));
const rainMesh=new THREE.LineSegments(rainGeo,new THREE.LineBasicMaterial({color:0xdceef5,transparent:true,opacity:0.42}));
rainMesh.frustumCulled=false;rainMesh.visible=false;scene.add(rainMesh);
/* clouds */
{
const items=[];
for(let i=0;i<9;i++)items.push({p:new THREE.Vector3(rndR(-45,45),rndR(22,34),rndR(-60,20)),
s:[rndR(4,9),rndR(1.2,2.2),rndR(3,6)],ry:rndR(0,6.28)});
instanced(new THREE.IcosahedronGeometry(1,0),
new THREE.MeshStandardMaterial({color:0xf2eee6,roughness:1,transparent:true,opacity:0.85}),
items,Z_PLAZA,false);
}
/* ─────────────────────── camera rig (custom orbit) ─────────────────────── */
const rig={
theta:0.66,phi:0.95,radius:32,target:new THREE.Vector3(0,0.6,-4),
dTheta:0.66,dPhi:0.95,dRadius:32,dTarget:new THREE.Vector3(0,0.6,-4)};
function applyRig(){
rig.theta=lerp(rig.theta,rig.dTheta,0.09);
rig.phi=lerp(rig.phi,rig.dPhi,0.09);
rig.radius=lerp(rig.radius,rig.dRadius,0.09);
rig.target.lerp(rig.dTarget,0.09);
const sp=Math.sin(rig.phi),cp=Math.cos(rig.phi);
camera.position.set(
rig.target.x+rig.radius*sp*Math.sin(rig.theta),
rig.target.y+rig.radius*cp,
rig.target.z+rig.radius*sp*Math.cos(rig.theta));
camera.lookAt(rig.target);
}
let dragging=false,lastX=0,lastY=0;
renderer.domElement.addEventListener('pointerdown',e=>{dragging=true;lastX=e.clientX;lastY=e.clientY;
renderer.domElement.setPointerCapture(e.pointerId);});
renderer.domElement.addEventListener('pointermove',e=>{
if(!dragging)return;
rig.dTheta-=(e.clientX-lastX)*0.005;
rig.dPhi=clamp(rig.dPhi-(e.clientY-lastY)*0.005,0.16,1.46);
lastX=e.clientX;lastY=e.clientY;});
renderer.domElement.addEventListener('pointerup',e=>{dragging=false;});
renderer.domElement.addEventListener('pointercancel',()=>{dragging=false;});
renderer.domElement.addEventListener('wheel',e=>{e.preventDefault();
rig.dRadius=clamp(rig.dRadius*(1+Math.sign(e.deltaY)*0.08),9,68);},{passive:false});
/* ─────────────────────────── labels + leaders ─────────────────────────── */
const labelDefs=[
{i:'Collection surface',s:'terraced catchment · 12 ha',z:'catch',
a:new THREE.Vector3(-7.6,baseHeight(-7.6,-18.5)+1.2,-18.5),o:[-96,-42]},
{i:'Runoff channel',s:'stone acequia',z:'catch',
a:new THREE.Vector3(-2.6,baseHeight(-2.6,-11.4)+0.8,-11.4),o:[72,-18]},
{i:'Catchment terraces',s:'milpa retaining walls',z:'catch',
a:new THREE.Vector3(6.0,baseHeight(6.0,-17)+0.6,-17),o:[86,6]},
{i:'Inflow spout',s:'aqueduct head',z:'arch',
a:new THREE.Vector3(1.3,0.45,-4.78),o:[58,-46]},
{i:'Reservoir water surface',s:'storage pool',z:'basin',
a:new THREE.Vector3(-2.2,WATER_Y+0.05,2.6),o:[-116,16]},
{i:'Basin floor',s:'cut limestone · −3.6 m',z:'basin',
a:new THREE.Vector3(0.2,-3.5,1.0),o:[-58,40]},
{i:'Basin terraces',s:'stepped revetment',z:'basin',
a:new THREE.Vector3(4.55,-1.2,1.1),o:[74,22]},
{i:'Temple platform',s:'built edge',z:'arch',
a:new THREE.Vector3(8.6,3.5,2.2),o:[64,-24]}
];
const labelRoot=document.getElementById('labels');
const svg=document.getElementById('leaders');
const labelObjs=labelDefs.map(d=>{
const el=document.createElement('div');
el.className='label '+d.z;
el.innerHTML=`<i>${d.s}</i><b>${d.i}</b>`;
labelRoot.appendChild(el);
const line=document.createElementNS('http://www.w3.org/2000/svg','line');
line.setAttribute('stroke',d.z==='basin'?'#43b6d6':d.z==='catch'?'#9fbd57':'#e2a44a');
line.setAttribute('stroke-width','1.2');line.setAttribute('opacity','0.75');
svg.appendChild(line);
const dot=document.createElementNS('http://www.w3.org/2000/svg','circle');
dot.setAttribute('r','3');dot.setAttribute('fill',d.z==='basin'?'#43b6d6':d.z==='catch'?'#9fbd57':'#e2a44a');
svg.appendChild(dot);
return {el,line,dot,def:d,vis:true};
});
function updateLabels(){
const w=innerWidth,h=innerHeight;
labelObjs.forEach(o=>{
const p=o.def.a.clone().project(camera);
if(p.z>1){o.el.style.display='none';o.line.style.display='none';o.dot.style.display='none';return;}
const ax=(p.x*0.5+0.5)*w, ay=(-p.y*0.5+0.5)*h;
const lx=ax+o.def.o[0], ly=ay+o.def.o[1];
o.el.style.transform=`translate(${lx}px,${ly}px) translate(-50%,-50%)`;
o.el.style.display=labelsOn?'':'none';
o.line.setAttribute('x1',ax);o.line.setAttribute('y1',ay);
o.line.setAttribute('x2',lx);o.line.setAttribute('y2',ly);
o.line.style.display=labelsOn?'':'none';
o.dot.setAttribute('cx',ax);o.dot.setAttribute('cy',ay);
o.dot.style.display=labelsOn?'':'none';
});
}
/* ─────────────────────────── UI wiring ─────────────────────────── */
let labelsOn=true,flowOn=true,rainOn=false,highlightMode='all';
function setHighlight(mode){
highlightMode=mode;
const dimZone=mode==='catchment'?Z_BASIN:(mode==='basin'?Z_CATCH:-1);
/* terrain vertex colours */
const c=tGeo.attributes.color.array;
for(let i=0;i<zoneArr.length;i++){
const r=zoneArr[i]===dimZone;
c[i*3]=lerp(baseCol[i*3],0.80,r?0.74:0);
c[i*3+1]=lerp(baseCol[i*3+1],0.80,r?0.74:0);
c[i*3+2]=lerp(baseCol[i*3+2],0.78,r?0.74:0);
}
tGeo.attributes.color.needsUpdate=true;
/* scene meshes */
regMeshes.forEach(o=>{
const zone=o.mesh.userData.zone==='basin'?Z_BASIN:o.mesh.userData.zone==='catchment'?Z_CATCH:-1;
const dim=(dimZone>=0&&zone===dimZone);
const m=o.mesh.material;
if(o.mesh===water){waterUni.uDim.value=dim?1:0;return;}
if(o.mesh===chanWater||o.mesh===fallMesh){flowUniforms.uOpacity.value=dim?0.25:1;return;}
if(o.baseColor&&m.color){m.color.copy(o.baseColor);if(dim)m.color.lerp(new THREE.Color(0xb9b6ab),0.78);}
m.opacity=dim?o.baseOpacity*0.25:o.baseOpacity;
const tr=dim?true:o.baseTransparent;
if(m.transparent!==tr){m.transparent=tr;m.needsUpdate=true;}
});
document.querySelectorAll('.swbtn').forEach(b=>b.classList.toggle('on',b.dataset.zone===mode));
}
document.querySelectorAll('.swbtn').forEach(b=>b.addEventListener('click',()=>setHighlight(b.dataset.zone)));
const views={
'v-all':{theta:0.66,phi:0.95,radius:32,target:[0,0.6,-4]},
'v-catch':{theta:0.52,phi:1.02,radius:18,target:[-4,3.0,-15]},
'v-basin':{theta:0.86,phi:1.12,radius:13.5,target:[0,-0.5,1]}};
Object.keys(views).forEach(id=>document.getElementById(id).addEventListener('click',()=>{
const v=views[id];
rig.dTheta=v.theta;rig.dPhi=v.phi;rig.dRadius=v.radius;rig.dTarget.set(...v.target);
document.querySelectorAll('#controls .row')[0].querySelectorAll('button').forEach(b=>b.classList.remove('on'));
document.getElementById(id).classList.add('on');
}));
document.getElementById('l-flow').addEventListener('click',e=>{flowOn=!flowOn;
e.target.classList.toggle('on',flowOn);
runoff.visible=flowOn;fallDrops.visible=flowOn;chanWater.visible=flowOn;fallMesh.visible=flowOn;});
document.getElementById('l-rain').addEventListener('click',e=>{rainOn=!rainOn;
e.target.classList.toggle('on',rainOn);rainMesh.visible=rainOn;});
document.getElementById('l-lab').addEventListener('click',e=>{labelsOn=!labelsOn;
e.target.classList.toggle('on',labelsOn);});
/* ─────────────────────────── animation loop ─────────────────────────── */
const clock=new THREE.Clock();
let t=0;
function animate(){
requestAnimationFrame(animate);
const dt=Math.min(clock.getDelta(),0.05); t+=dt;
applyRig();
waterUni.uTime.value=t; flowUniforms.uTime.value=t;
/* runoff along the acequia */
if(flowOn){
for(let i=0;i<NP;i++){
const s0=runState[i]; s0.s+=s0.v*dt;
if(s0.s>1)s0.s-=1;
const idx=clamp(Math.floor(s0.s*(chanSamples.length-1)),0,chanSamples.length-2);
const f=s0.s*(chanSamples.length-1)-idx;
const a=chanSamples[idx],b=chanSamples[idx+1];
const tx=-a.tangent?0:0;
const px=lerp(a.x,b.x,f),pz=lerp(a.z,b.z,f),py=lerp(a.y,b.y,f);
const nx=-(b.z-a.z),nz=(b.x-a.x);const L=Math.hypot(nx,nz)||1;
runPos[i*3]=px+(nx/L)*s0.o+ (Math.random()-0.5)*0.03;
runPos[i*3+1]=py+0.06+Math.random()*0.03;
runPos[i*3+2]=pz+(nz/L)*s0.o+(Math.random()-0.5)*0.03;
}
runGeo.attributes.position.needsUpdate=true;
/* droplets falling from the spout */
for(let i=0;i<fallPts.length;i++){
const f=fallPts[i]; f.p+=dt*1.5;
if(f.p>1)f.p-=1;
const y=lerp(0.24,WATER_Y,f.p*f.p);
fallPos[i*3]=1.34+f.ox*(1-f.p*0.4);
fallPos[i*3+1]=y;
fallPos[i*3+2]=lerp(-4.72,-3.95,f.p)+f.oz*(1-f.p*0.3);
}
fallGeo.attributes.position.needsUpdate=true;
}
/* splash rings */
splashRings.forEach(s=>{
const c=(t*0.62+s.ph)%1;
const sc=0.4+c*2.6;
s.m.scale.set(sc,sc,1);
s.m.material.opacity=Math.max(0,0.55*(1-c));
});
/* rain */
if(rainOn){
for(let i=0;i<RAIN;i++){
const r=rainState[i]; r.y-=r.v*dt;
const g=baseHeight(r.x,r.z);
if(r.y<g){r.y=rndR(20,28);r.x=rndR(-24,24);r.z=rndR(-30,-4);}
rainPos[i*6]=r.x;rainPos[i*6+1]=r.y;rainPos[i*6+2]=r.z;
rainPos[i*6+3]=r.x+0.08;rainPos[i*6+4]=r.y+0.75;rainPos[i*6+5]=r.z;
}
rainGeo.attributes.position.needsUpdate=true;
}
updateLabels();
renderer.render(scene,camera);
}
animate();
function resize(){
renderer.setSize(innerWidth,innerHeight);
camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();
svg.setAttribute('width',innerWidth);svg.setAttribute('height',innerHeight);
}
resize();addEventListener('resize',resize);
</script>
</body>
</html>
```