Prompt specification
Build or customize the Three.js 3D scene "Rover Wheelbase Over a Small Ridge" 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: Rover Wheelbase Over a Small Ridge
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rover-wheelbase-over-a-small-ridge-x3817
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: rover wheelbase over a small ridge. Model an original rover crossing a geometric ridge with visible wheel contact points. Show clearance and articulation while labeling traction and soil behavior as simplified. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (rover-wheelbase-over-a-small-ridge-x3817):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Aster-6 — Ridge Traversal Study</title>
<style>
:root {
--ink: #16343b;
--muted: #627479;
--paper: rgba(247, 244, 235, 0.88);
--line: rgba(22, 52, 59, 0.16);
--orange: #e56f3f;
--gold: #f0b64a;
--cyan: #35a7a0;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e5e8df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#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: 4;
pointer-events: none;
}
.title-block {
position: absolute;
top: 26px;
left: 28px;
width: min(390px, calc(100vw - 56px));
padding: 18px 20px 17px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(22, 52, 59, 0.09);
backdrop-filter: blur(12px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--orange);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 3px;
background: var(--orange);
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 43px);
line-height: 0.95;
letter-spacing: -0.045em;
font-weight: 760;
}
.subtitle {
margin: 12px 0 0;
max-width: 340px;
color: var(--muted);
font-size: 12.5px;
line-height: 1.55;
}
.status-panel {
position: absolute;
top: 26px;
right: 28px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
}
.pill {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 30px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
box-shadow: 0 8px 24px rgba(22, 52, 59, 0.06);
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.pill .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 3px rgba(53, 167, 160, 0.15);
}
.legend {
position: absolute;
left: 28px;
bottom: 28px;
width: 272px;
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 12px 34px rgba(22, 52, 59, 0.07);
backdrop-filter: blur(12px);
}
.legend-title {
margin-bottom: 10px;
color: var(--muted);
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 8px;
color: var(--ink);
font-size: 11.5px;
}
.swatch {
flex: 0 0 auto;
width: 18px;
height: 8px;
border-radius: 10px;
}
.swatch.contact { background: var(--gold); }
.swatch.clearance { background: var(--cyan); }
.swatch.links { background: var(--orange); }
.note {
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.controls {
position: absolute;
right: 28px;
bottom: 28px;
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--paper);
color: var(--ink);
min-height: 38px;
padding: 0 13px;
box-shadow: 0 8px 24px rgba(22, 52, 59, 0.07);
font: 750 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover { background: rgba(255, 255, 255, 0.96); }
button:active { transform: translateY(1px); }
.hint {
margin-right: 6px;
color: rgba(22, 52, 59, 0.72);
font: 600 9px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.04em;
text-align: right;
text-transform: uppercase;
}
#leaders {
position: fixed;
inset: 0;
z-index: 3;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke-width: 1.25;
stroke-dasharray: 3 3;
vector-effect: non-scaling-stroke;
}
#leaders circle {
stroke: white;
stroke-width: 1.5;
vector-effect: non-scaling-stroke;
}
#leaders .traction-line { stroke: var(--gold); }
#leaders .traction-dot { fill: var(--gold); }
#leaders .soil-line { stroke: #9d704e; }
#leaders .soil-dot { fill: #9d704e; }
#leaders .clearance-line { stroke: var(--cyan); }
#leaders .clearance-dot { fill: var(--cyan); }
#leaders .articulation-line { stroke: var(--orange); }
#leaders .articulation-dot { fill: var(--orange); }
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.callout {
position: absolute;
left: 0;
top: 0;
width: 158px;
padding: 10px 11px 9px;
border: 1px solid var(--line);
border-left: 3px solid var(--gold);
border-radius: 3px;
background: rgba(249, 247, 240, 0.94);
box-shadow: 0 8px 24px rgba(22, 52, 59, 0.10);
backdrop-filter: blur(10px);
will-change: transform;
}
.callout .kicker {
display: block;
margin-bottom: 4px;
color: var(--muted);
font: 750 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.callout strong {
display: block;
font-size: 12px;
line-height: 1.2;
font-weight: 760;
}
.callout small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9.5px;
line-height: 1.35;
}
#label-traction { border-left-color: var(--gold); }
#label-soil { border-left-color: #9d704e; }
#label-clearance { border-left-color: var(--cyan); }
#label-articulation { border-left-color: var(--orange); }
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #e5e8df;
color: var(--ink);
font: 750 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hide { opacity: 0; pointer-events: none; }
@media (max-width: 760px) {
.title-block {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 13px 15px;
}
h1 { font-size: 29px; }
.subtitle { display: none; }
.status-panel {
top: auto;
right: 14px;
bottom: 76px;
}
.pill { min-height: 25px; padding: 6px 8px; font-size: 8px; }
.legend {
left: 14px;
bottom: 14px;
width: 188px;
padding: 11px 12px;
}
.legend-row { font-size: 10px; }
.note { display: none; }
.controls { right: 14px; bottom: 14px; }
.hint { display: none; }
button { min-height: 34px; padding: 0 10px; font-size: 9px; }
.callout { width: 130px; padding: 8px 9px; }
.callout strong { font-size: 10.5px; }
.callout small { font-size: 8.5px; }
#label-soil { display: none; }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive 3D scene of a six-wheel rover crossing a geometric ridge"></div>
<svg id="leaders" aria-hidden="true">
<line id="line-traction" class="traction-line"></line>
<circle id="dot-traction" class="traction-dot" r="4"></circle>
<line id="line-soil" class="soil-line"></line>
<circle id="dot-soil" class="soil-dot" r="4"></circle>
<line id="line-clearance" class="clearance-line"></line>
<circle id="dot-clearance" class="clearance-dot" r="4"></circle>
<line id="line-articulation" class="articulation-line"></line>
<circle id="dot-articulation" class="articulation-dot" r="4"></circle>
</svg>
<div id="labels" aria-hidden="true">
<div id="label-traction" class="callout">
<span class="kicker">Traction</span>
<strong>Visible contact patch</strong>
<small>Stylized friction limit; no tire-slip simulation.</small>
</div>
<div id="label-soil" class="callout">
<span class="kicker">Soil behavior</span>
<strong>Cohesive regolith</strong>
<small>Simplified support and bearing assumption.</small>
</div>
<div id="label-clearance" class="callout">
<span class="kicker">Underbody clearance</span>
<strong id="clearance-value">0.00 m</strong>
<small>Measured to the sampled terrain surface.</small>
</div>
<div id="label-articulation" class="callout">
<span class="kicker">Articulation</span>
<strong>Rocker–bogie linkage</strong>
<small>Exaggerated travel for visual explanation.</small>
</div>
</div>
<div class="hud">
<section class="title-block">
<div class="eyebrow">Ridge trial / R-06</div>
<h1>Aster-6</h1>
<p class="subtitle">
An original six-wheel exploration concept crossing a faceted soil ridge.
Contact patches, body clearance, and suspension travel are made explicit.
</p>
</section>
<aside class="status-panel">
<div class="pill"><span class="dot"></span><span id="motion-state">Traversing</span></div>
<div class="pill">Triangular ridge / 1.05 m</div>
<div class="pill">2.90 m wheelbase / 6 contacts</div>
</aside>
<section class="legend">
<div class="legend-title">Scene key</div>
<div class="legend-row"><span class="swatch contact"></span>Sampled wheel contact</div>
<div class="legend-row"><span class="swatch clearance"></span>Vertical clearance</div>
<div class="legend-row"><span class="swatch links"></span>Articulated support links</div>
<div class="note">
* Kinematic visualization only. Soil, traction, and compliance are simplified;
values are not intended for engineering validation.
</div>
</section>
<div class="controls">
<div class="hint">Drag: orbit<br>Shift + drag: pan<br>Scroll: zoom</div>
<button id="pause-button" type="button">Pause</button>
<button id="reset-button" type="button">Reset view</button>
</div>
</div>
<div id="loading">Loading Three.js scene…</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.getElementById("scene");
const loading = document.getElementById("loading");
const pauseButton = document.getElementById("pause-button");
const resetButton = document.getElementById("reset-button");
const motionState = document.getElementById("motion-state");
const clearanceValue = document.getElementById("clearance-value");
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
loading.textContent = "WebGL could not be initialized";
throw error;
}
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;
renderer.domElement.setAttribute("aria-label", "Aster-6 rover on a geometric ridge");
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e5e8df");
scene.fog = new THREE.Fog("#e5e8df", 15, 31);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 0.8, 0);
let cameraRadius = 12.4;
let cameraTheta = 0.72;
let cameraPhi = 1.03;
function updateCamera() {
const spherical = new THREE.Spherical(cameraRadius, cameraPhi, cameraTheta);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraRadius = 12.4;
cameraTheta = 0.72;
cameraPhi = 1.03;
cameraTarget.set(0, 0.8, 0);
updateCamera();
}
updateCamera();
const hemi = new THREE.HemisphereLight("#f8f2df", "#6f776a", 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff3d7", 3.2);
sun.position.set(6, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rim = new THREE.DirectionalLight("#c4e7df", 1.0);
rim.position.set(-6, 5, -7);
scene.add(rim);
const palette = {
navy: new THREE.MeshStandardMaterial({ color: "#173a43", roughness: 0.72, metalness: 0.18 }),
navyDark: new THREE.MeshStandardMaterial({ color: "#102b31", roughness: 0.78, metalness: 0.16 }),
ivory: new THREE.MeshStandardMaterial({ color: "#eee7d5", roughness: 0.68, metalness: 0.04 }),
orange: new THREE.MeshStandardMaterial({ color: "#e66f3f", roughness: 0.6, metalness: 0.08 }),
cyan: new THREE.MeshStandardMaterial({ color: "#3aa7a0", roughness: 0.58, metalness: 0.16 }),
rubber: new THREE.MeshStandardMaterial({ color: "#20292a", roughness: 0.95, metalness: 0.02 }),
metal: new THREE.MeshStandardMaterial({ color: "#9ca9a7", roughness: 0.42, metalness: 0.62 }),
solar: new THREE.MeshStandardMaterial({ color: "#173e54", roughness: 0.34, metalness: 0.34 })
};
function addBox(parent, w, h, d, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Faceted terrain: a linear triangular ridge running across the scene.
const TERRAIN_W = 14;
const TERRAIN_D = 16;
const NX = 56;
const NZ = 64;
function terrainHeight(x, z) {
const ridge = 1.05 * Math.max(0, 1 - Math.abs(z) / 2.6);
const shoulder = 0.055 * Math.sin(x * 0.73 + z * 0.28)
+ 0.035 * Math.cos(z * 0.91 - x * 0.42);
return ridge + shoulder;
}
function terrainNormal(x, z) {
const e = 0.025;
const dx = (terrainHeight(x + e, z) - terrainHeight(x - e, z)) / (2 * e);
const dz = (terrainHeight(x, z + e) - terrainHeight(x, z - e)) / (2 * e);
return new THREE.Vector3(-dx, 1, -dz).normalize();
}
function buildTerrain() {
const positions = [];
const colors = [];
const indices = [];
const low = new THREE.Color("#b79260");
const high = new THREE.Color("#d5bb86");
const shade = new THREE.Color();
for (let iz = 0; iz <= NZ; iz++) {
const z = -TERRAIN_D / 2 + (iz / NZ) * TERRAIN_D;
for (let ix = 0; ix <= NX; ix++) {
const x = -TERRAIN_W / 2 + (ix / NX) * TERRAIN_W;
const y = terrainHeight(x, z);
positions.push(x, y, z);
const t = THREE.MathUtils.clamp(y / 1.05, 0, 1);
shade.copy(low).lerp(high, t * 0.72 + 0.10);
colors.push(shade.r, shade.g, shade.b);
}
}
for (let iz = 0; iz < NZ; iz++) {
for (let ix = 0; ix < NX; ix++) {
const a = iz * (NX + 1) + ix;
const b = a + 1;
const c = a + NX + 1;
const d = c + 1;
indices.push(a, c, b, 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.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
metalness: 0,
flatShading: true,
polygonOffset: true,
polygonOffsetFactor: 1,
polygonOffsetUnits: 1
});
const mesh = new THREE.Mesh(geometry, material);
mesh.receiveShadow = true;
scene.add(mesh);
const wire = new THREE.LineSegments(
new THREE.WireframeGeometry(geometry),
new THREE.LineBasicMaterial({
color: "#5b4b36",
transparent: true,
opacity: 0.09,
depthWrite: false
})
);
wire.position.y = 0.004;
scene.add(wire);
// Terrain skirt and base give the ridge a physical, model-like edge.
const perimeter = [];
for (let i = 0; i <= 56; i++) perimeter.push([-7 + i * 0.25, -8]);
for (let i = 1; i <= 64; i++) perimeter.push([7, -8 + i * 0.25]);
for (let i = 1; i <= 56; i++) perimeter.push([7 - i * 0.25, 8]);
for (let i = 1; i < 64; i++) perimeter.push([-7, 8 - i * 0.25]);
const skirtPositions = [];
for (let i = 0; i < perimeter.length - 1; i++) {
const [ax, az] = perimeter[i];
const [bx, bz] = perimeter[i + 1];
const ay = terrainHeight(ax, az);
const by = terrainHeight(bx, bz);
skirtPositions.push(
ax, ay, az, ax, -0.38, az, bx, by, bz,
bx, by, bz, ax, -0.38, az, bx, -0.38, bz
);
}
const skirtGeometry = new THREE.BufferGeometry();
skirtGeometry.setAttribute("position", new THREE.Float32BufferAttribute(skirtPositions, 3));
skirtGeometry.computeVertexNormals();
const skirt = new THREE.Mesh(
skirtGeometry,
new THREE.MeshStandardMaterial({ color: "#9a7953", roughness: 1, side: THREE.DoubleSide })
);
skirt.receiveShadow = true;
scene.add(skirt);
addBox(scene, 14.2, 0.16, 16.2,
new THREE.MeshStandardMaterial({ color: "#856847", roughness: 1 }),
0, -0.46, 0
);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({ color: "#e5e8df", roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.55;
floor.receiveShadow = true;
scene.add(floor);
// Bright crest reference line.
const crestPoints = [];
for (let x = -6.8; x <= 6.8; x += 0.2) {
crestPoints.push(new THREE.Vector3(x, terrainHeight(x, 0) + 0.025, 0));
}
scene.add(new THREE.Line(
new THREE.BufferGeometry().setFromPoints(crestPoints),
new THREE.LineBasicMaterial({ color: "#e9944d", transparent: true, opacity: 0.65 })
));
// Subtle wheel tracks conform to the faceted soil.
for (const x of [-1.08, 1.08]) {
const p = [];
const idx = [];
let row = 0;
for (let z = -7; z <= 7; z += 0.1) {
p.push(x - 0.045, terrainHeight(x - 0.045, z) + 0.018, z);
p.push(x + 0.045, terrainHeight(x + 0.045, z) + 0.018, z);
if (row > 0) {
const a = (row - 1) * 2;
idx.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
}
row++;
}
const trackGeometry = new THREE.BufferGeometry();
trackGeometry.setAttribute("position", new THREE.Float32BufferAttribute(p, 3));
trackGeometry.setIndex(idx);
trackGeometry.computeVertexNormals();
const track = new THREE.Mesh(
trackGeometry,
new THREE.MeshBasicMaterial({
color: "#65482e",
transparent: true,
opacity: 0.14,
depthWrite: false,
side: THREE.DoubleSide
})
);
scene.add(track);
}
}
buildTerrain();
// Deterministic scattered soil stones.
let randomSeed = 8147;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const rockGeometry = new THREE.IcosahedronGeometry(0.055, 0);
const rockMaterial = new THREE.MeshStandardMaterial({ color: "#9e805b", roughness: 1 });
const rocks = new THREE.InstancedMesh(rockGeometry, rockMaterial, 150);
const dummy = new THREE.Object3D();
for (let i = 0; i < 150; i++) {
const x = (random() - 0.5) * 13.2;
const z = (random() - 0.5) * 15.2;
const scale = 0.45 + random() * 1.5;
dummy.position.set(x, terrainHeight(x, z) + 0.035 * scale, z);
dummy.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
dummy.scale.set(scale, scale * (0.55 + random() * 0.55), scale);
dummy.updateMatrix();
rocks.setMatrixAt(i, dummy.matrix);
}
rocks.instanceMatrix.needsUpdate = true;
rocks.receiveShadow = true;
scene.add(rocks);
// Rover body.
const body = new THREE.Group();
scene.add(body);
addBox(body, 1.50, 0.34, 2.22, palette.navy, 0, 0, 0);
addBox(body, 1.23, 0.13, 1.78, palette.navyDark, 0, -0.215, 0);
addBox(body, 1.20, 0.25, 1.08, palette.ivory, 0, 0.285, -0.18);
addBox(body, 1.08, 0.045, 0.79, palette.solar, 0, 0.432, -0.18);
// Solar-cell divisions.
for (let x = -0.40; x <= 0.41; x += 0.20) {
addBox(body, 0.012, 0.009, 0.76, palette.metal, x, 0.459, -0.18);
}
for (let z = -0.50; z <= 0.14; z += 0.16) {
addBox(body, 1.02, 0.009, 0.012, palette.metal, 0, 0.459, z);
}
// Sloped nose.
const noseGeometry = new THREE.BufferGeometry();
noseGeometry.setAttribute("position", new THREE.Float32BufferAttribute([
-0.58, -0.09, 1.04, 0.58, -0.09, 1.04,
-0.40, 0.05, 1.42, 0.40, 0.05, 1.42,
-0.58, 0.18, 1.04, 0.58, 0.18, 1.04
], 3));
noseGeometry.setIndex([
0, 1, 2, 1, 3, 2,
4, 6, 5, 5, 6, 7,
0, 4, 1, 1, 4, 5,
2, 3, 6, 3, 7, 6,
0, 2, 4, 4, 2, 6,
1, 5, 3, 3, 5, 7
]);
noseGeometry.computeVertexNormals();
const nose = new THREE.Mesh(noseGeometry, palette.orange);
nose.castShadow = true;
nose.receiveShadow = true;
body.add(nose);
addBox(body, 1.12, 0.09, 0.11, palette.cyan, 0, -0.02, 1.40);
addBox(body, 0.025, 0.08, 1.24, palette.orange, -0.761, 0.025, -0.03);
addBox(body, 0.025, 0.08, 1.24, palette.orange, 0.761, 0.025, -0.03);
// Mast, camera head, lens, and antenna.
const mast = new THREE.Mesh(new THREE.CylinderGeometry(0.027, 0.035, 0.82, 12), palette.metal);
mast.position.set(0, 0.79, 0.48);
mast.castShadow = true;
body.add(mast);
addBox(body, 0.50, 0.20, 0.25, palette.ivory, 0, 1.20, 0.48);
addBox(body, 0.42, 0.035, 0.015, palette.navyDark, 0, 1.245, 0.612);
const lensGeometry = new THREE.CylinderGeometry(0.070, 0.070, 0.12, 18);
lensGeometry.rotateX(Math.PI / 2);
const lens = new THREE.Mesh(lensGeometry, palette.navyDark);
lens.position.set(0.08, 1.20, 0.66);
lens.castShadow = true;
body.add(lens);
const antenna = new THREE.Mesh(new THREE.CylinderGeometry(0.012, 0.018, 0.85, 8), palette.metal);
antenna.position.set(-0.43, 0.80, -0.47);
antenna.rotation.z = -0.08;
antenna.castShadow = true;
body.add(antenna);
const antennaTip = new THREE.Mesh(new THREE.SphereGeometry(0.045, 12, 8), palette.orange);
antennaTip.position.set(-0.465, 1.225, -0.47);
body.add(antennaTip);
// Wheel factory.
const WHEEL_RADIUS = 0.45;
function makeWheel(side) {
const wheel = new THREE.Group();
const tireGeometry = new THREE.TorusGeometry(0.30, 0.13, 10, 24);
tireGeometry.rotateY(Math.PI / 2);
const tire = new THREE.Mesh(tireGeometry, palette.rubber);
tire.castShadow = true;
tire.receiveShadow = true;
wheel.add(tire);
const hubGeometry = new THREE.CylinderGeometry(0.185, 0.185, 0.32, 18);
hubGeometry.rotateZ(Math.PI / 2);
const hub = new THREE.Mesh(hubGeometry, palette.cyan);
hub.castShadow = true;
wheel.add(hub);
const capGeometry = new THREE.CircleGeometry(0.142, 20);
capGeometry.rotateY(Math.PI / 2);
const capMaterial = palette.orange.clone();
capMaterial.side = THREE.DoubleSide;
const cap = new THREE.Mesh(capGeometry, capMaterial);
cap.position.x = side * 0.168;
wheel.add(cap);
for (let i = 0; i < 6; i++) {
const spoke = addBox(
wheel, 0.025, 0.235, 0.032, palette.ivory,
side * 0.184, 0, 0
);
spoke.rotation.x = (i / 6) * Math.PI * 2;
}
for (let i = 0; i < 14; i++) {
const angle = (i / 14) * Math.PI * 2;
const tread = addBox(
wheel, 0.345, 0.075, 0.105, palette.rubber,
0, Math.cos(angle) * 0.407, Math.sin(angle) * 0.407
);
tread.rotation.x = angle;
}
scene.add(wheel);
return wheel;
}
function makeContactPatch() {
const group = new THREE.Group();
const circleGeometry = new THREE.CircleGeometry(0.115, 24);
circleGeometry.rotateX(-Math.PI / 2);
const circle = new THREE.Mesh(
circleGeometry,
new THREE.MeshBasicMaterial({
color: "#f0b64a",
transparent: true,
opacity: 0.52,
depthWrite: false,
side: THREE.DoubleSide
})
);
group.add(circle);
const ringGeometry = new THREE.RingGeometry(0.135, 0.175, 24);
ringGeometry.rotateX(-Math.PI / 2);
const ring = new THREE.Mesh(
ringGeometry,
new THREE.MeshBasicMaterial({
color: "#f4c55e",
transparent: true,
opacity: 0.96,
depthWrite: false,
side: THREE.DoubleSide
})
);
group.add(ring);
scene.add(group);
return group;
}
const wheels = [];
const zOffsets = [-1.45, 0, 1.45];
for (const side of [-1, 1]) {
for (const zOffset of zOffsets) {
const wheel = makeWheel(side);
const patch = makeContactPatch();
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute("position", new THREE.Float32BufferAttribute([0, 0, 0, 0, 0, 0], 3));
const contactLine = new THREE.Line(
lineGeometry,
new THREE.LineDashedMaterial({
color: "#f0b64a",
dashSize: 0.065,
gapSize: 0.045,
transparent: true,
opacity: 0.82,
depthTest: false
})
);
contactLine.renderOrder = 6;
scene.add(contactLine);
wheels.push({
side,
zOffset,
wheel,
patch,
contactLine,
center: new THREE.Vector3(),
ground: new THREE.Vector3()
});
}
}
// Articulated rocker-bogie rods.
const rodGeometry = new THREE.CylinderGeometry(1, 1, 1, 12);
const upAxis = new THREE.Vector3(0, 1, 0);
function makeRod(material) {
const rod = new THREE.Mesh(rodGeometry, material);
rod.castShadow = true;
scene.add(rod);
return rod;
}
function setRod(rod, a, b, radius) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
rod.position.copy(a).add(b).multiplyScalar(0.5);
rod.quaternion.setFromUnitVectors(upAxis, direction.normalize());
rod.scale.set(radius, length, radius);
}
function makeJoint(material) {
const joint = new THREE.Mesh(new THREE.SphereGeometry(0.075, 14, 10), material);
joint.castShadow = true;
scene.add(joint);
return joint;
}
const suspension = [-1, 1].map(() => ({
mainFront: makeRod(palette.orange),
mainRear: makeRod(palette.orange),
bogieMiddle: makeRod(palette.cyan),
bogieRear: makeRod(palette.cyan),
mountJoint: makeJoint(palette.orange),
bogieJoint: makeJoint(palette.cyan)
}));
// Underbody clearance gauge.
const clearanceMaterial = new THREE.LineBasicMaterial({
color: "#35a7a0",
transparent: true,
opacity: 0.95,
depthTest: false
});
function dynamicLine(color = "#35a7a0") {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute([0, 0, 0, 0, 0, 0], 3));
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({ color, transparent: true, opacity: 0.95, depthTest: false })
);
line.renderOrder = 7;
scene.add(line);
return line;
}
const clearanceVertical = dynamicLine();
const clearanceTopTick = dynamicLine();
const clearanceBottomTick = dynamicLine();
const clearanceTopDot = new THREE.Mesh(
new THREE.SphereGeometry(0.038, 12, 8),
new THREE.MeshBasicMaterial({ color: "#35a7a0", depthTest: false })
);
const clearanceBottomDot = clearanceTopDot.clone();
clearanceTopDot.renderOrder = 8;
clearanceBottomDot.renderOrder = 8;
scene.add(clearanceTopDot, clearanceBottomDot);
const annotationWorld = {
traction: new THREE.Vector3(),
soil: new THREE.Vector3(),
clearance: new THREE.Vector3(),
articulation: new THREE.Vector3()
};
let previousBodyZ = 0;
let wheelSpin = 0;
let running = !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function updateRover(elapsed, now) {
// A slow reversible crossing keeps the ridge centered in the composition.
const bodyZ = 2.6 * Math.sin(elapsed * 0.38 - 0.40);
const deltaZ = bodyZ - previousBodyZ;
wheelSpin -= deltaZ / WHEEL_RADIUS;
previousBodyZ = bodyZ;
let leftY = 0;
let rightY = 0;
let frontY = 0;
let rearY = 0;
let averageY = 0;
let count = 0;
for (const item of wheels) {
const x = item.side * 1.08;
const z = bodyZ + item.zOffset;
const groundY = terrainHeight(x, z);
const centerY = groundY + WHEEL_RADIUS;
item.ground.set(x, groundY, z);
item.center.set(x, centerY, z);
item.wheel.position.copy(item.center);
item.wheel.rotation.x = wheelSpin;
item.patch.position.copy(item.ground).add(new THREE.Vector3(0, 0.024, 0));
item.patch.quaternion.setFromUnitVectors(upAxis, terrainNormal(x, z));
const pulse = 1 + 0.07 * Math.sin(now * 0.004 + count);
item.patch.scale.setScalar(pulse);
const positions = item.contactLine.geometry.attributes.position;
positions.setXYZ(0, x, groundY + 0.025, z);
positions.setXYZ(1, x, centerY + 0.03, z);
positions.needsUpdate = true;
item.contactLine.computeLineDistances();
if (item.side < 0) leftY += centerY;
else rightY += centerY;
if (item.zOffset > 1) frontY += centerY;
if (item.zOffset < -1) rearY += centerY;
averageY += centerY;
count++;
}
leftY /= 3;
rightY /= 3;
frontY /= 2;
rearY /= 2;
averageY /= count;
const pitch = -Math.atan2(frontY - rearY, 2.9);
const roll = Math.atan2(rightY - leftY, 2.16);
body.position.set(0, averageY + 0.31, bodyZ);
body.rotation.set(pitch, 0, roll);
body.updateMatrixWorld(true);
for (let index = 0; index < 2; index++) {
const side = index === 0 ? -1 : 1;
const links = suspension[index];
const front = wheels.find(w => w.side === side && w.zOffset === 1.45);
const middle = wheels.find(w => w.side === side && w.zOffset === 0);
const rear = wheels.find(w => w.side === side && w.zOffset === -1.45);
const mount = body.localToWorld(new THREE.Vector3(side * 0.63, -0.17, 0.18));
const frontHub = front.center.clone().add(new THREE.Vector3(0, 0.015, 0));
const middleHub = middle.center.clone().add(new THREE.Vector3(0, 0.015, 0));
const rearHub = rear.center.clone().add(new THREE.Vector3(0, 0.015, 0));
const bogie = middleHub.clone().add(rearHub).multiplyScalar(0.5);
bogie.y += 0.07;
setRod(links.mainFront, mount, frontHub, 0.055);
setRod(links.mainRear, mount, bogie, 0.055);
setRod(links.bogieMiddle, bogie, middleHub, 0.043);
setRod(links.bogieRear, bogie, rearHub, 0.043);
links.mountJoint.position.copy(mount);
links.bogieJoint.position.copy(bogie);
if (side === 1) annotationWorld.articulation.copy(bogie);
}
// Clearance is measured vertically from the transformed belly to sampled soil.
const underside = body.localToWorld(new THREE.Vector3(0.76, -0.235, 0.23));
const ground = new THREE.Vector3(
underside.x,
terrainHeight(underside.x, underside.z),
underside.z
);
const clearance = Math.max(0, underside.y - ground.y);
clearanceValue.textContent = `${clearance.toFixed(2)} m`;
const vPositions = clearanceVertical.geometry.attributes.position;
vPositions.setXYZ(0, underside.x, ground.y, underside.z);
vPositions.setXYZ(1, underside.x, underside.y, underside.z);
vPositions.needsUpdate = true;
const topPositions = clearanceTopTick.geometry.attributes.position;
topPositions.setXYZ(0, underside.x - 0.13, underside.y, underside.z);
topPositions.setXYZ(1, underside.x + 0.13, underside.y, underside.z);
topPositions.needsUpdate = true;
const bottomPositions = clearanceBottomTick.geometry.attributes.position;
bottomPositions.setXYZ(0, underside.x - 0.13, ground.y, underside.z);
bottomPositions.setXYZ(1, underside.x + 0.13, ground.y, underside.z);
bottomPositions.needsUpdate = true;
clearanceTopDot.position.copy(underside);
clearanceBottomDot.position.copy(ground);
annotationWorld.clearance.copy(underside).lerp(ground, 0.5);
const tractionWheel = wheels.find(w => w.side === -1 && w.zOffset === 1.45);
const soilWheel = wheels.find(w => w.side === 1 && w.zOffset === -1.45);
annotationWorld.traction.copy(tractionWheel.ground);
annotationWorld.soil.copy(soilWheel.ground);
}
// Screen-space annotations projected from 3D anchor points.
const annotations = [
{
key: "traction",
label: document.getElementById("label-traction"),
line: document.getElementById("line-traction"),
dot: document.getElementById("dot-traction"),
desktop: [-184, 48],
mobile: [-142, 35]
},
{
key: "soil",
label: document.getElementById("label-soil"),
line: document.getElementById("line-soil"),
dot: document.getElementById("dot-soil"),
desktop: [36, 50],
mobile: [36, 50]
},
{
key: "clearance",
label: document.getElementById("label-clearance"),
line: document.getElementById("line-clearance"),
dot: document.getElementById("dot-clearance"),
desktop: [42, -88],
mobile: [24, -76]
},
{
key: "articulation",
label: document.getElementById("label-articulation"),
line: document.getElementById("line-articulation"),
dot: document.getElementById("dot-articulation"),
desktop: [-184, -72],
mobile: [-145, -64]
}
];
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
const world = annotationWorld[annotation.key];
const projected = world.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.label.style.display = visible ? "block" : "none";
annotation.line.style.display = visible ? "block" : "none";
annotation.dot.style.display = visible ? "block" : "none";
if (!visible) continue;
const ax = (projected.x * 0.5 + 0.5) * width;
const ay = (-projected.y * 0.5 + 0.5) * height;
const offset = width < 760 ? annotation.mobile : annotation.desktop;
const labelWidth = annotation.label.offsetWidth;
const labelHeight = annotation.label.offsetHeight;
const lx = THREE.MathUtils.clamp(ax + offset[0], 10, width - labelWidth - 10);
const ly = THREE.MathUtils.clamp(ay + offset[1], 10, height - labelHeight - 10);
annotation.label.style.transform = `translate3d(${lx}px, ${ly}px, 0)`;
const endX = offset[0] < 0 ? lx + labelWidth : lx;
const endY = THREE.MathUtils.clamp(ay, ly + 10, ly + labelHeight - 10);
annotation.line.setAttribute("x1", ax);
annotation.line.setAttribute("y1", ay);
annotation.line.setAttribute("x2", endX);
annotation.line.setAttribute("y2", endY);
annotation.dot.setAttribute("cx", ax);
annotation.dot.setAttribute("cy", ay);
}
}
// Direct camera controls, implemented without Three.js addons.
const canvas = renderer.domElement;
let dragging = false;
let dragMode = "orbit";
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (dragMode === "orbit") {
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(cameraPhi - dy * 0.005, 0.30, 1.43);
} else {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = cameraRadius * 0.0015;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(up, dy * scale);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, -0.2, 3.5);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -4, 4);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -5, 5);
}
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) canvas.releasePointerCapture(event.pointerId);
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
6.0,
20.0
);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
pauseButton.addEventListener("click", () => {
running = !running;
pauseButton.textContent = running ? "Pause" : "Resume";
motionState.textContent = running ? "Traversing" : "Paused";
});
resetButton.addEventListener("click", resetCamera);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
let elapsed = 0;
function frame(now) {
const dt = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (running) elapsed += dt;
updateRover(elapsed, now);
updateCamera();
renderer.render(scene, camera);
updateAnnotations();
requestAnimationFrame(frame);
}
updateRover(0, performance.now());
renderer.render(scene, camera);
updateAnnotations();
loading.classList.add("hide");
setTimeout(() => loading.remove(), 350);
requestAnimationFrame(frame);
</script>
</body>
</html>
```