Prompt specification
Build or customize the Three.js 3D scene "Compressed tea bundle beside a pack saddle" 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: Compressed tea bundle beside a pack saddle
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/compressed-tea-bundle-beside-a-pack-saddle-x2629
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring mountain trade along the Tea Horse Road. Build a referenced compressed-tea bundle and mountain pack saddle on a small platform. Show how compact packaging relates to carrying space without asserting a universal historical weight. Stylized solid forms.
Working Three.js Starter (compressed-tea-bundle-beside-a-pack-saddle-x2629):
```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 — Compact Cargo</title>
<style>
:root {
--ink: #24332f;
--muted: #66716a;
--paper: #f3ecdc;
--paper-soft: rgba(247, 241, 228, 0.88);
--line: rgba(48, 67, 58, 0.18);
--red: #a94f3b;
--green: #315d4d;
--gold: #b78a45;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe3db;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas:active { cursor: grabbing; }
.hero {
position: fixed;
top: clamp(22px, 4vw, 48px);
left: clamp(22px, 4vw, 56px);
width: min(440px, calc(100vw - 44px));
pointer-events: none;
z-index: 5;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 2px;
content: "";
background: var(--red);
}
h1 {
max-width: 420px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5.2vw, 68px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
text-shadow: 0 2px 20px rgba(245, 240, 224, 0.45);
}
.intro {
max-width: 370px;
margin: 18px 0 0;
color: #526159;
font-size: 14px;
line-height: 1.65;
}
.note {
position: fixed;
top: clamp(22px, 4vw, 48px);
right: clamp(22px, 4vw, 48px);
width: min(320px, calc(100vw - 44px));
padding: 20px 21px 18px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 4px;
background: var(--paper-soft);
box-shadow: 0 14px 45px rgba(43, 61, 52, 0.12);
backdrop-filter: blur(14px);
z-index: 6;
}
.note-kicker {
margin-bottom: 9px;
color: var(--red);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.note h2 {
margin: 0 0 9px;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 500;
line-height: 1.16;
}
.note p {
margin: 0;
color: var(--muted);
font-size: 12.5px;
line-height: 1.6;
}
.note strong {
color: var(--ink);
font-weight: 750;
}
.note-rule {
height: 1px;
margin: 15px 0 12px;
background: var(--line);
}
.note-foot {
display: flex;
align-items: flex-start;
gap: 9px;
color: #6f756f;
font-size: 10.5px;
line-height: 1.45;
}
.note-foot svg {
flex: 0 0 auto;
margin-top: 1px;
color: var(--green);
}
#labels {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 4;
}
.callout {
position: absolute;
min-width: 136px;
padding: 8px 11px;
border: 1px solid rgba(55, 72, 63, 0.16);
border-radius: 3px;
background: rgba(247, 241, 228, 0.91);
box-shadow: 0 8px 24px rgba(42, 56, 48, 0.11);
opacity: 0;
transform: translate(-50%, calc(-100% - 13px));
transition: opacity 180ms ease;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.callout::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
content: "";
background: rgba(48, 67, 58, 0.42);
}
.callout::before {
position: absolute;
top: calc(100% + 10px);
left: calc(50% - 3px);
width: 7px;
height: 7px;
border: 2px solid rgba(247, 241, 228, 0.95);
border-radius: 50%;
content: "";
background: var(--red);
box-shadow: 0 0 0 1px rgba(48, 67, 58, 0.28);
}
.callout.visible { opacity: 1; }
.callout b {
display: block;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.02em;
}
.callout span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9.5px;
letter-spacing: 0.04em;
}
.controls {
position: fixed;
left: 50%;
bottom: clamp(18px, 3vw, 34px);
display: flex;
align-items: center;
gap: 8px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 7px;
background: rgba(246, 240, 227, 0.88);
box-shadow: 0 14px 40px rgba(41, 57, 48, 0.17);
backdrop-filter: blur(14px);
transform: translateX(-50%);
z-index: 8;
}
button {
border: 0;
border-radius: 4px;
padding: 10px 13px;
color: var(--ink);
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
cursor: pointer;
transition: background 160ms ease, color 160ms ease, transform 160ms ease;
white-space: nowrap;
}
button:hover { background: rgba(49, 93, 77, 0.09); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
button.primary {
color: #fffaf0;
background: var(--green);
}
button.primary:hover { background: #254d3f; }
.divider {
width: 1px;
height: 24px;
background: var(--line);
}
.hint {
position: fixed;
left: clamp(20px, 3vw, 38px);
bottom: clamp(22px, 3vw, 37px);
color: rgba(40, 57, 49, 0.72);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
pointer-events: none;
z-index: 5;
}
@media (max-width: 760px) {
.hero { top: 20px; left: 20px; }
h1 { max-width: 310px; font-size: 42px; }
.intro { display: none; }
.note {
top: auto;
right: 16px;
bottom: 86px;
width: 228px;
padding: 13px 14px;
}
.note h2 { font-size: 17px; }
.note p { font-size: 10.5px; }
.note-rule, .note-foot { display: none; }
.controls { bottom: 14px; }
button { padding: 10px; font-size: 10px; }
.hint { display: none; }
.callout { min-width: auto; padding: 6px 8px; }
.callout b { font-size: 9px; }
.callout span { display: none; }
.callout.space-label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { transition-duration: 0.01ms !important; }
}
</style>
</head>
<body>
<main id="viewport" aria-label="Interactive Three.js diorama of a compressed-tea bundle and a mountain pack saddle"></main>
<header class="hero">
<div class="eyebrow">Tea Horse Road networks · Trade study</div>
<h1>Compact cargo,<br>mountain routes.</h1>
<p class="intro">
A bound compressed-tea bundle and a high wooden pack saddle share a small
mountain waystation platform. Place the bundle in the pannier to compare
shape, clearance, and usable carrying space.
</p>
</header>
<aside class="note" aria-label="Interpretive note">
<div class="note-kicker">Cargo & space</div>
<h2>Less shape leaves more room.</h2>
<p>
Compact packaging can reduce the space occupied inside a pannier,
<strong>leaving room around the load</strong> for other cargo.
</p>
<div class="note-rule"></div>
<div class="note-foot">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="2"/>
<path d="M12 10v6M12 7h.01" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
<span>
Illustrative space comparison, not a fixed historical weight. Actual loads
varied by route, animal, season, cargo, and packaging.
</span>
</div>
</aside>
<div id="labels" aria-hidden="true">
<div class="callout" id="bundle-label">
<b>Compressed-tea bundle</b>
<span>Bound compressed bricks</span>
</div>
<div class="callout" id="saddle-label">
<b>Mountain pack saddle</b>
<span>Wooden frame and paired panniers</span>
</div>
<div class="callout space-label" id="space-label">
<b>Pannier space</b>
<span>Illustrative clearance</span>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Right-drag to pan</div>
<nav class="controls" aria-label="Scene controls">
<button class="primary" id="fit-button" aria-pressed="false">Place bundle in pannier</button>
<div class="divider"></div>
<button id="reset-button" title="Reset the camera">Reset view</button>
<button id="zoom-in" aria-label="Zoom in">+</button>
<button id="zoom-out" aria-label="Zoom out">−</button>
</nav>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute(
"aria-label",
"Stylized mountain trade diorama with a compressed-tea bundle and a loaded mule pack saddle"
);
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce4dc);
scene.fog = new THREE.Fog(0xdce4dc, 17, 43);
const camera = new THREE.PerspectiveCamera(39, innerWidth / innerHeight, 0.1, 100);
const hemi = new THREE.HemisphereLight(0xfff5dc, 0x60746b, 2.35);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe8c0, 3.3);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbcd5e1, 0.8);
fill.position.set(8, 5, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const mat = (color, roughness = 0.78, metalness = 0, flatShading = false) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness, flatShading });
const materials = {
ground: mat(0xa9b8a5, 1),
platformTop: mat(0xd3c3a3, 0.92),
platformEdge: mat(0x9d896d, 0.95),
road: mat(0xb99e70, 1),
mule: mat(0x786c5b, 0.9),
muleLight: mat(0x9a8c76, 0.88),
muleDark: mat(0x4f5148, 0.9),
hoof: mat(0x393d37, 0.86),
leather: mat(0x4f3527, 0.84),
leatherLight: mat(0x76503a, 0.88),
wood: mat(0x8a5f37, 0.78),
woodLight: mat(0xb1814d, 0.74),
wicker: mat(0x9a7549, 0.93),
wickerDark: mat(0x634a32, 0.95),
rope: mat(0xc2aa78, 0.92),
tea: mat(0x3d4935, 0.95),
teaTop: mat(0x505c40, 0.93),
teaSeal: mat(0x252f24, 0.8),
red: mat(0xa54e3a, 0.8),
gold: mat(0xb88b48, 0.78),
rock: mat(0x788076, 1, 0, true)
};
function addMesh(parent, geometry, material, position = [0, 0, 0], scale = null) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
if (scale) mesh.scale.set(...scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedBox(width, height, depth, radius = 0.06, bevel = 0.025) {
const w = width / 2;
const h = height / 2;
const r = Math.min(radius, w * 0.8, h * 0.8);
const shape = new THREE.Shape();
shape.moveTo(-w + r, -h);
shape.lineTo(w - r, -h);
shape.quadraticCurveTo(w, -h, w, -h + r);
shape.lineTo(w, h - r);
shape.quadraticCurveTo(w, h, w - r, h);
shape.lineTo(-w + r, h);
shape.quadraticCurveTo(-w, h, -w, h - r);
shape.lineTo(-w, -h + r);
shape.quadraticCurveTo(-w, -h, -w + r, -h);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: true,
bevelSize: bevel,
bevelThickness: bevel,
bevelSegments: 2,
curveSegments: 8,
steps: 1
});
geometry.center();
return geometry;
}
function cylinderBetween(start, end, radiusTop, radiusBottom, material, radial = 12) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, length, radial),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function tube(points, radius, material, closed = false, segments = 48) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
closed,
"centripetal"
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 8, closed),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function ribbonGeometry(points, width, y) {
const curve = new THREE.CatmullRomCurve3(
points.map(([x, z]) => new THREE.Vector3(x, y, z))
);
const segments = 90;
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const p = curve.getPoint(t);
const tangent = curve.getTangent(t);
const normal = new THREE.Vector3(-tangent.z, 0, tangent.x).normalize();
const left = p.clone().addScaledVector(normal, width / 2);
const right = p.clone().addScaledVector(normal, -width / 2);
positions.push(left.x, left.y, left.z, right.x, right.y, right.z);
uvs.push(0, t, 1, t);
if (i < segments) {
const a = i * 2;
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
// -------------------------------------------------------------------------
// Mountain landscape and small exhibit platform
// -------------------------------------------------------------------------
const ground = addMesh(
scene,
new THREE.CircleGeometry(60, 72),
materials.ground,
[0, -0.43, 0]
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
const platform = new THREE.Group();
scene.add(platform);
addMesh(
platform,
new THREE.CylinderGeometry(5.35, 5.45, 0.18, 64),
materials.platformEdge,
[0, -0.27, 0]
);
addMesh(
platform,
new THREE.CylinderGeometry(5.25, 5.35, 0.43, 64),
materials.platformTop,
[0, 0, 0]
);
const platformRim = addMesh(
platform,
new THREE.TorusGeometry(5.24, 0.035, 8, 96),
materials.rock,
[0, 0.22, 0]
);
platformRim.rotation.x = Math.PI / 2;
const road = addMesh(
platform,
ribbonGeometry(
[
[-4.7, 1.7],
[-3.8, 1.25],
[-2.8, 0.95],
[-1.5, 0.38],
[0.1, 0.12],
[1.7, -0.15],
[3.3, 0.28],
[4.7, 1.25]
],
0.62,
0.225
),
materials.road
);
road.castShadow = false;
const mountainColors = [0x70847c, 0x809087, 0x91a096, 0x667b77];
const snow = mat(0xe7e8dc, 0.95, 0, true);
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * Math.PI * 2 + 0.19;
const radius = 20 + (i % 4) * 2.1;
const height = 4.6 + ((i * 7) % 5) * 0.85;
const baseRadius = 2.5 + ((i * 3) % 4) * 0.55;
const mountain = new THREE.Group();
mountain.position.set(
Math.cos(angle) * radius,
-0.4,
Math.sin(angle) * radius
);
mountain.rotation.y = i * 0.71;
scene.add(mountain);
const cone = addMesh(
mountain,
new THREE.ConeGeometry(baseRadius, height, 5 + (i % 3), 1),
mat(mountainColors[i % mountainColors.length], 1, 0, true),
[0, height / 2, 0],
[1, 1, 0.72 + (i % 3) * 0.08]
);
cone.castShadow = false;
if (i % 3 !== 0) {
const cap = addMesh(
mountain,
new THREE.ConeGeometry(baseRadius * 0.27, height * 0.27, 5, 1),
snow,
[0, height * 0.865, 0],
[1, 1, 0.72]
);
cap.castShadow = false;
}
}
// Low-poly rocks around the platform edge.
const rockGeometry = new THREE.DodecahedronGeometry(0.24, 0);
for (let i = 0; i < 30; i++) {
const a = (i / 30) * Math.PI * 2;
const radius = 4.75 + (i % 3) * 0.15;
const size = 0.45 + (i % 5) * 0.08;
const rock = addMesh(
scene,
rockGeometry,
materials.rock,
[Math.cos(a) * radius, 0.32, Math.sin(a) * radius],
[size, size * 0.72, size * 0.86]
);
rock.rotation.set(i * 0.31, i * 0.73, i * 0.19);
}
// Route flags suggest a mountain trade way without assigning a specific date.
function routeFlag(x, z, colorMaterial, rotation = 0) {
const flag = new THREE.Group();
flag.position.set(x, 0.22, z);
flag.rotation.y = rotation;
scene.add(flag);
cylinderBetween([0, 0, 0], [0, 1.05, 0], 0.018, 0.024, materials.wood, 8);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[0, 0.98, 0, 0.55, 0.82, 0, 0, 0.65, 0],
3
)
);
geometry.computeVertexNormals();
const cloth = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: colorMaterial.color,
roughness: 0.9,
side: THREE.DoubleSide
})
);
cloth.castShadow = true;
flag.add(cloth);
}
routeFlag(-3.9, 1.65, materials.red, -0.4);
routeFlag(-1.55, 0.43, materials.gold, -0.1);
routeFlag(2.9, 0.12, materials.red, 0.2);
routeFlag(4.45, 1.05, materials.gold, 0.4);
// -------------------------------------------------------------------------
// Stylized mule
// -------------------------------------------------------------------------
const mule = new THREE.Group();
scene.add(mule);
addMesh(
mule,
new THREE.SphereGeometry(1, 28, 16),
materials.mule,
[0.72, 1.83, 0],
[1.68, 0.72, 0.68]
);
addMesh(
mule,
new THREE.SphereGeometry(1, 24, 14),
materials.muleLight,
[1.52, 1.92, 0],
[0.64, 0.69, 0.65]
);
mule.add(cylinderBetween(
[1.55, 1.98, 0],
[2.05, 2.91, 0],
0.29, 0.42, materials.mule, 14
));
const head = addMesh(
mule,
new THREE.SphereGeometry(1, 24, 14),
materials.mule,
[2.22, 3.03, 0],
[0.53, 0.34, 0.28]
);
head.rotation.z = -0.18;
addMesh(
mule,
new THREE.SphereGeometry(1, 20, 12),
materials.muleDark,
[2.67, 2.94, 0],
[0.29, 0.22, 0.23]
);
for (const z of [-0.16, 0.16]) {
const ear = addMesh(
mule,
new THREE.ConeGeometry(0.11, 0.42, 10),
materials.mule,
[2.03, 3.43, z]
);
ear.rotation.z = -0.18;
ear.rotation.x = z > 0 ? -0.08 : 0.08;
}
for (const z of [-0.245, 0.245]) {
addMesh(
mule,
new THREE.SphereGeometry(0.047, 12, 8),
materials.hoof,
[2.43, 3.10, z]
);
}
const legXs = [-0.42, 1.72];
const legZs = [-0.42, 0.42];
for (const x of legXs) {
for (const z of legZs) {
mule.add(cylinderBetween(
[x, 1.67, z],
[x + (x > 0 ? 0.04 : -0.03), 0.53, z],
0.13, 0.19, materials.mule, 10
));
mule.add(cylinderBetween(
[x + (x > 0 ? 0.04 : -0.03), 0.58, z],
[x + (x > 0 ? 0.04 : -0.03), 0.32, z],
0.105, 0.13, materials.muleDark, 10
));
addMesh(
mule,
new THREE.CylinderGeometry(0.16, 0.14, 0.18, 10),
materials.hoof,
[x + (x > 0 ? 0.04 : -0.03), 0.32, z]
);
}
}
mule.add(tube(
[[-0.88, 2.13, 0], [-1.12, 1.83, 0.02], [-1.15, 1.35, 0.06]],
0.055,
materials.muleDark
));
addMesh(
mule,
new THREE.SphereGeometry(0.1, 12, 8),
materials.muleDark,
[-1.15, 1.31, 0.06]
);
// -------------------------------------------------------------------------
// Mountain pack saddle: padded base, high wooden frame, girth and panniers
// -------------------------------------------------------------------------
const saddle = new THREE.Group();
scene.add(saddle);
addMesh(
saddle,
new THREE.SphereGeometry(1, 28, 12),
materials.leather,
[0.53, 2.52, 0],
[1.03, 0.17, 0.76]
);
const framePoints = [
[-0.42, 2.59],
[-0.26, 3.12],
[0.24, 3.48],
[0.88, 3.48],
[1.34, 3.06],
[1.46, 2.58]
];
for (const z of [-0.48, 0.48]) {
saddle.add(tube(
framePoints.map(([x, y]) => [x, y, z]),
0.075,
materials.wood
));
}
for (const x of [-0.08, 0.91]) {
saddle.add(cylinderBetween(
[x, 3.31, -0.51],
[x, 3.31, 0.51],
0.07, 0.07, materials.woodLight, 12
));
}
// Broad girth around the mule's body.
const girth = addMesh(
saddle,
new THREE.TorusGeometry(1, 0.065, 8, 48),
materials.leatherLight,
[0.46, 1.84, 0]
);
girth.rotation.y = Math.PI / 2;
girth.scale.set(0.70, 0.76, 1);
// Breast strap and rear tie.
saddle.add(tube(
[[1.82, 2.62, -0.42], [1.91, 2.46, 0], [1.82, 2.62, 0.42]],
0.045,
materials.leatherLight
));
saddle.add(tube(
[[-0.73, 2.57, -0.39], [-0.91, 2.29, 0], [-0.73, 2.57, 0.39]],
0.045,
materials.leatherLight
));
function createPannier(z, openTop) {
const pannier = new THREE.Group();
pannier.position.set(0.55, 1.83, z);
scene.add(pannier);
addMesh(
pannier,
roundedBox(1.38, 0.11, 0.72, 0.04, 0.018),
materials.wickerDark,
[0, -0.39, 0]
);
// Corner posts.
for (const x of [-0.64, 0.64]) {
for (const zz of [-0.32, 0.32]) {
addMesh(
pannier,
new THREE.BoxGeometry(0.075, 0.72, 0.075),
materials.wickerDark,
[x, -0.02, zz]
);
}
}
// Front and back lattice.
for (const zz of [-0.34, 0.34]) {
for (let x = -0.53; x <= 0.54; x += 0.265) {
addMesh(
pannier,
new THREE.BoxGeometry(0.052, 0.65, 0.055),
materials.wicker,
[x, -0.02, zz]
);
}
for (const y of [-0.28, 0, 0.28]) {
addMesh(
pannier,
new THREE.BoxGeometry(1.31, 0.052, 0.062),
materials.wickerDark,
[0, y, zz]
);
}
}
// End lattice.
for (const x of [-0.66, 0.66]) {
for (let zz = -0.21; zz <= 0.22; zz += 0.21) {
addMesh(
pannier,
new THREE.BoxGeometry(0.058, 0.65, 0.052),
materials.wicker,
[x, -0.02, zz]
);
}
for (const y of [-0.28, 0, 0.28]) {
addMesh(
pannier,
new THREE.BoxGeometry(0.065, 0.052, 0.67),
materials.wickerDark,
[x, y, 0]
);
}
}
if (!openTop) {
const flap = addMesh(
pannier,
roundedBox(1.33, 0.08, 0.67, 0.05, 0.02),
materials.leatherLight,
[0, 0.36, 0]
);
flap.rotation.x = 0.04;
}
// Suspension ropes from the pack frame.
const sign = Math.sign(z);
for (const x of [-0.43, 0.43]) {
pannier.add(tube(
[
[x, 0.31, -sign * 0.30],
[x - 0.08, 0.75, -sign * 0.22],
[x - 0.05, 1.28, -sign * 0.11]
],
0.024,
materials.rope
));
}
return pannier;
}
const nearPannier = createPannier(1.02, true);
const farPannier = createPannier(-1.02, false);
// Small leather tie over the far pannier.
farPannier.add(tube(
[[-0.47, 0.4, 0], [-0.1, 0.47, 0.02], [0.48, 0.4, 0]],
0.022,
materials.leather
));
// -------------------------------------------------------------------------
// Compressed-tea bundle: stacked bricks, seal, and hemp binding
// -------------------------------------------------------------------------
const teaBundle = new THREE.Group();
scene.add(teaBundle);
for (let i = 0; i < 3; i++) {
const brick = addMesh(
teaBundle,
roundedBox(0.82, 0.19, 0.50, 0.045, 0.018),
i === 2 ? materials.teaTop : materials.tea,
[i === 1 ? 0.018 : 0, -0.21 + i * 0.21, 0]
);
brick.rotation.y = i === 1 ? 0.018 : 0;
}
// Embossed-looking seal on the top brick.
addMesh(
teaBundle,
new THREE.CylinderGeometry(0.15, 0.15, 0.012, 24),
materials.teaSeal,
[0, 0.31, 0]
);
const sealRing = addMesh(
teaBundle,
new THREE.TorusGeometry(0.12, 0.012, 7, 24),
materials.teaTop,
[0, 0.322, 0]
);
sealRing.rotation.x = Math.PI / 2;
// Two loops cinching the bundle around its depth and height.
for (const x of [-0.27, 0.27]) {
teaBundle.add(tube(
[
[x, -0.35, -0.29],
[x, 0.34, -0.29],
[x, 0.34, 0.29],
[x, -0.35, 0.29]
],
0.018,
materials.rope,
true,
38
));
}
// Horizontal binding around the stack.
for (const y of [-0.105, 0.105]) {
teaBundle.add(tube(
[
[-0.44, y, -0.28],
[0.44, y, -0.28],
[0.44, y, 0.28],
[-0.44, y, 0.28]
],
0.018,
materials.rope,
true,
38
));
}
addMesh(
teaBundle,
new THREE.SphereGeometry(0.045, 12, 8),
materials.rope,
[0.26, -0.105, 0.31]
);
const bundleDisplay = new THREE.Vector3(-2.42, 0.74, 0.87);
const bundlePannier = new THREE.Vector3(0.55, 1.84, 1.02);
teaBundle.position.copy(bundleDisplay);
teaBundle.rotation.y = -0.27;
// Low display plinth.
const bundlePlinth = addMesh(
scene,
new THREE.CylinderGeometry(0.72, 0.78, 0.22, 12),
materials.wood,
[-2.42, 0.32, 0.87]
);
bundlePlinth.rotation.y = 0.18;
// Dashed volume showing the bundle-sized clearance inside the near pannier.
const fitOutlineGeometry = new THREE.EdgesGeometry(
new THREE.BoxGeometry(1.03, 0.67, 0.55)
);
const fitOutline = new THREE.LineSegments(
fitOutlineGeometry,
new THREE.LineDashedMaterial({
color: 0x315d4d,
dashSize: 0.07,
gapSize: 0.045,
transparent: true,
opacity: 0.58
})
);
fitOutline.position.copy(bundlePannier);
fitOutline.computeLineDistances();
scene.add(fitOutline);
// -------------------------------------------------------------------------
// Bundle placement animation
// -------------------------------------------------------------------------
const fitButton = document.getElementById("fit-button");
const bundleLabel = document.getElementById("bundle-label");
let bundlePlaced = false;
let bundleAnimation = null;
function toggleBundle() {
const destination = bundlePlaced ? bundleDisplay : bundlePannier;
const destinationRotation = bundlePlaced ? -0.27 : 0;
bundleAnimation = {
from: teaBundle.position.clone(),
to: destination.clone(),
fromRotation: teaBundle.rotation.y,
toRotation: destinationRotation,
start: performance.now(),
duration: reducedMotion ? 1 : 1450
};
bundlePlaced = !bundlePlaced;
fitButton.setAttribute("aria-pressed", String(bundlePlaced));
fitButton.textContent = bundlePlaced
? "Return bundle to display"
: "Place bundle in pannier";
}
fitButton.addEventListener("click", toggleBundle);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, and touch pinch
// -------------------------------------------------------------------------
const initialTarget = new THREE.Vector3(0.15, 1.65, 0);
const cameraTarget = initialTarget.clone();
const initialOffset = new THREE.Vector3(8.1, 5.2, 9.2);
const spherical = new THREE.Spherical().setFromVector3(initialOffset);
function applyCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.28, 1.43);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 6.8, 18.5);
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTarget.copy(initialTarget);
spherical.setFromVector3(initialOffset);
applyCamera();
}
const pointers = new Map();
let pinchDistance = 0;
let pointerMode = "orbit";
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
startX: event.clientX,
startY: event.clientY
});
pointerMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
previous.x = event.clientX;
previous.y = event.clientY;
if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
spherical.radius *= pinchDistance / Math.max(distance, 1);
applyCamera();
}
pinchDistance = distance;
return;
}
if (pointerMode === "pan") {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = forward.clone().cross(camera.up).normalize();
const panScale = spherical.radius * 0.0011;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.y += dy * panScale;
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 0.5, 4.0);
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
}
applyCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
applyCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
const step = 0.09;
if (event.key === "ArrowLeft") spherical.theta += step;
if (event.key === "ArrowRight") spherical.theta -= step;
if (event.key === "ArrowUp") spherical.phi -= step;
if (event.key === "ArrowDown") spherical.phi += step;
if (event.key === "+" || event.key === "=") spherical.radius *= 0.9;
if (event.key === "-" || event.key === "_") spherical.radius *= 1.1;
if (event.key.toLowerCase() === "r") resetCamera();
applyCamera();
});
document.getElementById("reset-button").addEventListener("click", resetCamera);
document.getElementById("zoom-in").addEventListener("click", () => {
spherical.radius *= 0.86;
applyCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
spherical.radius *= 1.16;
applyCamera();
});
applyCamera();
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const saddleLabel = document.getElementById("saddle-label");
const spaceLabel = document.getElementById("space-label");
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
element.classList.remove("visible");
return;
}
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
element.classList.add("visible");
}
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", resize);
function animate(now) {
requestAnimationFrame(animate);
if (bundleAnimation) {
const raw = THREE.MathUtils.clamp(
(now - bundleAnimation.start) / bundleAnimation.duration,
0,
1
);
const eased = raw * raw * (3 - 2 * raw);
teaBundle.position.lerpVectors(
bundleAnimation.from,
bundleAnimation.to,
eased
);
teaBundle.position.y += Math.sin(raw * Math.PI) * 0.62;
teaBundle.rotation.y = THREE.MathUtils.lerp(
bundleAnimation.fromRotation,
bundleAnimation.toRotation,
eased
);
if (raw >= 1) bundleAnimation = null;
}
fitOutline.visible = bundlePlaced || bundleAnimation !== null;
if (bundlePlaced) {
bundleLabel.querySelector("b").textContent = "Compressed-tea bundle";
bundleLabel.querySelector("span").textContent = "Compact load in pannier";
} else {
bundleLabel.querySelector("b").textContent = "Compressed-tea bundle";
bundleLabel.querySelector("span").textContent = "Bound compressed bricks";
}
positionLabel(
bundleLabel,
teaBundle.position.clone().add(new THREE.Vector3(0, 0.48, 0))
);
positionLabel(
saddleLabel,
new THREE.Vector3(0.32, 3.68, 0)
);
positionLabel(
spaceLabel,
bundlePannier.clone().add(new THREE.Vector3(0.05, 0.62, 0.1))
);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```