Prompt specification
Build or customize the Three.js 3D scene "Mountain exchange post with tea and pack animals" 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: Mountain exchange post with tea and pack animals
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mountain-exchange-post-with-tea-and-pack-animals-x2630
Scene Description Prompt:
I'd like to see this as a cutaway Three.js scene: Mountain exchange post with tea and pack animals. Create a historically grounded Tea Horse Road vignette with storehouse, steep path, and exchange area. Distinguish documented goods from illustrative quantities and individual participants. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (mountain-exchange-post-with-tea-and-pack-animals-x2630):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tea Horse Road — Mountain Exchange Post (cutaway diorama)</title>
<style>
:root{
--bg:#0f1319;
--ink:#e8e3d8;
--dim:#9aa2ac;
--doc:#57b07c; /* documented */
--ill:#d79a3d; /* illustrative */
--cmp:#5d97cf; /* composite */
--panel:rgba(16,20,26,.82);
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--ink);
font-family:"Iowan Old Style","Palatino Linotype",Palatino,Georgia,serif;overflow:hidden}
#scene{position:fixed;inset:0;display:block;touch-action:none}
#leaders{position:fixed;inset:0;pointer-events:none;z-index:4}
#labels{position:fixed;inset:0;pointer-events:none;z-index:5}
.lbl{position:absolute;left:0;top:0;max-width:215px;padding:5px 8px 5px 9px;
font:11.5px/1.32 "Helvetica Neue",Arial,sans-serif;letter-spacing:.01em;
background:rgba(13,17,22,.86);border-left:3px solid #888;border-radius:2px;
color:#eae6dd;box-shadow:0 3px 14px rgba(0,0,0,.45);pointer-events:auto}
.lbl b{font-weight:600}
.lbl .dot{display:inline-block;width:6px;height:6px;border-radius:50%;margin-right:6px;
vertical-align:middle;background:#888}
.lbl-doc{border-left-color:var(--doc)} .lbl-doc .dot{background:var(--doc)}
.lbl-ill{border-left-color:var(--ill)} .lbl-ill .dot{background:var(--ill)}
.lbl-cmp{border-left-color:var(--cmp)} .lbl-cmp .dot{background:var(--cmp)}
.leader{stroke-width:1;opacity:.75}
.leader-doc{stroke:var(--doc)} .leader-ill{stroke:var(--ill)} .leader-cmp{stroke:var(--cmp)}
#panel{position:fixed;left:0;top:0;bottom:0;width:352px;z-index:10;
background:var(--panel);backdrop-filter:blur(7px);-webkit-backdrop-filter:blur(7px);
border-right:1px solid rgba(255,255,255,.09);overflow-y:auto;padding:16px 18px 26px;
font-family:"Helvetica Neue",Arial,sans-serif;font-size:12.5px;line-height:1.5}
#panel::-webkit-scrollbar{width:7px} #panel::-webkit-scrollbar-thumb{background:#3a424c;border-radius:4px}
#panel h1{margin:2px 0 2px;font:600 19px/1.2 "Iowan Old Style",Georgia,serif;letter-spacing:.01em}
#panel h2{margin:16px 0 6px;font:600 11px/1 "Helvetica Neue",Arial,sans-serif;
text-transform:uppercase;letter-spacing:.14em;color:#a8b2bd}
#panel p{margin:6px 0;color:#c8ccd2}
#panel .sub{color:var(--dim);font-size:11.5px;margin:0 0 10px}
#panel hr{border:0;border-top:1px solid rgba(255,255,255,.1);margin:12px 0}
.key{display:flex;gap:8px;align-items:flex-start;margin:7px 0}
.key i{width:9px;height:9px;border-radius:2px;margin-top:4px;flex:0 0 auto}
.key div{flex:1}
.key b{font-weight:600;color:#f0ece3}
.key span{color:#aeb6bf;font-size:11.5px}
ul.tight{margin:4px 0 6px;padding-left:16px;color:#c2c7ce}
ul.tight li{margin:3px 0}
ul.tight li b{color:#eae6dd;font-weight:600}
.btnrow{display:flex;flex-wrap:wrap;gap:6px;margin:8px 0 4px}
button{font:11.5px "Helvetica Neue",Arial,sans-serif;color:#dfe4ea;background:#232a33;
border:1px solid #39424d;border-radius:3px;padding:5px 9px;cursor:pointer}
button:hover{background:#2e3742}
button.on{background:#3b4b3f;border-color:#5f7a68;color:#dff0e4}
.note{font-size:11px;color:#8e97a1;margin-top:10px;line-height:1.45}
.tag{display:inline-block;font-size:9.5px;letter-spacing:.09em;text-transform:uppercase;
padding:1px 5px;border-radius:2px;vertical-align:middle}
.tag-doc{background:rgba(87,176,124,.18);color:var(--doc);border:1px solid rgba(87,176,124,.4)}
.tag-ill{background:rgba(215,154,61,.16);color:var(--ill);border:1px solid rgba(215,154,61,.4)}
.tag-cmp{background:rgba(93,151,207,.16);color:var(--cmp);border:1px solid rgba(93,151,207,.4)}
#hud{position:fixed;right:14px;top:12px;z-index:9;display:flex;gap:6px;
font:11px "Helvetica Neue",Arial,sans-serif}
#hud .hint{background:rgba(16,20,26,.7);border:1px solid rgba(255,255,255,.1);
border-radius:3px;padding:6px 9px;color:#b8bec6}
#foot{position:fixed;left:352px;right:0;bottom:0;z-index:9;padding:7px 14px;
font:10.5px "Helvetica Neue",Arial,sans-serif;color:#7d858f;letter-spacing:.02em;
background:linear-gradient(to top,rgba(10,13,17,.75),transparent);pointer-events:none}
@media (max-width:900px){
#panel{width:300px;font-size:12px}
#foot{left:300px}
.lbl{max-width:170px;font-size:10.5px}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<svg id="leaders"></svg>
<div id="labels"></div>
<aside id="panel">
<h1>Tea Horse Road — a mountain exchange post</h1>
<p class="sub">Cutaway diorama · composite vignette of the tea–horse trade on the Sichuan–Tibet and Yunnan routes (c. 17th–19th c.)</p>
<h2>How to read this model</h2>
<div class="key"><i style="background:var(--doc)"></i><div><b>Documented</b><span> — goods, buildings, tools and practices that are attested in Ming–Qing statutes, customs registers and 19th–early-20th-century travel accounts.</span></div></div>
<div class="key"><i style="background:var(--ill)"></i><div><b>Illustrative</b> — numbers, dimensions, courtyard size, path grade and the particular arrangement shown here, invented to make the vignette legible. Not evidence.</span></div></div>
<div class="key"><i style="background:var(--cmp)"></i><div><b>Composite participants</b> — generic role types (tea porter, mule driver, broker, scribe). No named historical individual is depicted and no figure carries a likeness of any documented person.</span></div></div>
<p class="note">The section through the earth, the storehouse and the roof is a presentational device (hatched faces) — it is not a claim about how the post was built.</p>
<h2>Camera & display</h2>
<div class="btnrow">
<button data-view="0" class="on">Overview</button>
<button data-view="1">Storehouse cut</button>
<button data-view="2">Exchange yard</button>
<button data-view="3">Steep path</button>
</div>
<div class="btnrow">
<button id="btnLabels" class="on">Annotations</button>
<button id="btnRoof" class="on">Roof section</button>
<button id="btnFig">Figures</button>
</div>
<p class="note">Drag to orbit · wheel to zoom · shift-drag or right-drag to pan. Keyboard: 1–4 views, L labels, R roof, F figures.</p>
<h2>Documented goods and features</h2>
<ul class="tight">
<li><span class="tag tag-doc">documented</span> <b>Brick tea (边茶 / 磚茶)</b> — the principal export of the western Sichuan and Yunnan tea districts; compressed in bricks, wrapped in bamboo, carried in loads and packs.</li>
<li><span class="tag tag-doc">documented</span> <b>Salt</b> — salt bricks from the Sichuan salt wells, the classic counter-good in the plateau trade.</li>
<li><span class="tag tag-doc">documented</span> <b>Horses and ponies</b> — plateau livestock, the good sought in exchange for tea.</li>
<li><span class="tag tag-doc">documented</span> <b>Yak and mules</b> — the pack animals of the caravans; mules were also bought for the plateau.</li>
<li><span class="tag tag-doc">documented</span> <b>Wool, felt, hides, yak-hair ropes</b> — returning cargo of the tea caravans.</li>
<li><span class="tag tag-doc">documented</span> <b>Medicinal substances</b> — musk, antler, herbs, gathered in the plateau and traded south.</li>
<li><span class="tag tag-doc">documented</span> <b>Silver and coin</b> — payment media; the scale and the written account book were the instruments of the exchange.</li>
<li><span class="tag tag-doc">documented</span> <b>Storehouse on stone footing, rammed-earth walls, slate/earth roof, bamboo packing</b> — the vernacular building forms of the route.</li>
<li><span class="tag tag-doc">documented</span> <b>Mani piles and prayer-flag lines</b> — pass-side features recorded along the roads.</li>
</ul>
<h2>Illustrative (invented for this vignette)</h2>
<ul class="tight">
<li><span class="tag tag-ill">illustrative</span> <b>≈60 tea bricks</b> in this one storehouse; the brick and load sizes shown are schematic (documentary trade counted bricks, loads and packs, not metres).</li>
<li><span class="tag tag-ill">illustrative</span> <b>7 horses, 3 mules, 1 yak</b> — the numbers of animals in this scene, not of any real post.</li>
<li><span class="tag tag-ill">illustrative</span> <b>Six figures</b> — the number of people shown.</li>
<li><span class="tag tag-ill">illustrative</span> <b>Storehouse ≈ 11 × 8 × 5 m</b>, courtyard ≈ 23 × 15 m, path grade and switchback spacing — schematic.</li>
</ul>
<h2>The post itself</h2>
<p>This is a <b>composite</b> of documented mountain exchange points on the network, not a reconstruction of one dated building: the <b>Songpan</b> (松潘) and <b>Kangding</b> (康定) tea-and-horse posts in Sichuan, <b>Batang</b> (巴塘) and <b>Litang</b> (理塘) on the plateau, the tea country of <b>Mingshan/Mengding</b> near Ya'an (雅安), and Yunnan nodes such as <b>Lijiang</b>, whose tea-and-horse office (茶马司) is documented. Official exchange was regulated by Ming–Qing statutes on tea-and-horse trade (茶马章程 / 茶马制度) and by local officials; later travel accounts describe the brick-tea caravans, salt, horses and pack traffic in detail.</p>
<h2>On the people</h2>
<p>Records identify <b>roles</b> far better than faces: tea porters carrying loads on the back (背夫), mule drivers and caravan hands (马夫), brokers and horse dealers, and clerks keeping the accounts. Nothing in the sources allows a faithful depiction of any individual, so the figures here are deliberately generic composites, labelled as such, and no attempt is made to attach a name or a portrait to any of them.</p>
<hr>
<p class="note">Built with Three.js r160 (module build from cdnjs). All geometry is procedural — no external models or textures.</p>
</aside>
<div id="hud">
<div class="hint">DRAG orbit · WHEEL zoom · SHIFT-DRAG pan</div>
</div>
<div id="foot">Composite teaching model · “documented” = attested in sources; “illustrative” = invented for legibility; “composite” = generic role types, no named individuals.</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ─────────────────────────── 0. utility ─────────────────────────── */
function rng(seed){let s=seed>>>0;return()=>{s=(s*1664525+1013904223)>>>0;return s/4294967296;};}
const rnd = rng(20240517);
const clamp=(v,a,b)=>Math.min(b,Math.max(a,v));
const smooth=(e0,e1,x)=>{const t=clamp((x-e0)/(e1-e0),0,1);return t*t*(3-2*t);};
function ctex(w,h,fn){const c=document.createElement('canvas');c.width=w;c.height=h;const x=c.getContext('2d');fn(x,w,h);
const t=new THREE.CanvasTexture(c);t.colorSpace=THREE.SRGBColorSpace;return t;}
/* ─────────────────────────── 1. renderer ─────────────────────────── */
const canvas=document.getElementById('scene');
const renderer=new THREE.WebGLRenderer({canvas,antialias:true});
renderer.setPixelRatio(Math.min(window.devicePixelRatio,2));
renderer.setSize(innerWidth,innerHeight);
renderer.shadowMap.enabled=true;
renderer.shadowMap.type=THREE.PCFSoftShadowMap;
renderer.outputColorSpace=THREE.SRGBColorSpace;
renderer.toneMapping=THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure=1.05;
const scene=new THREE.Scene();
scene.background=new THREE.Color(0x11161d);
scene.fog=new THREE.Fog(0x11161d,78,205);
const camera=new THREE.PerspectiveCamera(42,innerWidth/innerHeight,0.4,420);
/* ─────────────────────────── 2. materials ────────────────────────── */
const std=(c,o={})=>new THREE.MeshStandardMaterial(Object.assign({color:c,roughness:.92,metalness:0},o));
const paveTex=ctex(512,512,(c,w,h)=>{c.fillStyle='#6d6a62';c.fillRect(0,0,w,h);const r=rng(7);
for(let i=0;i<1100;i++){const x=r()*w,y=r()*h,s=10+r()*36,v=96+r()*48;
c.fillStyle=`rgb(${v|0},${(v*.98)|0},${(v*.93)|0})`;c.fillRect(x,y,s,s*.72);}});
paveTex.wrapS=paveTex.wrapT=THREE.RepeatWrapping;paveTex.repeat.set(7,5);
const slateTex=ctex(256,256,(c,w,h)=>{c.fillStyle='#3c3f44';c.fillRect(0,0,w,h);const r=rng(3);
for(let row=0;row<8;row++)for(let i=0;i<8;i++){const v=68+r()*34;
c.fillStyle=`rgb(${v|0},${v|0},${(v+5)|0})`;c.fillRect(i*32+(row%2?16:0)-16,row*32,34,30);}});
slateTex.wrapS=slateTex.wrapT=THREE.RepeatWrapping;slateTex.repeat.set(3,2);
const hatchTex=ctex(128,128,(c,w,h)=>{c.fillStyle='#e4d4b2';c.fillRect(0,0,w,h);
c.strokeStyle='#b4553c';c.lineWidth=3.5;
for(let i=-h;i<w+h;i+=17){c.beginPath();c.moveTo(i,0);c.lineTo(i+h,h);c.stroke();}});
hatchTex.wrapS=hatchTex.wrapT=THREE.RepeatWrapping;hatchTex.repeat.set(4,4);
const M={
earth:std(0xc0a276), earth2:std(0xb0936a), stone:std(0x8b8880), rock:std(0x6d6a63),
wood:std(0x6b4a30), woodDark:std(0x452f1f), slate:std(0x5a5d63,{map:slateTex}),
tea:std(0x2e392b), bamboo:std(0xb79a5e), salt:std(0xe8e2d4), hide:std(0xa9855c),
felt:std(0x8d8477), yak:std(0x3a2f28), horse:std(0x7a4f33), mule:std(0x9b7350),
cloth:std(0xb3443a), iron:std(0x3d3f43,{metalness:.55,roughness:.5}),
hatch:new THREE.MeshStandardMaterial({map:hatchTex,roughness:.9,side:THREE.DoubleSide}),
pave:std(0xbdb9b0,{map:paveTex}), white:std(0xd8d2c4), paper:std(0xe8dfc6)
};
/* ─────────────────────────── 3. terrain ──────────────────────────── */
const PL={x0:-17.5,x1:6.5,z0:-7.5,z1:8.5,y:3.6};
const TW=116,TD=58,TZ0=-16,TZ1=42;
function baseH(x,z){
let h=(z-TZ0)*0.40;
h+=2.4*Math.sin(x*0.075+1.1)*Math.cos(z*0.05);
h+=1.1*Math.sin(x*0.19+0.4);
h+=0.8*Math.sin(z*0.23+x*0.07);
h+=smooth(30,42,z)*9;
return h;
}
function terrainH(x,z){
let h=baseH(x,z);
const kx=smooth(PL.x0-4,PL.x0+1,x)*(1-smooth(PL.x1-1,PL.x1+4,x));
const kz=smooth(PL.z0-4,PL.z0+1,z)*(1-smooth(PL.z1-1,PL.z1+4,z));
const k=kx*kz;
return h*(1-k)+PL.y*k;
}
(function buildTerrain(){
const g=new THREE.PlaneGeometry(TW,TD-TZ0,150,86);
g.rotateX(-Math.PI/2); g.translate(0,0,(TZ0+TZ1)/2);
const p=g.attributes.position, col=[];
const c=new THREE.Color();
for(let i=0;i<p.count;i++){
const x=p.getX(i),z=p.getZ(i),y=terrainH(x,z);
p.setY(i,y);
const rock=smooth(16,34,y), grass=(1-smooth(5,16,y))*(0.55+0.45*Math.sin(x*0.3)*Math.cos(z*0.22));
c.setRGB(0.42+0.30*(1-rock),0.38+0.24*(1-rock)-0.05*grass,0.29+0.17*(1-rock)-0.06*grass);
col.push(c.r,c.g,c.b);
}
g.setAttribute('color',new THREE.Float32BufferAttribute(col,3));
const m=new THREE.Mesh(g,new THREE.MeshStandardMaterial({vertexColors:true,roughness:1}));
m.receiveShadow=true;scene.add(m);
})();
(function buildSection(){ /* cut face of the hill + strata + plinth */
const xs=[],yTop=[],yBot=[];
for(let x=-TW/2;x<=TW/2;x+=1.5){xs.push(x);yTop.push(baseH(x,TZ0));yBot.push(-9.2);}
const bands=[{d:0.95,c:[0.30,0.22,0.14]},{d:1.25,c:[0.55,0.48,0.37]},{d:99,c:[0.36,0.37,0.39]}];
let off=0;
for(const b of bands){
const pos=[],col=[];
for(let i=0;i<xs.length-1;i++){
const t0=yTop[i]-off,t1=yTop[i+1]-off;
const d0=Math.min(b.d,yTop[i]-off+99),d1=Math.min(b.d,yTop[i+1]-off+99);
const b0=Math.max(yBot[i],t0-d0),b1=Math.max(yBot[i+1],t1-d1);
const q=[[xs[i],b0,TZ0],[xs[i+1],b1,TZ0],[xs[i+1],t1,TZ0],[xs[i],t0,TZ0]];
for(const v of q){pos.push(v[0],v[1],v[2]);col.push(b.c[0],b.c[1],b.c[2]);}
}
const gg=new THREE.BufferGeometry();
gg.setAttribute('position',new THREE.Float32BufferAttribute(pos,3));
gg.setAttribute('color',new THREE.Float32BufferAttribute(col,3));
const mm=new THREE.Mesh(gg,new THREE.MeshStandardMaterial({vertexColors:true,roughness:1,side:THREE.DoubleSide}));
mm.receiveShadow=true;scene.add(mm);
off+=b.d;
}
const plinth=new THREE.Mesh(new THREE.BoxGeometry(TW+1.2,1.5,TD-TZ0+1.2),std(0x22262c));
plinth.position.set(0,-9.95,(TZ0+TZ1)/2);plinth.receiveShadow=true;scene.add(plinth);
const plaqueTex=ctex(1024,180,(c,w,h)=>{c.fillStyle='#1b1e24';c.fillRect(0,0,w,h);
c.strokeStyle='#9a8a63';c.lineWidth=3;c.strokeRect(12,12,w-24,h-24);
c.fillStyle='#d9cfb4';c.textAlign='center';c.textBaseline='middle';
c.font='600 44px Georgia, serif';c.fillText('TEA HORSE ROAD · MOUNTAIN EXCHANGE POST',w/2,66);
c.font='italic 27px Georgia, serif';c.fillStyle='#9aa2ac';
c.fillText('composite cutaway diorama — documented goods · illustrative quantities · composite figures',w/2,116);});
const plaque=new THREE.Mesh(new THREE.PlaneGeometry(30,5.3),new THREE.MeshBasicMaterial({map:plaqueTex}));
plaque.position.set(0,-9.9,TZ0-0.66);scene.add(plaque);
})();
(function distantRidges(){
const g=new THREE.PlaneGeometry(300,120,70,12);g.rotateX(-Math.PI/2);
const p=g.attributes.position,col=[];
for(let i=0;i<p.count;i++){
const x=p.getX(i),z=p.getZ(i)+78;
p.setZ(i,z);
const h=30+13*Math.sin(x*0.045)+9*Math.sin(x*0.12+1.3)+Math.max(0,z-64)*0.22+6*Math.sin(z*0.1);
p.setY(i,h);const t=clamp((h-24)/34,0,1);
col.push(0.20+t*0.10,0.24+t*0.11,0.29+t*0.12);
}
g.setAttribute('color',new THREE.Float32BufferAttribute(col,3));
scene.add(new THREE.Mesh(g,new THREE.MeshStandardMaterial({vertexColors:true,roughness:1})));
})();
/* helpers for solids */
function B(w,h,d,m,x,y,z,parent=scene){
const mesh=new THREE.Mesh(new THREE.BoxGeometry(w,h,d),m);
mesh.position.set(x,y,z);mesh.castShadow=true;mesh.receiveShadow=true;parent.add(mesh);return mesh;
}
function C(rt,rb,h,m,x,y,z,parent=scene,seg=12){
const mesh=new THREE.Mesh(new THREE.CylinderGeometry(rt,rb,h,seg),m);
mesh.position.set(x,y,z);mesh.castShadow=true;mesh.receiveShadow=true;parent.add(mesh);return mesh;
}
function S(r,m,x,y,z,parent=scene,sx=1,sy=1,sz=1){
const mesh=new THREE.Mesh(new THREE.SphereGeometry(r,14,10),m);
mesh.position.set(x,y,z);mesh.scale.set(sx,sy,sz);mesh.castShadow=true;mesh.receiveShadow=true;parent.add(mesh);return mesh;
}
/* ───────────────────── 4. retaining walls & yard ─────────────────── */
(function retaining(){
const g=new THREE.Group();scene.add(g);
const r=rng(11);
for(let x=PL.x0;x<PL.x1;x+=1.35){
for(let row=0;row<2;row++){
B(1.2,0.55,0.85,row?M.stone:M.rock,x+0.6,PL.y-0.3-row*0.5,PL.z0+0.4+r()*0.1,g).rotation.y=(r()-0.5)*0.12;
}
}
for(let z=PL.z0;z<PL.z1;z+=1.35){
for(let row=0;row<2;row++){
B(0.85,0.55,1.2,row?M.stone:M.rock,PL.x0+0.4+r()*0.1,PL.y-0.3-row*0.5,z+0.6,g).rotation.y=(r()-0.5)*0.12;
}
}
})();
const yard=new THREE.Mesh(new THREE.PlaneGeometry(24,7.8),M.pave);
yard.rotation.x=-Math.PI/2;yard.position.set(-5.5,PL.y+0.02,-3.6);yard.receiveShadow=true;scene.add(yard);
/* ───────────────────────── 5. storehouse ─────────────────────────── */
const REF={};
const storehouse=new THREE.Group();scene.add(storehouse);
(function buildStorehouse(){
const x0=-14.6,x1=-3.4,zB=8.0,cutZ=2.45,H=5.0,T=0.7,floorY=PL.y+0.16;
const wallTop=floorY+H, ridgeZ=5.2, rise=1.7, half=2.8, th=Math.atan(rise/half), slopeLen=Math.hypot(rise,half);
// floor slab (only the un-cut part survives)
B(x1-x0+T,0.32,zB-cutZ,M.stone,(x0+x1)/2,floorY-0.16,(cutZ+zB)/2,storehouse);
// back wall
B(x1-x0+T,H,T,M.earth,(x0+x1)/2,floorY+H/2,zB-T/2,storehouse);
// side walls
B(T,H,zB-cutZ,M.earth,x0+T/2,floorY+H/2,(cutZ+zB)/2,storehouse);
B(T,H,zB-cutZ,M.earth,x1-T/2,floorY+H/2,(cutZ+zB)/2,storehouse);
// stone footing course
B(x1-x0+T+0.25,0.55,zB-cutZ+0.2,M.rock,(x0+x1)/2,floorY+0.05,(cutZ+zB)/2,storehouse);
// roof: two slate slopes (gable ridge along X)
const frontSlope=new THREE.Mesh(new THREE.BoxGeometry(x1-x0+0.8,th,slopeLen),M.slate);
frontSlope.position.set((x0+x1)/2,wallTop+rise/2,(cutZ+ridgeZ)/2);
frontSlope.rotation.x=-th;frontSlope.castShadow=true;frontSlope.receiveShadow=true;storehouse.add(frontSlope);
const backSlope=new THREE.Mesh(new THREE.BoxGeometry(x1-x0+0.8,th,slopeLen),M.slate);
backSlope.position.set((x0+x1)/2,wallTop+rise/2,(ridgeZ+zB)/2);
backSlope.rotation.x=th;backSlope.castShadow=true;backSlope.receiveShadow=true;storehouse.add(backSlope);
// ridge cap
B(x1-x0+0.9,0.28,0.5,M.stone,(x0+x1)/2,wallTop+rise+0.1,ridgeZ,storehouse);
// gable end stones (cut shape)
const gy=[floorY+H,zB,floorY+H,ridgeZ,wallTop+rise];
[[x0],[x1]].forEach(([gx])=>{
const g=new THREE.BufferGeometry();
g.setAttribute('position',new THREE.Float32BufferAttribute([gx,gy[0],cutZ,gx,gy[1],zB,gx,gy[2],ridgeZ],3));
g.computeVertexNormals();
const m=new THREE.Mesh(g,new THREE.MeshStandardMaterial({color:0x7e7a72,roughness:1,side:THREE.DoubleSide}));
m.castShadow=true;m.receiveShadow=true;storehouse.add(m);
});
// ── hatched section faces at the cut plane z = cutZ
const cut=new THREE.Group();storehouse.add(cut);
B(T,H,0.06,M.hatch,x0+T/2,floorY+H/2,cutZ-0.01,cut);
B(T,H,0.06,M.hatch,x1-T/2,floorY+H/2,cutZ-0.01,cut);
B(x1-x0,0.32,0.06,M.hatch,(x0+x1)/2,floorY-0.16,cutZ-0.01,cut);
const roofCut=new THREE.Mesh(new THREE.BoxGeometry(x1-x0+0.8,0.36,0.06),M.hatch);
roofCut.position.set((x0+x1)/2,wallTop+0.2,cutZ-0.01);cut.add(roofCut);
REF.roofCut=cut;
/* interior: stacked tea bricks */
const teaGroup=new THREE.Group();storehouse.add(teaGroup);
function brickStack(cx,cz,cols,rows,levels,mat,bw,bh,bd,band){
for(let l=0;l<levels;l++)for(let i=0;i<cols;i++)for(let j=0;j<rows;j++){
const off=((l%2)?0.06:0);
const b=B(bw,bh,bd,mat,cx+(i-(cols-1)/2)*(bw+0.05)+off,floorY+0.17+l*(bh+0.02),cz+(j-(rows-1)/2)*(bd+0.05),teaGroup);
if(band)B(bw*1.01,0.045,bd*0.22,M.bamboo,b.position.x,b.position.y,b.position.z,teaGroup);
}
}
brickStack(-12.3,6.6,7,3,4,M.tea,0.62,0.24,0.40,true); // tea bricks, bamboo straps
brickStack(-11.0,3.4,5,2,3,M.tea,0.62,0.24,0.40,true);
REF.tea=teaGroup;
// salt bricks
const saltGroup=new THREE.Group();storehouse.add(saltGroup);
brickStack(-5.6,6.4,4,2,4,M.salt,0.66,0.30,0.46,false);
REF.salt=saltGroup;
// felt / wool bales
const feltGroup=new THREE.Group();storehouse.add(feltGroup);
for(let i=0;i<4;i++){
S(0.42,M.felt,-9.6+i*0.62,floorY+0.35,2.95,feltGroup,1.0,0.72,1.15);
B(0.5,0.07,0.5,M.hide,-9.6+i*0.62,floorY+0.62,2.95,feltGroup);
}
REF.felt=feltGroup;
// ceiling beam + hanging bundles
B(10.6,0.32,0.32,M.woodDark,(x0+x1)/2,floorY+H-0.5,5.0,storehouse);
for(let i=0;i<5;i++){
C(0.16,0.13,1.1,M.hide,-12.6+i*2.1,floorY+H-1.5,5.0,storehouse);
C(0.03,0.03,0.6,M.woodDark,-12.6+i*2.1,floorY+H-0.85,5.0,storehouse,6);
}
// bamboo mats / empty packing
for(let i=0;i<5;i++)B(1.1,0.09,0.8,M.bamboo,-4.4,floorY+0.2+i*0.1,3.2,storehouse).rotation.y=rnd()*0.2;
// counting table with ledger book
const tbl=new THREE.Group();tbl.position.set(-7.6,floorY,3.9);storehouse.add(tbl);
B(2.0,0.12,1.0,M.wood,0,0.78,0,tbl);
[[-.85,-.38],[.85,-.38],[-.85,.38],[.85,.38]].forEach(([x,z])=>B(0.12,0.78,0.12,M.woodDark,x,0.39,z,tbl));
B(0.86,0.07,0.6,M.paper,-0.25,0.86,0,tbl).rotation.y=0.06;
B(0.05,0.09,0.62,M.woodDark,-0.68,0.88,0,tbl);
B(0.22,0.05,0.16,M.iron,0.62,0.85,0.1,tbl);
C(0.02,0.02,0.35,M.woodDark,0.45,0.9,0.1,tbl,6).rotation.z=Math.PI/2;
REF.table=tbl;
// a stored beam scale leaning against the wall
const bs=new THREE.Group();bs.position.set(-9.0,floorY,8.1);bs.rotation.x=0.35;storehouse.add(bs);
C(0.05,0.05,2.2,M.wood,0,1.1,0,bs,8);
B(0.06,0.06,0.5,M.iron,0,2.1,0,bs);
REF.house=storehouse;
})();
/* ───────────────────── 6. exchange yard props ────────────────────── */
const yardProps=new THREE.Group();scene.add(yardProps);
(function yardScene(){
// beam balance scale
const sc=new THREE.Group();sc.position.set(-6.6,PL.y,-2.6);yardProps.add(sc);
C(0.11,0.14,2.6,M.wood,0,1.3,0,sc,10);
B(1.7,0.14,0.16,M.wood,0,2.5,0,sc);
const beam=new THREE.Group();beam.position.set(0,2.62,0);beam.rotation.z=0.12;sc.add(beam);
B(3.0,0.09,0.11,M.woodDark,0,0,0,beam);
[-1.35,1.35].forEach(x=>{
C(0.018,0.018,1.0,M.woodDark,x,-0.5,0,beam,6);
const pan=C(0.42,0.34,0.14,M.iron,x,-1.05,0,beam,16);pan.scale.set(1,1,1);
});
REF.scale=sc;
// tea bricks stacked in the yard, covered with a tarpaulin
const yardStack=new THREE.Group();yardStack.position.set(-12.6,PL.y,-2.2);yardProps.add(yardStack);
for(let l=0;l<4;l++)for(let i=0;i<5;i++){
const b=B(0.62,0.24,0.42,M.tea,(i-2)*0.68,0.14+l*0.25,0,yardStack);
B(0.64,0.045,0.1,M.bamboo,b.position.x,b.position.y,b.position.z,yardStack);
}
const tarp=new THREE.Mesh(new THREE.CylinderGeometry(1.9,1.9,3.0,16,1,false,0,Math.PI),std(0xa89272));
tarp.rotation.z=Math.PI/2;tarp.rotation.y=Math.PI/2;tarp.position.set(0,0.95,0);
tarp.castShadow=true;tarp.receiveShadow=true;yardStack.add(tarp);
REF.yardStack=yardStack;
// salt heap with canvas cover
const salt=new THREE.Group();salt.position.set(-15.6,PL.y,-4.4);yardProps.add(salt);
for(let i=0;i<9;i++)B(0.6,0.28,0.44,M.salt,(rnd()-0.5)*1.2,0.16+Math.floor(i/4)*0.3,(rnd()-0.5)*1.0,salt).rotation.y=rnd()*0.2;
REF.saltYard=salt;
// small tea-stall canopy
const stall=new THREE.Group();stall.position.set(-11.0,PL.y,-5.6);yardProps.add(stall);
C(0.07,0.08,2.5,M.wood,-1.3,1.25,0,stall,8);C(0.07,0.08,2.5,M.wood,1.3,1.25,0,stall,8);
const cloth=new THREE.Mesh(new THREE.PlaneGeometry(3.2,2.4),new THREE.MeshStandardMaterial({color:0x9e4a3c,roughness:1,side:THREE.DoubleSide}));
cloth.rotation.x=-Math.PI/2+0.14;cloth.position.set(0,2.55,0);cloth.castShadow=true;stall.add(cloth);
B(2.2,0.1,0.9,M.wood,0,0.85,0.4,stall);
// hitching rail + buckets
B(4.4,0.16,0.16,M.wood,1.6,1.1,-4.2,yardProps);
[ -0.4,0.9,2.2,3.5 ].forEach(x=>C(0.09,0.11,1.2,M.wood,x,0.6,-4.2,yardProps,8));
// medicinal / misc goods basket
const basket=new THREE.Group();basket.position.set(-2.2,PL.y,-4.9);yardProps.add(basket);
const bm=new THREE.Mesh(new THREE.CylinderGeometry(0.45,0.34,0.42,14),M.bamboo);
bm.position.y=0.21;bm.castShadow=true;basket.add(bm);
for(let i=0;i<5;i++)S(0.11,M.felt,(rnd()-0.5)*0.5,0.46,(rnd()-0.5)*0.5,basket);
// mani pile (玛尼堆) near the path head
const mani=new THREE.Group();mani.position.set(5.2,PL.y,-5.6);yardProps.add(mani);
for(let i=0;i<34;i++){const t=i/34,a=rnd()*Math.PI,rad=t*1.1;
const s=S(0.16+0.1*t,M.stone,Math.cos(a)*rad,0.06+t*0.95,Math.sin(a)*rad,mani,1.2,0.55,1.0);}
REF.mani=mani;
// prayer flags across the yard
const pa=new THREE.Vector3(-16.4,PL.y+3.4,-6.4),pb=new THREE.Vector3(4.2,PL.y+3.1,-6.4);
C(0.07,0.09,4.0,M.wood,pa.x,PL.y+2.0,pa.z,yardProps,8);
C(0.07,0.09,4.0,M.wood,pb.x,PL.y+2.0,pb.z,yardProps,8);
const flagCols=[0x2f6bb5,0xf2f2f2,0xb63a2c,0x3f8f52,0xe2b13a];
for(let i=0;i<26;i++){
const t=(i+0.5)/26;
const x=pa.x+(pb.x-pa.x)*t, sag=Math.sin(Math.PI*t)*0.55;
const y=pa.y+(pb.y-pa.y)*t-sag;
const fl=new THREE.Mesh(new THREE.PlaneGeometry(0.42,0.55),new THREE.MeshStandardMaterial({color:flagCols[i%5],roughness:1,side:THREE.DoubleSide}));
fl.position.set(x,y-0.3,pa.z);fl.rotation.y=0.12*Math.sin(i);yardProps.add(fl);
}
})();
/* ───────────────────────── 7. the steep path ─────────────────────── */
const pathPts=[[6,-1],[13,1],[9,5.5],[16,8],[12,12.5],[19,15.5],[15,19],[22,22],[19,26],[26,29],[23,33]];
const pathPoints=[];
for(let i=0;i<pathPts.length-1;i++){
const a=pathPts[i],b=pathPts[i+1];
for(let j=0;j<8;j++){const t=j/8,x=a[0]+(b[0]-a[0])*t,z=a[1]+(b[1]-a[1])*t;
pathPoints.push(new THREE.Vector3(x,terrainH(x,z)+0.16,z));}
}
const lp=pathPts[pathPts.length-1];
pathPoints.push(new THREE.Vector3(lp[0],terrainH(lp[0],lp[1])+0.16,lp[1]));
(function buildPath(){
const W=2.7,pos=[],uv=[],idx=[];
for(let i=0;i<pathPoints.length;i++){
const p=pathPoints[i];
const prev=pathPoints[Math.max(0,i-1)],next=pathPoints[Math.min(pathPoints.length-1,i+1)];
const d=new THREE.Vector3().subVectors(next,prev);d.y=0;d.normalize();
const perp=new THREE.Vector3(-d.z,0,d.x).multiplyScalar(W/2);
const a=p.clone().add(perp),b=p.clone().sub(perp);
pos.push(a.x,a.y,a.z,b.x,b.y,b.z);
uv.push(0,i*0.25,1,i*0.25);
if(i<pathPoints.length-1){const o=i*2;idx.push(o,o+1,o+2,o+1,o+3,o+2);}
}
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();
const tex=paveTex.clone();tex.needsUpdate=true;tex.repeat.set(1,1);
const m=new THREE.Mesh(g,new THREE.MeshStandardMaterial({map:tex,roughness:1}));
m.receiveShadow=true;scene.add(m);
// stone steps
for(let i=0;i<pathPoints.length-1;i+=1){
const p=pathPoints[i],q=pathPoints[i+1];
const d=new THREE.Vector3().subVectors(q,p);const len=d.length();d.normalize();
const yaw=Math.atan2(d.x,d.z);
const st=B(2.6,0.34,0.62,M.stone,p.x,p.y-0.06,p.z);
st.rotation.y=yaw;st.rotation.x=Math.atan2(p.y-q.y,len)*0.5;
}
})();
function pathAt(i){return pathPoints[clamp(i,0,pathPoints.length-1)];}
/* ──────────────────────── 8. figures & animals ───────────────────── */
const FIG=new THREE.Group();scene.add(FIG);
function human(o={}){
const g=new THREE.Group();
const coat=o.coat??0x5d5347, trous=o.trous??0x3b3630, skin=o.skin??0xc79f78;
const cm=std(coat),tm=std(trous),sm=std(skin);
const l1=C(0.085,0.07,0.86,tm,-0.12,0.43,0,g,8),l2=C(0.085,0.07,0.86,tm,0.12,0.43,0,g,8);
if(o.walk){l1.rotation.x=0.34;l2.rotation.x=-0.34;}
const torso=C(0.24,0.2,0.62,cm,0,1.13,0,g,10);
const a1=C(0.07,0.06,0.58,cm,-0.28,1.16,0.04,g,8),a2=C(0.07,0.06,0.58,cm,0.28,1.16,0.04,g,8);
if(o.carry){a1.rotation.x=-0.9;a2.rotation.x=-0.9;}
const head=S(0.145,sm,0,1.58,0,g,1,1.12,1);
if(o.hat==='conical'){const h=C(0.02,0.2,0.24,std(0x2b2a26),0,1.72,0,g,12);h.rotation.z=0.06;}
else if(o.hat==='wrap'){const h=S(0.16,std(0xa8322c),0,1.66,0,g,1,0.8,1);}
else if(o.hat==='brim'){C(0.24,0.24,0.05,std(0x2b2a26),0,1.66,0,g,14);C(0.15,0.16,0.14,std(0x2b2a26),0,1.74,0,g,12);}
if(o.backLoad){
const b=new THREE.Mesh(new THREE.CylinderGeometry(0.32,0.26,0.5,12),M.bamboo);
b.position.set(0,1.18,-0.34);b.castShadow=true;g.add(b);
B(0.62,0.08,0.5,M.tea,0,1.45,-0.34,g);
C(0.02,0.02,0.5,M.woodDark,0,1.2,0.02,g,6);
}
if(o.pole){
const pole=C(0.045,0.045,1.7,M.wood,0,1.55,0.12,g,8);pole.rotation.x=Math.PI/2;
[-0.75,0.75].forEach(x=>{
C(0.02,0.02,0.42,M.woodDark,x,1.24,0.62,g,6);
const bk=C(0.26,0.21,0.34,M.bamboo,x,0.87,0.62,g,12);
B(0.44,0.06,0.42,M.tea,x,1.06,0.62,g);
});
}
return g;
}
function quadruped(o={}){
const g=new THREE.Group();
const body=o.body??0x7a4f33, dark=o.dark??0x4a3524;
const bm=std(body), dm=std(dark);
const bodyM=S(0.5,bm,0,0.92,0,g,0.62,0.6,1.0);
const legP=[[-.28,.55],[.28,.55],[-.28,-.55],[.28,-.55]];
legP.forEach(([x,z])=>{const l=C(0.085,0.07,0.88,dm,x,0.44,z,g,8);l.rotation.x=0;});
const neck=C(0.15,0.2,0.72,bm,0,1.34,0.66,g,10);neck.rotation.x=-0.55;
const head=B(0.24,0.28,0.52,bm,0,1.56,1.06,g);head.rotation.x=0.18;
if(o.ears){C(0.03,0.06,0.24,bm,-0.08,1.74,0.96,g,6);C(0.03,0.06,0.24,bm,0.08,1.74,0.96,g,6);}
if(o.mane){B(0.1,0.2,0.9,dm,0,1.42,0.7,g);}
if(o.horns){const h1=C(0.02,0.09,0.42,std(0xd8d2c4),-0.24,1.72,0.98,g,8);h1.rotation.z=-0.9;h1.rotation.x=-0.2;
const h2=C(0.02,0.09,0.42,std(0xd8d2c4),0.24,1.72,0.98,g,8);h2.rotation.z=0.9;h2.rotation.x=-0.2;}
if(o.hump){S(0.3,dm,0,1.3,0.42,g,1.1,0.8,1.1);}
if(o.skirt){const sk=new THREE.Mesh(new THREE.CylinderGeometry(0.66,0.72,0.72,14),dm);sk.position.set(0,0.62,0);sk.castShadow=true;g.add(sk);}
if(o.tail){const t=C(0.06,0.03,0.7,dm,0,1.1,-0.92,g,8);t.rotation.x=0.7;}
if(o.saddle){B(0.9,0.16,1.1,std(o.saddleColor??0x7d3b32),0,1.42,0,g);}
if(o.load){
[-0.55,0.55].forEach(x=>{B(0.6,0.62,0.86,std(0xb79a5e),x,1.28,0,g);});
B(1.5,0.08,0.1,M.woodDark,0,1.62,0,g);
}
return g;
}
/* horses at the hitching rail */
const horses=[];
[[-0.2,-4.4],[1.1,-4.5],[2.4,-4.3],[3.7,-4.6]].forEach((p,i)=>{
const h=quadruped({body:[0x6f452c,0x8a5a38,0x4f3a2a,0x7b5230][i],mane:true,tail:true,ears:true});
h.position.set(p[0],PL.y,p[1]);h.rotation.y=Math.PI*0.92+rnd()*0.2;FIG.add(h);horses.push(h);
});
/* a yak and mules */
const yak=quadruped({body:0x342a24,dark:0x241d19,horns:true,hump:true,skirt:true});
yak.position.set(27.4,terrainH(27.4,30.4),30.4);yak.rotation.y=2.3;FIG.add(yak);REF.yak=yak;
const mules=[];
for(let i=0;i<3;i++){
const mu=quadruped({body:0x9b7350,dark:0x5c4330,ears:true,mane:true,tail:true,load:true});
const p=pathAt(16+i*5);
mu.position.copy(p);mu.position.y-=0.1;
const q=pathAt(17+i*5);mu.lookAt(q.x,q.y,q.z);FIG.add(mu);mules.push(mu);
}
REF.mules=mules;
/* people */
const porter1=human({coat:0x4d4438,backLoad:true,hat:'wrap',walk:true});
const pp=pathAt(9);porter1.position.set(pp.x,pp.y-0.1,pp.z);porter1.rotation.y=2.4;FIG.add(porter1);REF.porter1=porter1;
const porter2=human({coat:0x6b5b46,pole:true,hat:'conical',walk:true});
const pp2=pathAt(27);porter2.position.set(pp2.x,pp2.y-0.1,pp2.z);porter2.rotation.y=1.1;FIG.add(porter2);REF.porter2=porter2;
const driver=human({coat:0x3f4a52,hat:'brim'});
const dp=pathAt(21);driver.position.set(dp.x-0.8,dp.y-0.1,dp.z-0.5);driver.rotation.y=1.9;FIG.add(driver);REF.driver=driver;
const broker=human({coat:0x7a4f3a,hat:'wrap'});
broker.position.set(-5.6,PL.y,-3.5);broker.rotation.y=1.2;FIG.add(broker);REF.broker=broker;
const scribe=human({coat:0x3d5a63,hat:'wrap'});
scribe.position.set(-9.0,PL.y,-2.6);scribe.rotation.y=0.4;scribe.rotation.x=-0.35;FIG.add(scribe);REF.scribe=scribe;
const porter3=human({coat:0x5b4a3a,backLoad:true,hat:'conical'});
porter3.position.set(-12.0,PL.y,-1.0);porter3.rotation.y=-0.6;FIG.add(porter3);REF.porter3=porter3;
/* scrub, rocks, conifers */
(function scatter(){
const r=rng(99);
for(let i=0;i<340;i++){
const x=-TW/2+r()*TW, z=TZ0+2+r()*(TZ1-TZ0-4);
if(x>PL.x0-2&&x<PL.x1+2&&z>PL.z0-2&&z<PL.z1+2) continue;
const y=terrainH(x,z);
if(r()<0.55){const rock=new THREE.Mesh(new THREE.DodecahedronGeometry(0.22+r()*0.5),r()<0.5?M.rock:M.stone);
rock.position.set(x,y+0.1,z);rock.rotation.set(r()*3,r()*3,r()*3);rock.castShadow=true;scene.add(rock);}
else{const bush=new THREE.Mesh(new THREE.IcosahedronGeometry(0.3+r()*0.4,0),std(0x4a5a3c));
bush.position.set(x,y+0.15,z);bush.scale.y=0.7;bush.castShadow=true;scene.add(bush);}
}
for(let i=0;i<26;i++){
const x=-50+r()*95,z=6+r()*30;
if(x>PL.x0-3&&x<PL.x1+3&&z>PL.z0-3&&z<PL.z1+3)continue;
const y=terrainH(x,z),h=2.6+r()*2.6;
C(0.16,0.22,h*0.4,std(0x4a3a2c),x,y+h*0.2,z,scene,6);
const c1=new THREE.Mesh(new THREE.ConeGeometry(h*0.32,h*0.72,8),std(0x3f5340));
c1.position.set(x,y+h*0.62,z);c1.castShadow=true;scene.add(c1);
const c2=new THREE.Mesh(new THREE.ConeGeometry(h*0.24,h*0.55,8),std(0x455a45));
c2.position.set(x,y+h*0.92,z);c2.castShadow=true;scene.add(c2);
}
})();
/* ─────────────────────────── 9. lighting ─────────────────────────── */
scene.add(new THREE.HemisphereLight(0xbcd2e8,0x4a3f33,0.62));
const sun=new THREE.DirectionalLight(0xfff0d6,1.55);
sun.position.set(38,52,-34);sun.castShadow=true;
sun.shadow.mapSize.set(2048,2048);
const sc=sun.shadow.camera;sc.left=-62;sc.right=62;sc.top=52;sc.bottom=-30;sc.near=1;sc.far=160;
sun.shadow.bias=-0.0006;sun.shadow.normalBias=0.06;
scene.add(sun);scene.add(sun.target);
const fill=new THREE.DirectionalLight(0x8fb0d6,0.32);fill.position.set(-40,26,30);scene.add(fill);
/* ───────────────────── 10. annotations / labels ──────────────────── */
const labelLayer=document.getElementById('labels'),leaderSvg=document.getElementById('leaders');
const LABELS=[];
function addLabel(cat,html,anchor,off){
const el=document.createElement('div');el.className='lbl lbl-'+cat;el.innerHTML='<span class="dot"></span>'+html;
labelLayer.appendChild(el);
const line=document.createElementNS('http://www.w3.org/2000/svg','line');
line.setAttribute('class','leader leader-'+cat);leaderSvg.appendChild(line);
LABELS.push({el,line,anchor:anchor.clone(),off});
}
function wp(obj,dx=0,dy=0,dz=0){const v=new THREE.Vector3();obj.getWorldPosition(v);v.x+=dx;v.y+=dy;v.z+=dz;return v;}
const TAGD='<span class="tag tag-doc">documented</span> ';
const TAGI='<span class="tag tag-ill">illustrative</span> ';
const TAGC='<span class="tag tag-cmp">composite</span> ';
addLabel('doc',TAGD+'<b>Brick tea (边茶)</b> — the principal export good; compressed, bamboo-wrapped bricks.',wp(REF.tea,-12.3,1.15,6.6),[-190,-70]);
addLabel('ill',TAGI+'≈60 bricks in this storehouse — <b>illustrative count</b>; brick size schematic.',wp(REF.tea,-11.0,0.9,3.4),[170,-18]);
addLabel('doc',TAGD+'<b>Salt bricks</b> from the Sichuan salt wells — the classic counter-good.',wp(REF.salt,-5.6,1.3,6.4),[170,-46]);
addLabel('doc',TAGD+'<b>Wool, felt and hides</b> — returning cargo of the tea caravans.',wp(REF.felt,-9.6,0.7,2.95),[-175,40]);
addLabel('doc',TAGD+'<b>Ledger and ink</b> — exchange was accounted in writing.',wp(REF.table,0,1.05,0),[-185,10]);
addLabel('doc',TAGD+'<b>Beam scale (衡)</b> — weighing tea, salt and animals for the transaction.',wp(REF.scale,0,2.8,0),[150,-70]);
addLabel('ill',TAGI+'Courtyard size, building dimensions and <b>6 figures</b> — invented for legibility.',new THREE.Vector3(-14.0,PL.y+0.3,-6.2),[-150,64]);
addLabel('doc',TAGD+'<b>Horses and ponies</b> — plateau stock, sought in exchange for tea.',wp(horses[1],0,1.9,0),[150,-30]);
addLabel('ill',TAGI+'7 horses, 3 mules, 1 yak — <b>illustrative numbers</b>.',wp(horses[3],0,1.6,0),[168,18]);
addLabel('doc',TAGD+'<b>Yak and mules</b> — the pack animals of the caravans.',wp(REF.yak,0,1.7,0),[120,-40]);
addLabel('doc',TAGD+'<b>Tea bricks covered for sale</b>, with <b>silver and coin</b> changing hands.',wp(REF.yardStack,0,1.2,0),[-190,20]);
addLabel('doc',TAGD+'<b>Mani pile (玛尼堆)</b> and prayer flags — documented pass-side features.',wp(REF.mani,0,1.3,0),[165,10]);
addLabel('doc',TAGD+'<b>Rammed-earth storehouse</b> on stone footing, slate roof — vernacular forms of the route.',wp(REF.house,-14.6,5.2,5.2),[-190,-30]);
addLabel('ill',TAGI+'The cut through the roof, wall and hillside is a <b>presentational device</b>.',new THREE.Vector3(-3.4,PL.y+5.4,2.45),[165,-20]);
addLabel('doc',TAGD+'<b>Steep stone path</b> between tea posts — grade and switchbacks here are schematic.',pathAt(34).clone().add(new THREE.Vector3(0,1.4,0)),[150,-34]);
addLabel('cmp',TAGC+'Tea porter with a bamboo back-load (背夫).',wp(REF.porter1,0,1.9,0),[140,26]);
addLabel('cmp',TAGC+'Mule driver (马夫) with the loaded caravan.',wp(REF.driver,0,1.9,0),[150,-18]);
addLabel('cmp',TAGC+'Horse dealer / broker at the scale.',wp(REF.broker,0,1.9,0),[-170,-6]);
addLabel('cmp',TAGC+'Clerk keeping the accounts.',wp(REF.scribe,0,1.9,0),[-165,-44]);
addLabel('cmp',TAGC+'A post at a mountain pass — composite of Songpan, Kangding, Batang-type posts.',new THREE.Vector3(-2.0,PL.y+2.6,-6.0),[60,60]);
/* ──────────────────── 11. camera + interaction ───────────────────── */
const cam={target:new THREE.Vector3(0,9,2),dist:66,yaw:2.75,pitch:0.40};
function applyCam(){
const cp=Math.cos(cam.pitch),sp=Math.sin(cam.pitch);
camera.position.set(cam.target.x+Math.sin(cam.yaw)*cp*cam.dist,
cam.target.y+sp*cam.dist,
cam.target.z+Math.cos(cam.yaw)*cp*cam.dist);
camera.lookAt(cam.target);
}
let tween=null;
function gotoView(i){
const ph=terrainH(16,14);
const views=[
{target:new THREE.Vector3(0,9,2),dist:66,yaw:2.75,pitch:0.40},
{target:new THREE.Vector3(-9,6.4,4.6),dist:25,yaw:3.06,pitch:0.20},
{target:new THREE.Vector3(-5.5,5.0,-2.4),dist:29,yaw:2.95,pitch:0.30},
{target:new THREE.Vector3(16,ph+2.5,14),dist:42,yaw:2.55,pitch:0.22}
];
const v=views[i];
tween={t:0,from:{target:cam.target.clone(),dist:cam.dist,yaw:cam.yaw,pitch:cam.pitch},
to:{target:v.target.clone(),dist:v.dist,yaw:v.yaw,pitch:v.pitch}};
document.querySelectorAll('[data-view]').forEach(b=>b.classList.toggle('on',+b.dataset.view===i));
}
document.querySelectorAll('[data-view]').forEach(b=>b.addEventListener('click',()=>gotoView(+b.dataset.view)));
let labelsOn=true,roofOn=true,figOn=true;
document.getElementById('btnLabels').addEventListener('click',e=>{labelsOn=!labelsOn;e.target.classList.toggle('on',labelsOn);
labelLayer.style.display=labelsOn?'block':'none';leaderSvg.style.display=labelsOn?'block':'none';});
document.getElementById('btnRoof').addEventListener('click',e=>{roofOn=!roofOn;e.target.classList.toggle('on',roofOn);
REF.roofCut.visible=roofOn;});
document.getElementById('btnFig').addEventListener('click',e=>{figOn=!figOn;e.target.classList.toggle('on',figOn);
FIG.visible=figOn;});
window.addEventListener('keydown',e=>{
if(e.key>='1'&&e.key<='4')gotoView(+e.key-1);
if(e.key.toLowerCase()==='l')document.getElementById('btnLabels').click();
if(e.key.toLowerCase()==='r')document.getElementById('btnRoof').click();
if(e.key.toLowerCase()==='f')document.getElementById('btnFig').click();
});
let drag=false,pan=false,lx=0,ly=0;
canvas.addEventListener('contextmenu',e=>e.preventDefault());
canvas.addEventListener('pointerdown',e=>{drag=true;pan=(e.button===2||e.shiftKey);lx=e.clientX;ly=e.clientY;tween=null;
canvas.setPointerCapture(e.pointerId);});
window.addEventListener('pointerup',()=>drag=false);
window.addEventListener('pointermove',e=>{
if(!drag)return;
const dx=e.clientX-lx,dy=e.clientY-ly;lx=e.clientX;ly=e.clientY;
if(pan){const right=new THREE.Vector3().setFromMatrixColumn(camera.matrix,0);
const up=new THREE.Vector3().setFromMatrixColumn(camera.matrix,1);
const k=cam.dist*0.0016;
cam.target.addScaledVector(right,-dx*k).addScaledVector(up,dy*k);}
else{cam.yaw-=dx*0.005;cam.pitch=clamp(cam.pitch+dy*0.004,-0.15,1.25);}
});
canvas.addEventListener('wheel',e=>{e.preventDefault();tween=null;cam.dist=clamp(cam.dist*(1+e.deltaY*0.0011),7,150);},{passive:false});
function resize(){renderer.setSize(innerWidth,innerHeight);camera.aspect=innerWidth/innerHeight;camera.updateProjectionMatrix();}
window.addEventListener('resize',resize);
/* ───────────────────────── 12. render loop ───────────────────────── */
const clock=new THREE.Clock();
function animate(){
requestAnimationFrame(animate);
const dt=clock.getDelta();
if(tween){
tween.t=Math.min(1,tween.t+dt/1.15);
const e=tween.t<.5?4*tween.t**3:1-Math.pow(-2*tween.t+2,3)/2;
cam.target.lerpVectors(tween.from.target,tween.to.target,e);
cam.dist=THREE.MathUtils.lerp(tween.from.dist,tween.to.dist,e);
cam.yaw=THREE.MathUtils.lerp(tween.from.yaw,tween.to.yaw,e);
cam.pitch=THREE.MathUtils.lerp(tween.from.pitch,tween.to.pitch,e);
if(tween.t>=1)tween=null;
}
applyCam();
renderer.render(scene,camera);
// update annotation screen positions
const W=innerWidth,H=innerHeight;
for(const L of LABELS){
const v=L.anchor.clone().project(camera);
if(v.z>1||v.z<-1){L.el.style.display='none';L.line.setAttribute('stroke-opacity','0');continue;}
const ax=(v.x*0.5+0.5)*W, ay=(-v.y*0.5+0.5)*H;
const lx=ax+L.off[0], ly=ay+L.off[1];
L.el.style.display='block';
L.el.style.transform=`translate(-50%,-50%) translate(${lx.toFixed(1)}px,${ly.toFixed(1)}px)`;
L.line.setAttribute('x1',ax.toFixed(1));L.line.setAttribute('y1',ay.toFixed(1));
L.line.setAttribute('x2',lx.toFixed(1));L.line.setAttribute('y2',ly.toFixed(1));
L.line.setAttribute('stroke-opacity','0.7');
}
}
applyCam();animate();
</script>
</body>
</html>
```