Prompt specification
Build or customize the Three.js 3D scene "Fictional Lunar Sampling Site" 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: Fictional Lunar Sampling Site
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/fictional-lunar-sampling-site-x3819
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing rover movement over uneven terrain. Build an original bounded lunar-like terrain with crater rims, rocks, and sample markers. Use source-informed visual features but label the site as fictional. Voxel style.
Working Three.js Starter (fictional-lunar-sampling-site-x3819):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cinder-9 — Fictional Lunar Analog Rover</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(8, 13, 20, 0.78);
--line: rgba(146, 190, 204, 0.25);
--text: #e6eef2;
--muted: #8fa5af;
--cyan: #68e7ed;
--orange: #ff7948;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 70% 15%, #172030 0, transparent 38%),
linear-gradient(160deg, #080c14, #030509 70%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
user-select: none;
}
.panel {
position: absolute;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#site {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
content: "";
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
h1 {
margin: 10px 0 5px;
font-size: clamp(25px, 4vw, 38px);
font-weight: 750;
line-height: 0.95;
letter-spacing: -0.045em;
text-transform: uppercase;
}
#site p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.fiction {
display: inline-block;
margin-top: 12px;
padding: 5px 8px;
border: 1px solid rgba(255, 121, 72, 0.45);
color: #ffab89;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#telemetry {
top: 22px;
right: 22px;
width: 205px;
padding: 14px 16px;
border-radius: 4px;
font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.t-row {
display: flex;
justify-content: space-between;
gap: 20px;
}
.t-row span:first-child {
color: var(--muted);
}
#sample-count {
color: var(--cyan);
}
#instructions {
bottom: 22px;
left: 22px;
max-width: 390px;
padding: 13px 16px;
border-radius: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.65;
}
#instructions strong {
color: var(--text);
}
kbd {
display: inline-block;
min-width: 20px;
margin: 0 2px;
padding: 2px 5px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-bottom-width: 2px;
border-radius: 3px;
background: rgba(255, 255, 255, 0.06);
color: #eaf5f8;
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
#controls {
position: absolute;
right: 22px;
bottom: 22px;
display: grid;
grid-template-columns: repeat(3, 46px);
grid-template-rows: repeat(2, 44px);
gap: 6px;
pointer-events: auto;
}
#controls button {
border: 1px solid var(--line);
border-radius: 4px;
background: rgba(10, 17, 25, 0.86);
color: var(--text);
font: 700 17px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;
}
#controls button:active,
#controls button.active {
border-color: var(--cyan);
background: rgba(72, 197, 204, 0.2);
color: #d8ffff;
box-shadow: 0 0 18px rgba(104, 231, 237, 0.15);
}
#controls .forward {
grid-column: 2;
}
#controls .left {
grid-column: 1;
grid-row: 2;
}
#controls .back {
grid-column: 2;
grid-row: 2;
}
#controls .right {
grid-column: 3;
grid-row: 2;
}
#reset {
position: absolute;
right: 176px;
bottom: 22px;
height: 44px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 4px;
background: rgba(10, 17, 25, 0.86);
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
cursor: pointer;
pointer-events: auto;
}
#crosshair {
position: absolute;
top: 50%;
left: 50%;
width: 18px;
height: 18px;
transform: translate(-50%, -50%);
opacity: 0.35;
}
#crosshair::before,
#crosshair::after {
position: absolute;
content: "";
background: #dceff2;
}
#crosshair::before {
top: 8px;
left: 0;
width: 18px;
height: 1px;
}
#crosshair::after {
top: 0;
left: 8px;
width: 1px;
height: 18px;
}
#toast {
position: absolute;
top: 24%;
left: 50%;
padding: 10px 16px;
transform: translate(-50%, -8px);
border: 1px solid rgba(104, 231, 237, 0.35);
border-radius: 3px;
background: rgba(7, 15, 21, 0.86);
color: #bafcff;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
opacity: 0;
transition: opacity 180ms ease, transform 180ms ease;
}
#toast.show {
transform: translate(-50%, 0);
opacity: 1;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #05080e;
color: var(--cyan);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
#site {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
#site p {
display: none;
}
.fiction {
margin-top: 9px;
}
#telemetry {
top: 126px;
right: 12px;
width: 174px;
padding: 10px 12px;
font-size: 10px;
}
#instructions {
display: none;
}
#controls {
right: 12px;
bottom: 12px;
grid-template-columns: repeat(3, 42px);
grid-template-rows: repeat(2, 42px);
}
#reset {
right: 150px;
bottom: 12px;
height: 42px;
}
}
</style>
</head>
<body>
<div id="loading">GENERATING FICTIONAL TERRAIN…</div>
<div id="ui">
<section id="site" class="panel">
<div class="eyebrow">Planetary field simulation</div>
<h1>Cinder-9</h1>
<p>
A bounded voxel lunar-analog field with impact rims, fractured rock,
route markers, and autonomous sample beacons.
</p>
<span class="fiction">Fictional research site — not an actual lunar location</span>
</section>
<section id="telemetry" class="panel">
<div class="t-row"><span>STATUS</span><span id="status">ROVER ACTIVE</span></div>
<div class="t-row"><span>VELOCITY</span><span id="speed">0.0 m/s</span></div>
<div class="t-row"><span>HEADING</span><span id="heading">000°</span></div>
<div class="t-row"><span>POSITION</span><span id="position">0.0, 0.0</span></div>
<div class="t-row"><span>SAMPLES</span><span id="sample-count">0 / 3</span></div>
</section>
<section id="instructions" class="panel">
<strong>Drive:</strong>
<kbd>W</kbd><kbd>S</kbd> throttle
<kbd>A</kbd><kbd>D</kbd> steer<br />
<strong>Camera:</strong> drag to orbit · mouse wheel to zoom<br />
<strong>Objective:</strong> approach the cyan sample markers and collect them.
</section>
<button id="reset" type="button" title="Reset camera">RESET VIEW</button>
<div id="controls" aria-label="Rover controls">
<button class="forward" data-code="KeyW" aria-label="Forward">▲</button>
<button class="left" data-code="KeyA" aria-label="Left">◀</button>
<button class="back" data-code="KeyS" aria-label="Backward">▼</button>
<button class="right" data-code="KeyD" aria-label="Right">▶</button>
</div>
<div id="crosshair"></div>
<div id="toast">SAMPLE SECURED</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x050810);
scene.fog = new THREE.Fog(0x050810, 38, 82);
const camera = new THREE.PerspectiveCamera(
47,
innerWidth / innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0x9eb8cf, 0x272229, 1.65);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffeed4, 3.25);
sun.position.set(-15, 26, 13);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x4b8aa5, 0.75);
rimLight.position.set(18, 8, -22);
scene.add(rimLight);
// ------------------------------------------------------------
// Deterministic utilities and noise
// ------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(90421);
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function smoothstep(edge0, edge1, value) {
const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
return t * t * (3 - 2 * t);
}
function hash2(x, z) {
const value = Math.sin(x * 127.1 + z * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
function noise2(x, z) {
const ix = Math.floor(x);
const iz = Math.floor(z);
const fx = x - ix;
const fz = z - iz;
const ux = fx * fx * (3 - 2 * fx);
const uz = fz * fz * (3 - 2 * fz);
const a = hash2(ix, iz);
const b = hash2(ix + 1, iz);
const c = hash2(ix, iz + 1);
const d = hash2(ix + 1, iz + 1);
return THREE.MathUtils.lerp(
THREE.MathUtils.lerp(a, b, ux),
THREE.MathUtils.lerp(c, d, ux),
uz
);
}
function fbm(x, z) {
let value = 0;
let amplitude = 0.5;
let frequency = 1;
for (let octave = 0; octave < 4; octave++) {
value += noise2(x * frequency, z * frequency) * amplitude;
frequency *= 2.03;
amplitude *= 0.5;
}
return value;
}
// ------------------------------------------------------------
// Original bounded terrain layout
// ------------------------------------------------------------
const GRID_SIZE = 30;
const CELL = 1.08;
const TERRAIN_SIZE = GRID_SIZE * CELL;
const HALF_SIZE = TERRAIN_SIZE / 2;
const TERRAIN_BOTTOM = -1.65;
const craters = [
{ x: -5.5, z: 2.0, radius: 5.2, depth: 2.75, name: "ALPHA" },
{ x: 6.4, z: -5.2, radius: 4.1, depth: 2.25, name: "BETA" },
{ x: 7.4, z: 7.0, radius: 3.1, depth: 1.65, name: "GAMMA" }
];
function rawTerrainHeight(x, z) {
let height =
0.72 +
fbm(x * 0.125 + 9.4, z * 0.125 - 4.1) * 1.03 +
fbm(x * 0.34 - 11.2, z * 0.34 + 8.7) * 0.24;
for (const crater of craters) {
const distance = Math.hypot(x - crater.x, z - crater.z);
const d = distance / crater.radius;
// Bowl depression.
if (d < 1.08) {
height -= crater.depth * (1 - smoothstep(0.04, 1.08, d));
}
// Raised, blocky impact rim.
const rim = Math.exp(-Math.pow((d - 1.0) / 0.135, 2));
height += crater.depth * 0.37 * rim;
// Low ejecta shoulder.
const ejecta = Math.exp(-Math.pow((d - 1.3) / 0.32, 2));
height += crater.depth * 0.065 * ejecta;
}
return clamp(height, 0.25, 2.5);
}
const heightGrid = new Float32Array(GRID_SIZE * GRID_SIZE);
const terrainPositions = [];
for (let iz = 0; iz < GRID_SIZE; iz++) {
for (let ix = 0; ix < GRID_SIZE; ix++) {
const x = (ix - (GRID_SIZE - 1) / 2) * CELL;
const z = (iz - (GRID_SIZE - 1) / 2) * CELL;
const top = TERRAIN_BOTTOM + rawTerrainHeight(x, z);
heightGrid[iz * GRID_SIZE + ix] = top;
terrainPositions.push({ x, z, top });
}
}
function heightAt(x, z) {
const gridX = clamp(x / CELL + (GRID_SIZE - 1) / 2, 0, GRID_SIZE - 1.001);
const gridZ = clamp(z / CELL + (GRID_SIZE - 1) / 2, 0, GRID_SIZE - 1.001);
const x0 = Math.floor(gridX);
const z0 = Math.floor(gridZ);
const x1 = Math.min(x0 + 1, GRID_SIZE - 1);
const z1 = Math.min(z0 + 1, GRID_SIZE - 1);
const tx = gridX - x0;
const tz = gridZ - z0;
const h00 = heightGrid[z0 * GRID_SIZE + x0];
const h10 = heightGrid[z0 * GRID_SIZE + x1];
const h01 = heightGrid[z1 * GRID_SIZE + x0];
const h11 = heightGrid[z1 * GRID_SIZE + x1];
return THREE.MathUtils.lerp(
THREE.MathUtils.lerp(h00, h10, tx),
THREE.MathUtils.lerp(h01, h11, tx),
tz
);
}
function craterDistance(x, z) {
let nearest = 10;
for (const crater of craters) {
nearest = Math.min(
nearest,
Math.hypot(x - crater.x, z - crater.z) / crater.radius
);
}
return nearest;
}
// Column bodies make the terrain read as a solid voxel slab.
const columnGeometry = new THREE.BoxGeometry(CELL * 0.985, 1, CELL * 0.985);
const columnMaterial = new THREE.MeshStandardMaterial({
color: 0x35343a,
roughness: 1,
metalness: 0
});
const columns = new THREE.InstancedMesh(
columnGeometry,
columnMaterial,
terrainPositions.length
);
columns.receiveShadow = true;
const tileGeometry = new THREE.BoxGeometry(CELL * 0.965, 1, CELL * 0.965);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
metalness: 0.01
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
terrainPositions.length
);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
terrainPositions.forEach((position, index) => {
const columnHeight = position.top - TERRAIN_BOTTOM;
dummy.position.set(
position.x,
TERRAIN_BOTTOM + columnHeight / 2,
position.z
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, columnHeight, 1);
dummy.updateMatrix();
columns.setMatrixAt(index, dummy.matrix);
dummy.position.set(position.x, position.top + 0.035, position.z);
dummy.scale.set(1, 0.07, 1);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
const variation = fbm(position.x * 0.24 + 31, position.z * 0.24 - 14);
const craterD = craterDistance(position.x, position.z);
color.setRGB(
0.36 + variation * 0.095,
0.345 + variation * 0.085,
0.32 + variation * 0.075
);
// Darker crater floors and slightly brighter raised rims.
if (craterD < 0.82) {
color.multiplyScalar(0.72 + craterD * 0.13);
} else if (craterD < 1.14) {
color.multiplyScalar(1.07);
}
tiles.setColorAt(index, color);
});
columns.instanceMatrix.needsUpdate = true;
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(columns, tiles);
const base = new THREE.Mesh(
new THREE.BoxGeometry(TERRAIN_SIZE + 0.65, 0.72, TERRAIN_SIZE + 0.65),
new THREE.MeshStandardMaterial({
color: 0x202127,
roughness: 0.88,
metalness: 0.12
})
);
base.position.y = TERRAIN_BOTTOM - 0.36;
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
// ------------------------------------------------------------
// Rock fields and crater-rim ejecta
// ------------------------------------------------------------
const rockTransforms = [];
function addRockCluster(cx, cz, count, scaleMultiplier = 1) {
for (let i = 0; i < count; i++) {
const angle = random() * Math.PI * 2;
const radius = random() * 0.75;
const x = cx + Math.cos(angle) * radius;
const z = cz + Math.sin(angle) * radius;
const size = (0.16 + random() * 0.47) * scaleMultiplier;
rockTransforms.push({
x,
z,
size,
sx: size * (0.8 + random() * 0.75),
sy: size * (0.55 + random() * 0.8),
sz: size * (0.8 + random() * 0.75),
rx: (random() - 0.5) * 0.34,
ry: random() * Math.PI,
rz: (random() - 0.5) * 0.34,
shade: random()
});
}
}
for (let i = 0; i < 66; i++) {
const x = (random() - 0.5) * (TERRAIN_SIZE - 3);
const z = (random() - 0.5) * (TERRAIN_SIZE - 3);
if (Math.abs(x) < 2.5 && Math.abs(z - 11.2) < 2.2) continue;
addRockCluster(x, z, 2 + Math.floor(random() * 5));
}
for (const crater of craters) {
const rimRocks = 28;
for (let i = 0; i < rimRocks; i++) {
const angle = (i / rimRocks) * Math.PI * 2 + random() * 0.11;
const radius = crater.radius * (0.94 + random() * 0.15);
const x = crater.x + Math.cos(angle) * radius;
const z = crater.z + Math.sin(angle) * radius;
rockTransforms.push({
x,
z,
size: 0.17 + random() * 0.27,
sx: 0.2 + random() * 0.42,
sy: 0.15 + random() * 0.3,
sz: 0.2 + random() * 0.42,
rx: (random() - 0.5) * 0.45,
ry: random() * Math.PI,
rz: (random() - 0.5) * 0.45,
shade: random()
});
}
}
const rockMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
}),
rockTransforms.length
);
rockMesh.castShadow = true;
rockMesh.receiveShadow = true;
rockTransforms.forEach((rock, index) => {
dummy.position.set(
rock.x,
heightAt(rock.x, rock.z) + rock.sy * 0.45,
rock.z
);
dummy.rotation.set(rock.rx, rock.ry, rock.rz);
dummy.scale.set(rock.sx, rock.sy, rock.sz);
dummy.updateMatrix();
rockMesh.setMatrixAt(index, dummy.matrix);
const shade = rock.shade;
color.setRGB(
0.27 + shade * 0.15,
0.265 + shade * 0.14,
0.25 + shade * 0.13
);
rockMesh.setColorAt(index, color);
});
rockMesh.instanceMatrix.needsUpdate = true;
rockMesh.instanceColor.needsUpdate = true;
scene.add(rockMesh);
// ------------------------------------------------------------
// Canvas-based voxel signage
// ------------------------------------------------------------
function roundedRectangle(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + width - r, y);
context.quadraticCurveTo(x + width, y, x + width, y + r);
context.lineTo(x + width, y + height - r);
context.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
context.lineTo(x + r, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
function createLabelSprite(
text,
options = {
width: 512,
height: 128,
accent: "#68e7ed",
scale: new THREE.Vector2(3.2, 0.8)
}
) {
const canvas = document.createElement("canvas");
canvas.width = options.width;
canvas.height = options.height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRectangle(
context,
6,
6,
canvas.width - 12,
canvas.height - 12,
13
);
context.fillStyle = "rgba(6, 13, 20, 0.88)";
context.fill();
context.strokeStyle = options.accent;
context.lineWidth = 4;
context.stroke();
context.fillStyle = options.accent;
context.fillRect(22, 25, 7, canvas.height - 50);
context.fillStyle = "#e7f2f5";
context.font = "700 42px ui-monospace, SFMono-Regular, Menlo, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2 + 7, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.copy(options.scale);
return sprite;
}
const siteSign = createLabelSprite("CINDER-9 // FICTIONAL", {
width: 640,
height: 128,
accent: "#ff7948",
scale: new THREE.Vector2(6.4, 1.28)
});
siteSign.position.set(-11.5, heightAt(-11.5, 11.5) + 2.15, 11.5);
scene.add(siteSign);
for (const crater of craters) {
const label = createLabelSprite(`CRATER ${crater.name}`, {
width: 512,
height: 112,
accent: "#8ca0aa",
scale: new THREE.Vector2(3.4, 0.74)
});
label.position.set(
crater.x,
heightAt(crater.x, crater.z) + 2.8,
crater.z
);
scene.add(label);
}
// ------------------------------------------------------------
// Rover
// ------------------------------------------------------------
const rover = new THREE.Group();
rover.position.set(0, heightAt(0, 11.2), 11.2);
scene.add(rover);
const roverMaterials = {
body: new THREE.MeshStandardMaterial({
color: 0xbcc1c0,
roughness: 0.55,
metalness: 0.48
}),
dark: new THREE.MeshStandardMaterial({
color: 0x171b20,
roughness: 0.78,
metalness: 0.18
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff6f38,
roughness: 0.48,
metalness: 0.18
}),
blue: new THREE.MeshStandardMaterial({
color: 0x153846,
emissive: 0x08232a,
emissiveIntensity: 0.65,
roughness: 0.35,
metalness: 0.45
}),
glass: new THREE.MeshStandardMaterial({
color: 0x2f7180,
emissive: 0x12424b,
emissiveIntensity: 1.4,
roughness: 0.22,
metalness: 0.25
})
};
const bodyPivot = new THREE.Group();
bodyPivot.position.y = 0.56;
rover.add(bodyPivot);
function addRoverBox(parent, size, position, material, rotation = [0, 0, 0]) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
addRoverBox(bodyPivot, [1.35, 0.38, 1.95], [0, 0.08, 0], roverMaterials.body);
addRoverBox(bodyPivot, [1.13, 0.18, 1.62], [0, 0.36, 0.03], roverMaterials.dark);
addRoverBox(bodyPivot, [0.95, 0.12, 0.75], [0, 0.52, -0.36], roverMaterials.blue);
addRoverBox(bodyPivot, [0.88, 0.15, 0.48], [0, 0.51, 0.48], roverMaterials.orange);
addRoverBox(bodyPivot, [0.12, 0.68, 0.12], [0, 0.88, 0.2], roverMaterials.dark);
addRoverBox(bodyPivot, [0.43, 0.25, 0.34], [0, 1.24, 0.2], roverMaterials.body);
addRoverBox(bodyPivot, [0.29, 0.13, 0.04], [0, 1.24, 0.01], roverMaterials.glass);
addRoverBox(bodyPivot, [0.06, 0.5, 0.06], [0.48, 0.72, 0.52], roverMaterials.dark);
addRoverBox(bodyPivot, [0.06, 0.5, 0.06], [-0.48, 0.72, 0.52], roverMaterials.dark);
addRoverBox(bodyPivot, [0.15, 0.14, 0.12], [0.43, 0.32, -1.01], roverMaterials.glass);
addRoverBox(bodyPivot, [0.15, 0.14, 0.12], [-0.43, 0.32, -1.01], roverMaterials.glass);
addRoverBox(bodyPivot, [0.3, 0.08, 0.08], [0, 0.37, -1.05], roverMaterials.orange);
const wheelGroups = [];
const wheelPositions = [
[-0.75, -0.72], [0.75, -0.72],
[-0.75, 0], [0.75, 0],
[-0.75, 0.72], [0.75, 0.72]
];
for (const [x, z] of wheelPositions) {
const wheel = new THREE.Group();
wheel.position.set(x, 0.37, z);
rover.add(wheel);
addRoverBox(
wheel,
[0.38, 0.55, 0.68],
[0, 0, 0],
roverMaterials.dark
);
const hubSide = x < 0 ? -0.205 : 0.205;
addRoverBox(
wheel,
[0.42, 0.16, 0.16],
[hubSide, 0, 0],
roverMaterials.body
);
addRoverBox(
wheel,
[0.44, 0.055, 0.055],
[hubSide, 0, 0],
roverMaterials.orange
);
wheelGroups.push(wheel);
}
// ------------------------------------------------------------
// Sample markers
// ------------------------------------------------------------
const sampleDefinitions = [
{ x: -9.9, z: 3.0, code: "S-01" },
{ x: 9.45, z: -3.6, code: "S-02" },
{ x: 7.0, z: 9.95, code: "S-03" }
];
const samples = [];
function createSampleMarker(definition) {
const group = new THREE.Group();
group.position.set(
definition.x,
heightAt(definition.x, definition.z),
definition.z
);
const markerColor = 0x62e5ed;
const markerMaterial = new THREE.MeshStandardMaterial({
color: markerColor,
emissive: markerColor,
emissiveIntensity: 1.2,
roughness: 0.4
});
addRoverBox(group, [0.62, 0.12, 0.62], [0, 0.09, 0], roverMaterials.dark);
addRoverBox(group, [0.09, 1.15, 0.09], [0, 0.66, 0], markerMaterial);
const beacon = addRoverBox(
group,
[0.29, 0.29, 0.29],
[0, 1.3, 0],
markerMaterial,
[0, Math.PI / 4, 0]
);
// Four square pieces form a voxel ring around the sample.
addRoverBox(group, [0.52, 0.035, 0.055], [0, 0.18, 0.45], markerMaterial);
addRoverBox(group, [0.52, 0.035, 0.055], [0, 0.18, -0.45], markerMaterial);
addRoverBox(group, [0.055, 0.035, 0.52], [0.45, 0.18, 0], markerMaterial);
addRoverBox(group, [0.055, 0.035, 0.52], [-0.45, 0.18, 0], markerMaterial);
const label = createLabelSprite(definition.code, {
width: 256,
height: 96,
accent: "#68e7ed",
scale: new THREE.Vector2(1.75, 0.66)
});
label.position.set(0, 1.85, 0);
group.add(label);
scene.add(group);
const sample = {
...definition,
group,
beacon,
markerMaterial,
collected: false
};
samples.push(sample);
return sample;
}
sampleDefinitions.forEach(createSampleMarker);
// Corner boundary beacons make the finite field easy to read.
for (const x of [-HALF_SIZE + 0.65, HALF_SIZE - 0.65]) {
for (const z of [-HALF_SIZE + 0.65, HALF_SIZE - 0.65]) {
const beaconMaterial = new THREE.MeshStandardMaterial({
color: 0xff7546,
emissive: 0xff4d22,
emissiveIntensity: 1.3,
roughness: 0.5
});
addRoverBox(
scene,
[0.16, 0.9, 0.16],
[x, heightAt(x, z) + 0.45, z],
roverMaterials.dark
);
addRoverBox(
scene,
[0.22, 0.22, 0.22],
[x, heightAt(x, z) + 1.02, z],
beaconMaterial
);
}
}
// ------------------------------------------------------------
// Stars
// ------------------------------------------------------------
const starPositions = [];
for (let i = 0; i < 550; i++) {
starPositions.push(
(random() - 0.5) * 150,
9 + random() * 80,
(random() - 0.5) * 150
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xbdd2df,
size: 0.13,
transparent: true,
opacity: 0.7,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(stars);
// ------------------------------------------------------------
// Voxel dust particles
// ------------------------------------------------------------
const DUST_COUNT = 150;
const dustMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.43,
depthWrite: false
}),
DUST_COUNT
);
const dustStates = Array.from({ length: DUST_COUNT }, () => ({
life: 0,
maxLife: 1,
position: new THREE.Vector3(),
velocity: new THREE.Vector3(),
size: 0.08,
rotation: 0
}));
let dustCursor = 0;
function spawnDust(x, y, z, tint = 0x817d75, burst = false) {
const dust = dustStates[dustCursor];
dustCursor = (dustCursor + 1) % DUST_COUNT;
dust.position.set(x, y, z);
dust.velocity.set(
(random() - 0.5) * (burst ? 2.4 : 0.8),
burst ? 0.7 + random() * 1.4 : 0.25 + random() * 0.55,
(random() - 0.5) * (burst ? 2.4 : 0.8)
);
dust.maxLife = burst ? 0.65 + random() * 0.65 : 0.45 + random() * 0.6;
dust.life = dust.maxLife;
dust.size = burst ? 0.07 + random() * 0.08 : 0.035 + random() * 0.055;
dust.rotation = random() * Math.PI;
color.setHex(tint);
dustMesh.setColorAt(dustCursor === 0 ? DUST_COUNT - 1 : dustCursor - 1, color);
if (dustMesh.instanceColor) dustMesh.instanceColor.needsUpdate = true;
}
dustStates.forEach((dust, index) => {
dummy.position.set(0, -100, 0);
dummy.scale.setScalar(0);
dummy.updateMatrix();
dustMesh.setMatrixAt(index, dummy.matrix);
});
scene.add(dustMesh);
// ------------------------------------------------------------
// Direct camera controls: orbit, pan-free tracking, zoom
// ------------------------------------------------------------
const cameraState = {
radius: 28,
theta: 0.72,
phi: 1.02
};
const cameraFocus = new THREE.Vector3(
rover.position.x,
rover.position.y + 0.7,
rover.position.z
);
const desiredFocus = new THREE.Vector3();
const spherical = new THREE.Spherical();
function resetCamera() {
cameraState.radius = 28;
cameraState.theta = 0.72;
cameraState.phi = 1.02;
cameraFocus.copy(rover.position);
cameraFocus.y += 0.7;
}
document.getElementById("reset").addEventListener("click", resetCamera);
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.27, 1.42);
});
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(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9,
58
);
},
{ passive: false }
);
// ------------------------------------------------------------
// Keyboard and touch driving
// ------------------------------------------------------------
const keys = Object.create(null);
const driveCodes = new Set([
"KeyW", "KeyS", "KeyA", "KeyD",
"ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"
]);
window.addEventListener("keydown", (event) => {
if (driveCodes.has(event.code)) {
event.preventDefault();
keys[event.code] = true;
}
if (event.code === "KeyC" || event.code === "KeyR") {
resetCamera();
}
});
window.addEventListener("keyup", (event) => {
keys[event.code] = false;
});
window.addEventListener("blur", () => {
for (const code of Object.keys(keys)) keys[code] = false;
});
document.querySelectorAll("[data-code]").forEach((button) => {
const code = button.dataset.code;
button.addEventListener("pointerdown", (event) => {
event.preventDefault();
keys[code] = true;
button.classList.add("active");
button.setPointerCapture(event.pointerId);
});
const release = (event) => {
keys[code] = false;
button.classList.remove("active");
if (event.pointerId !== undefined && button.hasPointerCapture(event.pointerId)) {
button.releasePointerCapture(event.pointerId);
}
};
button.addEventListener("pointerup", release);
button.addEventListener("pointercancel", release);
button.addEventListener("lostpointercapture", release);
});
// ------------------------------------------------------------
// Rover simulation and telemetry
// ------------------------------------------------------------
let speed = 0;
let heading = 0;
let dustAccumulator = 0;
let telemetryAccumulator = 0;
const speedElement = document.getElementById("speed");
const headingElement = document.getElementById("heading");
const positionElement = document.getElementById("position");
const sampleCountElement = document.getElementById("sample-count");
const toastElement = document.getElementById("toast");
let toastTimer;
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.classList.remove("show");
}, 1700);
}
function updateRover(deltaTime) {
const forwardInput =
(keys.KeyW || keys.ArrowUp ? 1 : 0) -
(keys.KeyS || keys.ArrowDown ? 1 : 0);
const steeringInput =
(keys.KeyD || keys.ArrowRight ? 1 : 0) -
(keys.KeyA || keys.ArrowLeft ? 1 : 0);
const targetSpeed = forwardInput * 3.5;
speed = THREE.MathUtils.damp(speed, targetSpeed, 4.8, deltaTime);
const steeringDirection = speed < -0.05 ? -1 : 1;
heading += steeringInput * deltaTime * 1.35 * steeringDirection;
if (heading > Math.PI) heading -= Math.PI * 2;
if (heading < -Math.PI) heading += Math.PI * 2;
const forward = new THREE.Vector3(
Math.sin(heading),
0,
-Math.cos(heading)
);
if (Math.abs(speed) > 0.015) {
rover.position.addScaledVector(forward, speed * deltaTime);
}
const boundary = HALF_SIZE - 1.15;
const wasClamped =
Math.abs(rover.position.x) > boundary ||
Math.abs(rover.position.z) > boundary;
rover.position.x = clamp(rover.position.x, -boundary, boundary);
rover.position.z = clamp(rover.position.z, -boundary, boundary);
if (wasClamped) speed *= 0.45;
const right = new THREE.Vector3(
Math.cos(heading),
0,
Math.sin(heading)
);
const centerHeight = heightAt(rover.position.x, rover.position.z);
const frontPoint = rover.position.clone().addScaledVector(forward, 0.78);
const backPoint = rover.position.clone().addScaledVector(forward, -0.78);
const rightPoint = rover.position.clone().addScaledVector(right, 0.72);
const leftPoint = rover.position.clone().addScaledVector(right, -0.72);
const frontHeight = heightAt(frontPoint.x, frontPoint.z);
const backHeight = heightAt(backPoint.x, backPoint.z);
const rightHeight = heightAt(rightPoint.x, rightPoint.z);
const leftHeight = heightAt(leftPoint.x, leftPoint.z);
const targetY = centerHeight + 0.06;
rover.position.y = THREE.MathUtils.damp(
rover.position.y,
targetY,
10,
deltaTime
);
rover.rotation.y = -heading;
const targetPitch = Math.atan2(frontHeight - backHeight, 1.56);
const targetRoll = Math.atan2(rightHeight - leftHeight, 1.44);
bodyPivot.rotation.x = THREE.MathUtils.damp(
bodyPivot.rotation.x,
targetPitch,
7,
deltaTime
);
bodyPivot.rotation.z = THREE.MathUtils.damp(
bodyPivot.rotation.z,
targetRoll,
7,
deltaTime
);
for (const wheel of wheelGroups) {
wheel.rotation.x -= speed * deltaTime / 0.34;
}
// Rear-wheel dust while moving.
if (Math.abs(speed) > 1.2) {
dustAccumulator += deltaTime * Math.abs(speed) * 8;
while (dustAccumulator >= 1) {
dustAccumulator -= 1;
const rear = rover.position.clone().addScaledVector(forward, -0.95);
spawnDust(
rear.x + (random() - 0.5) * 0.45,
heightAt(rear.x, rear.z) + 0.18,
rear.z + (random() - 0.5) * 0.45
);
}
}
// Proximity-based sample collection.
for (const sample of samples) {
if (sample.collected) continue;
const distance = Math.hypot(
rover.position.x - sample.x,
rover.position.z - sample.z
);
if (distance < 1.05) {
sample.collected = true;
sample.markerMaterial.color.setHex(0x78f29a);
sample.markerMaterial.emissive.setHex(0x39d866);
sample.markerMaterial.emissiveIntensity = 1.65;
for (let i = 0; i < 22; i++) {
spawnDust(
sample.x,
heightAt(sample.x, sample.z) + 0.65,
sample.z,
i % 2 ? 0x68e7ed : 0x78f29a,
true
);
}
sampleCountElement.textContent =
`${samples.filter((item) => item.collected).length} / ${samples.length}`;
showToast(`${sample.code} SECURED`);
}
}
}
function updateDust(deltaTime) {
dustStates.forEach((dust, index) => {
if (dust.life > 0) {
dust.life -= deltaTime;
dust.position.addScaledVector(dust.velocity, deltaTime);
dust.velocity.y -= deltaTime * 0.55;
dust.rotation += deltaTime * 1.4;
const lifeRatio = clamp(dust.life / dust.maxLife, 0, 1);
const size = dust.size * lifeRatio;
dummy.position.copy(dust.position);
dummy.rotation.set(
dust.rotation * 0.6,
dust.rotation,
dust.rotation * 0.35
);
dummy.scale.setScalar(size);
} else {
dummy.position.set(0, -100, 0);
dummy.scale.setScalar(0);
}
dummy.updateMatrix();
dustMesh.setMatrixAt(index, dummy.matrix);
});
dustMesh.instanceMatrix.needsUpdate = true;
}
function updateCamera(deltaTime) {
desiredFocus.set(
rover.position.x,
rover.position.y + 0.75,
rover.position.z
);
cameraFocus.lerp(
desiredFocus,
1 - Math.exp(-deltaTime * 1.55)
);
spherical.set(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraFocus);
camera.lookAt(cameraFocus);
}
function updateTelemetry(deltaTime) {
telemetryAccumulator += deltaTime;
if (telemetryAccumulator < 0.08) return;
telemetryAccumulator = 0;
speedElement.textContent = `${Math.abs(speed).toFixed(1)} m/s`;
const degrees = ((heading * 180 / Math.PI) + 360) % 360;
headingElement.textContent = `${Math.round(degrees).toString().padStart(3, "0")}°`;
positionElement.textContent =
`${rover.position.x.toFixed(1)}, ${rover.position.z.toFixed(1)}`;
}
// ------------------------------------------------------------
// Resize and main loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const deltaTime = Math.min(clock.getDelta(), 0.05);
updateRover(deltaTime);
updateDust(deltaTime);
updateCamera(deltaTime);
updateTelemetry(deltaTime);
renderer.render(scene, camera);
}
updateCamera(1);
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```