Prompt specification
Build or customize the Three.js 3D scene "Length area and volume unit display" 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: Length area and volume unit display
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/length-area-and-volume-unit-display-x1749
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts length, area, and volume units with low-poly objects. Put a unit rod, a square tile, and a cube on adjacent supports, all sharing the same base edge length. Label length, square units, and cubic units separately. Beside them, arrange several tiles across two dimensions and unit cubes across three dimensions, making the different counting rules visible. Keep one shared scale throughout rather than enlarging the cube or square independently for display.
Working Three.js Starter (length-area-and-volume-unit-display-x1749):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Length, Area, and Volume — One Shared Scale</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09111f;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
.intro {
top: 28px;
left: 30px;
max-width: 430px;
}
.eyebrow {
margin-bottom: 8px;
color: #69e4c1;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: #f4f7ff;
font-size: clamp(27px, 3.3vw, 48px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 1.02;
}
.intro p {
max-width: 390px;
margin: 12px 0 0;
color: #aab7cc;
font-size: 14px;
line-height: 1.55;
}
.scale-badge {
top: 28px;
right: 30px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 15px 11px 12px;
border: 1px solid rgba(126, 161, 211, 0.25);
border-radius: 14px;
background: rgba(13, 23, 41, 0.78);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(12px);
color: #e9efff;
font-size: 12px;
font-weight: 650;
}
.scale-symbol {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border-radius: 9px;
background: #69e4c1;
color: #07131e;
font-size: 19px;
font-weight: 900;
}
.scale-badge small {
display: block;
margin-bottom: 2px;
color: #8291aa;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.controls {
right: 30px;
bottom: 26px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
.hint {
padding: 10px 13px;
border: 1px solid rgba(126, 161, 211, 0.18);
border-radius: 12px;
background: rgba(13, 23, 41, 0.72);
color: #9eacc1;
font-size: 11px;
backdrop-filter: blur(10px);
}
button {
padding: 10px 14px;
border: 1px solid rgba(105, 228, 193, 0.35);
border-radius: 12px;
background: rgba(105, 228, 193, 0.12);
color: #bff8e8;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(10px);
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(105, 228, 193, 0.22);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid #69e4c1;
outline-offset: 3px;
}
@media (max-width: 720px) {
.intro {
top: 20px;
left: 20px;
max-width: calc(100vw - 40px);
}
.intro p {
max-width: 310px;
font-size: 12px;
}
.scale-badge {
top: auto;
right: 20px;
bottom: 76px;
}
.controls {
right: 20px;
bottom: 20px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional measurement scene"></main>
<header class="hud intro">
<div class="eyebrow">Measurement Lab</div>
<h1>One unit.<br>Three dimensions.</h1>
<p>
The rod, tile, cube, and every counted object use the same edge length.
Compare one edge, one square, and one solid.
</p>
</header>
<div class="hud scale-badge">
<div class="scale-symbol">1</div>
<div>
<small>Shared scale</small>
edge = 1 unit
</div>
</div>
<div class="hud controls">
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<button id="reset" type="button">Reset view</button>
</div>
<noscript>This scene requires JavaScript.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// One shared measurement scale is used by every object in the scene.
// The rod's length, tile's side, and cube's edge are all exactly UNIT.
// ---------------------------------------------------------------------
const UNIT = 1.0;
const COLORS = {
background: 0x09111f,
ground: 0x0c1627,
plinth: 0x1b2a42,
plinthEdge: 0x31445f,
rod: 0xff866e,
tileA: 0x49d9ad,
tileB: 0x35b994,
cubeA: 0x709eff,
cubeB: 0x587fe0,
width: 0xf6c96b,
depth: 0xff8194,
height: 0x6be9c8
};
const scene = new THREE.Scene();
scene.background = new THREE.Color(COLORS.background);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(-0.25, 0.85, 0);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const canvas = renderer.domElement;
canvas.setAttribute("role", "img");
canvas.setAttribute(
"aria-label",
"Low-poly objects demonstrating length, square units, and cubic units on one shared scale"
);
document.getElementById("scene").appendChild(canvas);
// Lighting ----------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb9dcff, 0x172033, 2.1));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5e8fff, 1.6);
rimLight.position.set(9, 5, -9);
scene.add(rimLight);
// Ground and grid ----------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(36, 36),
new THREE.MeshStandardMaterial({
color: COLORS.ground,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x334966, 0x203149);
grid.position.y = -0.008;
grid.material.transparent = true;
grid.material.opacity = 0.24;
grid.material.depthWrite = false;
scene.add(grid);
// Materials ---------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.7,
metalness: 0.04,
flatShading: true,
...options
});
}
const materials = {
plinth: standardMaterial(COLORS.plinth, { roughness: 0.88 }),
plinthTop: standardMaterial(COLORS.plinthEdge, { roughness: 0.8 }),
rod: standardMaterial(COLORS.rod, { roughness: 0.48 }),
tileA: standardMaterial(COLORS.tileA, { roughness: 0.62 }),
tileB: standardMaterial(COLORS.tileB, { roughness: 0.65 }),
cubeA: standardMaterial(COLORS.cubeA, { roughness: 0.48 }),
cubeB: standardMaterial(COLORS.cubeB, { roughness: 0.52 })
};
// Utility functions -------------------------------------------------------
function addEdges(mesh, color = 0x07111e, opacity = 0.48) {
const edges = new THREE.EdgesGeometry(mesh.geometry, 20);
const outline = new THREE.LineSegments(
edges,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
mesh.add(outline);
return mesh;
}
function makeBox(width, height, depth, material, x, y, z, outlined = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
if (outlined) addEdges(mesh);
scene.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makeLabel(eyebrow, title, subtitle, accent, worldWidth = 1.95) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 900;
labelCanvas.height = 220;
const ctx = labelCanvas.getContext("2d");
roundedRect(ctx, 5, 5, 890, 210, 28);
ctx.fillStyle = "rgba(11, 21, 38, 0.94)";
ctx.fill();
ctx.strokeStyle = "rgba(155, 181, 220, 0.24)";
ctx.lineWidth = 3;
ctx.stroke();
roundedRect(ctx, 24, 25, 8, 170, 4);
ctx.fillStyle = accent;
ctx.fill();
ctx.textAlign = "left";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = accent;
ctx.font = "800 24px system-ui, sans-serif";
ctx.fillText(eyebrow, 58, 52);
ctx.fillStyle = "#f3f7ff";
ctx.font = "800 45px system-ui, sans-serif";
ctx.fillText(title, 58, 112, 805);
ctx.fillStyle = "#a9b8cf";
ctx.font = "500 29px system-ui, sans-serif";
ctx.fillText(subtitle, 58, 165, 805);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldWidth * 220 / 900, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function makePill(text, accent, x, y, z, worldWidth = 1.05) {
const pillCanvas = document.createElement("canvas");
pillCanvas.width = 400;
pillCanvas.height = 120;
const ctx = pillCanvas.getContext("2d");
roundedRect(ctx, 4, 4, 392, 112, 30);
ctx.fillStyle = accent;
ctx.fill();
ctx.fillStyle = "#07131e";
ctx.font = "800 38px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 200, 60);
const texture = new THREE.CanvasTexture(pillCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(worldWidth, worldWidth * 120 / 400, 1);
sprite.renderOrder = 21;
scene.add(sprite);
return sprite;
}
function addDimension(start, end, tickDirection, color) {
const points = [
start.clone(),
end.clone(),
start.clone().add(tickDirection),
end.clone().add(tickDirection)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({ color })
);
scene.add(line);
}
function addSupport(x, accent) {
makeBox(1.38, 0.32, 1.44, materials.plinth, x, 0.16, 0);
makeBox(1.22, 0.035, 1.28, materials.plinthTop, x, 0.3275, 0);
// Small front marker on each support.
makeBox(
0.10,
0.15,
0.025,
standardMaterial(accent, { roughness: 0.45 }),
x,
0.17,
0.733,
false
);
}
// ---------------------------------------------------------------------
// First group: rod, square tile, and cube on adjacent supports.
// Every object uses UNIT directly; there is no independent enlargement.
// ---------------------------------------------------------------------
const rodX = -6.6;
const tileX = -4.65;
const cubeX = -2.7;
const supportTop = 0.345;
addSupport(rodX, COLORS.rod);
addSupport(tileX, COLORS.tileA);
addSupport(cubeX, COLORS.cubeA);
// Unit rod: hexagonal, low-poly, exactly UNIT long.
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, UNIT, 6, 1, false),
materials.rod
);
rod.rotation.z = Math.PI / 2;
rod.position.set(rodX, supportTop + 0.115, 0);
rod.castShadow = true;
rod.receiveShadow = true;
addEdges(rod, 0x7a211c, 0.35);
scene.add(rod);
// One square tile: UNIT by UNIT.
const singleTile = makeBox(
UNIT,
0.105,
UNIT,
materials.tileA,
tileX,
supportTop + 0.0525,
0
);
singleTile.rotation.y = 0;
// One unit cube: UNIT in all three dimensions.
makeBox(
UNIT,
UNIT,
UNIT,
materials.cubeA,
cubeX,
supportTop + UNIT / 2,
0
);
const rodLabel = makeLabel(
"1D · LENGTH",
"LENGTH",
"1 edge = 1 unit",
"#ff9a83",
1.95
);
rodLabel.position.set(rodX, 2.02, 0);
const tileLabel = makeLabel(
"2D · AREA",
"SQUARE UNITS",
"1 face = 1 square unit",
"#69e4c1",
1.95
);
tileLabel.position.set(tileX, 2.02, 0);
const cubeLabel = makeLabel(
"3D · VOLUME",
"CUBIC UNITS",
"1 solid = 1 cubic unit",
"#89b1ff",
1.95
);
cubeLabel.position.set(cubeX, 2.02, 0);
// Identical one-unit measuring bars in front of the three supports.
const sharedTick = new THREE.Vector3(0, 0, 0.11);
for (const x of [rodX, tileX, cubeX]) {
addDimension(
new THREE.Vector3(x - UNIT / 2, 0.045, 0.91),
new THREE.Vector3(x + UNIT / 2, 0.045, 0.91),
sharedTick,
0x9aabc2
);
}
// ---------------------------------------------------------------------
// Second group: count square tiles in two dimensions.
// 3 columns × 3 rows = 9 unit tiles.
// ---------------------------------------------------------------------
const tileArrayX = 0.55;
const tileCountX = 3;
const tileCountZ = 3;
const arrayPlatformHeight = 0.28;
makeBox(
tileCountX * UNIT + 0.28,
arrayPlatformHeight,
tileCountZ * UNIT + 0.28,
materials.plinth,
tileArrayX,
arrayPlatformHeight / 2,
0
);
for (let ix = 0; ix < tileCountX; ix++) {
for (let iz = 0; iz < tileCountZ; iz++) {
const x = tileArrayX + (ix - 1) * UNIT;
const z = (iz - 1) * UNIT;
const material = (ix + iz) % 2 === 0
? materials.tileA
: materials.tileB;
makeBox(
UNIT,
0.105,
UNIT,
material,
x,
arrayPlatformHeight + 0.0525,
z
);
}
}
const tileArrayLabel = makeLabel(
"COUNT IN 2D",
"SQUARE UNITS",
"3 × 3 tiles = 9 square units",
"#69e4c1",
3.85
);
tileArrayLabel.position.set(tileArrayX, 1.83, 0);
// Dimension lines showing the two counting directions.
addDimension(
new THREE.Vector3(tileArrayX - 1.5, 0.38, 1.72),
new THREE.Vector3(tileArrayX + 1.5, 0.38, 1.72),
new THREE.Vector3(0, 0.12, 0),
COLORS.width
);
addDimension(
new THREE.Vector3(tileArrayX + 1.55, 0.38, -1.5),
new THREE.Vector3(tileArrayX + 1.55, 0.38, 1.5),
new THREE.Vector3(0, 0.12, 0),
COLORS.depth
);
makePill(
"3 across",
"#f6c96b",
tileArrayX,
0.68,
1.91,
1.12
);
makePill(
"3 deep",
"#ff8194",
tileArrayX + 1.78,
0.68,
0,
1.02
);
// ---------------------------------------------------------------------
// Third group: count unit cubes in three dimensions.
// 3 wide × 3 deep × 2 high = 18 unit cubes.
// ---------------------------------------------------------------------
const cubeArrayX = 4.95;
const cubeCountX = 3;
const cubeCountZ = 3;
const cubeCountY = 2;
makeBox(
cubeCountX * UNIT + 0.28,
arrayPlatformHeight,
cubeCountZ * UNIT + 0.28,
materials.plinth,
cubeArrayX,
arrayPlatformHeight / 2,
0
);
for (let iy = 0; iy < cubeCountY; iy++) {
for (let iz = 0; iz < cubeCountZ; iz++) {
for (let ix = 0; ix < cubeCountX; ix++) {
const x = cubeArrayX + (ix - 1) * UNIT;
const z = (iz - 1) * UNIT;
const y = arrayPlatformHeight + UNIT / 2 + iy * UNIT;
const material = (ix + iz + iy) % 2 === 0
? materials.cubeA
: materials.cubeB;
makeBox(UNIT, UNIT, UNIT, material, x, y, z);
}
}
}
const cubeArrayLabel = makeLabel(
"COUNT IN 3D",
"CUBIC UNITS",
"3 × 3 × 2 = 18 cubic units",
"#89b1ff",
4.15
);
cubeArrayLabel.position.set(cubeArrayX, 3.28, 0);
// Width, depth, and height dimensions.
addDimension(
new THREE.Vector3(cubeArrayX - 1.5, 0.38, 1.72),
new THREE.Vector3(cubeArrayX + 1.5, 0.38, 1.72),
new THREE.Vector3(0, 0.12, 0),
COLORS.width
);
addDimension(
new THREE.Vector3(cubeArrayX + 1.55, 0.38, -1.5),
new THREE.Vector3(cubeArrayX + 1.55, 0.38, 1.5),
new THREE.Vector3(0, 0.12, 0),
COLORS.depth
);
addDimension(
new THREE.Vector3(cubeArrayX + 1.66, arrayPlatformHeight, 1.58),
new THREE.Vector3(cubeArrayX + 1.66, arrayPlatformHeight + 2, 1.58),
new THREE.Vector3(0.11, 0, 0),
COLORS.height
);
makePill(
"3 wide",
"#f6c96b",
cubeArrayX,
0.68,
1.91,
1.02
);
makePill(
"3 deep",
"#ff8194",
cubeArrayX + 1.80,
0.68,
0,
1.02
);
makePill(
"2 high",
"#6be9c8",
cubeArrayX + 1.86,
1.35,
1.58,
1.02
);
// ---------------------------------------------------------------------
// Direct camera controls: no Three.js addons are used.
// ---------------------------------------------------------------------
let theta = 0.5;
let phi = 1.02;
let zoom = 1;
const cameraRadius = 22;
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(theta),
cameraTarget.y + cameraRadius * Math.cos(phi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
// Keep the entire instructional composition visible on narrow screens.
const viewHeight = Math.max(8.7, 15.4 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height, false);
updateCamera();
}
function resetView() {
theta = 0.5;
phi = 1.02;
zoom = 1;
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
theta -= deltaX * 0.005;
phi = THREE.MathUtils.clamp(phi + deltaY * 0.0045, 0.45, 1.35);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.8
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") theta += 0.08;
else if (key === "ArrowRight") theta -= 0.08;
else if (key === "ArrowUp") phi = Math.max(0.45, phi - 0.06);
else if (key === "ArrowDown") phi = Math.min(1.35, phi + 0.06);
else if (key === "+" || key === "=") zoom = Math.min(1.8, zoom * 1.08);
else if (key === "-") zoom = Math.max(0.65, zoom / 1.08);
else if (key === "r" || key === "R") resetView();
else return;
event.preventDefault();
updateCamera();
});
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```