Prompt specification
Build or customize the Three.js 3D scene "Stacked contour hill rings" 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: Stacked contour hill rings
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stacked-contour-hill-rings-x1293
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Build a stepped hill from nested contour plates with equal height intervals. Label three elevations and leave one side open to expose the vertical spacing.
Working Three.js Starter (stacked-contour-hill-rings-x1293):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Contour Hill — Three.js</title>
<style>
:root {
--ink: #243b43;
--paper: #f4efe6;
--muted: #6f7b78;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
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%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 5;
top: 28px;
left: 30px;
width: min(290px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #657b78;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(31px, 4vw, 52px);
font-weight: 750;
letter-spacing: -0.055em;
line-height: 0.94;
}
.subtitle {
margin: 13px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.subtitle strong {
color: var(--ink);
font-weight: 700;
}
#label-layer {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.elevation-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 8px 5px 7px;
border-left: 3px solid var(--accent);
border-radius: 2px 5px 5px 2px;
background: rgba(250, 247, 239, 0.94);
box-shadow: 0 5px 16px rgba(36, 59, 67, 0.12);
color: var(--ink);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
white-space: nowrap;
transform: translate(15px, -50%);
transition: opacity 150ms ease;
}
.elevation-label.flip {
transform: translate(calc(-100% - 15px), -50%);
}
.elevation-label::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
content: "";
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.elevation-label.is-hidden {
opacity: 0;
}
.footer {
position: fixed;
z-index: 5;
right: 26px;
bottom: 24px;
display: flex;
align-items: center;
gap: 14px;
color: #61716f;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.footer .divider {
width: 1px;
height: 18px;
background: rgba(36, 59, 67, 0.2);
}
#reset {
padding: 9px 12px;
border: 1px solid rgba(36, 59, 67, 0.25);
border-radius: 999px;
background: rgba(250, 247, 239, 0.82);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
}
#reset:hover {
background: #fffaf0;
border-color: rgba(36, 59, 67, 0.45);
}
@media (max-width: 650px) {
.title-card {
top: 20px;
left: 20px;
}
.subtitle {
max-width: 230px;
}
.footer {
right: 18px;
bottom: 18px;
gap: 9px;
}
.footer .desktop-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="label-layer" aria-hidden="true"></div>
<header class="title-card">
<div class="eyebrow">Topographic model / 01</div>
<h1>Contour<br />Hill</h1>
<p class="subtitle">
Nested contour plates with <strong>equal 120 m intervals</strong>.
The near side is cut away to reveal the elevation spacing.
</p>
</header>
<footer class="footer">
<span class="desktop-hint">Drag to orbit · Scroll to zoom</span>
<span class="divider"></span>
<button id="reset" type="button">Reset view</button>
</footer>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.getElementById("scene");
const labelLayer = document.getElementById("label-layer");
const resetButton = document.getElementById("reset");
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf4efe6);
scene.fog = new THREE.Fog(0xf4efe6, 14, 29);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional contour hill"
);
sceneRoot.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xfff9ec,
0x61706c,
1.75
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff7e8, 2.8);
sun.position.set(5.5, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 24;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc7dfeb, 1.15);
fill.position.set(-6, 5, -7);
scene.add(fill);
// ------------------------------------------------------------
// Ground and display platform
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
new THREE.MeshStandardMaterial({
color: 0xf4efe6,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.2;
ground.receiveShadow = true;
scene.add(ground);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5.45, 5.58, 0.2, 96),
new THREE.MeshStandardMaterial({
color: 0xe8dfcf,
roughness: 0.95
})
);
platform.position.y = -0.1;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xbeb3a0,
transparent: true,
opacity: 0.5
});
[3.85, 4.55, 5.12].forEach((radius) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.012, 6, 160),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.006;
scene.add(ring);
});
// ------------------------------------------------------------
// Nested contour plates
//
// Local shape coordinates are X/Y. After rotating the extrusion
// by -90 degrees, extrusion depth becomes world Y.
// ------------------------------------------------------------
const BASE_RADIUS = 3.05;
const LEVEL_HEIGHT = 1.2;
const WEDGE_CENTER_LOCAL = -Math.PI / 4;
const WEDGE_HALF = Math.PI * 0.23;
const plateScales = [1, 0.72, 0.44];
const palettes = [
{ top: 0x8ea68a, side: 0x617762, accent: "#8ea68a" },
{ top: 0xd8ad62, side: 0xa77c3f, accent: "#d8ad62" },
{ top: 0xd87359, side: 0xa84f3f, accent: "#d87359" }
];
function radialVariation(angle) {
return (
1 +
0.075 * Math.sin(3 * angle + 0.4) +
0.035 * Math.cos(5 * angle - 0.8) +
0.018 * Math.sin(9 * angle)
);
}
function makeContourShape(scale) {
const shape = new THREE.Shape();
const start = WEDGE_CENTER_LOCAL + WEDGE_HALF;
const end = WEDGE_CENTER_LOCAL + Math.PI * 2 - WEDGE_HALF;
const segments = 112;
// The center vertex and major outer arc leave a radial sector open.
shape.moveTo(0, 0);
for (let i = 0; i <= segments; i++) {
const angle = start + (end - start) * (i / segments);
const radius = BASE_RADIUS * scale * radialVariation(angle);
const x = Math.cos(angle) * radius;
const y = Math.sin(angle) * radius;
if (i === 0) {
shape.lineTo(x, y);
} else {
shape.lineTo(x, y);
}
}
shape.closePath();
return shape;
}
const contourGroup = new THREE.Group();
scene.add(contourGroup);
plateScales.forEach((scale, index) => {
const geometry = new THREE.ExtrudeGeometry(makeContourShape(scale), {
depth: LEVEL_HEIGHT,
steps: 1,
bevelEnabled: false,
curveSegments: 1
});
geometry.rotateX(-Math.PI / 2);
const palette = palettes[index];
const topMaterial = new THREE.MeshStandardMaterial({
color: palette.top,
roughness: 0.8,
metalness: 0
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: palette.side,
roughness: 0.88,
metalness: 0,
polygonOffset: true,
polygonOffsetFactor: 1,
polygonOffsetUnits: 1
});
const mesh = new THREE.Mesh(geometry, [topMaterial, sideMaterial]);
mesh.position.y = index * LEVEL_HEIGHT;
mesh.castShadow = true;
mesh.receiveShadow = true;
contourGroup.add(mesh);
const edgeGeometry = new THREE.EdgesGeometry(geometry, 28);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x243b43,
transparent: true,
opacity: 0.28
});
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
edges.position.y = index * LEVEL_HEIGHT;
contourGroup.add(edges);
});
// ------------------------------------------------------------
// Highlight the two vertical cut faces
// ------------------------------------------------------------
const sectionMaterial = new THREE.LineBasicMaterial({
color: 0x243b43,
transparent: true,
opacity: 0.72
});
function boundaryPoint(angle, scale, y) {
const radius = BASE_RADIUS * scale * radialVariation(angle);
return new THREE.Vector3(
Math.cos(angle) * radius,
y,
-Math.sin(angle) * radius
);
}
plateScales.forEach((scale, index) => {
const bottom = index * LEVEL_HEIGHT;
const top = bottom + LEVEL_HEIGHT;
[WEDGE_CENTER_LOCAL + WEDGE_HALF,
WEDGE_CENTER_LOCAL + Math.PI * 2 - WEDGE_HALF
].forEach((angle) => {
const edge = boundaryPoint(angle, scale, 0);
const points = [
new THREE.Vector3(0, bottom, 0),
new THREE.Vector3(edge.x, bottom, edge.z),
new THREE.Vector3(edge.x, top, edge.z),
new THREE.Vector3(0, top, 0)
];
const lineGeometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.LineLoop(lineGeometry, sectionMaterial);
line.renderOrder = 3;
contourGroup.add(line);
});
});
// ------------------------------------------------------------
// Elevation gauge in the open side
// ------------------------------------------------------------
const annotationGroup = new THREE.Group();
scene.add(annotationGroup);
const gaugeAngle = Math.PI / 4;
const gaugeRadius = 1.78;
const gaugeX = Math.cos(gaugeAngle) * gaugeRadius;
const gaugeZ = Math.sin(gaugeAngle) * gaugeRadius;
const gaugeMaterial = new THREE.LineBasicMaterial({
color: 0x243b43,
transparent: true,
opacity: 0.86,
depthTest: false
});
const gaugeLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(gaugeX, 0.03, gaugeZ),
new THREE.Vector3(gaugeX, LEVEL_HEIGHT * 3 + 0.04, gaugeZ)
]),
gaugeMaterial
);
gaugeLine.renderOrder = 20;
annotationGroup.add(gaugeLine);
const tangentX = -Math.sin(gaugeAngle);
const tangentZ = Math.cos(gaugeAngle);
const labelAnchors = [];
for (let i = 0; i < 3; i++) {
const y = (i + 1) * LEVEL_HEIGHT;
const tick = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(
gaugeX - tangentX * 0.15,
y,
gaugeZ - tangentZ * 0.15
),
new THREE.Vector3(
gaugeX + tangentX * 0.15,
y,
gaugeZ + tangentZ * 0.15
)
]),
gaugeMaterial
);
tick.renderOrder = 21;
annotationGroup.add(tick);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 16, 10),
new THREE.MeshBasicMaterial({
color: palettes[i].top,
depthTest: false
})
);
marker.position.set(gaugeX, y, gaugeZ);
marker.renderOrder = 22;
annotationGroup.add(marker);
const label = document.createElement("div");
label.className = "elevation-label";
label.style.setProperty("--accent", palettes[i].accent);
label.textContent = `${(i + 1) * 120} m`;
labelLayer.appendChild(label);
labelAnchors.push({
element: label,
position: new THREE.Vector3(gaugeX, y, gaugeZ)
});
}
// ------------------------------------------------------------
// Camera controls implemented directly, without add-ons
// ------------------------------------------------------------
const initialView = {
theta: Math.PI / 4,
phi: 1.0,
radius: 11.2,
target: new THREE.Vector3(0, 1.35, 0)
};
const goal = {
theta: initialView.theta,
phi: initialView.phi,
radius: initialView.radius,
target: initialView.target.clone()
};
const current = {
theta: initialView.theta,
phi: initialView.phi,
radius: initialView.radius,
target: initialView.target.clone()
};
let dragging = false;
let pointerId = null;
let lastX = 0;
let lastY = 0;
let panMode = false;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
panMode = event.shiftKey || event.button === 2;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panMode) {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const panScale = current.radius * 0.00125;
goal.target.addScaledVector(right, -dx * panScale);
goal.target.addScaledVector(up, dy * panScale);
goal.target.x = THREE.MathUtils.clamp(goal.target.x, -2.5, 2.5);
goal.target.y = THREE.MathUtils.clamp(goal.target.y, 0.45, 3.2);
goal.target.z = THREE.MathUtils.clamp(goal.target.z, -2.5, 2.5);
} else {
goal.theta -= dx * 0.006;
goal.phi = THREE.MathUtils.clamp(
goal.phi - dy * 0.005,
0.28,
1.43
);
}
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
goal.radius = THREE.MathUtils.clamp(
goal.radius * Math.exp(event.deltaY * 0.001),
6.6,
18
);
},
{ passive: false }
);
function resetView() {
goal.theta = initialView.theta;
goal.phi = initialView.phi;
goal.radius = initialView.radius;
goal.target.copy(initialView.target);
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
// ------------------------------------------------------------
// Projection of elevation labels
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const cameraAzimuth = Math.atan2(
camera.position.z - current.target.z,
camera.position.x - current.target.x
);
const cutawayAzimuth = Math.PI / 4;
const angularDifference = Math.atan2(
Math.sin(cameraAzimuth - cutawayAzimuth),
Math.cos(cameraAzimuth - cutawayAzimuth)
);
const annotationVisible =
Math.abs(angularDifference) < WEDGE_HALF + 0.32;
annotationGroup.visible = annotationVisible;
labelAnchors.forEach(({ element, position }) => {
projected.copy(position).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
element.classList.toggle("flip", projected.x > 0.34);
element.classList.toggle(
"is-hidden",
!annotationVisible || !onScreen
);
});
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.fov = camera.aspect < 0.75 ? 52 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", resize);
resize();
let previousTime = performance.now();
function animate(time) {
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
const damping = 1 - Math.exp(-dt * 12);
current.theta = THREE.MathUtils.lerp(
current.theta,
goal.theta,
damping
);
current.phi = THREE.MathUtils.lerp(
current.phi,
goal.phi,
damping
);
current.radius = THREE.MathUtils.lerp(
current.radius,
goal.radius,
damping
);
current.target.lerp(goal.target, damping);
camera.position.set(
current.target.x +
current.radius *
Math.sin(current.phi) *
Math.cos(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z +
current.radius *
Math.sin(current.phi) *
Math.sin(current.theta)
);
camera.lookAt(current.target);
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```