Prompt specification
Build or customize the Three.js 3D scene "Base-ten unit rod and flat set" 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: Base-ten unit rod and flat set
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/base-ten-unit-rod-and-flat-set-x1717
Scene Description Prompt:
Show a low-poly unit cube, ten-cube rod, and hundred-unit flat with exact visible subdivisions. One HTML scene using Three.js from cdnjs.
Working Three.js Starter (base-ten-unit-rod-and-flat-set-x1717):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>One, Ten, Hundred — Three.js Unit Study</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
color: #edf7ff;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
top: 28px;
left: 30px;
z-index: 10;
width: min(430px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.65);
}
.eyebrow {
margin-bottom: 9px;
color: #65dfd1;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 750;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 390px;
margin: 14px 0 0;
color: #a8bdd0;
font-size: 14px;
line-height: 1.55;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 18px;
}
.chip {
padding: 7px 10px;
border: 1px solid rgba(137, 179, 211, 0.24);
border-radius: 999px;
background: rgba(8, 21, 37, 0.68);
color: #cde1f1;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
backdrop-filter: blur(8px);
}
.controls {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 20;
display: flex;
align-items: center;
gap: 14px;
color: #91a9bd;
font-size: 12px;
}
.help {
padding: 9px 12px;
border: 1px solid rgba(137, 179, 211, 0.16);
border-radius: 9px;
background: rgba(7, 17, 31, 0.72);
backdrop-filter: blur(10px);
}
button {
padding: 10px 14px;
border: 1px solid rgba(119, 220, 208, 0.42);
border-radius: 9px;
background: rgba(16, 56, 68, 0.78);
color: #dffcf8;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
background 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(24, 82, 92, 0.92);
transform: translateY(-1px);
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #07111f;
color: #65dfd1;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
@media (max-width: 700px) {
.hud {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.subtitle {
max-width: 320px;
font-size: 12px;
}
.chips {
margin-top: 12px;
}
.controls {
right: 12px;
bottom: 12px;
}
.help {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive Three.js scene showing a unit cube, ten-cube rod, and hundred-unit flat"></div>
<header class="hud">
<div class="eyebrow">Polyhedra / Unit Study</div>
<h1>One, ten,<br>hundred.</h1>
<p class="subtitle">
Every visible seam marks an exact one-unit boundary.
The forms use 1, 10, and 100 cubic cells.
</p>
<div class="chips">
<span class="chip">1 × 1 × 1 UNIT</span>
<span class="chip">10 × 1 × 1 ROD</span>
<span class="chip">10 × 10 × 1 FLAT</span>
<span class="chip">CELL PITCH = 1</span>
</div>
</header>
<div class="controls">
<div class="help">Drag: orbit · Shift-drag: pan · Scroll: zoom</div>
<button id="reset" type="button">Reset view</button>
</div>
<div id="loading">Building unit study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneElement = document.querySelector("#scene");
const loadingElement = document.querySelector("#loading");
const resetButton = document.querySelector("#reset");
// ------------------------------------------------------------
// Renderer, scene, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneElement.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.016);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
200
);
const hemisphere = new THREE.HemisphereLight(
0xc7e9ff,
0x172033,
2.15
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-9, 18, 12);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -19;
keyLight.shadow.camera.right = 19;
keyLight.shadow.camera.top = 19;
keyLight.shadow.camera.bottom = -19;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 50;
keyLight.shadow.bias = -0.0007;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4bc9ff, 1.5);
rimLight.position.set(12, 8, -12);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9e45, 30, 18, 2);
warmLight.position.set(-8, 4, 7);
scene.add(warmLight);
// ------------------------------------------------------------
// Ground and shared geometries
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x081727,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const groundGrid = new THREE.GridHelper(
44,
44,
0x2d536e,
0x19364c
);
groundGrid.position.y = 0.002;
groundGrid.material.transparent = true;
groundGrid.material.opacity = 0.2;
groundGrid.material.depthWrite = false;
scene.add(groundGrid);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const cubeEdgesGeometry = new THREE.EdgesGeometry(cubeGeometry);
const subdivisionEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x092039,
transparent: true,
opacity: 0.78,
depthWrite: false
});
const unitEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xd4fff9,
transparent: true,
opacity: 0.95,
depthWrite: false
});
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0x10243a,
roughness: 0.82,
metalness: 0.18
});
const pedestalEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x2b5672,
transparent: true,
opacity: 0.7
});
const flatMaterials = [
new THREE.MeshStandardMaterial({
color: 0x3972ce,
roughness: 0.72,
metalness: 0.08,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x4380df,
roughness: 0.72,
metalness: 0.08,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x3268bf,
roughness: 0.76,
metalness: 0.06,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x4b88e7,
roughness: 0.7,
metalness: 0.08,
flatShading: true
})
];
const rodMaterials = [
new THREE.MeshStandardMaterial({
color: 0xf39a3d,
roughness: 0.68,
metalness: 0.07,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xffb64c,
roughness: 0.66,
metalness: 0.06,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xe88931,
roughness: 0.7,
metalness: 0.07,
flatShading: true
})
];
const unitFaceMaterials = [
new THREE.MeshStandardMaterial({
color: 0x55dcca, roughness: 0.62, metalness: 0.06, flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x2ebcab, roughness: 0.66, metalness: 0.05, flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x8cf3df, roughness: 0.58, metalness: 0.04, flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x239c91, roughness: 0.72, metalness: 0.04, flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x43cdbd, roughness: 0.64, metalness: 0.05, flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x2fb3a7, roughness: 0.68, metalness: 0.05, flatShading: true
})
];
// ------------------------------------------------------------
// Helpers
// ------------------------------------------------------------
function addPedestal(width, depth, x, z) {
const geometry = new THREE.BoxGeometry(width, 0.12, depth);
const pedestal = new THREE.Mesh(geometry, pedestalMaterial);
pedestal.position.set(x, 0.04, z);
pedestal.receiveShadow = true;
pedestal.castShadow = true;
scene.add(pedestal);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry),
pedestalEdgeMaterial
);
pedestal.add(edges);
}
function addCell(x, z, material, edgeMaterial = subdivisionEdgeMaterial) {
const cell = new THREE.Mesh(cubeGeometry, material);
// Pedestals are 0.12 high; each cell is exactly one unit high.
cell.position.set(x, 0.62, z);
cell.castShadow = true;
cell.receiveShadow = true;
scene.add(cell);
// Each unit cube receives its own outline. Adjacent outlines
// coincide at exact integer boundaries, making all seams visible.
const edges = new THREE.LineSegments(
cubeEdgesGeometry,
edgeMaterial
);
edges.renderOrder = 2;
cell.add(edges);
return cell;
}
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(title, subtitle, accent, x, y, z) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 752, 204, 32);
ctx.fillStyle = "rgba(5, 17, 31, 0.88)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.lineWidth = 4;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(38, 39, 8, 142);
ctx.textBaseline = "middle";
ctx.fillStyle = "#f0f9ff";
ctx.font = "800 58px system-ui, sans-serif";
ctx.fillText(title, 70, 83);
ctx.fillStyle = "#a8c0d4";
ctx.font = "700 30px system-ui, sans-serif";
ctx.fillText(subtitle, 70, 150);
const texture = new THREE.CanvasTexture(canvas);
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.position.set(x, y, z);
sprite.scale.set(4.25, 1.22, 1);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
// ------------------------------------------------------------
// 1. Low-poly unit cube
// ------------------------------------------------------------
const unitX = -6.8;
const unitZ = -1.8;
addPedestal(1.75, 1.75, unitX, unitZ);
const unitCube = new THREE.Mesh(
cubeGeometry,
unitFaceMaterials
);
unitCube.position.set(unitX, 0.62, unitZ);
unitCube.castShadow = true;
unitCube.receiveShadow = true;
scene.add(unitCube);
const unitEdges = new THREE.LineSegments(
cubeEdgesGeometry,
unitEdgeMaterial
);
unitEdges.renderOrder = 3;
unitCube.add(unitEdges);
makeLabel(
"1 × 1 × 1",
"LOW-POLY UNIT CUBE",
"#65dfd1",
unitX,
2.05,
unitZ
);
// ------------------------------------------------------------
// 2. Ten-cube rod: 10 cells in one straight line
// ------------------------------------------------------------
const rodX = -5.0;
const rodZ = 4.1;
const rodCount = 10;
addPedestal(10.75, 1.75, rodX, rodZ);
for (let index = 0; index < rodCount; index++) {
const cellX = rodX + index - (rodCount - 1) / 2;
addCell(cellX, rodZ, rodMaterials[index % rodMaterials.length]);
}
makeLabel(
"10 × 1 × 1",
"TEN-CUBE ROD",
"#ffb64c",
rodX,
2.05,
rodZ
);
// ------------------------------------------------------------
// 3. Hundred-unit flat: 10 × 10 = 100 cells
// ------------------------------------------------------------
const flatX = 4.1;
const flatZ = -1.2;
const flatSize = 10;
addPedestal(10.75, 10.75, flatX, flatZ);
for (let row = 0; row < flatSize; row++) {
for (let column = 0; column < flatSize; column++) {
const cellX =
flatX + column - (flatSize - 1) / 2;
const cellZ =
flatZ + row - (flatSize - 1) / 2;
const paletteIndex =
(row + column * 2 + (row % 2)) % flatMaterials.length;
addCell(cellX, cellZ, flatMaterials[paletteIndex]);
}
}
makeLabel(
"10 × 10 × 1",
"HUNDRED-UNIT FLAT",
"#66a8ff",
flatX,
1.9,
flatZ - 5.35
);
console.assert(rodCount === 10, "The rod must contain exactly 10 cells.");
console.assert(
flatSize * flatSize === 100,
"The flat must contain exactly 100 cells."
);
// ------------------------------------------------------------
// Custom camera controls — no Three.js addons
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(-0.2, 0.55, -0.25),
theta: 0.61,
phi: 0.91,
radius: 27
};
let userAdjustedCamera = false;
let drag = null;
function fittingRadius() {
const aspect = window.innerWidth / window.innerHeight;
const responsiveScale = Math.max(1, 1.15 / aspect);
return THREE.MathUtils.clamp(27 * responsiveScale, 18, 70);
}
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y +
controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetCamera() {
controls.target.set(-0.2, 0.55, -0.25);
controls.theta = 0.61;
controls.phi = 0.91;
controls.radius = fittingRadius();
userAdjustedCamera = false;
updateCamera();
}
function panCamera(deltaX, deltaY) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrixWorld, 1);
const visibleHeight =
2 *
controls.radius *
Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5));
const panSpeed = visibleHeight / window.innerHeight;
controls.target
.addScaledVector(right, -deltaX * panSpeed)
.addScaledVector(up, deltaY * panSpeed);
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-16,
16
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-16,
16
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.shiftKey
};
userAdjustedCamera = true;
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag || drag.id !== event.pointerId) return;
const deltaX = event.clientX - drag.x;
const deltaY = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan || event.shiftKey) {
panCamera(deltaX, deltaY);
} else {
controls.theta -= deltaX * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - deltaY * 0.006,
0.25,
1.46
);
}
updateCamera();
});
function endDrag(event) {
if (drag && drag.id === event.pointerId) {
drag = null;
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
11,
75
);
userAdjustedCamera = true;
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
if (!userAdjustedCamera) {
controls.radius = fittingRadius();
}
updateCamera();
});
// ------------------------------------------------------------
// Initial frame and render loop
// ------------------------------------------------------------
resetCamera();
renderer.render(scene, camera);
loadingElement.remove();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```