Prompt specification
Build or customize the Three.js 3D scene "Crescent dune relief study" 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: Crescent dune relief study
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/crescent-dune-relief-study-x1133
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a low-poly crescent dune. Model a broad gentle windward slope leading toward a crest, with a steeper slip face on the lee side and two horns extending downwind. Place a wind-direction arrow beside the base, aligned with that geometry. Use a few subtle bands of warm sand color and enough facets to reveal the changing slope without making the surface noisy. A small ground cross-section can expose the relief beneath the crest. Keep the dune alone on a flat terrain patch so the intended transport direction and contrast between the two sides are easy to inspect.
Working Three.js Starter (crescent-dune-relief-study-x1133):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Crescent Dune — Low-Poly Wind Study</title>
<style>
:root {
color-scheme: light;
--ink: #43372c;
--muted: #766858;
--paper: rgba(248, 242, 231, 0.88);
--line: rgba(67, 55, 44, 0.16);
--accent: #28575a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee5d8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.title-card {
position: fixed;
top: 24px;
left: 26px;
z-index: 10;
width: min(310px, calc(100vw - 52px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 43px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: fixed;
right: 22px;
top: 22px;
z-index: 20;
display: flex;
gap: 7px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 999px;
padding: 9px 13px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
cursor: pointer;
backdrop-filter: blur(10px);
box-shadow: 0 4px 18px rgba(73, 51, 32, 0.06);
}
button:hover {
border-color: rgba(40, 87, 90, 0.45);
color: var(--accent);
}
button:active {
transform: translateY(1px);
}
.hint {
position: fixed;
right: 24px;
bottom: 20px;
z-index: 10;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(248, 242, 231, 0.72);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 640px) {
.title-card {
top: 18px;
left: 18px;
}
.subtitle {
max-width: 220px;
}
.controls {
top: auto;
right: 16px;
bottom: 62px;
}
.hint {
right: 16px;
bottom: 16px;
max-width: 245px;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive low-poly crescent dune scene"></div>
<header class="title-card">
<div class="eyebrow">Aeolian form / 01</div>
<h1>Crescent Dune</h1>
<p class="subtitle">
Broad windward slope, sharp crest, steep slip face, and two downwind horns.
</p>
</header>
<nav class="controls" aria-label="Camera controls">
<button id="reset-view" type="button">Reset</button>
<button id="plan-view" type="button">Plan</button>
</nav>
<div class="hint">
Drag to orbit · Shift-drag to pan · Scroll to zoom<br />
Double-click to reset · R reset · T plan
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee5d8);
scene.fog = new THREE.Fog(0xeee5d8, 27, 50);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// The camera is the target of a barchan dune:
// wind travels in world +X.
const view = {
target: new THREE.Vector3(0, 0.75, 0),
radius: 18.5,
theta: 0.67,
phi: 1.08
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
updateCamera();
// Lighting: broad sky fill and a warm directional sun.
const hemisphere = new THREE.HemisphereLight(0xfff4df, 0x896548, 1.85);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedce, 3.2);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xdce7e5, 0.55);
fill.position.set(8, 5, -8);
scene.add(fill);
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
// Flat, isolated terrain patch.
const groundShape = roundedRectangleShape(30, 22, 1.6);
const groundGeometry = new THREE.ShapeGeometry(groundShape, 12);
groundGeometry.rotateX(-Math.PI / 2);
const groundBorder = new THREE.Mesh(
groundGeometry,
new THREE.MeshStandardMaterial({
color: 0xcab79a,
roughness: 1
})
);
groundBorder.position.y = -0.045;
groundBorder.scale.set(1.012, 1, 1.012);
scene.add(groundBorder);
const ground = new THREE.Mesh(
groundGeometry,
new THREE.MeshStandardMaterial({
color: 0xeadfc9,
roughness: 1,
metalness: 0
})
);
ground.position.y = 0;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------------
// Dune geometry
// ------------------------------------------------------------------
//
// +X is downwind. Each row is an asymmetric cross-section:
// a long, low windward ramp followed by a compact, steep lee face.
// Moving the crest downwind with increasing |z| creates the horns.
const DUNE = {
halfWidth: 4.35,
height: 2.25,
crestBase: -0.75,
crestCurve: 0.34,
windwardLength: 6.2,
leeLength: 2.4
};
const WIND_SEGMENTS = 13;
const LEE_SEGMENTS = 8;
const ROW_SEGMENTS = 22;
function makeCrossSection(z) {
const lateral = Math.abs(z) / DUNE.halfWidth;
const plan = Math.max(0, 1 - lateral * lateral);
const envelope = Math.pow(plan, 0.64);
const height = DUNE.height * envelope;
const crestX =
DUNE.crestBase + DUNE.crestCurve * z * z;
const windwardLength =
DUNE.windwardLength * Math.pow(plan, 0.32);
const leeLength =
DUNE.leeLength * Math.pow(plan, 0.46);
const points = [];
// Windward face: broad and gently rising.
for (let i = 0; i <= WIND_SEGMENTS; i++) {
const u = i / WIND_SEGMENTS;
const x = crestX - windwardLength * (1 - u);
const h = height * Math.pow(u, 1.32);
points.push(new THREE.Vector3(x, h, z));
}
// Lee face: a short, steep, nearly planar slip face.
for (let i = 1; i <= LEE_SEGMENTS; i++) {
const v = i / LEE_SEGMENTS;
const x = crestX + leeLength * v;
const h = height * Math.pow(1 - v, 1.12);
points.push(new THREE.Vector3(x, h, z));
}
return points;
}
const rows = [];
for (let i = 0; i <= ROW_SEGMENTS; i++) {
const z =
-DUNE.halfWidth +
(2 * DUNE.halfWidth * i) / ROW_SEGMENTS;
rows.push(makeCrossSection(z));
}
const positions = [];
const colors = [];
const sandBands = [
new THREE.Color(0xb8794e),
new THREE.Color(0xc48755),
new THREE.Color(0xce9460),
new THREE.Color(0xdba16b),
new THREE.Color(0xe5b37b)
];
function hash(value) {
const n = Math.sin(value * 127.1 + 311.7) * 43758.5453123;
return n - Math.floor(n);
}
function bandColor(centroidY, triangleIndex) {
const normalized = THREE.MathUtils.clamp(
centroidY / DUNE.height,
0,
0.9999
);
let band = 0;
if (normalized > 0.23) band = 1;
if (normalized > 0.46) band = 2;
if (normalized > 0.69) band = 3;
if (normalized > 0.87) band = 4;
const color = sandBands[band].clone();
// Very restrained facet-to-facet variation keeps the bands
// readable without making the surface look noisy.
color.offsetHSL(0, 0, (hash(triangleIndex) - 0.5) * 0.022);
return color;
}
function pushTriangle(a, b, c, triangleIndex) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
const centroidY = (a.y + b.y + c.y) / 3;
const color = bandColor(centroidY, triangleIndex);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
let triangleIndex = 0;
for (let zIndex = 0; zIndex < ROW_SEGMENTS; zIndex++) {
const rowA = rows[zIndex];
const rowB = rows[zIndex + 1];
const columns = rowA.length;
for (let column = 0; column < columns - 1; column++) {
const a = rowA[column];
const b = rowA[column + 1];
const c = rowB[column + 1];
const d = rowB[column];
// Upward-facing winding.
pushTriangle(a, c, b, triangleIndex++);
pushTriangle(a, d, c, triangleIndex++);
}
}
const duneGeometry = new THREE.BufferGeometry();
duneGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
duneGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
duneGeometry.computeVertexNormals();
duneGeometry.computeBoundingSphere();
const dune = new THREE.Mesh(
duneGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
metalness: 0,
flatShading: true
})
);
dune.castShadow = true;
dune.receiveShadow = true;
scene.add(dune);
// ------------------------------------------------------------------
// Ground-level wind arrow
// ------------------------------------------------------------------
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-2.15, -0.11);
arrowShape.lineTo(0.85, -0.11);
arrowShape.lineTo(0.85, -0.43);
arrowShape.lineTo(2.15, 0);
arrowShape.lineTo(0.85, 0.43);
arrowShape.lineTo(0.85, 0.11);
arrowShape.lineTo(-2.15, 0.11);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
arrowGeometry.rotateX(-Math.PI / 2);
const arrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshStandardMaterial({
color: 0x28585b,
roughness: 0.82,
metalness: 0,
side: THREE.DoubleSide
})
);
const arrowGroup = new THREE.Group();
arrowGroup.position.set(-5.35, 0.035, 5.35);
arrowGroup.add(arrow);
scene.add(arrowGroup);
function makeLabel(text, foreground = "#28585b") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillStyle = "rgba(248, 242, 231, 0.92)";
context.strokeStyle = "rgba(40, 87, 90, 0.36)";
context.lineWidth = 3;
context.beginPath();
context.roundRect(8, 12, 496, 104, 24);
context.fill();
context.stroke();
context.fillStyle = foreground;
context.font = "700 38px Arial, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.75, 0.44, 1);
return sprite;
}
const windLabel = makeLabel("WIND");
windLabel.position.set(-1.0, 0.55, 0);
arrowGroup.add(windLabel);
// ------------------------------------------------------------------
// Small cutaway section
// ------------------------------------------------------------------
//
// This compact vertical slice uses the actual centerline profile.
// Its layered face exposes the relief beneath the crest while leaving
// the main dune untouched.
const sectionGroup = new THREE.Group();
sectionGroup.position.set(1.45, 0, 6.25);
scene.add(sectionGroup);
const centralProfile = makeCrossSection(0);
const rawMinX = centralProfile[0].x;
const rawMaxX = centralProfile[centralProfile.length - 1].x;
const rawCenterX = (rawMinX + rawMaxX) / 2;
const sectionScaleX = 0.62;
const sectionScaleY = 0.56;
const sectionProfile = centralProfile.map((point) => ({
x: (point.x - rawCenterX) * sectionScaleX,
y: point.y * sectionScaleY
}));
const sectionWidth =
sectionProfile[sectionProfile.length - 1].x -
sectionProfile[0].x;
const strata = [
{ bottom: 0.00, top: 0.20, color: 0x915938 },
{ bottom: 0.20, top: 0.43, color: 0xa96940 },
{ bottom: 0.43, top: 0.68, color: 0xba7b49 },
{ bottom: 0.68, top: 0.94, color: 0xc99059 },
{ bottom: 0.94, top: 1.20, color: 0xd9a46c },
{ bottom: 1.20, top: 1.40, color: 0xe5b982 }
];
const sectionPositions = [];
const sectionColors = [];
function sectionTriangle(a, b, c, color) {
sectionPositions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
sectionColors.push(color.r, color.g, color.b);
}
}
function addSectionQuad(a, b, c, d, color) {
sectionTriangle(a, b, c, color);
sectionTriangle(a, c, d, color);
}
for (const stratum of strata) {
const color = new THREE.Color(stratum.color);
for (let i = 0; i < sectionProfile.length - 1; i++) {
const p0 = sectionProfile[i];
const p1 = sectionProfile[i + 1];
// Insert crossings so each stratum remains clipped cleanly
// to the curved dune profile.
const cuts = [p0, p1];
for (const level of [stratum.bottom, stratum.top]) {
const h0 = p0.y - level;
const h1 = p1.y - level;
if ((h0 < 0 && h1 > 0) || (h1 < 0 && h0 > 0)) {
const amount = (level - p0.y) / (p1.y - p0.y);
cuts.push({
x: p0.x + (p1.x - p0.x) * amount,
y: level
});
}
}
cuts.sort((a, b) => a.x - b.x);
for (let j = 0; j < cuts.length - 1; j++) {
const a = cuts[j];
const b = cuts[j + 1];
if (a.y < stratum.bottom || b.y < stratum.bottom) continue;
const topA = Math.min(stratum.top, a.y);
const topB = Math.min(stratum.top, b.y);
if (topA <= stratum.bottom || topB <= stratum.bottom) continue;
addSectionQuad(
new THREE.Vector3(a.x, stratum.bottom, 0),
new THREE.Vector3(b.x, stratum.bottom, 0),
new THREE.Vector3(b.x, topB, 0),
new THREE.Vector3(a.x, topA, 0),
color
);
}
}
}
const sectionGeometry = new THREE.BufferGeometry();
sectionGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(sectionPositions, 3)
);
sectionGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(sectionColors, 3)
);
sectionGeometry.computeVertexNormals();
const sectionFace = new THREE.Mesh(
sectionGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 1,
side: THREE.DoubleSide,
flatShading: true
})
);
sectionFace.position.z = 0.01;
sectionFace.castShadow = true;
sectionFace.receiveShadow = true;
sectionGroup.add(sectionFace);
const sectionBase = new THREE.Mesh(
new THREE.BoxGeometry(sectionWidth + 0.12, 0.14, 0.3),
new THREE.MeshStandardMaterial({
color: 0x70503b,
roughness: 1
})
);
sectionBase.position.set(0, -0.075, 0);
sectionBase.castShadow = true;
sectionBase.receiveShadow = true;
sectionGroup.add(sectionBase);
const profileLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(
sectionProfile.map(
(point) => new THREE.Vector3(point.x, point.y + 0.015, 0.025)
)
),
new THREE.LineBasicMaterial({
color: 0x68442f,
transparent: true,
opacity: 0.8
})
);
sectionGroup.add(profileLine);
const crestLocalX =
(DUNE.crestBase - rawCenterX) * sectionScaleX;
const crestLocalY = DUNE.height * sectionScaleY;
const crestLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(crestLocalX, 0.02, 0.028),
new THREE.Vector3(crestLocalX, crestLocalY, 0.028)
]),
new THREE.LineBasicMaterial({
color: 0x68442f,
transparent: true,
opacity: 0.45
})
);
sectionGroup.add(crestLine);
const sectionLabel = makeLabel("CREST SECTION", "#6d4933");
sectionLabel.position.set(crestLocalX, crestLocalY + 0.38, 0.03);
sectionGroup.add(sectionLabel);
// ------------------------------------------------------------------
// Direct camera controls: no external controls addon.
// ------------------------------------------------------------------
let dragging = false;
let panning = false;
let pointerX = 0;
let pointerY = 0;
const forward = new THREE.Vector3();
const right = new THREE.Vector3();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
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;
if (panning || event.shiftKey) {
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
right.crossVectors(forward, camera.up).normalize();
const worldPerPixel = view.radius * 0.00145;
view.target.addScaledVector(right, -dx * worldPerPixel);
view.target.addScaledVector(forward, dy * worldPerPixel);
view.target.x = THREE.MathUtils.clamp(view.target.x, -10, 10);
view.target.z = THREE.MathUtils.clamp(view.target.z, -8, 8);
} else {
view.theta -= dx * 0.0058;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.005,
0.12,
1.46
);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
panning = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
7.5,
31
);
updateCamera();
},
{ passive: false }
);
function resetView() {
view.target.set(0, 0.75, 0);
view.radius = 18.5;
view.theta = 0.67;
view.phi = 1.08;
updateCamera();
}
function planView() {
view.target.set(0, 0.3, 0);
view.radius = 19;
view.theta = 0;
view.phi = 0.13;
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#reset-view").addEventListener("click", resetView);
document.querySelector("#plan-view").addEventListener("click", planView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetView();
if (event.key.toLowerCase() === "t") planView();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```