Prompt specification
Build or customize the Three.js 3D scene "Compass rose on a trail marker" 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: Compass rose on a trail marker
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/compass-rose-on-a-trail-marker-x1289
Scene Description Prompt:
A voxel trail marker with fixed cardinal labels, a compass rose, arrow, and asymmetrical rock. Three.js from cdnjs, one HTML file.
Working Three.js Starter (compass-rose-on-a-trail-marker-x1289):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Trail Marker</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd9d5;
font-family: Arial, Helvetica, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 2;
padding: 13px 16px 12px;
color: #203b38;
background: rgba(245, 239, 216, 0.9);
border: 1px solid rgba(32, 59, 56, 0.2);
box-shadow: 0 8px 30px rgba(31, 47, 43, 0.12);
backdrop-filter: blur(8px);
pointer-events: none;
}
.title-card strong {
display: block;
margin-bottom: 4px;
font-size: 13px;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.title-card span {
display: block;
font-size: 10px;
letter-spacing: 0.16em;
opacity: 0.68;
text-transform: uppercase;
}
.help {
position: fixed;
right: 20px;
bottom: 18px;
z-index: 2;
padding: 9px 12px;
color: #f4efd9;
background: rgba(25, 51, 48, 0.76);
border: 1px solid rgba(255, 255, 255, 0.12);
font-size: 10px;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
#reset {
position: fixed;
top: 24px;
right: 24px;
z-index: 3;
padding: 10px 13px;
color: #f4efd9;
background: rgba(25, 51, 48, 0.84);
border: 1px solid rgba(255, 255, 255, 0.14);
font: inherit;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
}
#reset:hover {
background: rgba(35, 70, 65, 0.96);
}
@media (max-width: 600px) {
.title-card {
top: 14px;
left: 14px;
}
#reset {
top: 14px;
right: 14px;
}
.help {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div class="title-card">
<strong>Ridgeline Trail</strong>
<span>Compass marker · sector 07</span>
</div>
<button id="reset" type="button">Reset view</button>
<div class="help">Drag to orbit · scroll to zoom · double-click to reset</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd9d5);
scene.fog = new THREE.Fog(0xcbd9d5, 19, 39);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute("aria-label", "Interactive voxel trail marker");
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe8f4ed, 0x63704e, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cc, 3.3);
sun.position.set(-8, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cc8cb, 0.75);
fill.position.set(9, 5, -8);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const mats = {
ground: material(0x9ba878),
groundDark: material(0x839465),
baseDark: material(0x3d514b),
base: material(0x53665e),
roseField: material(0x244b47),
cream: material(0xf0dfb8),
white: material(0xfff0c8),
coral: material(0xe56c4e),
arrow: material(0xf3a43b, { roughness: 0.66 }),
pivot: material(0x314a46, { metalness: 0.18, roughness: 0.6 }),
rockA: material(0x7e897f),
rockB: material(0x68766f),
rockC: material(0x92998b),
rockD: material(0x596860),
path: material(0xb7ae91),
pathLight: material(0xc7bda0),
trunk: material(0x715843),
pineA: material(0x355b49),
pineB: material(0x416b54),
pineC: material(0x2e5143),
grassA: material(0x647c4f),
grassB: material(0x778d58)
};
function box(w, h, d, x, y, z, mat, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextTexture(text, options = {}) {
const {
width = 256,
height = 256,
fontSize = 180,
color = "#203b38",
background = null,
subtitle = ""
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
if (background) {
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
} else {
ctx.clearRect(0, 0, width, height);
}
ctx.fillStyle = color;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = `900 ${fontSize}px Arial, sans-serif`;
ctx.fillText(text, width / 2, subtitle ? height * 0.42 : height / 2);
if (subtitle) {
ctx.font = `700 ${Math.round(height * 0.1)}px Arial, sans-serif`;
ctx.fillText(subtitle, width / 2, height * 0.72);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
// Ground and low voxel terrain.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
mats.ground
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
// Main stepped stone foundation.
box(5.55, 0.32, 5.55, 0, 0.16, 0, mats.baseDark);
box(5.12, 0.30, 5.12, 0, 0.47, 0, mats.base);
box(3.88, 0.055, 3.88, 0, 0.642, 0, mats.roseField);
// Subtle corner stones on the foundation.
for (const x of [-2.28, 2.28]) {
for (const z of [-2.28, 2.28]) {
box(0.46, 0.36, 0.46, x, 0.18, z, mats.rockB);
box(0.38, 0.20, 0.38, x, 0.42, z, mats.rockC);
}
}
// Eight-point voxel compass rose.
const roseY = 0.697;
// North and south cardinal points.
box(0.56, 0.055, 0.32, 0, roseY, -0.20, mats.coral);
box(0.36, 0.055, 0.32, 0, roseY, -0.52, mats.coral);
box(0.18, 0.055, 0.32, 0, roseY, -0.84, mats.coral);
box(0.56, 0.055, 0.32, 0, roseY, 0.20, mats.cream);
box(0.36, 0.055, 0.32, 0, roseY, 0.52, mats.cream);
box(0.18, 0.055, 0.32, 0, roseY, 0.84, mats.cream);
// East and west cardinal points.
box(0.32, 0.055, 0.56, 0.20, roseY, 0, mats.cream);
box(0.32, 0.055, 0.36, 0.52, roseY, 0, mats.cream);
box(0.32, 0.055, 0.18, 0.84, roseY, 0, mats.cream);
box(0.32, 0.055, 0.56, -0.20, roseY, 0, mats.cream);
box(0.32, 0.055, 0.36, -0.52, roseY, 0, mats.cream);
box(0.32, 0.055, 0.18, -0.84, roseY, 0, mats.cream);
// Smaller diagonal steps.
const diagonalOffsets = [
[0.53, -0.53],
[0.76, -0.76],
[-0.53, -0.53],
[-0.76, -0.76],
[0.53, 0.53],
[0.76, 0.76],
[-0.53, 0.53],
[-0.76, 0.76]
];
diagonalOffsets.forEach(([x, z], i) => {
box(0.24, 0.05, 0.24, x, roseY, z, i % 2 ? mats.cream : mats.roseField);
});
box(0.28, 0.07, 0.28, 0, roseY, 0, mats.cream);
// Fixed physical cardinal labels.
function addCardinalLabel(letter, yaw, plaqueMaterial) {
const holder = new THREE.Group();
holder.rotation.y = yaw;
scene.add(holder);
box(0.76, 0.08, 0.76, 0, 0.70, -2.18, plaqueMaterial, holder);
const texture = makeTextTexture(letter, {
color: letter === "N" ? "#f8e9c2" : "#203b38",
fontSize: 195
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.58, 0.58),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide,
depthWrite: false
})
);
label.rotation.x = -Math.PI / 2;
label.position.set(0, 0.746, -2.18);
label.renderOrder = 2;
holder.add(label);
}
addCardinalLabel("N", 0, mats.coral);
addCardinalLabel("E", -Math.PI / 2, mats.cream);
addCardinalLabel("S", Math.PI, mats.cream);
addCardinalLabel("W", Math.PI / 2, mats.cream);
// Raised voxel arrow pointing north.
const pivot = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.44, 0.18, 12),
mats.pivot
);
pivot.position.y = 0.78;
pivot.castShadow = true;
pivot.receiveShadow = true;
scene.add(pivot);
box(0.27, 0.20, 1.30, 0, 0.96, 0.30, mats.arrow);
box(0.64, 0.20, 0.40, 0, 0.96, -0.52, mats.arrow);
box(0.43, 0.20, 0.31, 0, 0.96, -0.87, mats.arrow);
box(0.22, 0.20, 0.24, 0, 0.96, -1.13, mats.arrow);
// Front trail plaque.
box(2.26, 0.42, 0.09, 0, 0.49, 2.58, mats.cream);
const signTexture = makeTextTexture("RIDGELINE", {
width: 1024,
height: 256,
fontSize: 102,
color: "#203b38",
background: "#f0dfb8",
subtitle: "TRAIL 07"
});
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(2.12, 0.37),
new THREE.MeshBasicMaterial({ map: signTexture })
);
sign.position.set(0, 0.49, 2.631);
scene.add(sign);
// Deliberately uneven, asymmetrical voxel rock.
const rock = new THREE.Group();
rock.position.set(-3.55, 0, 0.58);
scene.add(rock);
box(1.55, 0.42, 1.38, -0.38, 0.21, 0.18, mats.rockB, rock);
box(1.26, 0.82, 1.05, 0.42, 0.64, -0.16, mats.rockA, rock);
box(0.84, 0.70, 0.78, 0.13, 1.22, -0.20, mats.rockC, rock);
box(0.76, 0.62, 0.84, -0.76, 0.60, 0.53, mats.rockD, rock);
box(0.55, 0.52, 0.52, -0.18, 1.61, 0.18, mats.rockA, rock);
box(0.60, 0.34, 0.66, 0.65, 1.18, 0.33, mats.rockB, rock);
box(0.47, 0.30, 0.46, -0.72, 0.98, -0.28, mats.rockC, rock);
// A path of low stone blocks leading toward the marker.
const pathData = [
[0.15, 3.55, 1.42, 0.78],
[-0.18, 4.45, 1.28, 0.72],
[0.22, 5.32, 1.36, 0.80],
[-0.10, 6.28, 1.50, 0.74],
[0.30, 7.20, 1.25, 0.68],
[-0.22, 8.15, 1.42, 0.76],
[0.12, 9.15, 1.34, 0.72],
[-0.12, 10.16, 1.48, 0.78],
[0.18, 11.20, 1.30, 0.70]
];
pathData.forEach(([x, z, width, depth], i) => {
const stone = box(
width,
0.14 + (i % 3) * 0.025,
depth,
x,
0.075,
z,
i % 2 ? mats.pathLight : mats.path
);
stone.rotation.y = (i % 2 ? 1 : -1) * 0.07;
});
// Small blocky pine trees for depth.
function addPine(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(0.42, 2.2, 0.42, 0, 1.1, 0, mats.trunk, group);
box(2.35, 0.72, 2.35, 0, 1.65, 0, mats.pineA, group);
box(1.90, 0.70, 1.90, 0, 2.27, 0, mats.pineB, group);
box(1.42, 0.68, 1.42, 0, 2.87, 0, mats.pineC, group);
box(0.86, 0.66, 0.86, 0, 3.43, 0, mats.pineB, group);
}
addPine(-7.2, -6.2, 1.05);
addPine(6.8, -7.8, 0.92);
addPine(-9.0, 1.2, 0.82);
addPine(8.7, 1.8, 0.78);
addPine(0.7, -10.4, 1.12);
// Deterministic grass tufts.
let seed = 7193;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 64; i++) {
const x = (random() - 0.5) * 23;
const z = (random() - 0.5) * 23;
if (Math.hypot(x, z) < 4.2) continue;
if (z > 2.8 && Math.abs(x) < 1.8) continue;
if (Math.hypot(x + 3.55, z - 0.58) < 2.1) continue;
const tuft = new THREE.Group();
tuft.position.set(x, 0, z);
scene.add(tuft);
const height = 0.18 + random() * 0.22;
box(
0.07,
height,
0.07,
(random() - 0.5) * 0.20,
height / 2,
(random() - 0.5) * 0.20,
i % 2 ? mats.grassA : mats.grassB,
tuft
);
}
// Direct camera controls, implemented without addons.
const orbit = {
theta: 0.70,
phi: 0.94,
radius: 13.1
};
const defaultOrbit = { ...orbit };
const target = new THREE.Vector3(0, 0.72, 0);
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
function resetCamera() {
Object.assign(orbit, defaultOrbit);
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.38,
1.42
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
7.5,
21
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
updateCamera();
renderer.setAnimationLoop(() => renderer.render(scene, camera));
</script>
</body>
</html>
```