Prompt specification
Build or customize the Three.js 3D scene "Abbasid-era text comparison table" 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: Abbasid-era text comparison table
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/abbasid-era-text-comparison-table-x2326
Scene Description Prompt:
An illustrative low-poly Abbasid-era Baghdad study table holds manuscripts, ink, and measuring tools for comparing diagrams. One HTML scene using Three.js from cdnjs.
Working Three.js Starter (abbasid-era-text-comparison-table-x2326):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Abbasid Geometry Table</title>
<style>
:root {
color-scheme: dark;
font-family: Georgia, "Times New Roman", serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #18151a;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 24px;
left: 24px;
z-index: 2;
max-width: min(390px, calc(100vw - 48px));
padding: 17px 20px 16px;
color: #f0d49b;
background:
linear-gradient(135deg, rgba(40, 28, 20, 0.9), rgba(25, 21, 25, 0.78));
border: 1px solid rgba(221, 177, 91, 0.48);
border-radius: 3px;
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.3);
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #bf8e4c;
font: 600 10px/1.2 system-ui, sans-serif;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 4vw, 31px);
font-weight: 500;
line-height: 1.05;
letter-spacing: 0.015em;
}
.subtitle {
margin-top: 9px;
color: #cbb994;
font: 12px/1.5 system-ui, sans-serif;
}
.controls {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 3;
display: flex;
align-items: center;
gap: 10px;
color: #ddc89a;
font: 11px/1.3 system-ui, sans-serif;
letter-spacing: 0.04em;
}
.controls span {
padding: 9px 12px;
background: rgba(28, 23, 22, 0.72);
border: 1px solid rgba(221, 177, 91, 0.25);
border-radius: 3px;
backdrop-filter: blur(8px);
}
button {
padding: 9px 12px;
color: #f0d49b;
background: rgba(43, 31, 23, 0.86);
border: 1px solid rgba(221, 177, 91, 0.45);
border-radius: 3px;
font: 11px system-ui, sans-serif;
cursor: pointer;
}
button:hover {
background: rgba(81, 55, 31, 0.94);
}
#loading {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
color: #d6b879;
background: #18151a;
font: 13px system-ui, sans-serif;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 0.5s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.title-card {
top: 14px;
left: 14px;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls .desktop-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="An illustrative Abbasid-era geometry study table in Baghdad"></main>
<section class="title-card">
<div class="eyebrow">Bayt al-Hikma · Baghdad</div>
<h1>The Geometry Table</h1>
<div class="subtitle">
An illustrative ninth-century study scene: manuscripts, ink, dividers,
rulers, and diagrams for comparison.
</div>
</section>
<div class="controls">
<span class="desktop-hint">Drag to orbit · Wheel to zoom · Arrow keys to pan</span>
<button id="reset" type="button">Reset view</button>
</div>
<div id="loading">Preparing the study…</div>
<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 mount = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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;
mount.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x242027);
scene.fog = new THREE.FogExp2(0x30252a, 0.026);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
70
);
const controls = {
yaw: 0.55,
pitch: 0.48,
distance: 7.5,
targetYaw: 0.55,
targetPitch: 0.48,
targetDistance: 7.5,
target: new THREE.Vector3(0, 1.35, 0),
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const horizontal = Math.cos(controls.pitch);
camera.position.set(
controls.target.x +
Math.sin(controls.yaw) * horizontal * controls.distance,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z +
Math.cos(controls.yaw) * horizontal * controls.distance
);
camera.lookAt(controls.target);
}
updateCamera();
// ------------------------------------------------------------
// Materials and helpers
// ------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
...options
});
}
const wood = material(0x663b22);
const darkWood = material(0x3d2419);
const carvedWood = material(0x754526);
const brass = material(0xb58a42, {
metalness: 0.72,
roughness: 0.32
});
const darkBrass = material(0x705326, {
metalness: 0.6,
roughness: 0.45
});
const parchment = material(0xd5b77b, { roughness: 1 });
const inkMaterial = material(0x171a1b, { roughness: 0.34 });
const reedMaterial = material(0x8a6739, { roughness: 0.9 });
const plaster = material(0xb78662, { roughness: 0.96 });
const stone = material(0x775a4b, { roughness: 0.95 });
function mesh(geometry, mat, position, cast = true, receive = true) {
const object = new THREE.Mesh(geometry, mat);
if (position) object.position.set(...position);
object.castShadow = cast;
object.receiveShadow = receive;
scene.add(object);
return object;
}
function cylinderBetween(a, b, radius, mat, radialSegments = 7) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
);
const object = new THREE.Mesh(geometry, mat);
object.position.copy(a).add(b).multiplyScalar(0.5);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
object.castShadow = true;
object.receiveShadow = true;
return object;
}
function groupAt(x, y, z, rotationY = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.y = rotationY;
scene.add(group);
return group;
}
// ------------------------------------------------------------
// Procedural textures
// ------------------------------------------------------------
let randomSeed = 9127;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function makeParchmentTexture(variant = 0) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 800;
const ctx = canvas.getContext("2d");
const gradient = ctx.createLinearGradient(0, 0, 640, 800);
gradient.addColorStop(0, "#dfc58f");
gradient.addColorStop(0.52, "#d3b477");
gradient.addColorStop(1, "#c49b61");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 640, 800);
for (let i = 0; i < 1500; i++) {
const x = random() * 640;
const y = random() * 800;
const r = random() * 2.8 + 0.2;
ctx.fillStyle =
random() > 0.42
? `rgba(87, 53, 24, ${random() * 0.1})`
: `rgba(255, 240, 190, ${random() * 0.12})`;
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2);
ctx.fill();
}
// Edge staining.
const edge = ctx.createRadialGradient(
320, 400, 100,
320, 400, 430
);
edge.addColorStop(0, "rgba(90,50,20,0)");
edge.addColorStop(1, "rgba(82,45,18,0.28)");
ctx.fillStyle = edge;
ctx.fillRect(0, 0, 640, 800);
// Decorative manuscript frame.
ctx.strokeStyle = "rgba(72, 42, 27, 0.65)";
ctx.lineWidth = 3;
ctx.strokeRect(29, 28, 582, 744);
ctx.lineWidth = 1.2;
ctx.strokeRect(39, 38, 562, 724);
ctx.fillStyle = "rgba(66, 38, 27, 0.82)";
ctx.font = "25px Georgia";
ctx.direction = "rtl";
ctx.textAlign = "center";
ctx.fillText("كتاب الهندسة", 320, 76);
ctx.direction = "ltr";
ctx.strokeStyle = "rgba(106, 55, 34, 0.5)";
ctx.beginPath();
ctx.moveTo(230, 91);
ctx.lineTo(410, 91);
ctx.stroke();
function pseudoWriting(startY, count) {
for (let row = 0; row < count; row++) {
const y = startY + row * 32;
let x = 72;
ctx.strokeStyle = "rgba(39, 31, 29, 0.76)";
ctx.lineWidth = 2.2;
ctx.lineCap = "round";
ctx.beginPath();
while (x < 555) {
const length = 14 + random() * 24;
ctx.moveTo(x, y);
ctx.quadraticCurveTo(
x + length * 0.25,
y - 5 - random() * 5,
x + length * 0.55,
y
);
ctx.quadraticCurveTo(
x + length * 0.8,
y + 3 + random() * 4,
x + length,
y - 1
);
x += length + 7 + random() * 10;
}
ctx.stroke();
if (random() > 0.45) {
ctx.fillStyle = "rgba(39, 31, 29, 0.72)";
ctx.beginPath();
ctx.arc(95 + random() * 400, y - 7, 1.8, 0, Math.PI * 2);
ctx.fill();
}
}
}
if (variant === 0) {
pseudoWriting(133, 5);
ctx.strokeStyle = "rgba(109, 48, 32, 0.66)";
ctx.lineWidth = 2;
ctx.strokeRect(78, 350, 484, 285);
ctx.fillStyle = "rgba(109, 48, 32, 0.7)";
ctx.font = "italic 20px Georgia";
ctx.textAlign = "left";
ctx.fillText("Fig. I — proportions of the circle", 90, 379);
ctx.strokeStyle = "rgba(35, 38, 43, 0.85)";
ctx.lineWidth = 3;
ctx.beginPath();
ctx.arc(320, 505, 92, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(320, 405);
ctx.lineTo(320, 605);
ctx.moveTo(220, 505);
ctx.lineTo(420, 505);
ctx.stroke();
ctx.strokeStyle = "rgba(126, 49, 34, 0.8)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(320, 505, 54, 0, Math.PI * 2);
ctx.stroke();
pseudoWriting(666, 2);
} else if (variant === 1) {
// Diagram A: circle, triangle, and measurement rays.
ctx.strokeStyle = "rgba(31, 34, 39, 0.9)";
ctx.lineWidth = 3.5;
ctx.beginPath();
ctx.arc(321, 351, 154, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(190, 446);
ctx.lineTo(320, 205);
ctx.lineTo(449, 446);
ctx.closePath();
ctx.stroke();
ctx.strokeStyle = "rgba(116, 50, 33, 0.82)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(321, 351, 102, 0, Math.PI * 2);
ctx.stroke();
ctx.strokeStyle = "rgba(31, 34, 39, 0.75)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(321, 170);
ctx.lineTo(321, 530);
ctx.moveTo(145, 351);
ctx.lineTo(495, 351);
ctx.stroke();
ctx.fillStyle = "rgba(116, 50, 33, 0.85)";
ctx.font = "italic 20px Georgia";
ctx.textAlign = "left";
ctx.fillText("Diagram A", 78, 563);
ctx.fillText("r", 331, 198);
ctx.fillText("diameter", 405, 343);
pseudoWriting(612, 4);
} else {
// Diagram B: overlapping polygons for visual comparison.
ctx.strokeStyle = "rgba(31, 34, 39, 0.9)";
ctx.lineWidth = 3.5;
ctx.beginPath();
ctx.moveTo(320, 188);
ctx.lineTo(455, 340);
ctx.lineTo(396, 522);
ctx.lineTo(235, 522);
ctx.lineTo(180, 340);
ctx.closePath();
ctx.stroke();
ctx.strokeStyle = "rgba(116, 50, 33, 0.82)";
ctx.lineWidth = 2.5;
ctx.beginPath();
ctx.moveTo(320, 220);
ctx.lineTo(430, 430);
ctx.lineTo(205, 430);
ctx.closePath();
ctx.stroke();
ctx.strokeStyle = "rgba(31, 34, 39, 0.72)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(320, 188);
ctx.lineTo(320, 540);
ctx.moveTo(165, 351);
ctx.lineTo(475, 351);
ctx.stroke();
ctx.fillStyle = "rgba(116, 50, 33, 0.85)";
ctx.font = "italic 20px Georgia";
ctx.textAlign = "left";
ctx.fillText("Diagram B", 78, 580);
ctx.fillText("five angles", 405, 466);
pseudoWriting(625, 4);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
renderer.capabilities.getMaxAnisotropy(),
8
);
return texture;
}
function makeRugTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 640;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#583432";
ctx.fillRect(0, 0, 1024, 640);
ctx.fillStyle = "#9c5940";
ctx.fillRect(48, 48, 928, 544);
ctx.fillStyle = "#d0a15d";
ctx.fillRect(65, 65, 894, 510);
ctx.fillStyle = "#783c33";
ctx.fillRect(83, 83, 858, 474);
for (let y = 125; y < 560; y += 72) {
for (let x = 125; x < 920; x += 76) {
ctx.save();
ctx.translate(x, y);
ctx.rotate(Math.PI / 4);
ctx.strokeStyle = "#d0a15d";
ctx.lineWidth = 4;
ctx.strokeRect(-17, -17, 34, 34);
ctx.fillStyle = "#b76f48";
ctx.fillRect(-8, -8, 16, 16);
ctx.restore();
}
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// ------------------------------------------------------------
// Room, arch, floor, and shelf
// ------------------------------------------------------------
const floor = mesh(
new THREE.PlaneGeometry(18, 14),
material(0x725446),
[0, -0.02, 0],
false,
true
);
floor.rotation.x = -Math.PI / 2;
const rug = mesh(
new THREE.PlaneGeometry(7.4, 4.7),
material(0xffffff, { map: makeRugTexture(), roughness: 1 }),
[0, 0.005, 0.35],
false,
true
);
rug.rotation.x = -Math.PI / 2;
mesh(
new THREE.BoxGeometry(12, 5.6, 0.25),
plaster,
[0, 2.8, -4.45],
false,
true
);
mesh(
new THREE.BoxGeometry(0.25, 5.6, 12),
plaster,
[-6, 2.8, 0],
false,
true
);
// Low-poly wall pilasters.
for (const x of [-4.5, 4.5]) {
mesh(
new THREE.BoxGeometry(0.42, 5.2, 0.22),
stone,
[x, 2.6, -4.22],
false,
true
);
}
function makeArchShape(width, bottom, top) {
const half = width / 2;
const shoulder = top - half;
const shape = new THREE.Shape();
shape.moveTo(-half, bottom);
shape.lineTo(half, bottom);
shape.lineTo(half, shoulder);
shape.quadraticCurveTo(half, top, 0, top);
shape.quadraticCurveTo(-half, top, -half, shoulder);
shape.closePath();
return shape;
}
const windowSky = mesh(
new THREE.ShapeGeometry(makeArchShape(2.75, 0.78, 2.48)),
new THREE.MeshBasicMaterial({ color: 0x263b4d }),
[0, 0, -4.30],
false,
false
);
const moon = mesh(
new THREE.CircleGeometry(0.27, 16),
new THREE.MeshBasicMaterial({ color: 0xe6d2a1 }),
[-0.55, 1.83, -4.285],
false,
false
);
// Arch frame.
for (const x of [-1.43, 1.43]) {
mesh(
new THREE.BoxGeometry(0.16, 0.86, 0.18),
darkWood,
[x, 0.39, -4.19]
);
}
const archFrame = mesh(
new THREE.TorusGeometry(1.43, 0.09, 6, 32, Math.PI),
darkWood,
[0, 0.82, -4.19]
);
archFrame.castShadow = true;
// Window lattice.
for (const x of [-0.72, 0, 0.72]) {
mesh(
new THREE.BoxGeometry(0.045, 1.56, 0.055),
carvedWood,
[x, 1.56, -4.20]
);
}
for (const y of [1.05, 1.48, 1.91]) {
mesh(
new THREE.BoxGeometry(2.62, 0.045, 0.055),
carvedWood,
[0, y, -4.20]
);
}
// Shelf and books.
mesh(
new THREE.BoxGeometry(2.3, 0.12, 0.55),
darkWood,
[3.55, 2.2, -4.0]
);
mesh(
new THREE.BoxGeometry(2.3, 0.12, 0.55),
darkWood,
[3.55, 3.15, -4.0]
);
const bookColors = [0x6b3b2b, 0x7b6235, 0x3f5048, 0x8b5a2f, 0x574052];
for (let i = 0; i < 7; i++) {
const book = mesh(
new THREE.BoxGeometry(0.14, 0.62 + random() * 0.13, 0.38),
material(bookColors[i % bookColors.length]),
[2.72 + i * 0.22, 2.58, -4.02]
);
book.rotation.z = (random() - 0.5) * 0.12;
}
// A small ceramic vessel on the upper shelf.
const vesselProfile = [
new THREE.Vector2(0.12, 0),
new THREE.Vector2(0.23, 0.08),
new THREE.Vector2(0.28, 0.25),
new THREE.Vector2(0.21, 0.42),
new THREE.Vector2(0.11, 0.49),
new THREE.Vector2(0.13, 0.55)
];
const vessel = mesh(
new THREE.LatheGeometry(vesselProfile, 10),
material(0x47706a, { roughness: 0.52 }),
[4.35, 3.22, -4.0]
);
vessel.rotation.y = 0.2;
// ------------------------------------------------------------
// The central study table
// ------------------------------------------------------------
const tableTop = mesh(
new THREE.BoxGeometry(5.25, 0.18, 2.95),
wood,
[0, 1.66, 0]
);
tableTop.rotation.y = -0.015;
mesh(
new THREE.BoxGeometry(5.05, 0.035, 2.75),
carvedWood,
[0, 1.765, 0]
);
// Tapered low-poly legs.
for (const x of [-2.15, 2.15]) {
for (const z of [-1.05, 1.05]) {
const leg = mesh(
new THREE.CylinderGeometry(0.16, 0.23, 1.52, 6),
darkWood,
[x, 0.76, z]
);
leg.rotation.y = Math.PI / 6;
}
}
// Aprons and lower cross rails.
mesh(
new THREE.BoxGeometry(4.62, 0.34, 0.1),
darkWood,
[0, 1.44, 1.34]
);
mesh(
new THREE.BoxGeometry(4.62, 0.34, 0.1),
darkWood,
[0, 1.44, -1.34]
);
mesh(
new THREE.BoxGeometry(0.1, 0.34, 2.35),
darkWood,
[-2.25, 1.44, 0]
);
mesh(
new THREE.BoxGeometry(0.1, 0.34, 2.35),
darkWood,
[2.25, 1.44, 0]
);
for (const z of [-1.05, 1.05]) {
mesh(
new THREE.BoxGeometry(4.15, 0.12, 0.11),
darkWood,
[0, 0.48, z]
);
}
// Brass trim and carved diamonds on the front apron.
mesh(
new THREE.BoxGeometry(4.45, 0.025, 0.02),
brass,
[0, 1.57, 1.398]
);
for (let i = 0; i < 9; i++) {
const diamond = mesh(
new THREE.OctahedronGeometry(0.105),
i % 2 === 0 ? brass : carvedWood,
[-1.95 + i * 0.485, 1.43, 1.405]
);
diamond.scale.set(1, 0.72, 0.35);
}
// ------------------------------------------------------------
// Manuscripts
// ------------------------------------------------------------
function addSheet(width, height, variant, position, angle = 0) {
const group = groupAt(...position, angle);
const texture = makeParchmentTexture(variant);
const page = new THREE.Mesh(
new THREE.PlaneGeometry(width, height, 1, 1),
material(0xffffff, {
map: texture,
roughness: 1,
side: THREE.DoubleSide
})
);
page.rotation.x = -Math.PI / 2;
page.position.y = 0.006;
page.castShadow = true;
page.receiveShadow = true;
group.add(page);
return group;
}
// Open folio with two related diagrams.
addSheet(1.28, 1.48, 1, [-0.92, 1.802, 0.08], 0.015);
addSheet(1.28, 1.48, 2, [0.39, 1.802, 0.08], -0.012);
// Spine and page blocks.
mesh(
new THREE.BoxGeometry(0.075, 0.045, 1.48),
darkWood,
[-0.265, 1.805, 0.08]
);
// A stack of loose manuscripts on the left.
for (let i = 0; i < 7; i++) {
const page = mesh(
new THREE.BoxGeometry(1.02 + random() * 0.08, 0.026, 0.78),
i % 3 === 0 ? material(0xe1c58c) : parchment,
[
-1.94 + (random() - 0.5) * 0.07,
1.807 + i * 0.028,
0.61 + (random() - 0.5) * 0.07
]
);
page.rotation.y = (random() - 0.5) * 0.13;
}
// Top sheet with a diagram.
addSheet(0.96, 0.72, 1, [-1.94, 2.01, 0.61], -0.08);
// Rolled manuscript and ties.
const scroll = mesh(
new THREE.CylinderGeometry(0.115, 0.115, 1.2, 12),
parchment,
[-1.65, 1.91, -0.83]
);
scroll.rotation.z = Math.PI / 2;
scroll.rotation.y = -0.13;
for (const x of [-1.95, -1.38]) {
const tie = mesh(
new THREE.TorusGeometry(0.12, 0.014, 5, 12),
material(0x713a2b),
[x, 1.91, -0.83]
);
tie.rotation.y = Math.PI / 2;
}
// ------------------------------------------------------------
// Ink pot, reed pens, and spilled ink
// ------------------------------------------------------------
const inkGroup = groupAt(1.98, 1.79, -0.67, -0.16);
const coaster = new THREE.Mesh(
new THREE.CylinderGeometry(0.36, 0.38, 0.045, 12),
material(0x3b2a25)
);
coaster.position.y = 0.023;
coaster.castShadow = true;
coaster.receiveShadow = true;
inkGroup.add(coaster);
const inkProfile = [
new THREE.Vector2(0.22, 0),
new THREE.Vector2(0.29, 0.035),
new THREE.Vector2(0.31, 0.16),
new THREE.Vector2(0.27, 0.31),
new THREE.Vector2(0.18, 0.38),
new THREE.Vector2(0.18, 0.46),
new THREE.Vector2(0.135, 0.47)
];
const inkPot = new THREE.Mesh(
new THREE.LatheGeometry(inkProfile, 12),
material(0x214e4c, { roughness: 0.45 })
);
inkPot.position.y = 0.045;
inkPot.castShadow = true;
inkPot.receiveShadow = true;
inkGroup.add(inkPot);
const inkRim = new THREE.Mesh(
new THREE.TorusGeometry(0.158, 0.018, 6, 16),
darkBrass
);
inkRim.rotation.x = Math.PI / 2;
inkRim.position.y = 0.515;
inkRim.castShadow = true;
inkGroup.add(inkRim);
const inkSurface = new THREE.Mesh(
new THREE.CircleGeometry(0.135, 16),
new THREE.MeshStandardMaterial({
color: 0x090b0d,
roughness: 0.18,
metalness: 0.05
})
);
inkSurface.rotation.x = -Math.PI / 2;
inkSurface.position.y = 0.516;
inkGroup.add(inkSurface);
// Reed pens.
const penA = cylinderBetween(
new THREE.Vector3(1.52, 1.82, -0.48),
new THREE.Vector3(2.47, 1.91, -0.83),
0.014,
reedMaterial,
7
);
scene.add(penA);
const penB = cylinderBetween(
new THREE.Vector3(1.64, 1.82, -0.41),
new THREE.Vector3(2.55, 1.88, -0.63),
0.012,
material(0xb08a52),
7
);
scene.add(penB);
const nib = cylinderBetween(
new THREE.Vector3(1.50, 1.82, -0.47),
new THREE.Vector3(1.36, 1.815, -0.42),
0.017,
inkMaterial,
7
);
scene.add(nib);
// A small ink spill.
const spill = mesh(
new THREE.CircleGeometry(0.105, 12),
new THREE.MeshStandardMaterial({
color: 0x15171a,
roughness: 0.28
}),
[2.47, 1.786, -0.43],
false,
true
);
spill.rotation.x = -Math.PI / 2;
spill.scale.set(1, 0.62, 1);
// ------------------------------------------------------------
// Measuring tools: ruler, dividers, square, and astrolabe
// ------------------------------------------------------------
const ruler = groupAt(1.34, 1.81, 0.78, -0.14);
const rulerBody = new THREE.Mesh(
new THREE.BoxGeometry(1.92, 0.035, 0.19),
brass
);
rulerBody.castShadow = true;
rulerBody.receiveShadow = true;
ruler.add(rulerBody);
for (let i = 0; i <= 24; i++) {
const major = i % 4 === 0;
const mark = new THREE.Mesh(
new THREE.BoxGeometry(0.009, 0.008, major ? 0.11 : 0.065),
inkMaterial
);
mark.position.set(-0.88 + i * 0.073, 0.021, -0.025);
ruler.add(mark);
}
// Brass dividers.
const dividerJoint = new THREE.Vector3(0.98, 1.86, 0.34);
const dividerTipA = new THREE.Vector3(0.69, 1.815, 0.87);
const dividerTipB = new THREE.Vector3(1.30, 1.815, 0.87);
scene.add(
cylinderBetween(
dividerJoint,
dividerTipA,
0.024,
brass,
8
)
);
scene.add(
cylinderBetween(
dividerJoint,
dividerTipB,
0.024,
brass,
8
)
);
const dividerCap = mesh(
new THREE.SphereGeometry(0.06, 8, 6),
darkBrass,
[0.98, 1.86, 0.34]
);
for (const tip of [dividerTipA, dividerTipB]) {
const point = mesh(
new THREE.ConeGeometry(0.025, 0.09, 7),
inkMaterial,
[tip.x, 1.815, tip.z]
);
point.rotation.z = Math.PI;
}
// Geometric set square.
const squareShape = new THREE.Shape();
squareShape.moveTo(-0.35, -0.35);
squareShape.lineTo(0.35, -0.35);
squareShape.lineTo(-0.35, 0.35);
squareShape.closePath();
const square = mesh(
new THREE.ShapeGeometry(squareShape),
material(0xc09a50, {
metalness: 0.55,
roughness: 0.42,
side: THREE.DoubleSide
}),
[0.24, 1.795, 0.96],
false,
true
);
square.rotation.x = -Math.PI / 2;
square.rotation.z = -0.32;
// Small astrolabe plate.
const astrolabe = groupAt(1.33, 1.815, -0.71, 0.12);
const plate = new THREE.Mesh(
new THREE.CircleGeometry(0.41, 24),
material(0xa87b37, {
metalness: 0.65,
roughness: 0.38,
side: THREE.DoubleSide
})
);
plate.rotation.x = -Math.PI / 2;
plate.castShadow = true;
plate.receiveShadow = true;
astrolabe.add(plate);
const outerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.026, 6, 28),
brass
);
outerRing.rotation.x = Math.PI / 2;
outerRing.position.y = 0.012;
outerRing.castShadow = true;
astrolabe.add(outerRing);
const innerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.25, 0.012, 5, 24),
darkBrass
);
innerRing.rotation.x = Math.PI / 2;
innerRing.position.y = 0.022;
astrolabe.add(innerRing);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const start = new THREE.Vector3(0, 0.025, 0);
const end = new THREE.Vector3(
Math.cos(angle) * 0.39,
0.025,
Math.sin(angle) * 0.39
);
const spoke = cylinderBetween(start, end, 0.007, brass, 5);
astrolabe.add(spoke);
}
const alidade = mesh(
new THREE.BoxGeometry(0.68, 0.025, 0.035),
darkBrass,
[1.33, 1.85, -0.71]
);
alidade.rotation.y = 0.42;
const astrolabeLoop = mesh(
new THREE.TorusGeometry(0.075, 0.018, 5, 12),
brass,
[1.33, 1.84, -1.16]
);
astrolabeLoop.rotation.x = Math.PI / 2;
// A tiny weight and measuring cup.
mesh(
new THREE.CylinderGeometry(0.09, 0.11, 0.12, 8),
darkBrass,
[2.25, 1.84, 0.32]
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf2d4a0, 0x3b2733, 1.85));
const keyLight = new THREE.DirectionalLight(0xffd39a, 3.5);
keyLight.position.set(-3.8, 7.5, 4.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x91a9c7, 1.15);
fillLight.position.set(5, 4, -3);
scene.add(fillLight);
const tableGlow = new THREE.PointLight(0xffbd70, 9, 8, 2);
tableGlow.position.set(0, 4.2, 1.5);
scene.add(tableGlow);
// Hanging low-poly lamp above the table.
const lampCord = mesh(
new THREE.CylinderGeometry(0.012, 0.012, 2.2, 6),
darkBrass,
[0, 5.15, -0.1]
);
const lamp = mesh(
new THREE.ConeGeometry(0.48, 0.38, 8, 1, true),
brass,
[0, 3.95, -0.1]
);
lamp.rotation.x = Math.PI;
const lampBulb = mesh(
new THREE.SphereGeometry(0.095, 8, 6),
new THREE.MeshBasicMaterial({ color: 0xffd28c }),
[0, 3.82, -0.1],
false,
false
);
// ------------------------------------------------------------
// Floating dust
// ------------------------------------------------------------
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(180 * 3);
for (let i = 0; i < 180; i++) {
dustPositions[i * 3] = (random() - 0.5) * 10;
dustPositions[i * 3 + 1] = 0.5 + random() * 4.6;
dustPositions[i * 3 + 2] = (random() - 0.5) * 8;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xf3d9a0,
size: 0.025,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
scene.add(dust);
// ------------------------------------------------------------
// Custom camera interaction
// ------------------------------------------------------------
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.targetYaw -= dx * 0.0055;
controls.targetPitch = THREE.MathUtils.clamp(
controls.targetPitch + dy * 0.0045,
0.16,
1.02
);
});
function endDrag(event) {
controls.dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.targetDistance = THREE.MathUtils.clamp(
controls.targetDistance + event.deltaY * 0.004,
4.1,
11
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
window.addEventListener("keydown", (event) => {
const panSpeed = 0.12;
switch (event.key) {
case "ArrowLeft":
controls.target.x -= panSpeed;
break;
case "ArrowRight":
controls.target.x += panSpeed;
break;
case "ArrowUp":
controls.target.z -= panSpeed;
break;
case "ArrowDown":
controls.target.z += panSpeed;
break;
case "+":
case "=":
controls.targetDistance = Math.max(
4.1,
controls.targetDistance - 0.35
);
break;
case "-":
controls.targetDistance = Math.min(
11,
controls.targetDistance + 0.35
);
break;
}
});
document.querySelector("#reset").addEventListener("click", () => {
controls.targetYaw = 0.55;
controls.targetPitch = 0.48;
controls.targetDistance = 7.5;
controls.target.set(0, 1.35, 0);
});
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const damping = 1 - Math.pow(0.001, delta);
controls.yaw = THREE.MathUtils.lerp(
controls.yaw,
controls.targetYaw,
damping
);
controls.pitch = THREE.MathUtils.lerp(
controls.pitch,
controls.targetPitch,
damping
);
controls.distance = THREE.MathUtils.lerp(
controls.distance,
controls.targetDistance,
damping
);
updateCamera();
dust.rotation.y = elapsed * 0.012;
dust.position.y = Math.sin(elapsed * 0.16) * 0.08;
lampBulb.material.color.setHSL(
0.105,
0.67,
0.76 + Math.sin(elapsed * 2.1) * 0.035
);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```