Prompt specification
Build or customize the Three.js 3D scene "Domino spacing comparison" 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: Domino spacing comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/domino-spacing-comparison-x0329
Scene Description Prompt:
Domino spacing comparison. Place three small domino groups with close, moderate, and excessive spacing; show a side view making each tile's height and neighboring gap directly comparable. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (domino-spacing-comparison-x0329):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Domino Spacing Comparison</title>
<style>
:root {
color-scheme: dark;
--background: #080d16;
--panel: rgba(12, 18, 31, 0.82);
--border: rgba(170, 198, 230, 0.18);
--text: #eef5ff;
--muted: #91a1b8;
--close: #ffad66;
--moderate: #63d6e6;
--excessive: #a892ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--background);
color: var(--text);
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: 5;
pointer-events: none;
}
.title-card {
top: 22px;
left: 22px;
width: min(430px, calc(100vw - 44px));
padding: 16px 18px 17px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: #83dce8;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0 0 7px;
font-size: clamp(22px, 2.6vw, 34px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.title-card p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.bottom-bar {
right: 20px;
bottom: 18px;
left: 20px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 14px;
}
.legend {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
padding: 9px;
border: 1px solid var(--border);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 30px;
padding: 6px 9px;
border-radius: 8px;
color: #dbe7f8;
background: rgba(255, 255, 255, 0.035);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.legend-item strong {
color: #fff;
font-variant-numeric: tabular-nums;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.close {
color: var(--close);
}
.moderate {
color: var(--moderate);
}
.excessive {
color: var(--excessive);
}
.controls {
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 40px;
padding: 0 13px;
border: 1px solid var(--border);
border-radius: 10px;
color: #dce9f8;
background: var(--panel);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover {
border-color: rgba(170, 198, 230, 0.42);
background: rgba(26, 38, 58, 0.9);
}
button:focus-visible {
outline: 2px solid #83dce8;
outline-offset: 2px;
}
.hint {
margin-bottom: 3px;
color: rgba(190, 207, 230, 0.6);
font-size: 11px;
text-align: right;
}
@media (max-width: 800px) {
.title-card {
top: 14px;
left: 14px;
width: min(360px, calc(100vw - 28px));
padding: 13px 14px;
}
.title-card p {
display: none;
}
.bottom-bar {
right: 12px;
bottom: 12px;
left: 12px;
align-items: stretch;
flex-direction: column;
}
.legend {
width: 100%;
}
.legend-item {
flex: 1 1 auto;
justify-content: center;
}
.controls {
align-self: flex-end;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive orthographic domino spacing comparison"></main>
<section class="hud title-card">
<div class="eyebrow">Voxel construction / side elevation</div>
<h1>Same tiles. Different spacing.</h1>
<p>
Three two-domino groups use identical 4 × 8 voxel tiles.
A shared baseline and top guide make their heights directly comparable.
</p>
</section>
<section class="hud bottom-bar">
<div class="legend" aria-label="Comparison legend">
<div class="legend-item">
<span class="dot" style="color: #dce9f8"></span>
Tile height <strong>2.14</strong>
</div>
<div class="legend-item close">
<span class="dot"></span>
Close <strong>0.16</strong>
</div>
<div class="legend-item moderate">
<span class="dot"></span>
Moderate <strong>0.50</strong>
</div>
<div class="legend-item excessive">
<span class="dot"></span>
Excessive <strong>1.10</strong>
</div>
</div>
<div class="controls">
<div class="hint">Drag to pan · Scroll to zoom · Double-click to reset</div>
<button id="toggleAnnotations" type="button" aria-pressed="true">
Dimensions on
</button>
<button id="resetView" type="button">Reset view</button>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three groups of voxel dominoes with close, moderate, and excessive spacing"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#080d16");
const WORLD_WIDTH = 12.8;
const MIN_VIEW_HEIGHT = 4.8;
const CAMERA_DISTANCE = 12;
const camera = new THREE.OrthographicCamera(-6, 6, 3, -3, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.78, 0);
let zoom = 1;
// -------------------------------------------------------------------------
// Lighting and backdrop
// -------------------------------------------------------------------------
scene.add(new THREE.AmbientLight(0xffffff, 0.52));
const hemisphere = new THREE.HemisphereLight(0xc8e4ff, 0x17131f, 1.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.55);
keyLight.position.set(-3.5, 7, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
keyLight.shadow.bias = -0.00015;
keyLight.target.position.set(0, 0.8, 0);
scene.add(keyLight, keyLight.target);
const rimLight = new THREE.DirectionalLight(0x7dddf2, 0.7);
rimLight.position.set(5, 3, 6);
scene.add(rimLight);
// A vertical wall gives the blocks soft shadows while preserving a true
// orthographic side view.
const wall = new THREE.Mesh(
new THREE.PlaneGeometry(40, 20),
new THREE.MeshStandardMaterial({
color: 0x0b1220,
roughness: 1,
metalness: 0
})
);
wall.position.set(0, 1, -0.62);
wall.receiveShadow = true;
scene.add(wall);
// -------------------------------------------------------------------------
// Domino dimensions
//
// Each domino is visibly constructed from 4 columns × 8 rows of blocks.
// There is also a small gap between adjacent blocks.
// -------------------------------------------------------------------------
const BLOCK = 0.25;
const VOXEL_GAP = 0.02;
const BLOCK_DEPTH = 0.32;
const COLUMNS = 4;
const ROWS = 8;
const TILE_WIDTH = COLUMNS * BLOCK + (COLUMNS - 1) * VOXEL_GAP;
const TILE_HEIGHT = ROWS * BLOCK + (ROWS - 1) * VOXEL_GAP;
const blockGeometry = new THREE.BoxGeometry(
BLOCK,
BLOCK,
BLOCK_DEPTH
);
const edgeGeometry = new THREE.EdgesGeometry(blockGeometry, 25);
const groups = [
{
name: "CLOSE",
subtitle: "TILES ALMOST TOUCHING",
gap: 0.16,
center: -3.8,
accent: 0xffad66
},
{
name: "MODERATE",
subtitle: "CLEAR, USEFUL CLEARANCE",
gap: 0.5,
center: 0,
accent: 0x63d6e6
},
{
name: "EXCESSIVE",
subtitle: "DISCONNECTED / HARD TO USE",
gap: 1.1,
center: 3.95,
accent: 0xa892ff
}
];
const annotations = new THREE.Group();
scene.add(annotations);
function createBlockMaterials(accent) {
const accentColor = new THREE.Color(accent);
const pale = new THREE.Color(0xf1f4ed);
const base = accentColor.clone().lerp(pale, 0.24);
return [0.82, 0.94, 1.0, 1.07].map((factor) => {
const color = base.clone().multiplyScalar(factor);
return new THREE.MeshStandardMaterial({
color,
roughness: 0.62,
metalness: 0.035
});
});
}
function createDomino(centerX, accent) {
const domino = new THREE.Group();
domino.position.x = centerX;
const materials = createBlockMaterials(accent);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x111827,
transparent: true,
opacity: 0.34
});
for (let row = 0; row < ROWS; row++) {
for (let column = 0; column < COLUMNS; column++) {
const x =
-TILE_WIDTH / 2 +
BLOCK / 2 +
column * (BLOCK + VOXEL_GAP);
const y =
BLOCK / 2 +
row * (BLOCK + VOXEL_GAP);
const materialIndex =
(row + column * 2) % materials.length;
const block = new THREE.Mesh(
blockGeometry,
materials[materialIndex]
);
block.position.set(x, y, 0);
block.castShadow = true;
block.receiveShadow = true;
const edges = new THREE.LineSegments(
edgeGeometry,
edgeMaterial
);
block.add(edges);
domino.add(block);
}
}
// Traditional domino center division, placed in the central voxel seam.
const divider = new THREE.Mesh(
new THREE.BoxGeometry(TILE_WIDTH, 0.018, 0.026),
new THREE.MeshStandardMaterial({
color: 0x182235,
roughness: 0.72,
metalness: 0.05
})
);
divider.position.set(
0,
4 * BLOCK + 3.5 * VOXEL_GAP,
BLOCK_DEPTH / 2 + 0.012
);
divider.castShadow = true;
domino.add(divider);
scene.add(domino);
return domino;
}
// -------------------------------------------------------------------------
// Line and dimension helpers
// -------------------------------------------------------------------------
function solidLine(points, color, opacity = 1, parent = annotations) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
const line = new THREE.Line(geometry, material);
parent.add(line);
return line;
}
function dashedHorizontalLine(
x1,
x2,
y,
z,
color,
dash = 0.1,
gap = 0.07
) {
const positions = [];
const stride = dash + gap;
for (let x = x1; x < x2; x += stride) {
const end = Math.min(x + dash, x2);
positions.push(x, y, z, end, y, z);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.48
});
const line = new THREE.LineSegments(geometry, material);
annotations.add(line);
return line;
}
function arrowHead(position, rotationZ, color) {
const geometry = new THREE.ConeGeometry(0.055, 0.16, 3);
const material = new THREE.MeshBasicMaterial({ color });
const arrow = new THREE.Mesh(geometry, material);
arrow.position.set(...position);
arrow.rotation.z = rotationZ;
annotations.add(arrow);
return arrow;
}
// -------------------------------------------------------------------------
// Canvas-based labels, avoiding external fonts or rendering addons
// -------------------------------------------------------------------------
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.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function createLabel(
title,
subtitle,
accent,
worldWidth,
parent = annotations
) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 240;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 5, 5, 1014, 230, 28);
ctx.fillStyle = "rgba(10, 16, 28, 0.92)";
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = `#${new THREE.Color(accent).getHexString()}`;
ctx.stroke();
roundedRect(ctx, 24, 27, 13, 186, 7);
ctx.fillStyle = `#${new THREE.Color(accent).getHexString()}`;
ctx.fill();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f2f7ff";
ctx.font = "800 64px Inter, system-ui, sans-serif";
ctx.fillText(title, 522, 94);
ctx.fillStyle = "#a9b8cc";
ctx.font = "650 27px Inter, system-ui, sans-serif";
ctx.fillText(subtitle, 522, 166);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(
worldWidth,
worldWidth * (canvas.height / canvas.width),
1
);
sprite.renderOrder = 20;
parent.add(sprite);
return sprite;
}
// -------------------------------------------------------------------------
// Common baseline, top guide, and shared height dimension
// -------------------------------------------------------------------------
const baselineLeft = -5.72;
const baselineRight = 5.78;
solidLine(
[
[baselineLeft, 0, 0.34],
[baselineRight, 0, 0.34]
],
0x8395ad,
0.68
);
dashedHorizontalLine(
baselineLeft,
baselineRight,
TILE_HEIGHT,
-0.22,
0xc8d8ea,
0.11,
0.075
);
const heightX = -5.83;
solidLine(
[
[heightX, 0, 0.42],
[heightX, TILE_HEIGHT, 0.42]
],
0xc9d8e8,
0.9
);
solidLine(
[
[heightX, 0, 0.42],
[baselineLeft + 0.04, 0, 0.42]
],
0xc9d8e8,
0.5
);
arrowHead([heightX, 0.08, 0.42], Math.PI, 0xc9d8e8);
arrowHead([heightX, TILE_HEIGHT - 0.08, 0.42], 0, 0xc9d8e8);
const heightLabel = createLabel(
TILE_HEIGHT.toFixed(2),
"TILE HEIGHT",
0xc9d8e8,
1.28
);
heightLabel.position.set(-6.3, TILE_HEIGHT / 2, 0.65);
// -------------------------------------------------------------------------
// Build and annotate each comparison group
// -------------------------------------------------------------------------
for (const group of groups) {
const totalWidth = TILE_WIDTH * 2 + group.gap;
const startX = group.center - totalWidth / 2;
const firstTileCenter = startX + TILE_WIDTH / 2;
const secondTileCenter =
startX + TILE_WIDTH + group.gap + TILE_WIDTH / 2;
createDomino(firstTileCenter, group.accent);
createDomino(secondTileCenter, group.accent);
// Group name above the pair.
const groupLabel = createLabel(
group.name,
group.subtitle,
group.accent,
2.72
);
groupLabel.position.set(group.center, TILE_HEIGHT + 0.58, 0.65);
// Small accent tab above the group.
solidLine(
[
[group.center - 0.48, TILE_HEIGHT + 0.2, 0.48],
[group.center + 0.48, TILE_HEIGHT + 0.2, 0.48]
],
group.accent,
0.95
);
// Exact neighboring gap between the two tiles.
const gapLeft = startX + TILE_WIDTH;
const gapRight = gapLeft + group.gap;
const dimensionY = -0.43;
solidLine(
[
[gapLeft, -0.015, 0.43],
[gapLeft, -0.55, 0.43]
],
group.accent,
0.8
);
solidLine(
[
[gapRight, -0.015, 0.43],
[gapRight, -0.55, 0.43]
],
group.accent,
0.8
);
solidLine(
[
[gapLeft, dimensionY, 0.43],
[gapRight, dimensionY, 0.43]
],
group.accent,
1
);
arrowHead(
[gapLeft + 0.075, dimensionY, 0.43],
Math.PI / 2,
group.accent
);
arrowHead(
[gapRight - 0.075, dimensionY, 0.43],
-Math.PI / 2,
group.accent
);
const gapLabel = createLabel(
group.gap.toFixed(2),
"NEIGHBOR GAP",
group.accent,
1.3
);
gapLabel.position.set(
(gapLeft + gapRight) / 2,
-0.69,
0.65
);
}
// -------------------------------------------------------------------------
// Camera sizing and direct camera controls
// -------------------------------------------------------------------------
function updateCamera() {
const aspect =
renderer.domElement.clientWidth /
renderer.domElement.clientHeight;
const fittedHeight = Math.max(
MIN_VIEW_HEIGHT,
WORLD_WIDTH / aspect
);
const viewHeight = fittedHeight / zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.position.set(
cameraTarget.x,
cameraTarget.y,
CAMERA_DISTANCE
);
camera.lookAt(cameraTarget.x, cameraTarget.y, 0);
camera.updateProjectionMatrix();
}
function resize() {
renderer.setSize(
stage.clientWidth,
stage.clientHeight,
false
);
updateCamera();
}
function resetView() {
zoom = 1;
cameraTarget.set(0, 0.78, 0);
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
const worldPerPixel =
(camera.top - camera.bottom) /
renderer.domElement.clientHeight;
cameraTarget.x -= deltaX * worldPerPixel;
cameraTarget.y += deltaY * worldPerPixel;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(-event.deltaY * 0.001);
zoom = THREE.MathUtils.clamp(
zoom * factor,
0.72,
2.1
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#resetView").addEventListener(
"click",
resetView
);
const annotationButton =
document.querySelector("#toggleAnnotations");
let annotationsVisible = true;
annotationButton.addEventListener("click", () => {
annotationsVisible = !annotationsVisible;
annotations.visible = annotationsVisible;
annotationButton.setAttribute(
"aria-pressed",
String(annotationsVisible)
);
annotationButton.textContent = annotationsVisible
? "Dimensions on"
: "Dimensions off";
});
window.addEventListener("resize", resize);
resize();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```