Prompt specification
Build or customize the Three.js 3D scene "Two-row counting bead frame" 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: Two-row counting bead frame
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-row-counting-bead-frame-x0325
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts counting beads. Build a small frame with two rails and five beads per rail; leave clear spacing between beads so individual units can be counted directly. Voxel style.
Working Three.js Starter (two-row-counting-bead-frame-x0325):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Counting Beads</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e2d6;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
top: 24px;
left: 24px;
z-index: 2;
pointer-events: none;
color: #35424a;
}
.label {
display: inline-block;
margin-bottom: 9px;
padding: 6px 9px;
border: 2px solid #35424a;
background: #f7f0df;
box-shadow: 4px 4px 0 #35424a;
font-size: 11px;
font-weight: 900;
letter-spacing: 0.16em;
}
.hud h1 {
margin: 0;
font-size: clamp(25px, 4vw, 44px);
line-height: 1;
letter-spacing: -0.04em;
text-shadow: 2px 2px 0 #f7f0df;
}
.hud p {
margin: 10px 0 0;
padding: 7px 10px;
width: fit-content;
background: rgba(247, 240, 223, 0.88);
font-size: 13px;
font-weight: 700;
}
.hint {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 2;
padding: 9px 12px;
border: 2px solid rgba(53, 66, 74, 0.35);
background: rgba(247, 240, 223, 0.86);
color: #35424a;
pointer-events: none;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.03em;
}
@media (max-width: 600px) {
.hud {
top: 15px;
left: 15px;
}
.hud h1 {
font-size: 28px;
}
.hud p {
font-size: 11px;
}
.hint {
right: 12px;
bottom: 12px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div class="hud" aria-hidden="true">
<div class="label">COUNTING BEADS</div>
<h1>5 + 5 = 10</h1>
<p>Five clearly separated beads on each rail.</p>
</div>
<div class="hint" aria-hidden="true">
Drag to orbit · Scroll to zoom · Hover a bead
</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(0xe8e2d6);
scene.fog = new THREE.Fog(0xe8e2d6, 26, 60);
const camera = new THREE.PerspectiveCamera(
38,
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.12;
renderer.domElement.setAttribute(
"aria-label",
"Voxel counting frame with two rails and five beads on each rail"
);
renderer.domElement.tabIndex = 0;
document.body.appendChild(renderer.domElement);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x81786a, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 3.4);
keyLight.position.set(6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d9ff, 1.15);
fillLight.position.set(-7, 5, 4);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials and voxel helper
// -------------------------------------------------------------------------
function makeMaterial(color, roughness = 0.78, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
}
const materials = {
ground: makeMaterial(0xd8d0c1),
base: makeMaterial(0xb9ad98),
baseTop: makeMaterial(0xcfc3ad),
board: makeMaterial(0xf5eddc),
rowPanel: makeMaterial(0xe8dec9),
frame: makeMaterial(0x35424a),
frameSide: makeMaterial(0x44535b),
rail: makeMaterial(0x667574, 0.66),
upperHighlight: makeMaterial(0xffad9d),
upperShadow: makeMaterial(0xc64c43),
lowerHighlight: makeMaterial(0x83dfd5),
lowerShadow: makeMaterial(0x168a83)
};
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Ground and stepped voxel pedestal
// -------------------------------------------------------------------------
const ground = addBox(
scene,
[40, 0.2, 40],
[0, -1.24, 0],
materials.ground,
false
);
addBox(
scene,
[10.4, 0.38, 5.8],
[0, -0.95, -0.25],
materials.base
);
addBox(
scene,
[9.7, 0.18, 5.2],
[0, -0.69, -0.22],
materials.baseTop
);
// -------------------------------------------------------------------------
// Frame, backing board, and two rails
// -------------------------------------------------------------------------
const frame = new THREE.Group();
scene.add(frame);
// Recessed backing board.
addBox(
frame,
[8.6, 6.1, 0.32],
[0, 2.6, -0.58],
materials.board
);
// Subtle recessed panels make the two counting rows easy to distinguish.
addBox(
frame,
[7.9, 1.52, 0.08],
[0, 3.75, -0.38],
materials.rowPanel
);
addBox(
frame,
[7.9, 1.52, 0.08],
[0, 1.45, -0.38],
materials.rowPanel
);
// Chunky outer frame.
addBox(
frame,
[9.2, 0.5, 0.64],
[0, 5.72, -0.28],
materials.frame
);
addBox(
frame,
[9.2, 0.5, 0.64],
[0, -0.52, -0.28],
materials.frame
);
addBox(
frame,
[0.5, 6.25, 0.64],
[-4.35, 2.6, -0.28],
materials.frameSide
);
addBox(
frame,
[0.5, 6.25, 0.64],
[4.35, 2.6, -0.28],
materials.frameSide
);
// Two horizontal counting rails.
addBox(
frame,
[8.15, 0.28, 0.4],
[0, 3.75, -0.2],
materials.rail
);
addBox(
frame,
[8.15, 0.28, 0.4],
[0, 1.45, -0.2],
materials.rail
);
// -------------------------------------------------------------------------
// Beads: exactly five on each rail
// -------------------------------------------------------------------------
const beadMeshes = [];
const beadRecords = [];
function createBead({
x,
y,
color,
highlight,
shadow
}) {
const group = new THREE.Group();
group.position.set(x, y, 0.1);
const material = makeMaterial(color, 0.58, 0.04);
material.emissive.setHex(0x000000);
material.emissiveIntensity = 0;
// One main cube represents one countable unit.
const body = addBox(
group,
[0.78, 0.78, 0.72],
[0, 0, 0],
material
);
// Small voxel-style surface marks remain visually part of the same bead.
addBox(
group,
[0.13, 0.13, 0.035],
[-0.19, 0.19, 0.377],
highlight
);
addBox(
group,
[0.12, 0.1, 0.035],
[0.18, -0.19, 0.377],
shadow
);
const record = {
group,
body,
material,
hoverAmount: 0
};
body.userData.beadRecord = record;
beadMeshes.push(body);
beadRecords.push(record);
frame.add(group);
}
const beadXPositions = [-2.5, -1.25, 0, 1.25, 2.5];
// Upper rail: five coral beads.
beadXPositions.forEach((x) => {
createBead({
x,
y: 3.75,
color: 0xef6b5b,
highlight: materials.upperHighlight,
shadow: materials.upperShadow
});
});
// Lower rail: five turquoise beads.
beadXPositions.forEach((x) => {
createBead({
x,
y: 1.45,
color: 0x27b3a4,
highlight: materials.lowerHighlight,
shadow: materials.lowerShadow
});
});
// -------------------------------------------------------------------------
// Custom camera controls: drag to orbit, wheel/pinch to zoom
// -------------------------------------------------------------------------
const controlsTarget = new THREE.Vector3(0, 2.45, 0);
const spherical = new THREE.Spherical(12.5, 1.03, 0.72);
let fitDistance = 12.5;
let zoomFactor = 1;
let currentRadius = 12.5;
let initializedCamera = false;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let hoveredRecord = null;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function updateHover(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(beadMeshes, false);
hoveredRecord = hits.length > 0
? hits[0].object.userData.beadRecord
: null;
renderer.domElement.style.cursor = hoveredRecord
? "pointer"
: dragging
? "grabbing"
: "grab";
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.006,
0.42,
Math.PI * 0.46
);
} else {
updateHover(event);
}
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerType !== "mouse") {
hoveredRecord = null;
} else {
updateHover(event);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
hoveredRecord = null;
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomFactor = THREE.MathUtils.clamp(
zoomFactor * Math.exp(event.deltaY * 0.001),
0.68,
1.55
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.style.cursor = "grab";
// -------------------------------------------------------------------------
// Responsive framing
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
const verticalFov = THREE.MathUtils.degToRad(camera.fov);
const horizontalFov =
2 * Math.atan(Math.tan(verticalFov / 2) * camera.aspect);
// Keep the complete frame visible in both landscape and portrait layouts.
fitDistance = Math.max(
8.4 / (2 * Math.tan(verticalFov / 2)),
11.0 / (2 * Math.tan(horizontalFov / 2))
) * 1.08;
if (!initializedCamera) {
currentRadius = fitDistance;
spherical.radius = currentRadius;
initializedCamera = true;
}
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function animate() {
const desiredRadius = fitDistance * zoomFactor;
currentRadius += (desiredRadius - currentRadius) * 0.12;
spherical.radius = currentRadius;
camera.position.setFromSpherical(spherical).add(controlsTarget);
camera.lookAt(controlsTarget);
// Hover feedback makes every bead feel individually selectable.
beadRecords.forEach((record) => {
const target = record === hoveredRecord ? 1 : 0;
record.hoverAmount += (target - record.hoverAmount) * 0.14;
const scale = 1 + record.hoverAmount * 0.065;
record.group.scale.setScalar(scale);
record.material.emissive.setHex(0x5d3028);
record.material.emissiveIntensity = record.hoverAmount * 0.22;
});
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```