Prompt specification
Build or customize the Three.js 3D scene "Overlapping brick course sample" 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: Overlapping brick course sample
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/overlapping-brick-course-sample-x2173
Scene Description Prompt:
Overlapping brick course sample. Build three short masonry courses with alternating vertical joints. Expose individual rectangular bricks and keep mortar gaps visible so the overlap pattern can be counted. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (overlapping-brick-course-sample-x2173):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alternating Masonry Courses</title>
<style>
:root {
color-scheme: light;
--ink: #382a24;
--muted: #75675f;
--panel: rgba(255, 252, 247, 0.82);
--line: rgba(74, 49, 38, 0.16);
--accent: #b85e46;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ece7df;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(360px, calc(100vw - 36px));
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 12px 38px rgba(61, 43, 34, 0.1);
backdrop-filter: blur(12px);
pointer-events: none;
user-select: none;
}
.eyebrow {
margin-bottom: 6px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 28px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.description {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.bond {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(184, 94, 70, 0.22);
border-radius: 999px;
background: rgba(184, 94, 70, 0.08);
color: #8f4634;
font-size: 12px;
font-weight: 750;
}
.bond-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 3px rgba(184, 94, 70, 0.12);
}
.course-stats {
position: fixed;
z-index: 10;
left: 18px;
bottom: 18px;
display: grid;
grid-template-columns: repeat(3, minmax(100px, 1fr));
gap: 8px;
width: min(510px, calc(100vw - 36px));
pointer-events: none;
user-select: none;
}
.stat {
min-width: 0;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 8px 24px rgba(61, 43, 34, 0.08);
backdrop-filter: blur(10px);
}
.stat-number {
display: block;
margin-bottom: 2px;
color: var(--accent);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stat-value {
display: block;
overflow: hidden;
color: var(--ink);
font-size: 13px;
font-weight: 720;
text-overflow: ellipsis;
white-space: nowrap;
}
.controls {
position: fixed;
z-index: 12;
top: 18px;
right: 18px;
display: flex;
gap: 7px;
}
button {
min-width: 38px;
height: 38px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: var(--panel);
color: var(--ink);
box-shadow: 0 8px 24px rgba(61, 43, 34, 0.08);
backdrop-filter: blur(10px);
cursor: pointer;
font: inherit;
font-size: 13px;
font-weight: 720;
transition:
transform 120ms ease,
background 120ms ease;
}
button:hover {
background: #fffdf9;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.hint {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel);
color: var(--muted);
box-shadow: 0 8px 24px rgba(61, 43, 34, 0.07);
backdrop-filter: blur(10px);
font-size: 11px;
pointer-events: none;
user-select: none;
}
#tooltip {
position: fixed;
z-index: 20;
display: none;
max-width: 220px;
padding: 8px 10px;
border: 1px solid rgba(70, 45, 34, 0.18);
border-radius: 9px;
background: rgba(48, 34, 28, 0.9);
color: #fffaf5;
box-shadow: 0 8px 22px rgba(44, 30, 24, 0.2);
font-size: 11px;
font-weight: 650;
line-height: 1.35;
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 720px) {
.panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.description {
display: none;
}
.bond {
margin-top: 10px;
}
.controls {
top: auto;
right: 12px;
bottom: 94px;
}
.course-stats {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 5px;
}
.stat {
padding: 8px;
}
.stat-value {
font-size: 11px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="panel">
<div class="eyebrow">Masonry course study</div>
<h1>Alternating joint pattern</h1>
<p class="description">
Three short courses of exposed rectangular blocks. The vertical joints
alternate by half a brick so each course overlaps the joints beneath it.
</p>
<div class="bond">
<span class="bond-dot"></span>
A → B → A · 16 visible blocks
</div>
</div>
<div class="controls">
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
<button id="reset" type="button">Reset</button>
</div>
<div class="course-stats">
<div class="stat">
<span class="stat-number">Course 01</span>
<span class="stat-value">5 full bricks</span>
</div>
<div class="stat">
<span class="stat-number">Course 02</span>
<span class="stat-value">4 full + 2 half</span>
</div>
<div class="stat">
<span class="stat-number">Course 03</span>
<span class="stat-value">5 full bricks</span>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div id="tooltip" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xece7df);
scene.fog = new THREE.Fog(0xece7df, 18, 38);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional masonry course sample"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfffbf4, 0x8f8175, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0dc, 3.4);
keyLight.position.set(-4.5, 9, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xdbe8ff, 1.25);
fillLight.position.set(6, 4, -5);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0xe7e1d8,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.235;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Masonry dimensions
// ------------------------------------------------------------
const BRICK_WIDTH = 1.5;
const HALF_BRICK_WIDTH = 0.7;
const BRICK_HEIGHT = 0.62;
const BRICK_DEPTH = 0.82;
const JOINT = 0.1;
const COURSE_Y = [0.31, 1.02, 1.73];
const WALL_WIDTH = 7.9;
const wall = new THREE.Group();
scene.add(wall);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(8.5, 0.22, 1.3),
new THREE.MeshStandardMaterial({
color: 0xb9b0a6,
roughness: 0.95,
metalness: 0
})
);
plinth.position.set(0, -0.11, -0.015);
plinth.castShadow = true;
plinth.receiveShadow = true;
wall.add(plinth);
// Recessed backing makes every open joint readable.
const backing = new THREE.Mesh(
new THREE.BoxGeometry(8.16, 2.18, 0.18),
new THREE.MeshStandardMaterial({
color: 0xbdb5aa,
roughness: 1,
metalness: 0
})
);
backing.position.set(0, 0.99, -0.47);
backing.receiveShadow = true;
wall.add(backing);
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xd1c9bd,
roughness: 0.98,
metalness: 0
});
// Flush, slightly recessed mortar strips.
function addJointStrip(width, height, x, y) {
const strip = new THREE.Mesh(
new THREE.BoxGeometry(width, height, 0.8),
jointMaterial
);
strip.position.set(x, y, 0.005);
strip.receiveShadow = true;
wall.add(strip);
}
// Two horizontal bed joints.
addJointStrip(WALL_WIDTH, JOINT, 0, COURSE_Y[0] + BRICK_HEIGHT / 2 + JOINT / 2);
addJointStrip(WALL_WIDTH, JOINT, 0, COURSE_Y[1] + BRICK_HEIGHT / 2 + JOINT / 2);
// Course A joints.
[-2.4, -0.8, 0.8, 2.4].forEach((x) => {
addJointStrip(JOINT, BRICK_HEIGHT, x, COURSE_Y[0]);
addJointStrip(JOINT, BRICK_HEIGHT, x, COURSE_Y[2]);
});
// Course B joints, offset by half a brick.
[-3.2, -1.6, 0, 1.6, 3.2].forEach((x) => {
addJointStrip(JOINT, BRICK_HEIGHT, x, COURSE_Y[1]);
});
// ------------------------------------------------------------
// Individual voxel-like bricks
// ------------------------------------------------------------
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x56352b,
transparent: true,
opacity: 0.42
});
const brickMeshes = [];
let hoveredBrick = null;
const courseColors = [
["#bd6046", "#c56a4d", "#b85b43", "#c06449", "#bf6248"],
["#ad513c", "#b95a42", "#b85a42", "#bd6248"],
["#c66b4f", "#ba5b43", "#c26449", "#b95b42", "#c56a50"]
];
function addBrick({
x,
y,
width,
color,
label,
course,
brickNumber
}) {
const geometry = new THREE.BoxGeometry(
width,
BRICK_HEIGHT,
BRICK_DEPTH
);
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
emissive: 0x000000,
emissiveIntensity: 0
});
const brick = new THREE.Mesh(geometry, material);
brick.position.set(x, y, 0);
brick.castShadow = true;
brick.receiveShadow = true;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
edgeMaterial
);
brick.add(edges);
brick.userData = {
label,
course,
brickNumber,
baseColor: new THREE.Color(color)
};
brickMeshes.push(brick);
wall.add(brick);
return brick;
}
// Course 1: five full bricks.
[-3.2, -1.6, 0, 1.6, 3.2].forEach((x, index) => {
addBrick({
x,
y: COURSE_Y[0],
width: BRICK_WIDTH,
color: courseColors[0][index],
label: `Course 1 · Full brick ${index + 1}`,
course: 1,
brickNumber: index + 1
});
});
// Course 2: four full bricks plus two rectangular end halves.
addBrick({
x: -3.6,
y: COURSE_Y[1],
width: HALF_BRICK_WIDTH,
color: "#a94e3a",
label: "Course 2 · Left half brick",
course: 2,
brickNumber: 1
});
[-2.4, -0.8, 0.8, 2.4].forEach((x, index) => {
addBrick({
x,
y: COURSE_Y[1],
width: BRICK_WIDTH,
color: courseColors[1][index],
label: `Course 2 · Full brick ${index + 1}`,
course: 2,
brickNumber: index + 2
});
});
addBrick({
x: 3.6,
y: COURSE_Y[1],
width: HALF_BRICK_WIDTH,
color: "#ad513c",
label: "Course 2 · Right half brick",
course: 2,
brickNumber: 6
});
// Course 3: five full bricks, aligned with Course 1.
[-3.2, -1.6, 0, 1.6, 3.2].forEach((x, index) => {
addBrick({
x,
y: COURSE_Y[2],
width: BRICK_WIDTH,
color: courseColors[2][index],
label: `Course 3 · Full brick ${index + 1}`,
course: 3,
brickNumber: index + 1
});
});
// ------------------------------------------------------------
// Custom camera controls: no addon modules are used
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 0.9, 0);
const defaultYaw = 0.29;
const defaultPitch = 0.27;
let yaw = defaultYaw;
let pitch = defaultPitch;
let zoomFactor = 1;
let fitDistance = 10;
const pointer = {
down: false,
x: 0,
y: 0,
moved: false
};
const tooltip = document.getElementById("tooltip");
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
function calculateFitDistance() {
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const sceneWidth = 8.8;
const sceneHeight = 2.65;
const distanceForWidth =
sceneWidth / (2 * Math.tan(verticalFov / 2) * camera.aspect);
const distanceForHeight =
sceneHeight / (2 * Math.tan(verticalFov / 2));
return Math.max(distanceForWidth, distanceForHeight) * 1.12;
}
function updateCamera() {
fitDistance = calculateFitDistance();
const radius = fitDistance * zoomFactor;
camera.position.set(
target.x + Math.sin(yaw) * Math.cos(pitch) * radius,
target.y + Math.sin(pitch) * radius,
target.z + Math.cos(yaw) * Math.cos(pitch) * radius
);
camera.lookAt(target);
}
function resetView() {
yaw = defaultYaw;
pitch = defaultPitch;
zoomFactor = 1;
updateCamera();
}
function setHoveredBrick(nextBrick) {
if (hoveredBrick === nextBrick) return;
if (hoveredBrick) {
hoveredBrick.material.emissive.setHex(0x000000);
hoveredBrick.material.emissiveIntensity = 0;
}
hoveredBrick = nextBrick;
if (hoveredBrick) {
hoveredBrick.material.emissive.setHex(0x3a1209);
hoveredBrick.material.emissiveIntensity = 0.24;
tooltip.textContent = hoveredBrick.userData.label;
tooltip.style.display = "block";
} else {
tooltip.style.display = "none";
}
}
function updateHover(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(brickMeshes, false);
if (hits.length) {
setHoveredBrick(hits[0].object);
const tooltipWidth = 220;
const tooltipHeight = 40;
const left = Math.min(
event.clientX + 16,
window.innerWidth - tooltipWidth - 10
);
const top = Math.min(
event.clientY + 16,
window.innerHeight - tooltipHeight - 10
);
tooltip.style.left = `${Math.max(8, left)}px`;
tooltip.style.top = `${Math.max(8, top)}px`;
} else {
setHoveredBrick(null);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
pointer.down = true;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointer.down) {
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
pointer.moved = true;
}
yaw -= dx * 0.006;
pitch = THREE.MathUtils.clamp(
pitch + dy * 0.005,
-0.08,
1.08
);
updateCamera();
} else {
updateHover(event);
}
});
function endPointer(event) {
pointer.down = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("pointerleave", () => {
if (!pointer.down) setHoveredBrick(null);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomFactor = THREE.MathUtils.clamp(
zoomFactor * Math.exp(event.deltaY * 0.001),
0.62,
1.75
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
yaw -= 0.08;
break;
case "ArrowRight":
yaw += 0.08;
break;
case "ArrowUp":
pitch = THREE.MathUtils.clamp(pitch + 0.06, -0.08, 1.08);
break;
case "ArrowDown":
pitch = THREE.MathUtils.clamp(pitch - 0.06, -0.08, 1.08);
break;
case "+":
case "=":
zoomFactor = Math.max(0.62, zoomFactor * 0.9);
break;
case "-":
case "_":
zoomFactor = Math.min(1.75, zoomFactor * 1.1);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.getElementById("reset").addEventListener("click", resetView);
document.getElementById("zoom-in").addEventListener("click", () => {
zoomFactor = Math.max(0.62, zoomFactor * 0.9);
updateCamera();
});
document.getElementById("zoom-out").addEventListener("click", () => {
zoomFactor = Math.min(1.75, zoomFactor * 1.1);
updateCamera();
});
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
}
window.addEventListener("resize", onResize);
renderer.domElement.style.cursor = "grab";
updateCamera();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```