Prompt specification
Build or customize the Three.js 3D scene "Technique Adaptation Across Environments" 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: Technique Adaptation Across Environments
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/technique-adaptation-across-environments-x3296
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing craft techniques exchanged and adapted between communities. Create two fictional settlements with different local materials using a shared weaving principle. Compare adapted tools and products while preserving the same underlying interlacing rule. Voxel style.
Working Three.js Starter (technique-adaptation-across-environments-x3296):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Common Loom — Craft Exchange Atlas</title>
<style>
:root {
--ink: #243b39;
--muted: #6f7d75;
--paper: #f5f1e8;
--paper-dark: #e9e3d7;
--reed: #c98545;
--reed-light: #e8bd78;
--crag: #657f87;
--crag-light: #a7bdc0;
--mint: #a8cbb9;
--line: rgba(36, 59, 57, 0.14);
--shadow: 0 14px 40px rgba(36, 59, 57, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#viewport {
position: absolute;
inset: 0 390px 0 0;
overflow: hidden;
background: #dbe7df;
}
#scene {
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
#masthead {
position: absolute;
z-index: 4;
top: 24px;
left: 28px;
width: min(340px, calc(100% - 56px));
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
.brand-mark {
width: 34px;
height: 34px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 2px;
padding: 5px;
border-radius: 9px;
background: var(--ink);
box-shadow: var(--shadow);
}
.brand-mark span {
background: var(--paper);
}
.brand-mark span:nth-child(2),
.brand-mark span:nth-child(6),
.brand-mark span:nth-child(8) {
background: var(--reed-light);
}
.eyebrow {
font-size: 10px;
font-weight: 800;
line-height: 1.2;
letter-spacing: 0.17em;
text-transform: uppercase;
}
#masthead h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3vw, 43px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.04em;
}
#masthead p {
max-width: 285px;
margin: 11px 0 0;
color: #506862;
font-size: 12px;
line-height: 1.5;
}
.scene-label {
position: absolute;
z-index: 3;
transform: translate(-50%, -100%);
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 9px;
background: rgba(247, 244, 235, 0.9);
color: var(--ink);
box-shadow: 0 6px 18px rgba(27, 52, 49, 0.13);
padding: 7px 10px;
text-align: left;
white-space: nowrap;
cursor: pointer;
backdrop-filter: blur(8px);
transition:
transform 160ms ease,
background 160ms ease,
border-color 160ms ease;
}
.scene-label:hover,
.scene-label.active {
transform: translate(-50%, -100%) translateY(-2px);
background: #fffdf7;
border-color: var(--reed);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -6px;
width: 9px;
height: 9px;
transform: translateX(-50%) rotate(45deg);
background: inherit;
border-right: 1px solid rgba(255, 255, 255, 0.72);
border-bottom: 1px solid rgba(255, 255, 255, 0.72);
}
.scene-label .label-name {
display: block;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
.scene-label .label-sub {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.scene-label.place {
padding: 8px 13px;
border: 0;
border-radius: 6px;
background: var(--ink);
color: white;
box-shadow: var(--shadow);
}
.scene-label.place .label-name {
font-size: 11px;
letter-spacing: 0.16em;
}
.scene-label.place.reed {
background: #9d6337;
}
.scene-label.place.crag {
background: #526d76;
}
.scene-label.place::after {
display: none;
}
#legend {
position: absolute;
z-index: 4;
bottom: 22px;
left: 28px;
display: flex;
flex-wrap: wrap;
gap: 14px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 10px;
background: rgba(247, 244, 235, 0.84);
box-shadow: 0 8px 25px rgba(36, 59, 57, 0.1);
color: #536761;
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(8px);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: var(--reed);
}
.swatch.crag {
background: var(--crag);
}
.swatch.rule {
background:
linear-gradient(90deg, var(--ink) 50%, transparent 50%),
linear-gradient(var(--ink) 50%, transparent 50%);
background-size: 6px 6px;
border: 1px solid var(--ink);
}
#panel {
position: absolute;
z-index: 10;
top: 0;
right: 0;
width: 390px;
height: 100%;
padding: 30px 28px 24px;
overflow-y: auto;
border-left: 1px solid rgba(36, 59, 57, 0.12);
background:
linear-gradient(rgba(245, 241, 232, 0.97), rgba(245, 241, 232, 0.97)),
repeating-linear-gradient(
0deg,
transparent 0,
transparent 3px,
rgba(36, 59, 57, 0.025) 3px,
rgba(36, 59, 57, 0.025) 4px
);
box-shadow: -12px 0 40px rgba(36, 59, 57, 0.08);
}
#panel > .eyebrow {
color: #8a6b48;
}
#panel h2 {
margin: 9px 0 10px;
font-family: Georgia, "Times New Roman", serif;
font-size: 39px;
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
#panel h2 em {
color: #9c6840;
font-weight: 400;
}
.intro {
margin: 0;
color: #61716a;
font-size: 12px;
line-height: 1.6;
}
.rule-card {
margin-top: 22px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.48);
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.section-head strong {
font-size: 11px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.rule-number {
padding: 4px 7px;
border-radius: 5px;
background: var(--ink);
color: white;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.rule-copy {
margin: 11px 0 13px;
color: #61716a;
font-size: 11px;
line-height: 1.55;
}
.draft {
display: grid;
grid-template-columns: repeat(8, 1fr);
gap: 3px;
padding: 8px;
border-radius: 8px;
background: #e8e2d5;
}
.draft span {
position: relative;
height: 19px;
overflow: hidden;
border-radius: 3px;
background: var(--reed-light);
}
.draft span::before {
content: "";
position: absolute;
inset: 5px -2px;
background: var(--ink);
transform: rotate(12deg);
}
.draft span:nth-child(even)::before {
transform: rotate(-12deg);
background: #f9f4e9;
border: 2px solid var(--ink);
}
.sequence {
display: flex;
justify-content: space-between;
margin-top: 10px;
color: #7a857f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.11em;
}
.compare {
margin-top: 24px;
}
.compare-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 12px;
}
.community {
position: relative;
min-height: 193px;
padding: 15px 13px 13px;
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.43);
}
.community::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: var(--reed);
}
.community.crag::before {
background: var(--crag);
}
.community h3 {
margin: 3px 0 14px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
}
.community dl {
margin: 0;
}
.community dt {
margin-top: 10px;
color: #8a928c;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.community dd {
margin: 3px 0 0;
font-size: 10px;
line-height: 1.45;
}
.detail {
position: relative;
margin-top: 15px;
padding: 17px 17px 16px;
border-radius: 12px;
background: var(--ink);
color: white;
overflow: hidden;
}
.detail::after {
content: "";
position: absolute;
right: -20px;
bottom: -28px;
width: 90px;
height: 90px;
border: 16px solid rgba(255, 255, 255, 0.04);
transform: rotate(30deg);
}
.detail .eyebrow {
color: #b9d0c5;
}
.detail h3 {
margin: 7px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
line-height: 1.12;
}
.detail p {
position: relative;
z-index: 1;
margin: 0;
color: #d4ded9;
font-size: 10px;
line-height: 1.55;
}
.detail .detail-rule {
position: relative;
z-index: 1;
display: inline-block;
margin-top: 12px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 5px;
color: #f0d19c;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 9px;
margin-top: 14px;
}
.actions button {
min-height: 39px;
padding: 0 14px;
border: 1px solid var(--ink);
border-radius: 8px;
background: transparent;
color: var(--ink);
font-size: 10px;
font-weight: 800;
cursor: pointer;
transition:
color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.actions button.primary {
background: var(--ink);
color: white;
}
.actions button:hover {
transform: translateY(-1px);
}
.actions button.primary:hover {
background: #34514d;
}
.panel-note {
margin: 16px 0 0;
color: #87918b;
font-size: 9px;
line-height: 1.5;
text-align: center;
}
#loading {
position: absolute;
z-index: 30;
inset: 0 390px 0 0;
display: grid;
place-items: center;
background: #dbe7df;
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
#viewport {
inset: 0 0 43vh 0;
}
#panel {
top: auto;
bottom: 0;
width: 100%;
height: 43vh;
padding: 20px 24px;
border-top: 1px solid var(--line);
border-left: 0;
}
#panel h2 {
font-size: 30px;
}
.intro {
max-width: 610px;
}
.rule-card,
.compare {
display: none;
}
.detail {
margin-top: 12px;
}
#masthead {
top: 17px;
left: 18px;
}
#masthead p {
display: none;
}
#legend {
bottom: 13px;
left: 18px;
gap: 9px;
padding: 8px 10px;
}
#loading {
inset: 0 0 43vh 0;
}
.scene-label:not(.place) {
display: none;
}
}
@media (max-width: 520px) {
#masthead h1 {
font-size: 29px;
}
.brand {
margin-bottom: 6px;
}
#legend .legend-item:nth-child(3) {
display: none;
}
.actions {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<main id="viewport">
<canvas id="scene" aria-label="Interactive voxel diorama of two settlements exchanging weaving knowledge"></canvas>
<div id="labels"></div>
<header id="masthead">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<span></span><span></span><span></span>
<span></span><span></span><span></span>
<span></span><span></span><span></span>
</div>
<div class="eyebrow">Craft Exchange Atlas / 07</div>
</div>
<h1>Common Loom</h1>
<p>
Two settlements. Two local materials. The same over-and-under knowledge,
traveling between them.
</p>
</header>
<div id="legend" aria-label="Scene legend">
<div class="legend-item"><span class="swatch"></span> Reedfen fiber</div>
<div class="legend-item"><span class="swatch crag"></span> Cragmoor fiber</div>
<div class="legend-item"><span class="swatch rule"></span> Shared 1/1 draft</div>
</div>
<div id="loading">Building the two settlements…</div>
</main>
<aside id="panel">
<div class="eyebrow">A study in shared structure</div>
<h2>One weave,<br /><em>two homes.</em></h2>
<p class="intro">
Reedfen and Cragmoor adapted weaving to different landscapes. A technique
crossed the bridge, but each community rebuilt it with what it had.
</p>
<section class="rule-card">
<div class="section-head">
<strong>Shared weaving principle</strong>
<span class="rule-number">1 / 1</span>
</div>
<p class="rule-copy">
At each crossing, the weft passes over one warp and under the next.
Every new row reverses the sequence.
</p>
<div class="draft" aria-label="Alternating one-over, one-under weaving draft">
<span></span><span></span><span></span><span></span>
<span></span><span></span><span></span><span></span>
</div>
<div class="sequence">
<span>OVER</span><span>UNDER</span><span>OVER</span><span>UNDER</span>
</div>
</section>
<section class="compare">
<div class="section-head">
<strong>Same draft, local adaptation</strong>
<span class="eyebrow" style="color: #8a928c">Comparison</span>
</div>
<div class="compare-grid">
<article class="community reed">
<div class="eyebrow">Wetland settlement</div>
<h3>Reedfen</h3>
<dl>
<dt>Local stock</dt>
<dd>Marsh reed + sheep fleece</dd>
<dt>Adapted tool</dt>
<dd>Long, flat slip shuttle</dd>
<dt>Product</dt>
<dd>Light sleeping mat</dd>
</dl>
</article>
<article class="community crag">
<div class="eyebrow">Upland settlement</div>
<h3>Cragmoor</h3>
<dl>
<dt>Local stock</dt>
<dd>Mountain grass cord + goat hair</dd>
<dt>Adapted tool</dt>
<dd>Short, stone-weighted shuttle</dd>
<dt>Product</dt>
<dd>Reinforced pack panel</dd>
</dl>
</article>
</div>
</section>
<section class="detail" id="detail" aria-live="polite">
<div class="eyebrow" id="detailEyebrow">Exchange bridge</div>
<h3 id="detailTitle">The rule travels; the materials stay local.</h3>
<p id="detailBody">
A sample of the crossing sequence travels to Cragmoor. Its geometry is
unchanged, but reed fibers are replaced by tougher mountain cord.
</p>
<span class="detail-rule" id="detailRule">Shared rule: plain weave, 1/1</span>
</section>
<div class="actions">
<button class="primary" id="replay" type="button">Replay exchange ↗</button>
<button id="reset" type="button">Reset view</button>
</div>
<p class="panel-note">
Drag to orbit · Shift-drag to pan · Scroll to zoom<br />
Select a loom, tool, product, or the bridge to inspect it.
</p>
</aside>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const viewport = document.querySelector("#viewport");
const labelLayer = document.querySelector("#labels");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe7df);
scene.fog = new THREE.Fog(0xdbe7df, 28, 58);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const camera = new THREE.PerspectiveCamera(40, 1, 0.1, 100);
const clock = new THREE.Clock();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pickables = [];
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
const M = {
soilL: material(0x718b65),
soilR: material(0x71817a),
grassL: material(0x9db57e),
grassR: material(0x91a68d),
grassLight: material(0xb1c58f),
grassDark: material(0x687f61),
path: material(0xd0b58d),
pathR: material(0xa9a397),
water: material(0x6aa8a4, { roughness: 0.34, metalness: 0.05 }),
waterLight: material(0x9cc9c2, { roughness: 0.38 }),
clay: material(0xc47b55),
clayLight: material(0xd99569),
straw: material(0xc79b52),
wood: material(0x74523d),
woodLight: material(0xa7784f),
darkWood: material(0x493c33),
stone: material(0x728087),
stoneLight: material(0x99a5a3),
stoneDark: material(0x4e5c61),
roofR: material(0x4e6264),
reed: material(0xd2a158),
reedDark: material(0x9f7b43),
reedGreen: material(0x728c55),
wool: material(0xe2c998),
cragWool: material(0x9fb3b5),
cragCord: material(0x6e898c),
reedCord: material(0xbf9254),
cream: material(0xf1e7d2),
ink: material(0x304642),
window: material(0x9dc8bb, { emissive: 0x294a43, emissiveIntensity: 0.2 }),
fire: material(0xf1a54d, { emissive: 0xd46b27, emissiveIntensity: 0.7 }),
mint: material(0x83b59e),
leaf: material(0x527568),
leafLight: material(0x6d8b72),
white: material(0xf3f1e7)
};
function box(parent, size, position, mat, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function addHitbox(size, position, infoId) {
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const hit = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
hitMaterial
);
hit.position.set(...position);
hit.userData.infoId = infoId;
scene.add(hit);
pickables.push(hit);
}
// ---------- Lighting ----------
scene.add(new THREE.HemisphereLight(0xeaf4eb, 0x657065, 2.1));
const sun = new THREE.DirectionalLight(0xfff0ce, 3.1);
sun.position.set(-9, 17, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xb6d7db, 1.0);
rim.position.set(12, 9, -10);
scene.add(rim);
// ---------- Terrain and central water ----------
box(scene, [9.7, 0.72, 8.5], [-6.1, -0.48, 0], M.soilL);
box(scene, [9.7, 0.72, 8.5], [6.1, -0.48, 0], M.soilR);
box(scene, [9.5, 0.10, 8.3], [-6.1, -0.08, 0], M.grassL);
box(scene, [9.5, 0.10, 8.3], [6.1, -0.08, 0], M.grassR);
box(scene, [2.55, 0.24, 9.2], [0, -0.64, 0], M.water);
box(scene, [2.9, 0.18, 9.5], [0, -0.78, 0], M.stoneDark);
// Stepped banks.
for (let z = -4.0; z <= 4.0; z += 0.8) {
box(scene, [0.34, 0.28, 0.64], [-1.42, -0.35, z], M.stoneLight);
box(scene, [0.34, 0.28, 0.64], [1.42, -0.35, z], M.stoneLight);
}
// Irregular grass and path tiles.
const leftPatches = [
[-9.3, -2.8, 1.5, 1.1],
[-7.4, -3.6, 2.3, 0.7],
[-8.7, 2.6, 1.0, 1.6],
[-4.0, 2.9, 1.4, 1.2],
[-3.4, -3.5, 1.0, 0.8]
];
leftPatches.forEach(([x, z, w, d], i) => {
box(scene, [w, 0.045, d], [x, 0.0, z], i % 2 ? M.grassLight : M.grassDark);
});
const rightPatches = [
[9.0, -3.0, 1.7, 1.1],
[7.0, -3.6, 2.5, 0.7],
[9.0, 2.7, 1.2, 1.8],
[4.0, 3.1, 1.4, 1.0],
[3.2, -3.3, 1.1, 0.9]
];
rightPatches.forEach(([x, z, w, d], i) => {
box(scene, [w, 0.045, d], [x, 0.0, z], i % 2 ? M.grassDark : M.grassLight);
});
for (let i = 0; i < 7; i++) {
box(scene, [0.62, 0.055, 0.55], [-7.7 + i * 0.63, 0.035, -0.9], M.path);
box(scene, [0.62, 0.055, 0.55], [4.3 + i * 0.63, 0.035, -0.9], M.pathR);
}
// Water glints.
const waterGlints = [];
for (let i = 0; i < 13; i++) {
const glint = box(
scene,
[0.18 + Math.random() * 0.3, 0.025, 0.07],
[(Math.random() - 0.5) * 1.7, -0.49, -4.1 + i * 0.65],
M.waterLight,
{ castShadow: false }
);
waterGlints.push(glint);
}
// ---------- Buildings ----------
function makeHouse(x, z, scale, wallMat, roofMat, doorMat = M.darkWood) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [2.35 * scale, 1.7 * scale, 2.05 * scale], [0, 0.85 * scale, 0], wallMat);
box(g, [2.72 * scale, 0.29 * scale, 2.4 * scale], [0, 1.79 * scale, 0], roofMat);
box(g, [2.25 * scale, 0.27 * scale, 1.95 * scale], [0, 2.05 * scale, 0], roofMat);
box(g, [1.72 * scale, 0.25 * scale, 1.46 * scale], [0, 2.29 * scale, 0], roofMat);
box(
g,
[0.53 * scale, 1.02 * scale, 0.09],
[0.36 * scale, 0.52 * scale, 1.065 * scale],
doorMat
);
box(
g,
[0.42 * scale, 0.36 * scale, 0.08],
[-0.63 * scale, 1.06 * scale, 1.065 * scale],
M.window,
{ castShadow: false }
);
box(
g,
[0.30 * scale, 0.62 * scale, 0.30 * scale],
[0.72 * scale, 2.35 * scale, -0.35 * scale],
M.stoneDark
);
// Small stacked firewood.
for (let i = 0; i < 4; i++) {
box(
g,
[0.22 * scale, 0.18 * scale, 0.75 * scale],
[-0.85 * scale + (i % 2) * 0.25 * scale, 0.12 + Math.floor(i / 2) * 0.2 * scale, 1.25 * scale],
M.woodLight
);
}
return g;
}
makeHouse(-8.25, -2.25, 0.92, M.clay, M.straw, M.wood);
makeHouse(-4.45, -2.65, 0.78, M.clayLight, M.reedDark);
makeHouse(-8.45, 2.25, 0.67, M.clay, M.straw);
makeHouse(8.25, -2.25, 0.92, M.stone, M.roofR, M.ink);
makeHouse(4.45, -2.65, 0.78, M.stoneLight, M.darkWood, M.ink);
makeHouse(8.45, 2.25, 0.67, M.stone, M.roofR);
// ---------- Local vegetation ----------
function reedCluster(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
for (let i = 0; i < 7; i++) {
const h = (0.65 + Math.random() * 0.75) * scale;
const px = (Math.random() - 0.5) * 0.65 * scale;
const pz = (Math.random() - 0.5) * 0.55 * scale;
box(g, [0.07 * scale, h, 0.07 * scale], [px, h / 2, pz], M.reedGreen);
box(
g,
[0.18 * scale, 0.32 * scale, 0.10 * scale],
[px, h * 0.9, pz],
M.reed,
{ rotation: [0, 0, (Math.random() - 0.5) * 0.35] }
);
}
}
function pine(x, z, scale = 1) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [0.25 * scale, 1.25 * scale, 0.25 * scale], [0, 0.62 * scale, 0], M.wood);
box(g, [1.45 * scale, 0.62 * scale, 1.35 * scale], [0, 1.25 * scale, 0], M.leaf);
box(g, [1.05 * scale, 0.57 * scale, 1.0 * scale], [0, 1.78 * scale, 0], M.leafLight);
box(g, [0.65 * scale, 0.50 * scale, 0.65 * scale], [0, 2.26 * scale, 0], M.leaf);
}
reedCluster(-9.55, 0.6, 1.0);
reedCluster(-3.15, 3.65, 0.85);
reedCluster(-8.4, -3.75, 0.8);
reedCluster(-2.85, -3.55, 0.72);
reedCluster(-4.1, 2.85, 0.62);
pine(9.55, 0.45, 0.85);
pine(3.15, 3.55, 0.72);
pine(9.0, -3.65, 0.74);
pine(2.95, -3.45, 0.62);
// Upland rocks.
const rockPositions = [
[8.9, 1.25, 0.55],
[9.25, 1.55, 0.38],
[7.8, 3.55, 0.42],
[3.4, -1.4, 0.35],
[4.0, -1.25, 0.26]
];
rockPositions.forEach(([x, z, s], i) => {
box(scene, [s, s * 0.65, s * 0.85], [x, s * 0.28, z], i % 2 ? M.stone : M.stoneLight);
});
// ---------- Material drying racks ----------
function dryingRack(x, z, cordMat) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [0.18, 1.8, 0.18], [-1.1, 0.9, 0], M.wood);
box(g, [0.18, 1.8, 0.18], [1.1, 0.9, 0], M.wood);
box(g, [2.4, 0.16, 0.18], [0, 1.72, 0], M.wood);
for (let i = 0; i < 6; i++) {
box(g, [0.10, 0.9 + (i % 2) * 0.12, 0.10], [-0.9 + i * 0.36, 1.14, 0], cordMat);
}
}
dryingRack(-8.55, -3.8, M.reedCord);
dryingRack(8.6, -3.8, M.cragCord);
// ---------- Looms with the identical 1/1 draft ----------
const loomAnimations = [];
function createLoom(x, z, options) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
const frameMat = options.frameMat;
const warpMat = options.warpMat;
const weftMat = options.weftMat;
// Freestanding wooden frame.
box(g, [0.22, 3.0, 0.25], [-1.78, 1.5, 0], frameMat);
box(g, [0.22, 3.0, 0.25], [1.78, 1.5, 0], frameMat);
box(g, [3.78, 0.22, 0.28], [0, 3.0, 0], frameMat);
box(g, [3.56, 0.16, 0.18], [0, 0.47, 0], frameMat);
// Rear feet.
box(g, [0.75, 0.18, 1.0], [-1.65, 0.10, 0], frameMat);
box(g, [0.75, 0.18, 1.0], [1.65, 0.10, 0], frameMat);
const columns = 9;
const rows = 7;
const step = 0.32;
const bottom = 0.62;
const rowStep = 0.30;
// Warp threads.
for (let col = 0; col < columns; col++) {
const px = (col - (columns - 1) / 2) * step;
box(g, [0.055, 2.1, 0.06], [px, 1.59, -0.075], warpMat);
}
// Exactly the same parity pattern on both looms:
// parity = (row + column) % 2.
for (let row = 0; row < rows; row++) {
for (let col = 0; col < columns; col++) {
const px = (col - (columns - 1) / 2) * step;
const py = bottom + row * rowStep;
const front = (row + col) % 2 === 0;
box(
g,
[step * 0.96, 0.115, 0.13],
[px, py, front ? 0.055 : -0.115],
weftMat
);
}
}
// Small draft marker: two alternating samples.
box(g, [0.48, 0.58, 0.12], [2.18, 1.1, 0.12], M.cream);
box(g, [0.39, 0.17, 0.13], [2.18, 1.27, 0.20], options.markerMat);
box(g, [0.39, 0.17, 0.13], [2.18, 1.04, 0.20], M.ink);
box(g, [0.16, 0.42, 0.17], [1.98, 0.2, 0], frameMat);
// Distinct moving shuttle.
const shuttle = new THREE.Group();
g.add(shuttle);
if (options.shuttleType === "flat") {
box(shuttle, [0.86, 0.10, 0.17], [0, 0, 0], M.cream);
box(shuttle, [0.18, 0.11, 0.18], [-0.47, 0, 0], M.reed);
box(shuttle, [0.18, 0.11, 0.18], [0.47, 0, 0], M.reed);
box(shuttle, [0.20, 0.035, 0.055], [0, 0.07, 0], M.ink);
} else {
box(shuttle, [0.50, 0.20, 0.25], [0, 0, 0], M.darkWood);
box(shuttle, [0.23, 0.12, 0.29], [0, 0.17, 0], M.stoneDark);
box(shuttle, [0.16, 0.035, 0.07], [0, 0.25, 0], M.cream);
}
const glow = box(
g,
[0.42, 0.42, 0.42],
[0, 3.52, 0],
options.markerMat,
{ castShadow: false }
);
loomAnimations.push({
group: g,
shuttle,
glow,
rows,
offset: options.offset,
markerMat: options.markerMat
});
return g;
}
const reedLoom = createLoom(-6.15, 0.55, {
frameMat: M.wood,
warpMat: M.reed,
weftMat: M.reedCord,
markerMat: M.reedLight,
shuttleType: "flat",
offset: 0
});
const cragLoom = createLoom(6.15, 0.55, {
frameMat: M.darkWood,
warpMat: M.cragWool,
weftMat: M.cragCord,
markerMat: M.cragLight,
shuttleType: "weighted",
offset: 0.5
});
// ---------- Displayed adapted tools ----------
function displayFlatShuttle(x, z) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [0.75, 0.42, 0.75], [0, 0.21, 0], M.woodLight);
box(g, [0.95, 0.12, 0.22], [0, 0.63, 0], M.cream);
box(g, [0.20, 0.13, 0.23], [-0.50, 0.63, 0], M.reed);
box(g, [0.20, 0.13, 0.23], [0.50, 0.63, 0], M.reed);
}
function displayWeightedShuttle(x, z) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [0.75, 0.42, 0.75], [0, 0.21, 0], M.stoneDark);
box(g, [0.52, 0.21, 0.27], [0, 0.65, 0], M.darkWood);
box(g, [0.26, 0.15, 0.30], [0, 0.82, 0], M.stoneLight);
}
displayFlatShuttle(-3.55, 0.72);
displayWeightedShuttle(3.55, 0.72);
// ---------- Adapted products ----------
// Reedfen sleeping mat.
const matGroup = new THREE.Group();
matGroup.position.set(-6.05, 0.02, 3.2);
scene.add(matGroup);
box(matGroup, [2.8, 0.075, 2.05], [0, 0.04, 0], M.reed);
for (let i = 0; i < 10; i++) {
box(matGroup, [2.72, 0.035, 0.10], [0, 0.10, -0.91 + i * 0.20], i % 2 ? M.cream : M.reedDark);
}
box(matGroup, [2.85, 0.06, 0.14], [0, 0.10, -1.00], M.reedDark);
box(matGroup, [2.85, 0.06, 0.14], [0, 0.10, 1.00], M.reedDark);
// Cragmoor pack panel, retaining the same 1/1 crossing order.
const panelGroup = new THREE.Group();
panelGroup.position.set(6.0, 0.77, 3.05);
panelGroup.rotation.x = -0.08;
scene.add(panelGroup);
box(panelGroup, [2.55, 1.85, 0.20], [0, 0, -0.12], M.stoneDark);
box(panelGroup, [2.34, 1.64, 0.10], [0, 0, 0], M.cragWool);
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 7; col++) {
const front = (row + col) % 2 === 0;
box(
panelGroup,
[0.32, 0.13, 0.10],
[-0.96 + col * 0.32, -0.58 + row * 0.29, front ? 0.10 : 0.04],
M.cragCord
);
}
}
for (let i = 0; i < 7; i++) {
box(panelGroup, [0.045, 1.60, 0.08], [-0.96 + i * 0.32, 0, -0.04], M.cragWool);
}
box(panelGroup, [2.65, 0.18, 0.26], [0, 0.94, 0.02], M.darkWood);
box(panelGroup, [2.65, 0.18, 0.26], [0, -0.94, 0.02], M.darkWood);
// Pack under the panel.
box(scene, [2.35, 1.30, 1.1], [6.05, 0.65, 3.38], M.darkWood);
box(scene, [0.22, 1.45, 1.18], [5.45, 0.73, 3.38], M.cragCord);
box(scene, [0.22, 1.45, 1.18], [6.65, 0.73, 3.38], M.cragCord);
// ---------- Exchange bridge ----------
const bridge = new THREE.Group();
scene.add(bridge);
for (let i = 0; i < 8; i++) {
box(bridge, [0.37, 0.18, 1.72], [-1.30 + i * 0.37, 0.02, 0], M.woodLight);
}
box(bridge, [3.18, 0.15, 0.18], [0, 0.37, -0.83], M.wood);
box(bridge, [3.18, 0.15, 0.18], [0, 0.37, 0.83], M.wood);
for (const x of [-1.40, 1.40]) {
box(bridge, [0.18, 1.0, 0.18], [x, 0.45, -0.83], M.wood);
box(bridge, [0.18, 1.0, 0.18], [x, 0.45, 0.83], M.wood);
}
// Shared crossing plaques on either bank.
function patternPlaque(x, z, flip = false) {
const g = new THREE.Group();
g.position.set(x, 0, z);
scene.add(g);
box(g, [0.78, 0.18, 0.78], [0, 0.09, 0], M.stoneDark);
box(g, [0.13, 1.1, 0.13], [0, 0.62, 0], M.wood);
box(g, [0.74, 0.54, 0.13], [0, 1.15, 0], M.cream);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
const parity = flip ? (row + col + 1) % 2 : (row + col) % 2;
box(
g,
[0.20, 0.20, 0.055],
[-0.23 + col * 0.23, 1.04 + row * 0.22, 0.10],
parity ? M.ink : M.reedLight
);
}
}
}
patternPlaque(-1.95, 0, false);
patternPlaque(1.95, 0, true);
// Moving exchange sample: gold at Reedfen, mountain blue at Cragmoor.
const exchangePacket = new THREE.Group();
scene.add(exchangePacket);
const packetGold = material(0xd7a052, {
emissive: 0x5d3512,
emissiveIntensity: 0.32
});
const packetBlue = material(0x78979b, {
emissive: 0x24454a,
emissiveIntensity: 0.3
});
box(exchangePacket, [0.34, 0.14, 0.30], [-0.16, 0, 0], packetGold);
box(exchangePacket, [0.34, 0.14, 0.30], [0.16, 0, 0], packetBlue);
box(exchangePacket, [0.30, 0.30, 0.12], [0, 0.08, 0], M.cream);
const packetTrail = [];
for (let i = 0; i < 6; i++) {
const cube = box(
scene,
[0.10, 0.10, 0.10],
[0, 0.9, 0],
i % 2 ? packetGold : packetBlue,
{ castShadow: false }
);
cube.visible = false;
packetTrail.push(cube);
}
// Route markers on the bridge.
for (let i = 0; i < 7; i++) {
box(
scene,
[0.10, 0.035, 0.10],
[-1.2 + i * 0.4, 0.14, 0],
i < 3 ? M.reedLight : M.cragLight,
{ castShadow: false }
);
}
// ---------- Small voxel clouds ----------
function cloud(x, y, z, s) {
const g = new THREE.Group();
g.position.set(x, y, z);
scene.add(g);
box(g, [1.4 * s, 0.35 * s, 0.55 * s], [0, 0, 0], M.white, { castShadow: false });
box(g, [0.65 * s, 0.55 * s, 0.55 * s], [-0.45 * s, 0.16 * s, 0], M.white, { castShadow: false });
box(g, [0.75 * s, 0.65 * s, 0.55 * s], [0.35 * s, 0.20 * s, 0], M.white, { castShadow: false });
}
cloud(-10, 8.2, -8, 1.25);
cloud(8, 9.0, -10, 1.0);
cloud(-1, 10.0, 5, 0.8);
// ---------- Interactive information ----------
const info = {
exchange: {
eyebrow: "Exchange bridge",
title: "The rule travels; the materials stay local.",
body:
"A sample of the crossing sequence travels to Cragmoor. Its geometry is unchanged, but reed fibers are replaced by tougher mountain cord.",
rule: "Shared rule: plain weave, 1/1"
},
"reed-loom": {
eyebrow: "Reedfen · working loom",
title: "A wide loom for ribbon-like marsh reed.",
body:
"Reedfen stretches many warp strands close together. The broad weft crosses one over and one under, just as it does in Cragmoor.",
rule: "Unchanged: over 1, under 1, repeat"
},
"crag-loom": {
eyebrow: "Cragmoor · working loom",
title: "A compact loom for round mountain cord.",
body:
"Cragmoor spaces the warp for thicker, round fibers. The same alternating crossing order produces a denser and more durable fabric.",
rule: "Unchanged: over 1, under 1, repeat"
},
"reed-tool": {
eyebrow: "Reedfen · adapted tool",
title: "The long slip shuttle keeps flat reeds aligned.",
body:
"Its shallow, elongated body carries a strip of marsh reed without twisting. It is wide enough for the community's ribbon-like fibers.",
rule: "Tool changes; crossing rule does not"
},
"crag-tool": {
eyebrow: "Cragmoor · adapted tool",
title: "A stone weight stops round cord from rolling.",
body:
"The shorter shuttle grips mountain grass cord more securely. A small stone weight adds momentum through the thick crossings.",
rule: "Tool changes; crossing rule does not"
},
"reed-product": {
eyebrow: "Reedfen · adapted product",
title: "A light sleeping mat made from river-side stock.",
body:
"Marsh reed gives the mat a crisp grid and soft sheep fleece adds warmth at the edges. Its plain weave remains easy to repair.",
rule: "Same 1/1 draft, softer material"
},
"crag-product": {
eyebrow: "Cragmoor · adapted product",
title: "A reinforced panel for mountain packs.",
body:
"Tough mountain cord and goat hair withstand abrasion. The edge is doubled, but the field still preserves the shared one-over, one-under structure.",
rule: "Same 1/1 draft, tougher material"
}
};
const detailEyebrow = document.querySelector("#detailEyebrow");
const detailTitle = document.querySelector("#detailTitle");
const detailBody = document.querySelector("#detailBody");
const detailRule = document.querySelector("#detailRule");
function showInfo(id) {
const item = info[id] || info.exchange;
detailEyebrow.textContent = item.eyebrow;
detailTitle.textContent = item.title;
detailBody.textContent = item.body;
detailRule.textContent = item.rule;
document.querySelectorAll(".scene-label").forEach((label) => {
label.classList.toggle("active", label.dataset.info === id);
});
}
// Invisible, generous hit targets.
addHitbox([3.9, 3.4, 1.3], [-6.15, 1.55, 0.45], "reed-loom");
addHitbox([3.9, 3.4, 1.3], [6.15, 1.55, 0.45], "crag-loom");
addHitbox([1.5, 1.6, 1.2], [-3.55, 0.8, 0.72], "reed-tool");
addHitbox([1.5, 1.6, 1.2], [3.55, 0.8, 0.72], "crag-tool");
addHitbox([3.2, 0.9, 2.5], [-6.05, 0.45, 3.2], "reed-product");
addHitbox([3.0, 2.4, 1.7], [6.0, 1.2, 3.2], "crag-product");
addHitbox([3.6, 1.8, 2.0], [0, 0.75, 0], "exchange");
// ---------- DOM labels ----------
const labels = [];
function addLabel({ name, sub = "", position, infoId = "", place = "", reed = false }) {
const el = document.createElement("button");
el.type = "button";
el.className = `scene-label${place ? " place" : ""}${reed ? " reed" : ""}`;
el.dataset.info = infoId;
el.innerHTML = `<span class="label-name">${name}</span>${
sub ? `<span class="label-sub">${sub}</span>` : ""
}`;
el.addEventListener("click", () => showInfo(infoId));
labelLayer.appendChild(el);
labels.push({ el, position: new THREE.Vector3(...position) });
}
addLabel({
name: "REEDFEN",
sub: "river reed · flat shuttle · sleeping mat",
position: [-6.3, 4.25, -1.65],
infoId: "reed-loom",
place: true,
reed: true
});
addLabel({
name: "CRAGMOOR",
sub: "mountain cord · weighted shuttle · pack panel",
position: [6.3, 4.25, -1.65],
infoId: "crag-loom",
place: true
});
addLabel({
name: "Flat slip shuttle",
sub: "Reedfen adaptation",
position: [-3.55, 1.35, 0.72],
infoId: "reed-tool"
});
addLabel({
name: "Weighted shuttle",
sub: "Cragmoor adaptation",
position: [3.55, 1.35, 0.72],
infoId: "crag-tool"
});
addLabel({
name: "Woven mat",
sub: "soft local result",
position: [-6.0, 0.75, 3.2],
infoId: "reed-product"
});
addLabel({
name: "Pack panel",
sub: "tough local result",
position: [6.0, 2.15, 3.2],
infoId: "crag-product"
});
addLabel({
name: "Shared crossing",
sub: "watch the technique travel",
position: [0, 1.25, 0],
infoId: "exchange"
});
function updateLabels() {
const w = viewport.clientWidth;
const h = viewport.clientHeight;
labels.forEach(({ el, position }) => {
const projected = position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.05 &&
projected.y < 1.05;
el.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * w;
const y = (-projected.y * 0.5 + 0.5) * h;
el.style.left = `${x}px`;
el.style.top = `${y}px`;
});
}
// ---------- Camera controls, implemented without addons ----------
const desired = {
yaw: 0.14,
pitch: 0.61,
radius: 25,
target: new THREE.Vector3(0, 1.1, 0)
};
const current = {
yaw: desired.yaw,
pitch: desired.pitch,
radius: desired.radius,
target: desired.target.clone()
};
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-dt * 8);
current.yaw = THREE.MathUtils.lerp(current.yaw, desired.yaw, smoothing);
current.pitch = THREE.MathUtils.lerp(current.pitch, desired.pitch, smoothing);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, smoothing);
current.target.lerp(desired.target, smoothing);
const horizontal = Math.cos(current.pitch) * current.radius;
camera.position.set(
current.target.x + Math.sin(current.yaw) * horizontal,
current.target.y + Math.sin(current.pitch) * current.radius,
current.target.z + Math.cos(current.yaw) * horizontal
);
camera.lookAt(current.target);
}
function resetCamera() {
desired.yaw = 0.14;
desired.pitch = 0.61;
desired.radius = window.innerWidth <= 900 ? 27 : 25;
desired.target.set(0, 1.1, 0);
}
const pointers = new Map();
let moved = false;
let pinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
moved = false;
if (pointers.size === 2) pinchDistance = pointerDistance();
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) {
updatePointer(event);
updateHover(event);
return;
}
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (Math.abs(dx) + Math.abs(dy) > 1) moved = true;
if (pointers.size === 1) {
if (event.shiftKey || event.buttons === 2) {
const panScale = desired.radius * 0.0015;
const right = new THREE.Vector3(Math.cos(desired.yaw), 0, -Math.sin(desired.yaw));
const forward = new THREE.Vector3(Math.sin(desired.yaw), 0, Math.cos(desired.yaw));
desired.target.addScaledVector(right, -dx * panScale);
desired.target.addScaledVector(forward, -dy * panScale);
} else {
desired.yaw -= dx * 0.006;
desired.pitch = THREE.MathUtils.clamp(
desired.pitch + dy * 0.005,
0.30,
1.16
);
}
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (pinchDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius + (pinchDistance - distance) * 0.035,
16,
37
);
}
pinchDistance = distance;
moved = true;
}
});
function removePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) pinchDistance = 0;
}
canvas.addEventListener("pointerup", (event) => {
if (!moved && event.button === 0) {
selectAt(event);
}
removePointer(event);
});
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener("pointerleave", () => {
if (!pointers.size) canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.012,
16,
37
);
},
{ passive: false }
);
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickAt(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
showInfo(hits[0].object.userData.infoId);
}
}
function updateHover(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
canvas.style.cursor = hits.length ? "pointer" : "grab";
}
document.querySelector("#reset").addEventListener("click", resetCamera);
// ---------- Exchange animation ----------
let exchangeEpoch = 0;
let exchangeActive = true;
function replayExchange() {
exchangeEpoch = clock.elapsedTime;
exchangeActive = true;
showInfo("exchange");
}
document.querySelector("#replay").addEventListener("click", replayExchange);
function updateExchange(t) {
const cycle = 9;
const phase = ((t - exchangeEpoch) % cycle) / cycle;
const travel = THREE.MathUtils.clamp(phase / 0.82, 0, 1);
const visible = phase < 0.84;
exchangePacket.visible = visible;
if (visible) {
const x = THREE.MathUtils.lerp(-1.62, 1.62, travel);
exchangePacket.position.set(x, 0.68, 0);
exchangePacket.rotation.y = t * 0.8;
const adaptation = THREE.MathUtils.smoothstep(travel, 0.30, 0.75);
packetGold.color.lerpColors(
new THREE.Color(0xd7a052),
new THREE.Color(0x78979b),
adaptation
);
packetTrail.forEach((cube, i) => {
const trailPhase = travel - (i + 1) * 0.022;
cube.visible = trailPhase > 0;
if (trailPhase > 0) {
cube.position.set(
THREE.MathUtils.lerp(-1.62, 1.62, trailPhase),
0.68,
0
);
cube.scale.setScalar(1 - i * 0.1);
}
});
} else {
packetTrail.forEach((cube) => (cube.visible = false));
}
const arrival = Math.max(0, 1 - Math.abs(phase - 0.82) * 16);
cragLoom.children.forEach((child) => {
if (child.material === M.cragLight) {
child.scale.setScalar(1 + arrival * 0.12);
}
});
}
// ---------- Animation ----------
function updateLoom(t, loom, duration, rowOffset = 0) {
const total = loom.rows * duration;
const cycle = (t + rowOffset) % total;
const row = Math.floor(cycle / duration);
const progress = (cycle % duration) / duration;
const eased = progress * progress * (3 - 2 * progress);
loom.shuttle.position.set(
THREE.MathUtils.lerp(-1.48, 1.48, eased),
0.62 + row * 0.30,
0.39
);
const pulse = 0.97 + Math.sin(progress * Math.PI) * 0.08;
loom.shuttle.scale.set(pulse, 1, 1);
loom.glow.position.y = 3.48 + Math.sin(progress * Math.PI * 2) * 0.025;
}
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const t = clock.elapsedTime;
updateCamera(dt);
updateLoom(t, loomAnimations[0], 4.2, 0);
updateLoom(t, loomAnimations[1], 4.2, 2.1);
updateExchange(t);
waterGlints.forEach((glint, i) => {
glint.position.x += Math.sin(t * 0.8 + i) * 0.0015;
glint.material.emissiveIntensity = 0;
});
exchangePacket.position.y = 0.68 + Math.sin(t * 4) * 0.035;
updateLabels();
renderer.render(scene, camera);
}
showInfo("exchange");
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```