Prompt specification
Build or customize the Three.js 3D scene "Salt March walkers on a roadside segment" 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: Salt March walkers on a roadside segment
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/salt-march-walkers-on-a-roadside-segment-x2462
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this cutaway scene: Create a respectful referenced vignette of the 1930 Salt March with walkers, road, and village observers. Avoid inventing a specific speech or exact crowd arrangement.
Working Three.js Starter (salt-march-walkers-on-a-roadside-segment-x2462):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Salt March, 1930 — Interpretive Vignette</title>
<style>
:root {
--ink: #332f28;
--muted: #665f53;
--paper: #f1ead9;
--line: rgba(72, 62, 47, 0.28);
--accent: #8a5c34;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
background:
radial-gradient(circle at 74% 20%, rgba(255, 247, 218, 0.9), transparent 28%),
linear-gradient(180deg, #e7dfcc 0%, #d5c29d 54%, #bca47d 100%);
}
button,
a {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.interface {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
header {
position: absolute;
top: clamp(24px, 4vw, 58px);
left: clamp(22px, 5vw, 76px);
width: min(460px, calc(100vw - 44px));
text-shadow: 0 1px 16px rgba(247, 238, 216, 0.6);
}
.eyebrow {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 13px;
color: var(--accent);
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 38px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-size: clamp(44px, 6.2vw, 82px);
font-weight: 400;
line-height: 0.95;
letter-spacing: -0.045em;
}
.route {
margin: 19px 0 0;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.info-toggle {
position: absolute;
top: clamp(22px, 4vw, 48px);
right: clamp(22px, 4vw, 58px);
z-index: 5;
padding: 11px 15px;
border: 1px solid var(--line);
border-radius: 2px;
color: var(--ink);
background: rgba(246, 239, 221, 0.78);
box-shadow: 0 8px 30px rgba(63, 50, 33, 0.08);
backdrop-filter: blur(9px);
cursor: pointer;
pointer-events: auto;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.info-toggle:hover,
.info-toggle:focus-visible {
background: rgba(250, 245, 232, 0.96);
outline: 2px solid rgba(138, 92, 52, 0.35);
outline-offset: 3px;
}
#info-panel {
position: absolute;
top: 92px;
right: clamp(22px, 4vw, 58px);
z-index: 4;
width: min(350px, calc(100vw - 44px));
max-height: calc(100vh - 176px);
padding: 25px 27px 23px;
overflow: auto;
border: 1px solid rgba(85, 70, 49, 0.22);
border-radius: 2px;
opacity: 0;
visibility: hidden;
transform: translateX(12px);
transition:
opacity 220ms ease,
transform 220ms ease,
visibility 220ms;
background: rgba(244, 237, 219, 0.91);
box-shadow: 0 16px 55px rgba(63, 50, 33, 0.13);
backdrop-filter: blur(13px);
pointer-events: auto;
}
#info-panel.open {
opacity: 1;
visibility: visible;
transform: translateX(0);
}
.panel-label {
margin: 0 0 11px;
color: var(--accent);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#info-panel h2 {
margin: 0 0 13px;
font-size: 28px;
font-weight: 400;
line-height: 1.1;
}
#info-panel p {
margin: 0 0 13px;
color: #4f493f;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
line-height: 1.62;
}
.scene-note {
margin-top: 18px !important;
padding-top: 15px;
border-top: 1px solid var(--line);
color: #5b5144 !important;
font-style: italic;
}
.references {
margin: 18px 0 0;
padding: 16px 0 0;
border-top: 1px solid var(--line);
list-style: none;
}
.references li {
margin: 9px 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 1.4;
}
.references a {
color: #69462d;
text-underline-offset: 3px;
}
.references a:hover,
.references a:focus-visible {
color: #352719;
}
.caption {
position: absolute;
bottom: clamp(24px, 4vw, 52px);
left: clamp(22px, 5vw, 76px);
display: flex;
align-items: flex-start;
gap: 15px;
width: min(545px, calc(100vw - 44px));
color: #4c463c;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
line-height: 1.55;
letter-spacing: 0.015em;
}
.caption::before {
flex: 0 0 38px;
height: 1px;
margin-top: 8px;
content: "";
background: rgba(70, 57, 40, 0.55);
}
.caption strong {
color: #3f382e;
}
.controls-hint {
position: absolute;
right: clamp(22px, 4vw, 58px);
bottom: clamp(24px, 4vw, 48px);
padding: 8px 11px;
border: 1px solid rgba(73, 59, 42, 0.18);
color: rgba(57, 50, 40, 0.75);
background: rgba(240, 231, 211, 0.58);
backdrop-filter: blur(6px);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: #655a49;
background: #ded1b8;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 700ms ease, visibility 700ms;
}
#loading.loaded {
opacity: 0;
visibility: hidden;
}
@media (max-width: 760px) {
header {
top: 27px;
}
h1 {
font-size: 49px;
}
.route {
max-width: 260px;
font-size: 10px;
line-height: 1.6;
}
.info-toggle {
top: auto;
right: 18px;
bottom: 73px;
}
#info-panel {
top: 132px;
right: 18px;
width: calc(100vw - 36px);
max-height: calc(100vh - 230px);
}
.caption {
bottom: 22px;
font-size: 10px;
}
.controls-hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
#info-panel,
#loading {
transition: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="An interpretive three-dimensional scene of walkers and village observers during the 1930 Salt March"></main>
<div class="interface">
<header>
<div class="eyebrow">1930 · Civil Disobedience</div>
<h1>The Salt March</h1>
<p class="route">Sabarmati Ashram → Dandi</p>
</header>
<button
class="info-toggle"
id="info-toggle"
type="button"
aria-controls="info-panel"
aria-expanded="false"
>
Context & references
</button>
<aside id="info-panel" aria-label="Historical context and references">
<p class="panel-label">Historical context</p>
<h2>A protest carried on foot</h2>
<p>
Between 12 March and 5 April 1930, Mahatma Gandhi and a small group
walked approximately 240 miles (about 385 kilometres) from Sabarmati
Ashram to Dandi. Their journey challenged the British colonial salt
monopoly and became a defining act of civil disobedience.
</p>
<p>
Salt was taxed and tightly controlled under colonial rule. The march
connected the salt law with wider demands for self-rule and civil
liberty.
</p>
<p class="scene-note">
This is a composite, interpretive vignette. The number, spacing,
clothing, gestures, and placement of figures are illustrative and do
not reconstruct a particular documented moment, crowd arrangement, or
speech.
</p>
<ul class="references" aria-label="References">
<li>
<a href="https://www.britannica.com/event/Salt-March"
target="_blank" rel="noopener noreferrer">
Encyclopædia Britannica — Salt March
</a>
</li>
<li>
<a href="https://www.gandhiheritageportal.org/"
target="_blank" rel="noopener noreferrer">
Gandhi Heritage Portal
</a>
</li>
<li>
<a href="https://ngm.gov.in/"
target="_blank" rel="noopener noreferrer">
National Gandhi Museum
</a>
</li>
</ul>
</aside>
<div class="caption">
<p>
<strong>Interpretive vignette, not a literal reconstruction.</strong>
Figures and village activity are generalized to honor the march
without inventing a specific scene or attributed quotation.
</p>
</div>
<div class="controls-hint">Drag to orbit · scroll to zoom · arrow keys to look</div>
</div>
<div id="loading">Preparing the landscape</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const infoPanel = document.getElementById("info-panel");
const infoToggle = document.getElementById("info-toggle");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive interpretive view of the Salt March. Use pointer drag or arrow keys to orbit and the mouse wheel to zoom."
);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd7c6a6, 25, 76);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
180
);
const orbitTarget = new THREE.Vector3(-0.4, 1.0, -4.0);
const desiredOrbit = new THREE.Spherical(20.5, 1.16, 0.70);
const currentOrbit = desiredOrbit.clone();
const cameraOffset = new THREE.Vector3();
camera.position.setFromSpherical(currentOrbit).add(orbitTarget);
camera.lookAt(orbitTarget);
const hemi = new THREE.HemisphereLight(0xfff4d8, 0x76634a, 2.05);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe6b2, 3.15);
sun.position.set(-15, 22, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -26;
sun.shadow.camera.right = 26;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.00045;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9eb7b4, 0.55);
fill.position.set(18, 7, -19);
scene.add(fill);
let seed = 1930;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function standard(color, roughness = 0.88, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness,
...extra
});
}
const materials = {
earth: standard(0xa78f67),
earthLight: standard(0xb8a079),
road: standard(0xb29870),
roadWorn: standard(0xc5aa7d),
roadEdge: standard(0x8d7555),
mud: standard(0xb38e60),
mudDark: standard(0x967247),
roof: standard(0x806443),
wood: standard(0x60462f),
darkWood: standard(0x3e3227),
foliage: standard(0x667052),
foliageLight: standard(0x798063),
skin: standard(0x805c3d),
skinDark: standard(0x65472f),
cream: standard(0xeee3ca),
offWhite: standard(0xd8cbb2),
sandal: standard(0x4c392a),
glass: standard(0x292a26, 0.55),
sea: standard(0x819895, 0.7, { metalness: 0.04 })
};
function mesh(geometry, material, castShadow = true, receiveShadow = true) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = castShadow;
object.receiveShadow = receiveShadow;
return object;
}
// Quiet, gently undulating terrain.
const groundGeometry = new THREE.PlaneGeometry(140, 140, 70, 70);
groundGeometry.rotateX(-Math.PI / 2);
const groundPositions = groundGeometry.attributes.position;
for (let i = 0; i < groundPositions.count; i++) {
const x = groundPositions.getX(i);
const z = groundPositions.getZ(i);
const edgeDistance = Math.max(0, Math.abs(x) - 7);
const height =
(Math.sin(x * 0.16) * Math.cos(z * 0.11) +
Math.sin(z * 0.07 + x * 0.05) * 0.35) *
0.34 *
Math.min(1, edgeDistance / 7);
groundPositions.setY(i, height - 0.06);
}
groundGeometry.computeVertexNormals();
const ground = mesh(groundGeometry, materials.earth, false, true);
scene.add(ground);
// A subdued coastal horizon provides geographic context without depicting
// a literal reconstruction of the Dandi shoreline.
const sea = mesh(
new THREE.PlaneGeometry(150, 72),
materials.sea,
false,
false
);
sea.rotation.x = -Math.PI / 2;
sea.position.set(0, 0.015, -70);
scene.add(sea);
const roadCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-10.5, 0.075, 15),
new THREE.Vector3(-8.0, 0.075, 9),
new THREE.Vector3(-4.3, 0.075, 3),
new THREE.Vector3(-0.4, 0.075, -4),
new THREE.Vector3(1.4, 0.075, -11),
new THREE.Vector3(0.2, 0.075, -18),
new THREE.Vector3(4.0, 0.075, -25),
new THREE.Vector3(2.0, 0.075, -34)
]);
function roadFrame(t) {
const point = roadCurve.getPointAt(t);
const tangent = roadCurve.getTangentAt(t).normalize();
const side = new THREE.Vector3(tangent.z, 0, -tangent.x).normalize();
return { point, tangent, side };
}
function makeRibbon(curve, width, sideOffset = 0, material = materials.road, segments = 100) {
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const point = curve.getPointAt(t);
const tangent = curve.getTangentAt(t).normalize();
const side = new THREE.Vector3(tangent.z, 0, -tangent.x).normalize();
const widthHere = width * THREE.MathUtils.lerp(1.06, 0.78, t);
const left = point.clone().addScaledVector(side, sideOffset - widthHere / 2);
const right = point.clone().addScaledVector(side, sideOffset + widthHere / 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();
const ribbon = mesh(geometry, material, false, true);
ribbon.renderOrder = 1;
return ribbon;
}
scene.add(makeRibbon(roadCurve, 3.25));
scene.add(makeRibbon(roadCurve, 1.35, 0, materials.roadWorn));
scene.add(makeRibbon(roadCurve, 0.13, -1.59, materials.roadEdge));
scene.add(makeRibbon(roadCurve, 0.13, 1.59, materials.roadEdge));
const yAxis = new THREE.Vector3(0, 1, 0);
function cylinderBetween(a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const object = mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(yAxis, direction.normalize());
return object;
}
function makePerson({
cloth = materials.offWhite,
skin = materials.skin,
scale = 1,
shawl = false,
headCloth = false,
walking = false
} = {}) {
const root = new THREE.Group();
const torso = mesh(
new THREE.CylinderGeometry(0.23, 0.36, 0.98, 10),
cloth
);
torso.position.y = 1.19;
root.add(torso);
const lower = mesh(
new THREE.CylinderGeometry(0.31, 0.37, 0.42, 10),
cloth
);
lower.position.y = 0.78;
root.add(lower);
const neck = mesh(
new THREE.CylinderGeometry(0.09, 0.1, 0.18, 8),
skin
);
neck.position.y = 1.72;
root.add(neck);
const head = mesh(new THREE.SphereGeometry(0.205, 12, 9), skin);
head.position.y = 1.93;
head.scale.set(0.94, 1.08, 0.93);
root.add(head);
const leftFoot = mesh(new THREE.BoxGeometry(0.18, 0.09, 0.32), materials.sandal);
leftFoot.position.set(-0.13, 0.09, 0.055);
root.add(leftFoot);
const rightFoot = leftFoot.clone();
rightFoot.position.x = 0.13;
root.add(rightFoot);
const legs = [];
for (const side of [-1, 1]) {
const leg = cylinderBetween(
new THREE.Vector3(side * 0.12, 0.16, 0),
new THREE.Vector3(side * 0.13, 0.83, 0),
0.105,
skin
);
root.add(leg);
legs.push(leg);
}
const arms = [];
for (const side of [-1, 1]) {
const handZ = walking ? (side === 1 ? 0.18 : -0.16) : 0.015;
const arm = cylinderBetween(
new THREE.Vector3(side * 0.27, 1.56, 0),
new THREE.Vector3(side * 0.35, 1.12, handZ),
0.075,
cloth
);
root.add(arm);
arms.push(arm);
const hand = mesh(new THREE.SphereGeometry(0.085, 8, 6), skin);
hand.position.set(side * 0.35, 1.11, handZ);
root.add(hand);
}
if (shawl) {
const wrap = mesh(
new THREE.SphereGeometry(0.42, 12, 8),
materials.cream
);
wrap.position.set(0, 1.38, -0.03);
wrap.scale.set(1.02, 1.25, 0.52);
root.add(wrap);
}
if (headCloth) {
const covering = mesh(
new THREE.SphereGeometry(0.22, 12, 8, 0, Math.PI * 2, 0, Math.PI * 0.62),
cloth
);
covering.position.y = 1.97;
covering.scale.z = 0.96;
root.add(covering);
}
root.scale.setScalar(scale);
scene.add(root);
return { root, arms, legs };
}
function makeGandhi() {
const root = new THREE.Group();
const robe = mesh(
new THREE.CylinderGeometry(0.245, 0.46, 1.48, 14),
materials.cream
);
robe.position.y = 0.9;
root.add(robe);
const head = mesh(new THREE.SphereGeometry(0.215, 16, 12), materials.skin);
head.position.y = 1.84;
head.scale.set(0.93, 1.08, 0.91);
root.add(head);
const neck = mesh(
new THREE.CylinderGeometry(0.085, 0.1, 0.18, 8),
materials.skin
);
neck.position.y = 1.64;
root.add(neck);
const shawl = mesh(
new THREE.SphereGeometry(0.43, 16, 10),
materials.cream
);
shawl.position.set(0, 1.37, -0.035);
shawl.scale.set(1.03, 1.26, 0.48);
root.add(shawl);
const drape = mesh(
new THREE.PlaneGeometry(0.72, 0.85),
materials.cream
);
drape.position.set(-0.045, 1.02, -0.255);
drape.rotation.x = -0.06;
root.add(drape);
for (const side of [-1, 1]) {
const sandal = mesh(
new THREE.BoxGeometry(0.17, 0.075, 0.31),
materials.sandal
);
sandal.position.set(side * 0.13, 0.09, 0.05);
root.add(sandal);
}
const arm = cylinderBetween(
new THREE.Vector3(0.27, 1.55, 0),
new THREE.Vector3(0.39, 1.11, 0.12),
0.072,
materials.cream
);
root.add(arm);
const hand = mesh(new THREE.SphereGeometry(0.08, 8, 6), materials.skin);
hand.position.set(0.39, 1.11, 0.12);
root.add(hand);
const staff = mesh(
new THREE.CylinderGeometry(0.026, 0.032, 1.82, 8),
materials.wood
);
staff.position.set(0.47, 0.94, 0.02);
staff.rotation.z = -0.045;
root.add(staff);
// Simple round spectacles: a respectful, restrained visual identifier.
for (const side of [-1, 1]) {
const lens = mesh(
new THREE.TorusGeometry(0.058, 0.008, 5, 16),
materials.glass,
false,
false
);
lens.position.set(side * 0.075, 1.875, 0.192);
root.add(lens);
}
const bridge = cylinderBetween(
new THREE.Vector3(-0.018, 1.875, 0.196),
new THREE.Vector3(0.018, 1.875, 0.196),
0.006,
materials.glass,
5
);
root.add(bridge);
scene.add(root);
return { root };
}
const walkers = [];
function placeWalker(t, offset, person, phase) {
const { point, tangent } = roadFrame(t);
const position = point.clone().addScaledVector(roadFrame(t).side, offset);
position.y = 0.075;
person.root.position.copy(position);
person.root.rotation.y = Math.atan2(tangent.x, tangent.z);
scene.add(person.root);
walkers.push({
...person,
baseY: position.y,
phase
});
}
const gandhi = makeGandhi();
placeWalker(0.455, -0.05, gandhi, 0);
const companionCloths = [
standard(0xd8cdb7),
standard(0x8f7658),
standard(0xa9aa98),
standard(0xd4c3a1),
standard(0x6f7770)
];
const companionData = [
{ t: 0.375, offset: -0.66 },
{ t: 0.515, offset: 0.62 },
{ t: 0.565, offset: -0.52 },
{ t: 0.615, offset: 0.34 },
{ t: 0.655, offset: -0.28 }
];
companionData.forEach((data, index) => {
const person = makePerson({
cloth: companionCloths[index % companionCloths.length],
skin: index % 2 === 0 ? materials.skin : materials.skinDark,
scale: 0.95 + random() * 0.09,
shawl: index === 1 || index === 3,
headCloth: index === 4,
walking: true
});
placeWalker(data.t, data.offset, person, index * 1.37);
});
const observerCloths = [
standard(0xa66e4e),
standard(0x71817d),
standard(0xc6b896),
standard(0x6e6660),
standard(0xb29162),
standard(0x7b8471),
standard(0xd4c5aa)
];
const observerData = [
{ t: 0.285, offset: 2.75 },
{ t: 0.335, offset: -2.85 },
{ t: 0.395, offset: 2.62 },
{ t: 0.435, offset: -2.72 },
{ t: 0.505, offset: 2.85 },
{ t: 0.555, offset: -2.7 },
{ t: 0.605, offset: 2.65 },
{ t: 0.65, offset: -2.55 }
];
observerData.forEach((data, index) => {
const frame = roadFrame(data.t);
const position = frame.point.clone().addScaledVector(frame.side, data.offset);
const direction = frame.point.clone().sub(position).normalize();
const observer = makePerson({
cloth: observerCloths[index % observerCloths.length],
skin: index % 3 === 0 ? materials.skinDark : materials.skin,
scale: 0.91 + random() * 0.1,
shawl: index % 3 === 0,
headCloth: index % 4 === 1
});
observer.root.position.set(position.x, 0.075, position.z);
observer.root.rotation.y = Math.atan2(direction.x, direction.z);
});
function buildHut(x, z, scale = 1, rotation = -1.0) {
const root = new THREE.Group();
root.position.set(x, 0, z);
root.rotation.y = rotation;
root.scale.setScalar(scale);
const wall = mesh(
new THREE.BoxGeometry(2.65, 1.75, 2.25),
materials.mud
);
wall.position.y = 0.875;
root.add(wall);
const roof = mesh(
new THREE.ConeGeometry(1.95, 1.28, 4),
materials.roof
);
roof.position.y = 2.23;
roof.rotation.y = Math.PI / 4;
roof.scale.z = 0.83;
root.add(roof);
const door = mesh(
new THREE.BoxGeometry(0.68, 1.18, 0.055),
materials.darkWood
);
door.position.set(-0.25, 0.6, 1.145);
root.add(door);
const window = mesh(
new THREE.BoxGeometry(0.43, 0.35, 0.06),
materials.darkWood
);
window.position.set(0.65, 1.13, 1.15);
root.add(window);
const threshold = mesh(
new THREE.BoxGeometry(1.25, 0.12, 0.72),
materials.mudDark
);
threshold.position.set(-0.2, 0.06, 1.43);
root.add(threshold);
scene.add(root);
}
buildHut(8.2, -2.5, 1.0, -1.05);
buildHut(11.0, -6.2, 0.88, -0.8);
buildHut(8.0, -9.3, 0.96, -1.15);
buildHut(12.2, -13.0, 0.78, -0.72);
buildHut(6.8, -14.0, 0.67, -1.05);
const well = mesh(
new THREE.CylinderGeometry(0.66, 0.76, 0.54, 16),
materials.mudDark
);
well.position.set(6.0, 0.27, -5.1);
scene.add(well);
const wellOpening = mesh(
new THREE.CylinderGeometry(0.49, 0.49, 0.025, 16),
materials.darkWood,
false,
false
);
wellOpening.position.set(6.0, 0.555, -5.1);
scene.add(wellOpening);
function buildTree(x, z, scale = 1) {
const root = new THREE.Group();
root.position.set(x, 0, z);
root.scale.setScalar(scale);
const trunk = mesh(
new THREE.CylinderGeometry(0.16, 0.25, 2.6, 8),
materials.wood
);
trunk.position.y = 1.3;
root.add(trunk);
const canopy = mesh(
new THREE.IcosahedronGeometry(1.05, 1),
materials.foliage
);
canopy.position.y = 2.8;
canopy.scale.set(1.5, 0.58, 1.1);
root.add(canopy);
const crown = mesh(
new THREE.IcosahedronGeometry(0.74, 1),
materials.foliageLight
);
crown.position.set(0.38, 3.12, 0.1);
crown.scale.set(1.2, 0.62, 1.0);
root.add(crown);
scene.add(root);
}
[
[-8.0, -0.5, 0.9],
[4.9, -10.0, 0.8],
[10.0, 2.8, 1.05],
[-12.0, -11.0, 1.15],
[14.0, -17.0, 0.9],
[-17.0, 5.0, 1.0]
].forEach((args) => buildTree(...args));
// Low, hazy landforms beyond the coast.
for (let i = 0; i < 6; i++) {
const hill = mesh(
new THREE.IcosahedronGeometry(1, 2),
standard(i % 2 ? 0xa39a80 : 0xaaa087),
false,
false
);
hill.position.set(-34 + i * 14, -1.1, -43 - random() * 7);
hill.scale.set(10 + random() * 6, 2.1 + random() * 1.5, 5 + random() * 3);
hill.rotation.y = random() * Math.PI;
scene.add(hill);
}
// Instanced roadside grasses keep the scene light and painterly.
const grassGeometry = new THREE.ConeGeometry(0.045, 0.48, 3);
const grassMaterial = standard(0x747958);
const grassCount = 210;
const grass = new THREE.InstancedMesh(grassGeometry, grassMaterial, grassCount);
const dummy = new THREE.Object3D();
for (let i = 0; i < grassCount; i++) {
let x = random() * 64 - 32;
let z = random() * 55 - 32;
if (Math.abs(x) < 5.5 && z > -34 && z < 16) {
x += x < 0 ? -6 : 6;
}
const height = 0.55 + random() * 0.9;
dummy.position.set(x, height * 0.18, z);
dummy.rotation.set(0, random() * Math.PI, (random() - 0.5) * 0.18);
dummy.scale.set(0.7 + random() * 0.8, height, 0.7 + random() * 0.8);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
}
grass.receiveShadow = true;
scene.add(grass);
// Fine airborne dust catches the afternoon light.
const dustCount = 280;
const dustPositions = new Float32Array(dustCount * 3);
const dustBase = [];
for (let i = 0; i < dustCount; i++) {
const x = random() * 60 - 30;
const y = 0.25 + random() * 5.2;
const z = random() * 48 - 33;
dustPositions[i * 3] = x;
dustPositions[i * 3 + 1] = y;
dustPositions[i * 3 + 2] = z;
dustBase.push({ x, y, z, phase: random() * Math.PI * 2 });
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xf1dfb7,
size: 0.055,
transparent: true,
opacity: 0.3,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
// Direct camera controls, implemented without external examples or addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredOrbit.theta -= deltaX * 0.0055;
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi - deltaY * 0.0045,
0.66,
1.39
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * Math.exp(event.deltaY * 0.001),
10.5,
34
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") desiredOrbit.theta += step;
if (event.key === "ArrowRight") desiredOrbit.theta -= step;
if (event.key === "ArrowUp") {
desiredOrbit.phi = Math.max(0.66, desiredOrbit.phi - step);
}
if (event.key === "ArrowDown") {
desiredOrbit.phi = Math.min(1.39, desiredOrbit.phi + step);
}
if (event.key === "+" || event.key === "=") {
desiredOrbit.radius = Math.max(10.5, desiredOrbit.radius - 1.5);
}
if (event.key === "-" || event.key === "_") {
desiredOrbit.radius = Math.min(34, desiredOrbit.radius + 1.5);
}
});
function setPanel(open) {
infoPanel.classList.toggle("open", open);
infoToggle.setAttribute("aria-expanded", String(open));
infoToggle.textContent = open ? "Close context" : "Context & references";
}
infoToggle.addEventListener("click", () => {
setPanel(!infoPanel.classList.contains("open"));
});
if (window.innerWidth > 1120) {
setPanel(true);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const damping = 1 - Math.exp(-delta * 7);
currentOrbit.radius = THREE.MathUtils.lerp(
currentOrbit.radius,
desiredOrbit.radius,
damping
);
currentOrbit.phi = THREE.MathUtils.lerp(
currentOrbit.phi,
desiredOrbit.phi,
damping
);
currentOrbit.theta = THREE.MathUtils.lerp(
currentOrbit.theta,
desiredOrbit.theta,
damping
);
cameraOffset.setFromSpherical(currentOrbit);
camera.position.copy(cameraOffset).add(orbitTarget);
camera.lookAt(orbitTarget);
walkers.forEach((walker, index) => {
walker.root.position.y =
walker.baseY + Math.sin(elapsed * 1.55 + walker.phase) * 0.012;
// A restrained gait: only the lower legs move slightly.
if (walker.legs && walker.legs.length === 2) {
const swing = Math.sin(elapsed * 2.3 + walker.phase) * 0.035;
walker.legs[0].rotation.x = swing;
walker.legs[1].rotation.x = -swing;
}
});
const dustAttribute = dustGeometry.attributes.position;
for (let i = 0; i < dustCount; i++) {
const item = dustBase[i];
dustAttribute.setXYZ(
i,
item.x + Math.sin(elapsed * 0.16 + item.phase) * 1.1,
item.y + Math.sin(elapsed * 0.3 + item.phase) * 0.12,
item.z + Math.cos(elapsed * 0.12 + item.phase) * 0.45
);
}
dustAttribute.needsUpdate = true;
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => loading.classList.add("loaded"));
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```