Prompt specification
Build or customize the Three.js 3D scene "Hillside waypoint navigation board" 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: Hillside waypoint navigation board
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/hillside-waypoint-navigation-board-x1291
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a small hill with three visible landmarks and a movable traveler. Each waypoint displays a bearing from the traveler's current position, not from the camera.
Working Three.js Starter (hillside-waypoint-navigation-board-x1291):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Waymark — Low-Poly Expedition</title>
<style>
:root {
--ink: #17322d;
--muted: #587069;
--paper: rgba(248, 244, 226, 0.92);
--line: rgba(23, 50, 45, 0.14);
--accent: #ec7048;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #abc8c3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
max-width: 360px;
padding: 17px 19px 16px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(23, 50, 45, 0.14);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #c65332;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #e2633e;
box-shadow: 0 0 0 4px rgba(226, 99, 62, 0.14);
animation: pulse 2s infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 7px rgba(226, 99, 62, 0);
}
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 39px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
margin: 10px 0 0;
max-width: 310px;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.waypoint-panel {
position: absolute;
bottom: 24px;
left: 24px;
width: 310px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.54);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 15px 40px rgba(23, 50, 45, 0.16);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 15px 11px;
border-bottom: 1px solid var(--line);
}
.panel-head strong {
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.origin {
color: #d45b36;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#waypoint-list {
padding: 7px;
}
.waypoint-row {
display: grid;
grid-template-columns: 12px 1fr auto;
grid-template-rows: auto auto;
gap: 1px 9px;
width: 100%;
padding: 10px 9px;
border: 0;
border-radius: 11px;
background: transparent;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: background 150ms ease, transform 150ms ease;
}
.waypoint-row:hover,
.waypoint-row.selected {
background: rgba(23, 50, 45, 0.07);
}
.waypoint-row:active {
transform: scale(0.985);
}
.waypoint-color {
grid-row: 1 / 3;
align-self: center;
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.waypoint-name {
font-size: 12px;
font-weight: 750;
}
.waypoint-bearing {
grid-column: 3;
grid-row: 1 / 3;
align-self: center;
min-width: 69px;
color: var(--ink);
font-size: 15px;
font-variant-numeric: tabular-nums;
font-weight: 800;
text-align: right;
}
.waypoint-distance {
color: var(--muted);
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.panel-foot {
padding: 9px 14px 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.status {
display: flex;
align-items: center;
gap: 7px;
}
.status::before {
content: "";
width: 5px;
height: 5px;
flex: 0 0 auto;
border-radius: 50%;
background: #4b8f68;
}
.help {
position: absolute;
right: 24px;
bottom: 24px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.48);
border-radius: 13px;
background: rgba(248, 244, 226, 0.84);
box-shadow: 0 10px 30px rgba(23, 50, 45, 0.12);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
text-align: right;
backdrop-filter: blur(10px);
}
.help b {
color: var(--ink);
}
#markers {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.marker {
position: absolute;
display: flex;
align-items: center;
gap: 8px;
min-width: max-content;
padding: 7px 10px 7px 8px;
transform: translate(-50%, calc(-100% - 10px));
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 10px;
background: rgba(250, 247, 232, 0.92);
box-shadow: 0 7px 20px rgba(23, 50, 45, 0.17);
color: var(--ink);
font: inherit;
cursor: pointer;
pointer-events: auto;
transition: background 150ms ease, box-shadow 150ms ease;
backdrop-filter: blur(8px);
}
.marker::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 11px;
background: rgba(23, 50, 45, 0.48);
}
.marker:hover,
.marker.selected {
background: #fffaf0;
box-shadow: 0 9px 25px rgba(23, 50, 45, 0.22);
}
.marker-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.marker-name {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.02em;
}
.marker-bearing {
padding-left: 8px;
border-left: 1px solid var(--line);
color: var(--ink);
font-size: 11px;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.touch-pad {
position: absolute;
top: 112px;
right: 24px;
display: none;
grid-template-columns: repeat(3, 38px);
grid-template-rows: repeat(2, 38px);
gap: 5px;
pointer-events: auto;
}
.touch-pad button {
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 10px;
background: rgba(248, 244, 226, 0.88);
color: var(--ink);
font-size: 15px;
font-weight: 800;
touch-action: none;
box-shadow: 0 5px 15px rgba(23, 50, 45, 0.12);
}
.touch-pad button:active {
background: #fffaf0;
transform: scale(0.94);
}
.touch-up {
grid-column: 2;
}
.touch-left {
grid-column: 1;
grid-row: 2;
}
.touch-down {
grid-column: 2;
grid-row: 2;
}
.touch-right {
grid-column: 3;
grid-row: 2;
}
@media (pointer: coarse) {
.touch-pad {
display: grid;
}
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
padding: 12px 14px;
}
.subtitle {
display: none;
}
.waypoint-panel {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
}
.help {
display: none;
}
.touch-pad {
top: 95px;
right: 12px;
}
.marker {
padding: 5px 7px;
gap: 5px;
}
.marker-name {
font-size: 9px;
}
.marker-bearing {
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="app">
<div id="scene"></div>
<div id="markers"></div>
<div class="hud">
<section class="title-card">
<div class="eyebrow"><span class="live-dot"></span> Live expedition</div>
<h1>Waymark</h1>
<p class="subtitle">
Three landmarks, one small hill, and a traveler who never stops moving.
Every bearing is calculated from the traveler’s live position.
</p>
</section>
<section class="waypoint-panel" aria-label="Waypoint bearings">
<div class="panel-head">
<strong>Bearing to waypoint</strong>
<span class="origin">Origin: traveler</span>
</div>
<div id="waypoint-list"></div>
<div class="panel-foot">
<div class="status" id="status-text" aria-live="polite">
Wanderer is ready
</div>
</div>
</section>
<div class="help">
<b>WASD / arrows</b> move · <b>drag</b> orbit<br />
<b>right-drag</b> pan · <b>wheel</b> zoom · <b>tap</b> terrain
</div>
<div class="touch-pad" aria-label="Touch movement controls">
<button class="touch-up" data-code="KeyW" aria-label="Move north">↑</button>
<button class="touch-left" data-code="KeyA" aria-label="Move west">←</button>
<button class="touch-down" data-code="KeyS" aria-label="Move south">↓</button>
<button class="touch-right" data-code="KeyD" aria-label="Move east">→</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const markerHost = document.querySelector("#markers");
const listHost = document.querySelector("#waypoint-list");
const statusText = document.querySelector("#status-text");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xabc8c3);
scene.fog = new THREE.Fog(0xabc8c3, 52, 108);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
180
);
const renderer = new THREE.WebGLRenderer({
antialias: 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.05;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe8f4ee, 0x596446, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe2b0, 3.2);
sun.position.set(-14, 28, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -28;
sun.shadow.camera.right = 28;
sun.shadow.camera.top = 28;
sun.shadow.camera.bottom = -28;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 70;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xb8d8e8, 0.7);
fillLight.position.set(15, 10, -20);
scene.add(fillLight);
let randomSeed = 34791;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function terrainHeight(x, z) {
const radius = Math.sqrt(x * x + z * z) / 20;
const mound = Math.max(0, 1 - radius);
const variation =
0.89 +
0.08 * Math.sin(x * 0.42) * Math.cos(z * 0.37) +
0.04 * Math.sin((x + z) * 0.23);
const ripple = Math.sin(x * 0.82 + z * 0.57) * mound * 0.16;
return Math.max(
0,
4.75 * Math.pow(mound, 1.22) * variation + ripple
);
}
const ground = new THREE.Mesh(
new THREE.CircleGeometry(85, 64),
new THREE.MeshStandardMaterial({
color: 0x8f9c69,
roughness: 1,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.12;
ground.receiveShadow = true;
scene.add(ground);
function createTerrain() {
const size = 42;
const segments = 24;
const step = size / segments;
const positions = [];
const colors = [];
const lowColor = new THREE.Color(0x647c45);
const highColor = new THREE.Color(0x9aad62);
function point(x, z) {
return new THREE.Vector3(x, terrainHeight(x, z), z);
}
function addTriangle(a, b, c) {
positions.push(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
const height = (a.y + b.y + c.y) / 3;
const color = lowColor.clone().lerp(
highColor,
THREE.MathUtils.clamp(height / 4.8, 0, 1)
);
color.offsetHSL(
(random() - 0.5) * 0.018,
(random() - 0.5) * 0.05,
(random() - 0.5) * 0.055
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
for (let zIndex = 0; zIndex < segments; zIndex++) {
for (let xIndex = 0; xIndex < segments; xIndex++) {
const x0 = -size / 2 + xIndex * step;
const x1 = x0 + step;
const z0 = -size / 2 + zIndex * step;
const z1 = z0 + step;
const a = point(x0, z0);
const b = point(x1, z0);
const c = point(x0, z1);
const d = point(x1, z1);
addTriangle(a, c, b);
addTriangle(b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
const terrain = createTerrain();
function createPath(points, width = 0.95) {
const curve = new THREE.CatmullRomCurve3(
points.map(([x, z]) => new THREE.Vector3(x, 0, z)),
false,
"catmullrom",
0.35
);
const samples = curve.getPoints(70);
const positions = [];
const indices = [];
for (let i = 0; i < samples.length; i++) {
const p = samples[i];
const previous = samples[Math.max(0, i - 1)];
const next = samples[Math.min(samples.length - 1, i + 1)];
const dx = next.x - previous.x;
const dz = next.z - previous.z;
const length = Math.hypot(dx, dz) || 1;
const sideX = (-dz / length) * width * 0.5;
const sideZ = (dx / length) * width * 0.5;
const leftX = p.x + sideX;
const leftZ = p.z + sideZ;
const rightX = p.x - sideX;
const rightZ = p.z - sideZ;
positions.push(
leftX,
terrainHeight(leftX, leftZ) + 0.065,
leftZ,
rightX,
terrainHeight(rightX, rightZ) + 0.065,
rightZ
);
if (i < samples.length - 1) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: 0xc8ad77,
roughness: 1,
side: THREE.DoubleSide,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
}
createPath([
[0, 13],
[0, 8],
[-3, 3],
[-8, -5]
]);
createPath([
[0, 13],
[4, 9],
[7, 2],
[9, -3]
]);
createPath([
[0, 13],
[-2, 11],
[-4, 8]
], 0.72);
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0xc9bda0,
roughness: 0.95,
flatShading: true
});
const paleStoneMaterial = new THREE.MeshStandardMaterial({
color: 0xe4d7b9,
roughness: 0.92,
flatShading: true
});
const darkStoneMaterial = new THREE.MeshStandardMaterial({
color: 0x756f64,
roughness: 1,
flatShading: true
});
function addMesh(parent, geometry, material, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createBeacon() {
const group = new THREE.Group();
addMesh(
group,
new THREE.CylinderGeometry(2.0, 2.25, 0.42, 8),
darkStoneMaterial,
0,
0.21,
0
);
addMesh(
group,
new THREE.CylinderGeometry(1.35, 1.75, 4.5, 8),
stoneMaterial,
0,
2.7,
0
);
addMesh(
group,
new THREE.CylinderGeometry(1.52, 1.52, 0.22, 8),
paleStoneMaterial,
0,
3.7,
0
);
const roof = addMesh(
group,
new THREE.ConeGeometry(2.0, 1.25, 8),
new THREE.MeshStandardMaterial({
color: 0xb75238,
roughness: 0.9,
flatShading: true
}),
0,
5.55,
0
);
roof.rotation.y = Math.PI / 8;
const fireMaterial = new THREE.MeshStandardMaterial({
color: 0xffbd58,
emissive: 0xff6b24,
emissiveIntensity: 1.4,
roughness: 0.45,
flatShading: true
});
addMesh(
group,
new THREE.OctahedronGeometry(0.52),
fireMaterial,
0,
6.5,
0
);
const light = new THREE.PointLight(0xff8b3d, 4, 8, 2);
light.position.set(0, 6.5, 0);
group.add(light);
return group;
}
function createArch() {
const group = new THREE.Group();
group.rotation.y = 0.5;
addMesh(
group,
new THREE.BoxGeometry(5.2, 0.34, 1.8),
darkStoneMaterial,
0,
0.17,
0
);
addMesh(
group,
new THREE.BoxGeometry(1.05, 3.8, 1.2),
paleStoneMaterial,
-2,
2.15,
0
);
addMesh(
group,
new THREE.BoxGeometry(1.05, 3.8, 1.2),
paleStoneMaterial,
2,
2.15,
0
);
addMesh(
group,
new THREE.TorusGeometry(2, 0.42, 6, 24, Math.PI),
paleStoneMaterial,
0,
4.05,
0
);
addMesh(
group,
new THREE.OctahedronGeometry(0.45),
new THREE.MeshStandardMaterial({
color: 0xffd86f,
emissive: 0xc77619,
emissiveIntensity: 0.6,
flatShading: true
}),
0,
6.42,
0
);
return group;
}
function createShard() {
const group = new THREE.Group();
addMesh(
group,
new THREE.CylinderGeometry(2.2, 2.5, 0.45, 7),
darkStoneMaterial,
0,
0.225,
0
);
addMesh(
group,
new THREE.CylinderGeometry(1.55, 1.8, 0.45, 7),
stoneMaterial,
0,
0.63,
0
);
const crystalMaterial = new THREE.MeshStandardMaterial({
color: 0x74d6d0,
emissive: 0x176f78,
emissiveIntensity: 0.7,
roughness: 0.35,
metalness: 0.05,
flatShading: true
});
const mainCrystal = addMesh(
group,
new THREE.OctahedronGeometry(1),
crystalMaterial,
0,
2.55,
0
);
mainCrystal.scale.set(0.68, 2.05, 0.68);
const leftCrystal = addMesh(
group,
new THREE.OctahedronGeometry(0.8),
crystalMaterial,
-1.1,
1.65,
0.25
);
leftCrystal.scale.set(0.55, 1.35, 0.55);
leftCrystal.rotation.z = -0.35;
const rightCrystal = addMesh(
group,
new THREE.OctahedronGeometry(0.8),
crystalMaterial,
1.05,
1.62,
-0.15
);
rightCrystal.scale.set(0.55, 1.3, 0.55);
rightCrystal.rotation.z = 0.38;
const light = new THREE.PointLight(0x54d9df, 2.5, 7, 2);
light.position.set(0, 2.8, 0);
group.add(light);
return group;
}
const waypoints = [
{
name: "Ember Beacon",
position: new THREE.Vector3(-8, 0, -5),
color: "#ec7048",
labelOffset: 7.4,
build: createBeacon
},
{
name: "Moon Gate",
position: new THREE.Vector3(9, 0, -3),
color: "#d8a83d",
labelOffset: 7.0,
build: createArch
},
{
name: "Azure Shard",
position: new THREE.Vector3(-4, 0, 8),
color: "#3dbab8",
labelOffset: 5.2,
build: createShard
}
];
for (const waypoint of waypoints) {
waypoint.position.y = terrainHeight(
waypoint.position.x,
waypoint.position.z
);
const model = waypoint.build();
model.position.copy(waypoint.position);
scene.add(model);
waypoint.anchor = waypoint.position.clone().add(
new THREE.Vector3(0, waypoint.labelOffset, 0)
);
const marker = document.createElement("button");
marker.className = "marker";
marker.style.setProperty("--accent", waypoint.color);
marker.innerHTML = `
<span class="marker-dot"></span>
<span class="marker-name">${waypoint.name}</span>
<span class="marker-bearing">000°</span>
`;
marker.setAttribute(
"aria-label",
`Travel to ${waypoint.name}`
);
markerHost.appendChild(marker);
waypoint.marker = marker;
waypoint.markerBearing = marker.querySelector(".marker-bearing");
const row = document.createElement("button");
row.className = "waypoint-row";
row.style.setProperty("--accent", waypoint.color);
row.innerHTML = `
<span class="waypoint-color"></span>
<span class="waypoint-name">${waypoint.name}</span>
<span class="waypoint-distance">0.0 m away</span>
<span class="waypoint-bearing">000°</span>
`;
listHost.appendChild(row);
waypoint.row = row;
waypoint.rowBearing = row.querySelector(".waypoint-bearing");
waypoint.rowDistance = row.querySelector(".waypoint-distance");
marker.addEventListener("click", () => {
setWaypointDestination(waypoint);
});
row.addEventListener("click", () => {
setWaypointDestination(waypoint);
});
}
function createTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, terrainHeight(x, z), z);
group.scale.setScalar(scale);
addMesh(
group,
new THREE.CylinderGeometry(0.15, 0.22, 1.7, 5),
new THREE.MeshStandardMaterial({
color: 0x6c5136,
roughness: 1,
flatShading: true
}),
0,
0.85,
0
);
const foliageMaterial = new THREE.MeshStandardMaterial({
color: random() > 0.5 ? 0x365f49 : 0x477154,
roughness: 1,
flatShading: true
});
addMesh(
group,
new THREE.ConeGeometry(1.05, 2.65, 6),
foliageMaterial,
0,
2.25,
0
);
addMesh(
group,
new THREE.ConeGeometry(0.78, 2.0, 6),
foliageMaterial,
0,
3.15,
0
);
scene.add(group);
}
function createRock(x, z, scale) {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(scale, 0),
new THREE.MeshStandardMaterial({
color: random() > 0.5 ? 0x8b8978 : 0x77786a,
roughness: 1,
flatShading: true
})
);
rock.position.set(x, terrainHeight(x, z) + scale * 0.35, z);
rock.rotation.set(random(), random() * Math.PI, random());
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
}
for (let i = 0; i < 30; i++) {
const angle = random() * Math.PI * 2;
const radius = 12 + random() * 8;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
const nearWaypoint = waypoints.some(
(waypoint) =>
Math.hypot(
x - waypoint.position.x,
z - waypoint.position.z
) < 4
);
if (!nearWaypoint) {
createTree(x, z, 0.7 + random() * 0.7);
}
}
for (let i = 0; i < 20; i++) {
const angle = random() * Math.PI * 2;
const radius = 6 + random() * 13;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
if (
Math.hypot(x, z - 13) > 2 &&
!waypoints.some(
(waypoint) =>
Math.hypot(
x - waypoint.position.x,
z - waypoint.position.z
) < 3
)
) {
createRock(x, z, 0.25 + random() * 0.5);
}
}
function createTraveler() {
const root = new THREE.Group();
const visual = new THREE.Group();
root.add(visual);
const coatMaterial = new THREE.MeshStandardMaterial({
color: 0xe46f43,
roughness: 0.9,
flatShading: true
});
const pantsMaterial = new THREE.MeshStandardMaterial({
color: 0x294d61,
roughness: 1,
flatShading: true
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xe8b381,
roughness: 1,
flatShading: true
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x283630,
roughness: 1,
flatShading: true
});
addMesh(
visual,
new THREE.CylinderGeometry(0.28, 0.48, 0.85, 6),
coatMaterial,
0,
1.05,
0
);
addMesh(
visual,
new THREE.IcosahedronGeometry(0.27, 0),
skinMaterial,
0,
1.7,
0
);
addMesh(
visual,
new THREE.CylinderGeometry(0.45, 0.45, 0.08, 8),
darkMaterial,
0,
1.94,
0
);
addMesh(
visual,
new THREE.CylinderGeometry(0.27, 0.32, 0.22, 8),
coatMaterial,
0,
2.08,
0
);
addMesh(
visual,
new THREE.BoxGeometry(0.55, 0.68, 0.28),
new THREE.MeshStandardMaterial({
color: 0x8a6947,
roughness: 1,
flatShading: true
}),
0,
1.13,
-0.34
);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.19, 0.65, 0);
rightLeg.position.set(0.19, 0.65, 0);
visual.add(leftLeg, rightLeg);
addMesh(
leftLeg,
new THREE.BoxGeometry(0.22, 0.58, 0.24),
pantsMaterial,
0,
-0.28,
0
);
addMesh(
rightLeg,
new THREE.BoxGeometry(0.22, 0.58, 0.24),
pantsMaterial,
0,
-0.28,
0
);
addMesh(
leftLeg,
new THREE.BoxGeometry(0.25, 0.16, 0.39),
darkMaterial,
0,
-0.57,
0.07
);
addMesh(
rightLeg,
new THREE.BoxGeometry(0.25, 0.16, 0.39),
darkMaterial,
0,
-0.57,
0.07
);
scene.add(root);
return { root, visual, leftLeg, rightLeg };
}
const traveler = createTraveler();
const startPosition = new THREE.Vector3(0, 0, 13);
traveler.root.position.set(
startPosition.x,
terrainHeight(startPosition.x, startPosition.z),
startPosition.z
);
const destinationRing = new THREE.Mesh(
new THREE.RingGeometry(0.48, 0.66, 28),
new THREE.MeshBasicMaterial({
color: 0xfff0b1,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9
})
);
destinationRing.rotation.x = -Math.PI / 2;
destinationRing.visible = false;
scene.add(destinationRing);
let destination = null;
const pressedKeys = new Set();
function clearSelection() {
for (const waypoint of waypoints) {
waypoint.row.classList.remove("selected");
waypoint.marker.classList.remove("selected");
}
}
function setWaypointDestination(waypoint) {
const dx = traveler.root.position.x - waypoint.position.x;
const dz = traveler.root.position.z - waypoint.position.z;
const length = Math.hypot(dx, dz) || 1;
const standOff = waypoint.name === "Moon Gate" ? 3.4 : 2.8;
destination = {
x: waypoint.position.x + (dx / length) * standOff,
z: waypoint.position.z + (dz / length) * standOff,
name: waypoint.name
};
clearSelection();
waypoint.row.classList.add("selected");
waypoint.marker.classList.add("selected");
statusText.textContent = `Walking to ${waypoint.name}`;
}
function setGroundDestination(x, z) {
destination = { x, z, name: "selected point" };
clearSelection();
statusText.textContent = "Walking to selected point";
}
const cameraState = {
target: new THREE.Vector3(0, 1.3, 0),
yaw: 0.66,
pitch: 0.73,
distance: 48
};
function updateCamera() {
const horizontal = Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x +
Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y +
Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z +
Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function moveFromScreen(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObject(terrain, false)[0];
if (hit) {
const radius = Math.hypot(hit.point.x, hit.point.z);
if (radius < 19.3) {
setGroundDestination(hit.point.x, hit.point.z);
}
}
}
let drag = null;
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
if (drag) return;
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false,
mode:
event.button === 2 || event.shiftKey ? "pan" : "orbit"
};
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag || event.pointerId !== drag.id) return;
const dx = event.clientX - drag.lastX;
const dy = event.clientY - drag.lastY;
const totalX = event.clientX - drag.startX;
const totalY = event.clientY - drag.startY;
if (Math.hypot(totalX, totalY) > 5) {
drag.moved = true;
}
if (drag.mode === "orbit") {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.28,
1.38
);
} else {
const right = new THREE.Vector3(
Math.cos(cameraState.yaw),
0,
-Math.sin(cameraState.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraState.yaw),
0,
-Math.cos(cameraState.yaw)
);
const scale = cameraState.distance * 0.0016;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, -dy * scale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-13,
13
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-13,
13
);
}
drag.lastX = event.clientX;
drag.lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!drag || event.pointerId !== drag.id) return;
if (!drag.moved) {
moveFromScreen(event.clientX, event.clientY);
}
drag = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
drag = null;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.025,
22,
72
);
},
{ passive: false }
);
const movementCodes = [
"KeyW",
"KeyA",
"KeyS",
"KeyD",
"ArrowUp",
"ArrowLeft",
"ArrowDown",
"ArrowRight"
];
window.addEventListener("keydown", (event) => {
if (movementCodes.includes(event.code)) {
event.preventDefault();
pressedKeys.add(event.code);
destination = null;
clearSelection();
}
if (event.code === "KeyQ") {
cameraState.yaw -= 0.09;
}
if (event.code === "KeyE") {
cameraState.yaw += 0.09;
}
if (event.code === "KeyR") {
cameraState.target.set(0, 1.3, 0);
cameraState.yaw = 0.66;
cameraState.pitch = 0.73;
cameraState.distance = 48;
}
});
window.addEventListener("keyup", (event) => {
pressedKeys.delete(event.code);
});
window.addEventListener("blur", () => {
pressedKeys.clear();
});
document.querySelectorAll("[data-code]").forEach((button) => {
const code = button.dataset.code;
button.addEventListener("pointerdown", (event) => {
event.preventDefault();
button.setPointerCapture(event.pointerId);
pressedKeys.add(code);
destination = null;
clearSelection();
});
const release = () => pressedKeys.delete(code);
button.addEventListener("pointerup", release);
button.addEventListener("pointercancel", release);
});
const directionNames = [
"N",
"NNE",
"NE",
"ENE",
"E",
"ESE",
"SE",
"SSE",
"S",
"SSW",
"SW",
"WSW",
"W",
"WNW",
"NW",
"NNW"
];
function bearingTo(dx, dz) {
// World north is negative Z. Bearings increase clockwise: N=0, E=90.
const degrees =
(THREE.MathUtils.radToDeg(Math.atan2(dx, -dz)) + 360) % 360;
const rounded = Math.round(degrees) % 360;
const direction =
directionNames[Math.round(degrees / 22.5) % directionNames.length];
return {
degrees,
rounded,
direction,
text: `${rounded}° ${direction}`
};
}
const projected = new THREE.Vector3();
const clock = new THREE.Clock();
let walkTime = 0;
let facing = Math.PI;
function updateTraveler(delta) {
let horizontal = 0;
let vertical = 0;
const left =
pressedKeys.has("KeyA") || pressedKeys.has("ArrowLeft");
const right =
pressedKeys.has("KeyD") || pressedKeys.has("ArrowRight");
const up =
pressedKeys.has("KeyW") || pressedKeys.has("ArrowUp");
const down =
pressedKeys.has("KeyS") || pressedKeys.has("ArrowDown");
horizontal += Number(right) - Number(left);
vertical += Number(down) - Number(up);
let moving = false;
let moveX = horizontal;
let moveZ = vertical;
if (horizontal || vertical) {
const length = Math.hypot(moveX, moveZ);
moveX /= length;
moveZ /= length;
moving = true;
} else if (destination) {
const dx = destination.x - traveler.root.position.x;
const dz = destination.z - traveler.root.position.z;
const distance = Math.hypot(dx, dz);
if (distance < 0.14) {
statusText.textContent = `Arrived at ${destination.name}`;
destination = null;
} else {
moveX = dx / distance;
moveZ = dz / distance;
moving = true;
}
}
if (moving) {
const speed = pressedKeys.has("ShiftLeft") ? 7.2 : 4.7;
traveler.root.position.x += moveX * speed * delta;
traveler.root.position.z += moveZ * speed * delta;
const radius = Math.hypot(
traveler.root.position.x,
traveler.root.position.z
);
if (radius > 19.2) {
const scale = 19.2 / radius;
traveler.root.position.x *= scale;
traveler.root.position.z *= scale;
}
const targetFacing = Math.atan2(moveX, moveZ);
const difference = Math.atan2(
Math.sin(targetFacing - facing),
Math.cos(targetFacing - facing)
);
facing += difference * Math.min(1, delta * 12);
traveler.root.rotation.y = facing;
walkTime += delta * 10;
traveler.visual.position.y =
Math.abs(Math.sin(walkTime)) * 0.045;
traveler.leftLeg.rotation.x =
Math.sin(walkTime) * 0.55;
traveler.rightLeg.rotation.x =
-Math.sin(walkTime) * 0.55;
if (destination) {
const distance = Math.hypot(
destination.x - traveler.root.position.x,
destination.z - traveler.root.position.z
);
statusText.textContent =
`Walking to ${destination.name} · ${distance.toFixed(1)} m`;
} else {
statusText.textContent = "Wandering the hill";
}
} else {
traveler.visual.position.y = THREE.MathUtils.lerp(
traveler.visual.position.y,
0,
Math.min(1, delta * 10)
);
traveler.leftLeg.rotation.x = THREE.MathUtils.lerp(
traveler.leftLeg.rotation.x,
0,
Math.min(1, delta * 10)
);
traveler.rightLeg.rotation.x = THREE.MathUtils.lerp(
traveler.rightLeg.rotation.x,
0,
Math.min(1, delta * 10)
);
}
traveler.root.position.y = terrainHeight(
traveler.root.position.x,
traveler.root.position.z
);
}
function updateWaypointBearings() {
for (const waypoint of waypoints) {
const dx = waypoint.position.x - traveler.root.position.x;
const dz = waypoint.position.z - traveler.root.position.z;
const bearing = bearingTo(dx, dz);
const distance = Math.hypot(dx, dz);
waypoint.markerBearing.textContent = bearing.text;
waypoint.rowBearing.textContent = bearing.text;
waypoint.rowDistance.textContent = `${distance.toFixed(1)} m away`;
projected.copy(waypoint.anchor).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
waypoint.marker.style.display = onScreen ? "flex" : "none";
if (onScreen) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
waypoint.marker.style.left = `${x}px`;
waypoint.marker.style.top = `${y}px`;
}
}
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
updateTraveler(delta);
updateCamera();
if (destination) {
destinationRing.visible = true;
destinationRing.position.set(
destination.x,
terrainHeight(destination.x, destination.z) + 0.12,
destination.z
);
const pulse = 1 + Math.sin(performance.now() * 0.004) * 0.08;
destinationRing.scale.setScalar(pulse);
} else {
destinationRing.visible = false;
}
updateWaypointBearings();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```