Prompt specification
Build or customize the Three.js 3D scene "Suffrage petition roll on a desk" 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: Suffrage petition roll on a desk
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/suffrage-petition-roll-on-a-desk-x2453
Scene Description Prompt:
A voxel suffrage petition on an 1893 New Zealand desk, using abstract signature marks. One HTML file with Three.js from cdnjs.
Working Three.js Starter (suffrage-petition-roll-on-a-desk-x2453):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Suffrage Petition — New Zealand, 1893</title>
<style>
:root {
color-scheme: dark;
--cream: #eee1bd;
--muted: #b9b6a4;
--line: rgba(238, 225, 189, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #142321;
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.caption {
position: fixed;
top: 28px;
left: 30px;
z-index: 2;
width: min(390px, calc(100vw - 60px));
color: var(--cream);
pointer-events: none;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.55);
}
.eyebrow {
margin: 0 0 9px;
color: #d6bd83;
font: 600 10px/1.2 system-ui, sans-serif;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 48px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.035em;
}
.date {
margin: 12px 0 0;
color: var(--muted);
font: 500 12px/1.4 system-ui, sans-serif;
letter-spacing: 0.08em;
}
.rule {
width: 58px;
height: 1px;
margin-top: 17px;
background: var(--line);
}
.help {
position: fixed;
left: 30px;
bottom: 24px;
z-index: 2;
margin: 0;
color: rgba(238, 225, 189, 0.66);
font: 500 10px/1.4 system-ui, sans-serif;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
}
button {
position: fixed;
top: 28px;
right: 28px;
z-index: 3;
padding: 10px 13px;
border: 1px solid rgba(238, 225, 189, 0.27);
border-radius: 2px;
color: var(--cream);
background: rgba(16, 31, 28, 0.68);
backdrop-filter: blur(8px);
font: 600 10px/1 system-ui, sans-serif;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease;
}
button:hover {
border-color: rgba(238, 225, 189, 0.55);
background: rgba(28, 49, 44, 0.84);
}
button:focus-visible {
outline: 2px solid #d6bd83;
outline-offset: 3px;
}
@media (max-width: 600px) {
.caption {
top: 20px;
left: 20px;
}
.help {
left: 20px;
bottom: 18px;
}
button {
top: 20px;
right: 20px;
}
}
</style>
</head>
<body>
<header class="caption">
<p class="eyebrow">Wellington · Archive 04</p>
<h1>A petition<br>for the vote</h1>
<p class="date">NEW ZEALAND · 1893</p>
<div class="rule"></div>
</header>
<p class="help">Drag to orbit · Shift-drag to pan · Scroll to zoom</p>
<button id="reset" type="button">Reset view</button>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x142321);
scene.fog = new THREE.Fog(0x142321, 29, 53);
const camera = new THREE.PerspectiveCamera(
34,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const target = new THREE.Vector3(0, 0.4, 0);
const controls = {
theta: 0.48,
phi: 0.84,
radius: 22,
targetTheta: 0.48,
targetPhi: 0.84,
targetRadius: 22,
target
};
function updateCamera(immediate = false) {
const amount = immediate ? 1 : 0.11;
controls.theta +=
(controls.targetTheta - controls.theta) * amount;
controls.phi +=
(controls.targetPhi - controls.phi) * amount;
controls.radius +=
(controls.targetRadius - controls.radius) * amount;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
target.x + controls.radius * sinPhi * Math.sin(controls.theta),
target.y + controls.radius * Math.cos(controls.phi),
target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(target);
}
updateCamera(true);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xffe9c6, 0x183a34, 1.8));
const key = new THREE.DirectionalLight(0xffd6a0, 3.4);
key.position.set(-9, 16, 10);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -15;
key.shadow.camera.right = 15;
key.shadow.camera.top = 14;
key.shadow.camera.bottom = -14;
key.shadow.camera.near = 1;
key.shadow.camera.far = 42;
key.shadow.normalBias = 0.035;
key.shadow.bias = -0.00015;
scene.add(key);
const fill = new THREE.DirectionalLight(0x9ac8d0, 1.15);
fill.position.set(11, 8, -9);
scene.add(fill);
const rim = new THREE.PointLight(0xc38a4d, 18, 34, 2);
rim.position.set(-11, 5, -10);
scene.add(rim);
// -------------------------------------------------------------------------
// Small deterministic random helper
// -------------------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const rand = mulberry32(1893);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const dummy = new THREE.Object3D();
function box(width, height, depth, color, x, y, z, parent = scene) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0
});
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function instanceMesh(geometry, material, count) {
const mesh = new THREE.InstancedMesh(geometry, material, count);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
return mesh;
}
// -------------------------------------------------------------------------
// Voxel desk
// -------------------------------------------------------------------------
const desk = new THREE.Group();
scene.add(desk);
box(23.2, 1.0, 15.0, 0x3b211b, 0, -0.57, 0, desk);
const plankColors = [
0x633829,
0x6d3c2a,
0x593025,
0x71412d,
0x623428,
0x6a3928
];
for (let i = 0; i < 6; i++) {
const plank = box(
22.8,
0.24,
2.34,
plankColors[i],
0,
0.015,
-6.05 + i * 2.42,
desk
);
plank.receiveShadow = true;
}
// Desk legs and cross supports.
for (const x of [-9.6, 9.6]) {
for (const z of [-5.8, 5.8]) {
box(1.45, 7.2, 1.45, 0x321e19, x, -4.15, z, desk);
}
}
box(19.7, 0.75, 0.72, 0x3b241d, 0, -5.25, 5.65, desk);
box(19.7, 0.75, 0.72, 0x3b241d, 0, -5.25, -5.65, desk);
// Sparse voxel wood grain, mostly visible around the paper.
const grainCount = 95;
const grainMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const grain = instanceMesh(unitBox, grainMaterial, grainCount);
desk.add(grain);
const grainDark = new THREE.Color(0x3e241d);
const grainLight = new THREE.Color(0x815039);
for (let i = 0; i < grainCount; i++) {
const side = rand() < 0.5 ? -1 : 1;
const x = side * (5.1 + rand() * 5.6);
const z = -6.6 + rand() * 13.2;
dummy.position.set(x, 0.143, z);
dummy.rotation.set(0, (rand() - 0.5) * 0.08, 0);
dummy.scale.set(
0.18 + rand() * 0.95,
0.012,
0.018 + rand() * 0.028
);
dummy.updateMatrix();
grain.setMatrixAt(i, dummy.matrix);
grain.setColorAt(i, grainDark.clone().lerp(grainLight, rand() * 0.65));
}
grain.instanceMatrix.needsUpdate = true;
grain.instanceColor.needsUpdate = true;
// -------------------------------------------------------------------------
// 5×7 voxel alphabet
// -------------------------------------------------------------------------
const FONT = {
A: ["01110","10001","10001","11111","10001","10001","10001"],
B: ["11110","10001","10001","11110","10001","10001","11110"],
C: ["01111","10000","10000","10000","10000","10000","01111"],
D: ["11110","10001","10001","10001","10001","10001","11110"],
E: ["11111","10000","10000","11110","10000","10000","11111"],
F: ["11111","10000","10000","11110","10000","10000","10000"],
G: ["01111","10000","10000","10111","10001","10001","01111"],
H: ["10001","10001","10001","11111","10001","10001","10001"],
I: ["11111","00100","00100","00100","00100","00100","11111"],
J: ["00111","00010","00010","00010","10010","10010","01100"],
K: ["10001","10010","10100","11000","10100","10010","10001"],
L: ["10000","10000","10000","10000","10000","10000","11111"],
M: ["10001","11011","10101","10101","10001","10001","10001"],
N: ["10001","11001","10101","10011","10001","10001","10001"],
O: ["01110","10001","10001","10001","10001","10001","01110"],
P: ["11110","10001","10001","11110","10000","10000","10000"],
Q: ["01110","10001","10001","10001","10101","10010","01101"],
R: ["11110","10001","10001","11110","10100","10010","10001"],
S: ["01111","10000","10000","01110","00001","00001","11110"],
T: ["11111","00100","00100","00100","00100","00100","00100"],
U: ["10001","10001","10001","10001","10001","10001","01110"],
V: ["10001","10001","10001","10001","10001","01010","00100"],
W: ["10001","10001","10001","10101","10101","10101","01010"],
X: ["10001","10001","01010","00100","01010","10001","10001"],
Y: ["10001","10001","01010","00100","00100","00100","00100"],
Z: ["11111","00001","00010","00100","01000","10000","11111"],
"0": ["01110","10001","10011","10101","11001","10001","01110"],
"1": ["00100","01100","00100","00100","00100","00100","01110"],
"2": ["01110","10001","00001","00010","00100","01000","11111"],
"3": ["11110","00001","00001","01110","00001","00001","11110"],
"4": ["00010","00110","01010","10010","11111","00010","00010"],
"5": ["11111","10000","10000","11110","00001","00001","11110"],
"6": ["01110","10000","10000","11110","10001","10001","01110"],
"7": ["11111","00001","00010","00100","01000","01000","01000"],
"8": ["01110","10001","10001","01110","10001","10001","01110"],
"9": ["01110","10001","10001","01111","00001","00001","01110"],
".": ["00000","00000","00000","00000","00000","00110","00110"]
};
function pixelText(
text,
options = {}
) {
const {
x = 0,
z = 0,
y = 0.17,
scale = 0.06,
color = 0x302822,
align = "center",
parent = scene,
opacity = 1
} = options;
const textWidth = (text.length * 6 - 1) * scale;
let startX = x - textWidth / 2;
if (align === "left") {
startX = x;
} else if (align === "right") {
startX = x - textWidth;
}
const pixels = [];
for (let ci = 0; ci < text.length; ci++) {
const glyph = FONT[text[ci]] || FONT[" "];
if (!glyph) continue;
for (let row = 0; row < 7; row++) {
for (let col = 0; col < 5; col++) {
if (glyph[row][col] === "1") {
pixels.push({
x: startX + (ci * 6 + col) * scale,
z: z + row * scale
});
}
}
}
}
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.92,
metalness: 0,
transparent: opacity < 1,
opacity
});
const mesh = instanceMesh(unitBox, material, pixels.length);
parent.add(mesh);
for (let i = 0; i < pixels.length; i++) {
dummy.position.set(pixels[i].x, y, pixels[i].z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(scale * 0.84, 0.028, scale * 0.84);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
mesh.setColorAt(i, new THREE.Color(color));
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
return mesh;
}
// -------------------------------------------------------------------------
// Petition, paper layers and voxel typography
// -------------------------------------------------------------------------
const petition = new THREE.Group();
petition.position.y = 0.15;
petition.rotation.y = -0.12;
scene.add(petition);
// Dark green desk blotter.
box(9.85, 0.035, 12.35, 0x243c34, 0, 0, 0, petition);
// Three offset paper layers.
box(8.62, 0.035, 11.12, 0xbcae89, 0.06, 0.03, 0.05, petition);
box(8.58, 0.032, 11.08, 0xd0c29c, -0.045, 0.057, -0.035, petition);
box(8.60, 0.035, 11.10, 0xd9c99e, 0.035, 0.084, 0.025, petition);
// The visible sheet is built from individual paper voxels.
const cols = 17;
const rows = 22;
const cell = 0.5;
const paperTiles = [];
for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) {
const isTorn = (
col === cols - 1 &&
(row === 7 || row === 16)
);
if (!isTorn) {
paperTiles.push({
x: (col - (cols - 1) / 2) * cell,
z: (row - (rows - 1) / 2) * cell,
row,
col
});
}
}
}
const paperMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
metalness: 0
});
const paper = instanceMesh(unitBox, paperMaterial, paperTiles.length);
petition.add(paper);
const paperBase = new THREE.Color(0xe9dbb5);
const paperDark = new THREE.Color(0xd5c398);
const paperLight = new THREE.Color(0xf3e8ca);
paperTiles.forEach((tile, i) => {
const edgeLift =
(tile.col === cols - 1 && tile.row < 3) ||
(tile.row === rows - 1 && tile.col > 13)
? 0.028
: 0;
dummy.position.set(tile.x, 0.125 + edgeLift, tile.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.492, 0.055, 0.492);
dummy.updateMatrix();
paper.setMatrixAt(i, dummy.matrix);
const variation = rand();
const color = paperBase.clone()
.lerp(paperDark, variation * 0.48)
.lerp(paperLight, Math.max(0, variation - 0.72) * 0.6);
paper.setColorAt(i, color);
});
paper.instanceMatrix.needsUpdate = true;
paper.instanceColor.needsUpdate = true;
// Heading and petition text.
pixelText("VOTES FOR WOMEN", {
x: 0,
z: -4.45,
y: 0.171,
scale: 0.08,
color: 0x2d2721,
parent: petition
});
pixelText("NEW ZEALAND 1893", {
x: 0,
z: -3.69,
y: 0.168,
scale: 0.06,
color: 0x514538,
parent: petition
});
box(7.2, 0.018, 0.035, 0x766a55, 0, 0.164, -3.25, petition);
pixelText("THE FEMALE SUFFRAGE PETITION", {
x: 0,
z: -2.84,
y: 0.166,
scale: 0.042,
color: 0x4c4337,
parent: petition
});
pixelText("WE THE UNDERSIGNED PETITION THE", {
x: 0,
z: -2.28,
y: 0.166,
scale: 0.038,
color: 0x625748,
parent: petition
});
pixelText("PARLIAMENT OF NEW ZEALAND TO GRANT", {
x: 0,
z: -1.88,
y: 0.166,
scale: 0.038,
color: 0x625748,
parent: petition
});
pixelText("WOMEN THE RIGHT TO VOTE AT ALL", {
x: 0,
z: -1.48,
y: 0.166,
scale: 0.038,
color: 0x625748,
parent: petition
});
pixelText("PARLIAMENTARY ELECTIONS", {
x: 0,
z: -1.08,
y: 0.166,
scale: 0.038,
color: 0x625748,
parent: petition
});
box(7.25, 0.015, 0.028, 0x897b63, 0, 0.163, -0.62, petition);
// -------------------------------------------------------------------------
// Abstract, non-linguistic signature marks
// -------------------------------------------------------------------------
const signaturePixels = [];
const signatureColors = [];
const sigRand = mulberry32(7319);
function addSignature(cx, cz) {
const pixels = new Set();
const scale = 0.052;
const angle = (sigRand() - 0.5) * 0.22;
const points = [];
for (let i = 0; i < 12; i++) {
const px = i;
const pz = 2 + Math.round(
Math.sin(i * 0.9 + sigRand() * 0.6) * 1.15 +
(sigRand() - 0.5) * 1.1
);
points.push([px, pz]);
}
// Connecting pen strokes.
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
for (let p = 0; p <= 3; p++) {
const t = p / 3;
pixels.add(
`${Math.round(a[0] + (b[0] - a[0]) * t)},` +
`${Math.round(a[1] + (b[1] - a[1]) * t)}`
);
}
}
// Tall flourish.
const flourishX = 3 + Math.floor(sigRand() * 7);
for (let y = 0; y <= 5; y++) {
pixels.add(`${flourishX},${y}`);
}
// Small loop.
const loopX = 1 + Math.floor(sigRand() * 7);
const loopY = 1 + Math.floor(sigRand() * 2);
pixels.add(`${loopX},${loopY}`);
pixels.add(`${loopX + 1},${loopY}`);
pixels.add(`${loopX + 1},${loopY + 1}`);
pixels.add(`${loopX},${loopY + 1}`);
// Underline.
const underlineStart = Math.floor(sigRand() * 3);
const underlineLength = 5 + Math.floor(sigRand() * 4);
for (let x = underlineStart; x < underlineStart + underlineLength; x++) {
pixels.add(`${x},5`);
}
const cos = Math.cos(angle);
const sin = Math.sin(angle);
for (const key of pixels) {
const [px, py] = key.split(",").map(Number);
const dx = (px - 5.5) * scale;
const dz = (py - 2.5) * scale;
const x = cx + dx * cos - dz * sin;
const z = cz + dx * sin + dz * cos;
signaturePixels.push({ x, z });
signatureColors.push(
new THREE.Color(0x302720).lerp(
new THREE.Color(0x594334),
sigRand() * 0.45
)
);
}
}
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 5; col++) {
addSignature(
-3.2 + col * 1.6,
0.03 + row * 0.73
);
}
}
const signatureMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.95
});
const signatures = instanceMesh(
unitBox,
signatureMaterial,
signaturePixels.length
);
petition.add(signatures);
signaturePixels.forEach((pixel, i) => {
dummy.position.set(pixel.x, 0.164, pixel.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(0.047, 0.023, 0.047);
dummy.updateMatrix();
signatures.setMatrixAt(i, dummy.matrix);
signatures.setColorAt(i, signatureColors[i]);
});
signatures.instanceMatrix.needsUpdate = true;
signatures.instanceColor.needsUpdate = true;
// -------------------------------------------------------------------------
// Red New Zealand stamp
// -------------------------------------------------------------------------
const stampMaterial = new THREE.MeshStandardMaterial({
color: 0x91382e,
roughness: 1,
transparent: true,
opacity: 0.78,
depthWrite: false
});
const stamp = new THREE.Group();
petition.add(stamp);
const stampPixels = [];
const stampSize = 0.087;
const stampX = 2.48;
const stampZ = 4.03;
for (let i = 0; i < 10; i++) {
stampPixels.push([stampX + i * stampSize, stampZ]);
stampPixels.push([stampX + i * stampSize, stampZ + stampSize * 9]);
stampPixels.push([stampX, stampZ + i * stampSize]);
stampPixels.push([stampX + stampSize * 9, stampZ + i * stampSize]);
}
const stampMesh = instanceMesh(unitBox, stampMaterial, stampPixels.length);
stamp.add(stampMesh);
stampPixels.forEach((pixel, i) => {
dummy.position.set(pixel[0], 0.169, pixel[1]);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(stampSize * 0.9, 0.018, stampSize * 0.9);
dummy.updateMatrix();
stampMesh.setMatrixAt(i, dummy.matrix);
});
stampMesh.instanceMatrix.needsUpdate = true;
pixelText("NZ", {
x: stampX + stampSize * 4.5,
z: stampZ + stampSize * 3,
y: 0.171,
scale: 0.067,
color: 0x91382e,
parent: stamp,
opacity: 0.78
});
// -------------------------------------------------------------------------
// Voxel inkwell and quill
// -------------------------------------------------------------------------
const inkwell = new THREE.Group();
inkwell.position.set(-7.15, 0.13, -2.6);
scene.add(inkwell);
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x17221f,
roughness: 0.26,
metalness: 0.18
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xb38b4e,
roughness: 0.34,
metalness: 0.72
});
box(1.02, 0.67, 1.02, 0x17221f, 0, 0.335, 0, inkwell);
box(0.72, 0.42, 0.72, 0x202c27, 0, 0.86, 0, inkwell);
box(0.85, 0.13, 0.85, 0xb38b4e, 0, 1.125, 0, inkwell);
box(0.96, 0.08, 0.96, 0x765d38, 0, 0.045, 0, inkwell);
// A small label on the ink bottle.
box(0.47, 0.25, 0.025, 0xb5a47d, 0, 0.38, 0.522, inkwell);
const featherMaterial = new THREE.MeshStandardMaterial({
color: 0xe5dac1,
roughness: 0.9
});
const featherStart = new THREE.Vector3(-0.02, 1.18, 0);
const featherEnd = new THREE.Vector3(1.95, 2.85, -1.35);
for (let i = 0; i <= 15; i++) {
const t = i / 15;
const point = featherStart.clone().lerp(featherEnd, t);
const size = 0.075 + Math.sin(t * Math.PI) * 0.065;
const feather = new THREE.Mesh(unitBox, featherMaterial);
feather.scale.set(size, size, size);
feather.position.copy(point);
feather.rotation.y = -0.55;
feather.castShadow = true;
inkwell.add(feather);
if (i > 7 && i < 14) {
const barb = new THREE.Mesh(unitBox, featherMaterial);
barb.scale.set(0.095, 0.045, 0.045);
barb.position.copy(point);
barb.position.x += 0.08;
barb.position.z += (i % 2 ? 0.075 : -0.075);
barb.rotation.y = -0.55;
barb.castShadow = true;
inkwell.add(barb);
}
}
// Dark nib.
const nib = new THREE.Mesh(unitBox, new THREE.MeshStandardMaterial({
color: 0x25201b,
roughness: 0.55
}));
nib.scale.set(0.22, 0.10, 0.10);
nib.position.set(-0.16, 1.12, 0.02);
nib.rotation.y = -0.55;
nib.castShadow = true;
inkwell.add(nib);
// -------------------------------------------------------------------------
// Small brass desk paperweight
// -------------------------------------------------------------------------
const paperweight = new THREE.Group();
paperweight.position.set(6.85, 0.18, 2.95);
paperweight.rotation.y = -0.32;
scene.add(paperweight);
box(2.05, 0.22, 0.72, 0xa77d3d, 0, 0, 0, paperweight);
box(1.85, 0.08, 0.56, 0xc29a55, 0, 0.14, 0, paperweight);
for (const x of [-0.75, 0.75]) {
box(0.16, 0.09, 0.79, 0x70532f, x, 0, 0, paperweight);
}
// -------------------------------------------------------------------------
// Custom pointer and wheel camera controls
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.shiftKey || event.button === 2;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = camera.position.clone().sub(target);
forward.y = 0;
forward.normalize();
const panScale = controls.radius * 0.00125;
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(forward, -dy * panScale);
} else {
controls.targetTheta -= dx * 0.006;
controls.targetPhi = THREE.MathUtils.clamp(
controls.targetPhi - dy * 0.005,
0.34,
1.34
);
}
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.targetRadius = THREE.MathUtils.clamp(
controls.targetRadius * Math.exp(event.deltaY * 0.001),
12,
34
);
}, { passive: false });
document.getElementById("reset").addEventListener("click", () => {
controls.targetTheta = 0.48;
controls.targetPhi = 0.84;
controls.targetRadius = 22;
target.set(0, 0.4, 0);
});
canvas.addEventListener("dblclick", () => {
controls.targetTheta = 0.48;
controls.targetPhi = 0.84;
controls.targetRadius = 22;
target.set(0, 0.4, 0);
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
updateCamera();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```