Prompt specification
Build or customize the Three.js 3D scene "Coarse and fine abrasive tiles" 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: Coarse and fine abrasive tiles
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/coarse-and-fine-abrasive-tiles-x0297
Scene Description Prompt:
Compare equal-sized voxel sandpaper tiles with coarse and fine grains above smooth backing. Use Three.js from cdnjs in one standalone HTML file.
Working Three.js Starter (coarse-and-fine-abrasive-tiles-x0297):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Sandpaper — Coarse vs Fine</title>
<style>
:root {
color-scheme: light;
--ink: #20272c;
--muted: #667077;
--panel: rgba(248, 247, 243, 0.86);
--border: rgba(32, 39, 44, 0.12);
--coarse: #c8783f;
--fine: #e3ad64;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9d6ce;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-panel {
position: absolute;
top: 24px;
left: 28px;
max-width: 420px;
padding: 17px 20px 16px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(35, 39, 40, 0.09);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 6px;
color: #8a6b49;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 38px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
position: absolute;
top: 24px;
right: 28px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 11px;
padding: 10px 14px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 8px 24px rgba(35, 39, 40, 0.08);
backdrop-filter: blur(12px);
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffefa;
}
button:active {
transform: translateY(0);
}
.comparison {
position: absolute;
left: 50%;
bottom: 24px;
display: flex;
width: min(650px, calc(100% - 32px));
transform: translateX(-50%);
overflow: hidden;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(35, 39, 40, 0.1);
backdrop-filter: blur(12px);
}
.sample {
display: flex;
flex: 1;
align-items: center;
gap: 13px;
padding: 14px 18px;
}
.sample + .sample {
border-left: 1px solid var(--border);
}
.sample-icon {
position: relative;
flex: 0 0 auto;
width: 32px;
height: 32px;
border-radius: 9px;
background: #e8e4db;
box-shadow: inset 0 0 0 1px rgba(32, 39, 44, 0.1);
}
.sample-icon::before {
content: "";
position: absolute;
inset: 7px;
background:
radial-gradient(circle, var(--fine) 0 2px, transparent 2.5px) 0 0 / 9px 9px,
radial-gradient(circle, var(--fine) 0 2px, transparent 2.5px) 4px 4px / 9px 9px;
}
.sample.coarse .sample-icon::before {
background:
radial-gradient(circle, var(--coarse) 0 4px, transparent 4.5px) 1px 1px / 14px 14px,
radial-gradient(circle, var(--coarse) 0 4px, transparent 4.5px) 8px 8px / 14px 14px;
}
.sample b {
display: block;
font-size: 11px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.sample small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.hint {
position: absolute;
right: 28px;
bottom: 28px;
color: rgba(32, 39, 44, 0.56);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 10;
background: #d9d6ce;
color: #667077;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-panel {
top: 14px;
left: 14px;
right: 14px;
max-width: none;
padding: 13px 15px;
}
.subtitle {
max-width: 290px;
font-size: 11px;
}
.controls {
top: 126px;
right: 14px;
}
button {
padding: 9px 11px;
font-size: 11px;
}
.comparison {
bottom: 14px;
}
.sample {
gap: 9px;
padding: 11px;
}
.sample-icon {
width: 28px;
height: 28px;
}
.sample small {
font-size: 9px;
}
.hint {
display: none;
}
}
@media (max-width: 470px) {
.sample-icon {
display: none;
}
.sample b {
font-size: 10px;
}
.sample small {
font-size: 8px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive comparison of coarse and fine voxel sandpaper"></main>
<div class="hud">
<section class="title-panel">
<div class="eyebrow">Material study · 01</div>
<h1>Voxel Grit</h1>
<p class="subtitle">
Equal-sized sandpaper tiles with identical smooth backings.
Only the scale and density of the grains change.
</p>
</section>
<nav class="controls" aria-label="Camera controls">
<button id="reset" type="button">Reset view</button>
<button id="top" type="button">Top view</button>
</nav>
<section class="comparison" aria-label="Comparison legend">
<div class="sample coarse">
<span class="sample-icon" aria-hidden="true"></span>
<div>
<b>Coarse</b>
<small>Large, separated voxels</small>
</div>
</div>
<div class="sample fine">
<span class="sample-icon" aria-hidden="true"></span>
<div>
<b>Fine</b>
<small>Small, dense voxels</small>
</div>
</div>
</section>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
</div>
<div id="loading">Loading voxel 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 container = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9d6ce);
scene.fog = new THREE.Fog(0xd9d6ce, 13, 29);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional coarse and fine voxel sandpaper comparison"
);
container.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(
0xfff9ed,
0x707984,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d9, 4.1);
keyLight.position.set(-4.5, 9, 6);
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 = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9ddff, 1.15);
fillLight.position.set(6, 4, -5);
scene.add(fillLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xcfcac0,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.012;
floor.receiveShadow = true;
scene.add(floor);
const tileWidth = 3.38;
const tileDepth = 2.53;
const tileSpacing = 3.82;
const backingTop = 0.28;
const edgeMaterial = new THREE.MeshStandardMaterial({
color: 0x26333d,
roughness: 0.48,
metalness: 0.08
});
const backingMaterial = new THREE.MeshStandardMaterial({
color: 0x53636c,
roughness: 0.28,
metalness: 0.08
});
function addBacking(x) {
const group = new THREE.Group();
group.position.x = x;
const edge = new THREE.Mesh(
new THREE.BoxGeometry(tileWidth + 0.18, 0.2, tileDepth + 0.18),
edgeMaterial
);
edge.position.y = 0.1;
edge.castShadow = true;
edge.receiveShadow = true;
group.add(edge);
const smoothBacking = new THREE.Mesh(
new THREE.BoxGeometry(tileWidth, 0.08, tileDepth),
backingMaterial
);
smoothBacking.position.y = 0.24;
smoothBacking.castShadow = true;
smoothBacking.receiveShadow = true;
group.add(smoothBacking);
scene.add(group);
}
addBacking(-tileSpacing / 2);
addBacking(tileSpacing / 2);
function seededRandom(seed) {
let value = seed >>> 0;
return function random() {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
function addGrains({
x,
step,
grainMin,
grainMax,
seed,
lift,
roughness
}) {
const random = seededRandom(seed);
const grainWidth = tileWidth - 0.16;
const grainDepth = tileDepth - 0.16;
const columns = Math.floor(grainWidth / step);
const rows = Math.floor(grainDepth / step);
const count = columns * rows;
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness,
metalness: 0.02
});
const grains = new THREE.InstancedMesh(
geometry,
material,
count
);
grains.instanceMatrix.setUsage(THREE.StaticDrawUsage);
grains.castShadow = true;
grains.receiveShadow = true;
grains.frustumCulled = false;
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const jitterX = (random() - 0.5) * step * 0.22;
const jitterZ = (random() - 0.5) * step * 0.22;
const size =
grainMin + random() * (grainMax - grainMin);
const grainX =
x +
(column - (columns - 1) / 2) * step +
jitterX;
const grainZ =
(row - (rows - 1) / 2) * step +
jitterZ;
const elevation = random() * lift;
dummy.position.set(
grainX,
backingTop + size / 2 + elevation,
grainZ
);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(size, size, size);
dummy.updateMatrix();
grains.setMatrixAt(index, dummy.matrix);
const hue = 0.085 + (random() - 0.5) * 0.025;
const saturation = 0.58 + random() * 0.12;
const lightness = 0.49 + random() * 0.12;
color.setHSL(hue, saturation, lightness);
grains.setColorAt(index, color);
index++;
}
}
grains.instanceMatrix.needsUpdate = true;
if (grains.instanceColor) {
grains.instanceColor.needsUpdate = true;
}
scene.add(grains);
}
addGrains({
x: -tileSpacing / 2,
step: 0.275,
grainMin: 0.205,
grainMax: 0.265,
seed: 1251,
lift: 0.018,
roughness: 0.86
});
addGrains({
x: tileSpacing / 2,
step: 0.12,
grainMin: 0.087,
grainMax: 0.111,
seed: 9873,
lift: 0.009,
roughness: 0.97
});
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(title, subtitle) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 496, 144, 26);
ctx.fillStyle = "rgba(28, 37, 43, 0.9)";
ctx.fill();
ctx.strokeStyle = "rgba(255, 255, 255, 0.16)";
ctx.lineWidth = 2;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#fffaf0";
ctx.font = "800 48px system-ui, sans-serif";
ctx.fillText(title, 256, 64);
ctx.fillStyle = "rgba(255, 250, 240, 0.68)";
ctx.font = "700 22px system-ui, sans-serif";
ctx.letterSpacing = "2px";
ctx.fillText(subtitle, 256, 110);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.9, 0.594, 1);
sprite.renderOrder = 10;
return sprite;
}
const coarseLabel = makeLabel("COARSE", "LARGE VOXELS");
coarseLabel.position.set(-tileSpacing / 2, 1.35, -1.48);
scene.add(coarseLabel);
const fineLabel = makeLabel("FINE", "DENSE VOXELS");
fineLabel.position.set(tileSpacing / 2, 1.35, -1.48);
scene.add(fineLabel);
// Camera controls are implemented directly without Three.js addons.
const target = new THREE.Vector3(0, 0.2, 0);
const desired = {
theta: 0,
phi: 0.87,
radius: 10.6
};
const current = {
theta: 0,
phi: 0.87,
radius: 10.6
};
let hasInteracted = false;
const pointers = new Map();
function responsiveRadius() {
const aspect = window.innerWidth / window.innerHeight;
return aspect < 0.8 ? 16.4 : 10.6;
}
function setCamera() {
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
}
function resetView(immediate = false) {
desired.theta = 0;
desired.phi = 0.87;
desired.radius = responsiveRadius();
if (immediate) {
current.theta = desired.theta;
current.phi = desired.phi;
current.radius = desired.radius;
setCamera();
}
}
function topView() {
desired.theta = 0;
desired.phi = 0.035;
desired.radius = responsiveRadius() * 1.03;
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.classList.add("dragging");
hasInteracted = true;
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
if (pointers.size === 1) {
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
desired.theta -= deltaX * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi + deltaY * 0.005,
0.12,
1.42
);
} else if (pointers.size === 2) {
const entries = [...pointers.entries()];
const other = entries.find(([id]) => id !== event.pointerId)?.[1];
if (other) {
const oldDistance = Math.hypot(
previous.x - other.x,
previous.y - other.y
);
const newDistance = Math.hypot(
event.clientX - other.x,
event.clientY - other.y
);
if (oldDistance > 0 && newDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (oldDistance / newDistance),
6.8,
22
);
}
}
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("lostpointercapture", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
hasInteracted = true;
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
6.8,
22
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
hasInteracted = false;
resetView();
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
document.querySelector("#reset").addEventListener("click", () => {
hasInteracted = false;
resetView();
});
document.querySelector("#top").addEventListener("click", () => {
hasInteracted = true;
topView();
});
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.fov = aspect < 0.8 ? 52 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
if (!hasInteracted) {
resetView();
}
}
window.addEventListener("resize", onResize);
resetView(true);
onResize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-9 * delta);
current.theta = THREE.MathUtils.lerp(
current.theta,
desired.theta,
smoothing
);
current.phi = THREE.MathUtils.lerp(
current.phi,
desired.phi,
smoothing
);
current.radius = THREE.MathUtils.lerp(
current.radius,
desired.radius,
smoothing
);
setCamera();
renderer.render(scene, camera);
}
animate();
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
</script>
</body>
</html>
```