Prompt specification
Build or customize the Three.js 3D scene "Viscous and runny lava analogy" 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: Viscous and runny lava analogy
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/viscous-and-runny-lava-analogy-x1190
Scene Description Prompt:
Viscous and runny lava analogy. Place two tilted channels carrying differently paced schematic flows; compare resulting shapes with an explicit qualitative label, avoiding claims that color alone determines lava properties. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (viscous-and-runny-lava-analogy-x1190):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Viscous vs. Runny Lava — Schematic Channel Comparison</title>
<style>
:root {
color-scheme: dark;
--ink: #eef7ff;
--muted: #a9bac7;
--panel: rgba(8, 18, 27, 0.82);
--border: rgba(173, 210, 230, 0.22);
--accent: #ff7444;
--marker: #f2f7ed;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071019;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
#title-panel {
top: 18px;
left: 18px;
width: min(460px, calc(100vw - 36px));
padding: 15px 17px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(12px);
box-shadow: 0 12px 38px rgba(0, 0, 0, 0.24);
}
.eyebrow {
margin: 0 0 5px;
color: #86d4df;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.4vw, 31px);
line-height: 1.08;
letter-spacing: -0.025em;
}
#title-panel p {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
#controls {
top: 18px;
right: 18px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 38px;
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(8, 18, 27, 0.86);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(10px);
}
button:hover,
button:focus-visible {
border-color: rgba(173, 210, 230, 0.5);
background: rgba(22, 40, 53, 0.94);
outline: none;
}
.annotation {
position: fixed;
z-index: 9;
width: min(255px, 42vw);
padding: 10px 12px;
border: 1px solid var(--border);
border-radius: 11px;
background: rgba(7, 16, 24, 0.88);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
pointer-events: none;
transform: translate(-50%, -112%);
backdrop-filter: blur(10px);
transition: opacity 120ms linear;
}
.annotation::after {
content: "";
position: absolute;
left: 50%;
bottom: -12px;
width: 1px;
height: 12px;
background: rgba(220, 240, 250, 0.52);
}
.annotation .case {
display: block;
margin-bottom: 4px;
color: #8ed9e1;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.annotation strong {
display: block;
font-size: 13px;
line-height: 1.3;
}
#comparison {
left: 50%;
bottom: 18px;
width: min(850px, calc(100vw - 36px));
padding: 13px 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 12px 38px rgba(0, 0, 0, 0.28);
transform: translateX(-50%);
backdrop-filter: blur(12px);
}
#comparison h2 {
margin: 0 0 8px;
font-size: 13px;
letter-spacing: 0.02em;
}
.comparison-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.comparison-grid > div {
padding-left: 10px;
border-left: 3px solid #6fcbd5;
color: #d9e5ec;
font-size: 12px;
line-height: 1.4;
}
.comparison-grid > div:last-child {
border-left-color: #ff7444;
}
#comparison p {
margin: 9px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.42;
}
.marker-key {
display: inline-block;
width: 20px;
height: 3px;
margin: 0 4px 2px 0;
border-radius: 2px;
background: var(--marker);
vertical-align: middle;
}
@media (max-width: 700px) {
#title-panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 11px 13px;
}
#title-panel p {
display: none;
}
#controls {
top: 91px;
right: 10px;
}
button {
min-height: 34px;
padding: 7px 9px;
font-size: 11px;
}
#comparison {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px 12px;
}
.comparison-grid {
grid-template-columns: 1fr;
gap: 6px;
}
#comparison p {
font-size: 10px;
}
.annotation {
width: 180px;
padding: 8px 9px;
}
.annotation strong {
font-size: 11px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive 3D comparison of two schematic lava channels"></main>
<header id="title-panel" class="hud">
<p class="eyebrow">Schematic solid-shape study</p>
<h1>Viscous accumulation vs. runny advance</h1>
<p>
Drag to orbit, scroll to zoom, or use the view buttons.
<span class="marker-key"></span>White arrows indicate schematic motion.
</p>
</header>
<nav id="controls" class="hud" aria-label="Scene controls">
<button id="pause-button" type="button" aria-pressed="false">Pause motion</button>
<button id="iso-button" type="button">Isometric</button>
<button id="plan-button" type="button">Plan view</button>
</nav>
<div id="tag-a" class="annotation">
<span class="case">Case A · slow / more viscous</span>
<strong>Short, thick, blunt-to-rounded accumulation</strong>
</div>
<div id="tag-b" class="annotation">
<span class="case">Case B · fast / runnier</span>
<strong>Long, thin, tapered forward tongue</strong>
</div>
<section id="comparison" class="hud">
<h2>Qualitative comparison — matched slope and channel size</h2>
<div class="comparison-grid">
<div>
<strong>Slow-moving, more viscous analogy:</strong>
material accumulates into a shorter, thicker body with a rounded front.
</div>
<div>
<strong>Fast-moving, runnier analogy:</strong>
material advances farther as a thinner body with a tapered front.
</div>
</div>
<p>
This is an analogy, not a scale model. Both flows share the same color for
visual consistency; labels, marker pace, and solid geometry communicate
the distinction. Real lava also depends on temperature, crystal content,
slope, discharge, and channel geometry.
</p>
</section>
<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");
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.Fog(0x071019, 22, 40);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
100
);
scene.add(new THREE.HemisphereLight(0xc8ecff, 0x18202a, 1.5));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.6);
keyLight.position.set(8, 14, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65cde0, 1.1);
rimLight.position.set(-8, 7, -11);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0c1720,
roughness: 0.92,
metalness: 0.04
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x12222d,
roughness: 0.78,
metalness: 0.12
});
const channelMaterial = new THREE.MeshStandardMaterial({
color: 0x263946,
roughness: 0.66,
metalness: 0.22
});
const channelBedMaterial = new THREE.MeshStandardMaterial({
color: 0x101c25,
roughness: 0.82,
metalness: 0.12
});
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x1a2a34,
roughness: 0.75,
metalness: 0.18
});
// Exactly the same material is used for both lava bodies.
// Color is therefore not being used as the property discriminator.
const lavaMaterial = new THREE.MeshStandardMaterial({
color: 0xff6a35,
emissive: 0x7b1b05,
emissiveIntensity: 0.28,
roughness: 0.34,
metalness: 0.04,
side: THREE.DoubleSide
});
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xf2f7ed,
emissive: 0x63746c,
emissiveIntensity: 0.18,
roughness: 0.44,
metalness: 0.08
});
// -------------------------------------------------------------------------
// Ground and presentation platform
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.set(4.5, -1.33, 0);
ground.receiveShadow = true;
scene.add(ground);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(9.6, 9.9, 0.32, 64),
platformMaterial
);
platform.position.set(4.5, -1.18, 0);
platform.receiveShadow = true;
scene.add(platform);
const grid = new THREE.GridHelper(20, 20, 0x34515e, 0x1a2b35);
grid.position.set(4.5, -1.005, 0);
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// -------------------------------------------------------------------------
// Custom solid flow geometry
//
// A closed, stylized tube is generated from elliptical rings. The slow
// case receives a broader, lobed profile and a long rounded cap. The fast
// case receives a narrow, smoothly tapering profile.
// -------------------------------------------------------------------------
function createFlowGeometry(length, width, height, style) {
const radialSegments = 20;
const bodySegments = style === "slow" ? 34 : 42;
const capSegments = 10;
const backCap =
style === "slow" ? Math.min(0.58, width * 0.62) : 0.28;
const frontCap =
style === "slow" ? Math.min(0.76, width * 0.82) : 0.42;
const bodyEnd = length - frontCap;
function bodyProfile(t) {
if (style === "slow") {
return (
0.94 -
0.10 * t +
0.16 * Math.sin(Math.PI * t) +
0.035 * Math.sin(10 * Math.PI * t)
);
}
return 1 - 0.30 * t + 0.015 * Math.sin(Math.PI * t);
}
const startScale = bodyProfile(0);
const endScale = bodyProfile(1);
const rings = [];
// Rounded rear cap.
for (let j = 0; j <= capSegments; j++) {
const theta = (j / capSegments) * (Math.PI / 2);
rings.push({
x: -backCap + backCap * Math.sin(theta),
scale: Math.cos(theta) * startScale
});
}
// Main body.
for (let j = 1; j <= bodySegments; j++) {
const t = j / bodySegments;
rings.push({
x: bodyEnd * t,
scale: bodyProfile(t)
});
}
// Rounded or tapered leading cap.
for (let j = 1; j <= capSegments; j++) {
const theta = (j / capSegments) * (Math.PI / 2);
rings.push({
x: bodyEnd + frontCap * Math.sin(theta),
scale: Math.cos(theta) * endScale
});
}
const positions = [];
const indices = [];
for (const ring of rings) {
const radiusY = height * 0.5 * ring.scale;
const radiusZ = width * 0.5 * ring.scale;
for (let j = 0; j < radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
positions.push(
ring.x,
radiusY * Math.sin(angle),
radiusZ * Math.cos(angle)
);
}
}
for (let ringIndex = 0; ringIndex < rings.length - 1; ringIndex++) {
const current = ringIndex * radialSegments;
const next = (ringIndex + 1) * radialSegments;
for (let j = 0; j < radialSegments; j++) {
const nextJ = (j + 1) % radialSegments;
indices.push(
current + j,
next + j,
current + nextJ,
next + j,
next + nextJ,
current + nextJ
);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
// -------------------------------------------------------------------------
// Channels
// -------------------------------------------------------------------------
const CHANNEL_LENGTH = 10.8;
const CHANNEL_WIDTH = 1.45;
const CHANNEL_ANGLE = -0.115;
const CHANNEL_ORIGIN_Y = 0.36;
function addChannel(zPosition, style) {
const group = new THREE.Group();
group.position.set(0, CHANNEL_ORIGIN_Y, zPosition);
group.rotation.z = CHANNEL_ANGLE;
scene.add(group);
const base = new THREE.Mesh(
new THREE.BoxGeometry(CHANNEL_LENGTH, 0.26, CHANNEL_WIDTH),
channelMaterial
);
base.position.x = CHANNEL_LENGTH / 2;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const bed = new THREE.Mesh(
new THREE.BoxGeometry(
CHANNEL_LENGTH - 0.08,
0.08,
CHANNEL_WIDTH - 0.24
),
channelBedMaterial
);
bed.position.set(CHANNEL_LENGTH / 2, 0.145, 0);
bed.receiveShadow = true;
group.add(bed);
const railGeometry = new THREE.BoxGeometry(
CHANNEL_LENGTH,
0.38,
0.14
);
for (const side of [-1, 1]) {
const rail = new THREE.Mesh(railGeometry, channelMaterial);
rail.position.set(
CHANNEL_LENGTH / 2,
0.32,
side * (CHANNEL_WIDTH / 2 - 0.07)
);
rail.castShadow = true;
rail.receiveShadow = true;
group.add(rail);
}
// Source reservoir, sharing the lava material.
const reservoir = new THREE.Mesh(
new THREE.CylinderGeometry(0.62, 0.62, 0.42, 32),
lavaMaterial
);
reservoir.position.set(-0.5, 0.31, 0);
reservoir.castShadow = true;
group.add(reservoir);
const reservoirRim = new THREE.Mesh(
new THREE.TorusGeometry(0.62, 0.075, 10, 32),
channelMaterial
);
reservoirRim.rotation.x = Math.PI / 2;
reservoirRim.position.set(-0.5, 0.53, 0);
reservoirRim.castShadow = true;
group.add(reservoirRim);
const isSlow = style === "slow";
const flow = {
group,
style,
length: isSlow ? 4.75 : 8.95,
width: isSlow ? 0.94 : 0.57,
height: isSlow ? 0.44 : 0.20,
speed: isSlow ? 0.075 : 0.19,
markers: []
};
flow.mesh = new THREE.Mesh(
createFlowGeometry(
flow.length,
flow.width,
flow.height,
flow.style
),
lavaMaterial
);
flow.mesh.position.set(
0.05,
0.13 + flow.height * 0.5 - 0.02,
0
);
flow.mesh.castShadow = true;
flow.mesh.receiveShadow = true;
group.add(flow.mesh);
// Neutral motion arrows. Their pace, rather than color, distinguishes
// the two cases.
const markerGeometry = new THREE.ConeGeometry(0.105, 0.38, 12);
markerGeometry.rotateZ(-Math.PI / 2);
for (let i = 0; i < 3; i++) {
const marker = new THREE.Mesh(markerGeometry, markerMaterial);
marker.position.z = (i - 1) * Math.min(0.23, flow.width * 0.42);
marker.castShadow = true;
group.add(marker);
flow.markers.push(marker);
}
return flow;
}
function addSupports(zPosition) {
for (const x of [1.0, 8.9]) {
const undersideY =
CHANNEL_ORIGIN_Y +
Math.sin(CHANNEL_ANGLE) * x -
0.13 * Math.cos(CHANNEL_ANGLE);
const height = undersideY + 1.02;
const support = new THREE.Mesh(
new THREE.BoxGeometry(0.32, height, 0.48),
supportMaterial
);
support.position.set(x, -1.02 + height / 2, zPosition);
support.castShadow = true;
support.receiveShadow = true;
scene.add(support);
}
}
const slowFlow = addChannel(-1.85, "slow");
const fastFlow = addChannel(1.85, "fast");
addSupports(-1.85);
addSupports(1.85);
// -------------------------------------------------------------------------
// Custom camera controls, implemented without camera-control addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(4.6, -0.05, 0);
let azimuth = 0.72;
let polar = 1.02;
let radius = 17.2;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
cameraTarget.x + radius * sinPolar * Math.sin(azimuth),
cameraTarget.y + radius * Math.cos(polar),
cameraTarget.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
}
function setIsometricView() {
azimuth = 0.72;
polar = 1.02;
radius = 17.2;
updateCamera();
}
function setPlanView() {
azimuth = 0;
polar = 0.34;
radius = 16.2;
updateCamera();
}
updateCamera();
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
azimuth -= deltaX * 0.006;
polar = THREE.MathUtils.clamp(
polar - deltaY * 0.005,
0.2,
1.38
);
updateCamera();
});
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();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
10.5,
24
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", setIsometricView);
document.querySelector("#iso-button").addEventListener("click", setIsometricView);
document.querySelector("#plan-button").addEventListener("click", setPlanView);
let paused = false;
const pauseButton = document.querySelector("#pause-button");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume motion" : "Pause motion";
pauseButton.setAttribute("aria-pressed", String(paused));
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
azimuth += 0.08;
updateCamera();
} else if (event.key === "ArrowRight") {
azimuth -= 0.08;
updateCamera();
} else if (event.key === "+" || event.key === "=") {
radius = Math.max(10.5, radius - 0.7);
updateCamera();
} else if (event.key === "-") {
radius = Math.min(24, radius + 0.7);
updateCamera();
}
});
// -------------------------------------------------------------------------
// Animated motion markers
// -------------------------------------------------------------------------
function updateMarkers(flow, motionTime) {
for (let i = 0; i < flow.markers.length; i++) {
const phase =
(motionTime * flow.speed + i / flow.markers.length) % 1;
const marker = flow.markers[i];
marker.position.x = 0.25 + phase * (flow.length - 0.5);
marker.position.y =
flow.mesh.position.y +
flow.height * 0.58 +
0.12;
}
}
// -------------------------------------------------------------------------
// DOM annotations projected from 3D anchors
// -------------------------------------------------------------------------
const tagA = document.querySelector("#tag-a");
const tagB = document.querySelector("#tag-b");
const anchorA = new THREE.Vector3(2.15, 1.05, 0);
const anchorB = new THREE.Vector3(4.9, 0.95, 0);
const projected = new THREE.Vector3();
function placeAnnotation(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
let motionTime = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) motionTime += delta;
updateMarkers(slowFlow, motionTime);
updateMarkers(fastFlow, motionTime);
lavaMaterial.emissiveIntensity =
0.27 + Math.sin(motionTime * 1.7) * 0.035;
scene.updateMatrixWorld(true);
placeAnnotation(
tagA,
slowFlow.group.localToWorld(anchorA.clone())
);
placeAnnotation(
tagB,
fastFlow.group.localToWorld(anchorB.clone())
);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```