Prompt specification
Build or customize the Three.js 3D scene "Clay tokens beside grain measures" 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: Clay tokens beside grain measures
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/clay-tokens-beside-grain-measures-x2297
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Mesopotamian grain accounting with clay tokens. Place distinct clay counting tokens beside a grain bowl and storage jar. Use an explicit invented legend linking token shapes to represented quantities. Voxel style.
Working Three.js Starter (clay-tokens-beside-grain-measures-x2297):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>The Grain Tally — Mesopotamian Voxel Accounting</title>
<style>
:root {
--ink: #21150f;
--panel: rgba(34, 23, 17, 0.88);
--panel-border: rgba(244, 207, 142, 0.24);
--sand: #f2d39b;
--muted: #c6aa7c;
--gold: #e7aa52;
--clay: #b9683f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #241811;
color: var(--sand);
font-family: Georgia, "Times New Roman", serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--panel-border);
background:
linear-gradient(145deg, rgba(74, 45, 29, 0.38), transparent),
var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 22px 24px 20px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 8px;
color: var(--gold);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 3.2vw, 48px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
#intro p {
max-width: 330px;
margin: 13px 0 15px;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.summary {
display: inline-flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
border: 1px solid rgba(231, 170, 82, 0.25);
color: #f4d39b;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
letter-spacing: 0.04em;
}
.summary strong {
color: #ffd58c;
font-size: 14px;
}
#legend {
top: 22px;
right: 22px;
width: 310px;
padding: 18px;
}
.legend-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
padding-bottom: 12px;
border-bottom: 1px solid rgba(244, 207, 142, 0.14);
}
.legend-heading h2 {
margin: 0;
font-size: 18px;
font-weight: 500;
}
.legend-heading span {
color: var(--gold);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#token-list {
display: grid;
gap: 5px;
margin-top: 9px;
}
.token-row {
width: 100%;
min-height: 50px;
display: grid;
grid-template-columns: 42px 1fr auto;
align-items: center;
gap: 10px;
padding: 7px 8px;
border: 1px solid transparent;
border-radius: 2px;
background: transparent;
color: var(--sand);
text-align: left;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.token-row:hover,
.token-row:focus-visible,
.token-row.active {
border-color: rgba(231, 170, 82, 0.28);
background: rgba(231, 170, 82, 0.09);
outline: none;
transform: translateX(-2px);
}
.token-name {
display: block;
font-size: 14px;
}
.token-description {
display: block;
margin-top: 2px;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
}
.quantity {
color: #ffd58c;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: 700;
white-space: nowrap;
}
.shape {
position: relative;
width: 29px;
height: 29px;
margin: auto;
color: #c77949;
filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.35));
}
.shape.cube {
width: 19px;
height: 19px;
margin-top: 5px;
background: currentColor;
box-shadow:
4px -4px 0 rgba(255, 207, 137, 0.18),
4px 0 0 rgba(60, 27, 17, 0.35);
}
.shape.step {
width: 25px;
height: 25px;
margin-top: 2px;
background:
linear-gradient(
to top,
currentColor 0 8px,
transparent 8px
);
clip-path: polygon(
50% 0,
62% 0,
62% 25%,
74% 25%,
74% 50%,
87% 50%,
87% 76%,
100% 76%,
100% 100%,
0 100%,
0 76%,
13% 76%,
13% 50%,
26% 50%,
26% 25%,
38% 25%,
38% 0
);
}
.shape.ring {
width: 22px;
height: 22px;
margin-top: 3px;
border: 5px solid currentColor;
box-shadow: inset 0 0 0 2px rgba(35, 18, 12, 0.8);
}
.shape.rod {
width: 9px;
height: 27px;
margin: 1px auto 0;
background: currentColor;
box-shadow:
5px 0 0 rgba(255, 207, 137, 0.13),
-5px 0 0 rgba(35, 18, 12, 0.4);
}
.shape.cross {
width: 26px;
height: 26px;
margin-top: 1px;
background:
linear-gradient(currentColor, currentColor) center / 9px 26px no-repeat,
linear-gradient(currentColor, currentColor) center / 26px 9px no-repeat;
}
#legend-note {
margin: 12px 2px 0;
padding-top: 12px;
border-top: 1px solid rgba(244, 207, 142, 0.14);
color: #aa8c66;
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
line-height: 1.45;
}
#toolbar {
right: 22px;
bottom: 22px;
display: flex;
gap: 8px;
padding: 9px;
}
.tool-button {
border: 1px solid rgba(244, 207, 142, 0.22);
padding: 9px 13px;
background: rgba(238, 200, 137, 0.07);
color: var(--sand);
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.05em;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
.tool-button:hover,
.tool-button:focus-visible {
border-color: rgba(231, 170, 82, 0.6);
background: rgba(231, 170, 82, 0.15);
outline: none;
}
#status {
position: fixed;
z-index: 8;
left: 22px;
bottom: 22px;
max-width: min(460px, calc(100vw - 44px));
padding: 10px 13px;
border-left: 2px solid var(--gold);
background: rgba(30, 20, 14, 0.78);
color: #d5b987;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
line-height: 1.4;
pointer-events: none;
}
#controls-hint {
position: fixed;
z-index: 7;
left: 50%;
bottom: 26px;
transform: translateX(-50%);
color: rgba(244, 211, 155, 0.58);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
pointer-events: none;
}
#tooltip {
position: fixed;
z-index: 30;
display: none;
min-width: 170px;
padding: 10px 12px;
border: 1px solid rgba(244, 207, 142, 0.28);
background: rgba(34, 22, 16, 0.96);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
color: var(--sand);
pointer-events: none;
}
#tooltip strong {
display: block;
margin-bottom: 3px;
font-size: 13px;
font-weight: 500;
}
#tooltip span {
color: var(--gold);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #241811;
color: var(--gold);
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
#intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
#intro p {
display: none;
}
.summary {
margin-top: 10px;
}
#legend {
top: auto;
right: 12px;
bottom: 54px;
left: 12px;
width: auto;
padding: 12px;
}
.legend-heading {
padding-bottom: 8px;
}
#token-list {
display: flex;
gap: 6px;
overflow-x: auto;
padding-bottom: 5px;
}
.token-row {
flex: 0 0 185px;
grid-template-columns: 35px 1fr auto;
min-height: 46px;
}
#legend-note {
display: none;
}
#toolbar {
top: 12px;
right: 12px;
bottom: auto;
}
#status {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
#controls-hint {
display: none;
}
}
@media (max-width: 520px) {
h1 {
font-size: 28px;
}
.eyebrow {
font-size: 8px;
}
.summary {
font-size: 9px;
}
#toolbar {
top: 104px;
}
.tool-button {
padding: 8px 10px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel scene of grain accounting with clay tokens"></canvas>
<section id="intro" class="panel">
<p class="eyebrow">Mesopotamian Accounting · Voxel Study</p>
<h1>The Grain Tally</h1>
<p>
A clay-token counting table beside a grain bowl and storage jar.
Select a legend entry to inspect its token, or run the full count.
</p>
<div class="summary">
<span>One specimen of each token</span>
<strong>86 measures total</strong>
</div>
</section>
<aside id="legend" class="panel" aria-label="Clay token legend">
<div class="legend-heading">
<h2>Token key</h2>
<span>Invented legend</span>
</div>
<div id="token-list">
<button class="token-row" data-token="0">
<span class="shape cube" aria-hidden="true"></span>
<span>
<span class="token-name">Solid cube</span>
<span class="token-description">Compact clay block</span>
</span>
<span class="quantity">1 measure</span>
</button>
<button class="token-row" data-token="1">
<span class="shape step" aria-hidden="true"></span>
<span>
<span class="token-name">Stepped cone</span>
<span class="token-description">Three-tier pyramid</span>
</span>
<span class="quantity">5 measures</span>
</button>
<button class="token-row" data-token="2">
<span class="shape ring" aria-hidden="true"></span>
<span>
<span class="token-name">Pierced square</span>
<span class="token-description">Hollow clay frame</span>
</span>
<span class="quantity">10 measures</span>
</button>
<button class="token-row" data-token="3">
<span class="shape rod" aria-hidden="true"></span>
<span>
<span class="token-name">Tall rod</span>
<span class="token-description">Five stacked blocks</span>
</span>
<span class="quantity">20 measures</span>
</button>
<button class="token-row" data-token="4">
<span class="shape cross" aria-hidden="true"></span>
<span>
<span class="token-name">Cross seal</span>
<span class="token-description">Wide cruciform token</span>
</span>
<span class="quantity">50 measures</span>
</button>
</div>
<p id="legend-note">
This key is explicitly invented for the scene. It is not a historical
decoding of real Mesopotamian token shapes.
</p>
</aside>
<div id="toolbar" class="panel" aria-label="Scene controls">
<button id="count-button" class="tool-button">COUNT 86</button>
<button id="reset-button" class="tool-button">RESET VIEW</button>
</div>
<div id="status" role="status" aria-live="polite">
Drag to orbit · Scroll to zoom · Hover or select a token
</div>
<div id="controls-hint">Drag to orbit · Scroll to zoom</div>
<div id="tooltip"></div>
<div id="loading">Preparing the clay archive…</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 canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x241811);
scene.fog = new THREE.Fog(0x241811, 24, 43);
const camera = new THREE.OrthographicCamera(-12, 12, 8, -8, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.6, 0);
let cameraYaw = 0.64;
let cameraPitch = 0.67;
let cameraRadius = 22;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
let pointerDownX = 0;
let pointerDownY = 0;
const hemisphere = new THREE.HemisphereLight(0xf4d6a0, 0x3b2118, 1.8);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd391, 3.2);
sun.position.set(-8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.PointLight(0xe56d35, 28, 18, 2);
rimLight.position.set(7, 6, -4);
scene.add(rimLight);
const frontLight = new THREE.PointLight(0xffc66c, 16, 16, 2);
frontLight.position.set(-2, 4, 8);
scene.add(frontLight);
// Shared cube geometry keeps the whole scene intentionally voxel-based.
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, roughness = 0.88, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
});
}
function block(parent, size, position, material) {
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
ground: standardMaterial(0x3a281f),
floorA: standardMaterial(0x765039),
floorB: standardMaterial(0x684631),
floorC: standardMaterial(0x7d573d),
wallA: standardMaterial(0x9a6844),
wallB: standardMaterial(0x8c5b3b),
wallC: standardMaterial(0xa8734a),
reed: standardMaterial(0xb18a54),
darkClay: standardMaterial(0x6d3828),
bowl: standardMaterial(0xc67a4b),
bowlLight: standardMaterial(0xd18b59),
bowlDark: standardMaterial(0x9f5435),
jar: standardMaterial(0xa34d32),
jarLight: standardMaterial(0xb75b38),
jarDark: standardMaterial(0x803923),
grainA: standardMaterial(0xd9a743, 0.72),
grainB: standardMaterial(0xe6bd58, 0.7),
grainC: standardMaterial(0xb9822f, 0.76),
board: standardMaterial(0x493126),
boardEdge: standardMaterial(0x2d2019),
tablet: standardMaterial(0x9a5638),
tabletTop: standardMaterial(0xb36a44),
incision: standardMaterial(0x633123),
slate: standardMaterial(0x403b32),
gold: standardMaterial(0xd79b45, 0.55)
};
// -------------------------------------------------------------------------
// Floor and mud-brick architecture
// -------------------------------------------------------------------------
block(scene, [22, 0.45, 17], [0, -0.38, 0], materials.ground);
const floorMaterials = [materials.floorA, materials.floorB, materials.floorC];
for (let ix = 0; ix < 14; ix++) {
for (let iz = 0; iz < 10; iz++) {
const x = -10.5 + ix * 1.5;
const z = -6.75 + iz * 1.5;
const mat = floorMaterials[(ix * 7 + iz * 3) % floorMaterials.length];
block(
scene,
[1.43, 0.18, 1.43],
[x, -0.045 + Math.random() * 0.025, z],
mat
);
}
}
const wall = new THREE.Group();
scene.add(wall);
for (let row = 0; row < 5; row++) {
const offset = row % 2 === 0 ? -0.85 : 0;
for (let column = -6; column <= 6; column++) {
const x = column * 1.75 + offset;
const y = 0.38 + row * 0.72;
const mat = [materials.wallA, materials.wallB, materials.wallC][
Math.abs(column + row * 2) % 3
];
block(wall, [1.68, 0.64, 0.9], [x, y, -7.55], mat);
}
}
// Blocky reed-bundle columns frame the accounting area.
for (const x of [-8.7, 8.7]) {
const column = new THREE.Group();
column.position.set(x, 0.08, -6.55);
scene.add(column);
block(column, [2.3, 0.35, 2.1], [0, 0.18, 0], materials.wallC);
for (let i = -3; i <= 3; i++) {
block(
column,
[0.24, 3.8, 0.32],
[i * 0.28, 2.15, 0],
materials.reed
);
}
block(column, [2.2, 0.28, 1.9], [0, 4.15, 0], materials.wallB);
}
// Small stepped sand drifts.
const sand = new THREE.Group();
scene.add(sand);
for (const [x, z, count] of [
[-8.2, 5.4, 4],
[8.0, 5.6, 3],
[-7.5, -4.7, 3]
]) {
for (let i = 0; i < count; i++) {
block(
sand,
[0.8 - i * 0.12, 0.18, 0.55],
[x + i * 0.28, 0.12 + i * 0.08, z + Math.sin(i) * 0.18],
materials.floorC
);
}
}
// -------------------------------------------------------------------------
// Grain bowl: stepped square vessel
// -------------------------------------------------------------------------
const bowl = new THREE.Group();
bowl.position.set(-4.7, 0.08, -0.65);
scene.add(bowl);
// Broad base.
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
block(
bowl,
[0.94, 0.34, 0.94],
[x, 0.19, z],
(x + z) % 2 === 0 ? materials.bowl : materials.bowlLight
);
}
}
// Lower outer wall.
for (let x = -3; x <= 3; x++) {
for (let z = -3; z <= 3; z++) {
if (Math.abs(x) !== 3 && Math.abs(z) !== 3) continue;
block(
bowl,
[0.94, 0.65, 0.94],
[x, 0.62, z],
(x - z) % 3 === 0 ? materials.bowlDark : materials.bowl
);
}
}
// Inward-stepped upper rim.
for (let x = -2; x <= 2; x++) {
for (let z = -2; z <= 2; z++) {
if (Math.abs(x) !== 2 && Math.abs(z) !== 2) continue;
block(
bowl,
[0.94, 0.6, 0.94],
[x, 1.12, z],
(x + z) % 2 === 0 ? materials.bowlLight : materials.bowl
);
}
}
// Golden grain cubes filling the center.
const grainMaterials = [materials.grainA, materials.grainB, materials.grainC];
for (let x = -1; x <= 1; x++) {
for (let z = -1; z <= 1; z++) {
for (let layer = 0; layer < 3; layer++) {
const size = 0.23 + Math.random() * 0.09;
block(
bowl,
[size, size, size],
[
x * 0.62 + (Math.random() - 0.5) * 0.2,
0.72 + layer * 0.24 + Math.random() * 0.09,
z * 0.62 + (Math.random() - 0.5) * 0.2
],
grainMaterials[(x + z + layer + 9) % grainMaterials.length]
);
}
}
}
// -------------------------------------------------------------------------
// Storage jar: layered square amphora
// -------------------------------------------------------------------------
const jar = new THREE.Group();
jar.position.set(4.25, 0.08, -0.65);
scene.add(jar);
const jarLayers = [4, 5, 5, 4, 3];
const jarCell = 0.73;
jarLayers.forEach((width, layerIndex) => {
const half = Math.floor((width - 1) / 2);
for (let x = -half; x <= half; x++) {
for (let z = -half; z <= half; z++) {
// The final layer is a hollow neck.
if (layerIndex === jarLayers.length - 1 && x === 0 && z === 0) {
continue;
}
const mat = (x + z + layerIndex) % 3 === 0
? materials.jarLight
: ((x - z) % 4 === 0 ? materials.jarDark : materials.jar);
block(
jar,
[jarCell * 0.94, 0.58, jarCell * 0.94],
[
x * jarCell,
0.32 + layerIndex * 0.61,
z * jarCell
],
mat
);
}
}
});
// Dark mouth and a clay rim around it.
block(
jar,
[0.69, 0.09, 0.69],
[0, 3.1, 0],
standardMaterial(0x2a1713, 1)
);
for (const x of [-0.36, 0.36]) {
block(jar, [0.2, 0.32, 0.85], [x, 3.24, 0], materials.jarLight);
block(jar, [0.85, 0.32, 0.2], [0, 3.24, x], materials.jarLight);
}
// -------------------------------------------------------------------------
// Clay accounting tablet with stylized cuneiform marks
// -------------------------------------------------------------------------
const tablet = new THREE.Group();
tablet.position.set(0, 0.1, -3.75);
tablet.rotation.y = -0.13;
scene.add(tablet);
block(tablet, [4.7, 0.38, 2.75], [0, 0.19, 0], materials.tablet);
block(tablet, [4.36, 0.16, 2.42], [0, 0.46, 0], materials.tabletTop);
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 8; column++) {
const mark = new THREE.Group();
mark.position.set(-1.72 + column * 0.49, 0.56, -0.72 + row * 0.68);
mark.rotation.y = (row % 2 === 0 ? 1 : -1) * 0.2;
tablet.add(mark);
block(mark, [0.10, 0.045, 0.30], [-0.08, 0, 0], materials.incision);
block(mark, [0.10, 0.045, 0.27], [0.09, 0, 0.03], materials.incision);
}
}
// -------------------------------------------------------------------------
// Counting board and distinct clay tokens
// -------------------------------------------------------------------------
const board = new THREE.Group();
board.position.set(0, 0.08, 4.05);
scene.add(board);
block(board, [13.4, 0.24, 2.7], [0, 0.04, 0], materials.board);
block(board, [13.7, 0.13, 2.95], [0, -0.1, 0], materials.boardEdge);
const tokenDefinitions = [
{
name: "Solid cube",
quantity: 1,
color: 0xb9683f,
build(group) {
block(group, [0.78, 0.78, 0.78], [0, 0.39, 0], group.userData.clayMaterial);
}
},
{
name: "Stepped cone",
quantity: 5,
color: 0xa65031,
build(group) {
const cell = 0.43;
for (let layer = 0; layer < 3; layer++) {
const size = 3 - layer;
const offset = (size - 1) * cell * 0.5;
for (let x = 0; x < size; x++) {
for (let z = 0; z < size; z++) {
block(
group,
[cell * 0.92, cell * 0.92, cell * 0.92],
[
x * cell - offset,
0.22 + layer * cell,
z * cell - offset
],
group.userData.clayMaterial
);
}
}
}
}
},
{
name: "Pierced square",
quantity: 10,
color: 0xc47a4c,
build(group) {
const cell = 0.47;
for (let x = -1; x <= 1; x++) {
for (let z = -1; z <= 1; z++) {
if (x === 0 && z === 0) continue;
block(
group,
[cell * 0.92, 0.42, cell * 0.92],
[x * cell, 0.23, z * cell],
group.userData.clayMaterial
);
}
}
}
},
{
name: "Tall rod",
quantity: 20,
color: 0x8e402b,
build(group) {
for (let i = 0; i < 5; i++) {
block(
group,
[0.31, 0.31, 0.31],
[0, 0.18 + i * 0.34, 0],
group.userData.clayMaterial
);
}
}
},
{
name: "Cross seal",
quantity: 50,
color: 0xce8956,
build(group) {
const cell = 0.45;
for (let i = -1; i <= 1; i++) {
block(
group,
[cell * 0.94, 0.35, cell * 0.94],
[i * cell, 0.2, 0],
group.userData.clayMaterial
);
block(
group,
[cell * 0.94, 0.35, cell * 0.94],
[0, 0.2, i * cell],
group.userData.clayMaterial
);
}
}
}
];
const tokenMeshes = [];
function makeFloorNumber(text, parent, x, z, color = "#f1ca82") {
const textCanvas = document.createElement("canvas");
textCanvas.width = 256;
textCanvas.height = 80;
const context = textCanvas.getContext("2d");
context.fillStyle = "rgba(0,0,0,0)";
context.fillRect(0, 0, 256, 80);
context.fillStyle = color;
context.font = "bold 44px Arial";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 128, 42);
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(1.45, 0.46),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, 0.32, z);
parent.add(mesh);
return mesh;
}
tokenDefinitions.forEach((definition, index) => {
const x = -5 + index * 2.5;
block(board, [2.12, 0.14, 1.75], [x, 0.23, -0.06], materials.slate);
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0xe2a64e,
transparent: true,
opacity: 0.28,
depthWrite: false
});
const selection = block(
board,
[1.88, 0.025, 1.48],
[x, 0.315, -0.06],
selectionMaterial
);
selection.visible = false;
makeFloorNumber(String(definition.quantity), board, x, 1.03);
const clayMaterial = standardMaterial(definition.color, 0.9);
const token = new THREE.Group();
token.position.set(x, 0.31, -0.13);
token.rotation.y = (index - 2) * 0.07;
token.userData.clayMaterial = clayMaterial;
token.userData.definition = definition;
token.userData.index = index;
board.add(token);
definition.build(token);
token.traverse((child) => {
if (!child.isMesh) return;
child.userData.tokenIndex = index;
tokenMeshes.push(child);
});
definition.token = token;
definition.selection = selection;
definition.material = clayMaterial;
});
// -------------------------------------------------------------------------
// Scene labels generated with canvas textures
// -------------------------------------------------------------------------
function makeLabel(text, width = 4, color = "#f4d49b") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 100;
const context = labelCanvas.getContext("2d");
context.fillStyle = "rgba(32, 20, 14, 0.76)";
context.fillRect(0, 0, 512, 100);
context.strokeStyle = "rgba(244, 212, 155, 0.45)";
context.lineWidth = 3;
context.strokeRect(2, 2, 508, 96);
context.fillStyle = color;
context.font = "bold 30px Arial";
context.textAlign = "center";
context.textBaseline = "middle";
context.letterSpacing = "4px";
context.fillText(text, 256, 51);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: false
})
);
sprite.scale.set(width, width * 100 / 512, 1);
sprite.renderOrder = 10;
return sprite;
}
const bowlLabel = makeLabel("GRAIN BOWL", 3.6);
bowlLabel.position.set(-4.7, 3.55, -0.65);
scene.add(bowlLabel);
const jarLabel = makeLabel("STORAGE JAR", 3.8);
jarLabel.position.set(4.25, 4.55, -0.65);
scene.add(jarLabel);
const ledgerLabel = makeLabel("CLAY LEDGER", 3.3);
ledgerLabel.position.set(0, 1.45, -3.75);
scene.add(ledgerLabel);
const tokensLabel = makeLabel("COUNTING TOKENS", 4.5);
tokensLabel.position.set(0, 2.55, 4.05);
scene.add(tokensLabel);
// -------------------------------------------------------------------------
// Floating square dust motes
// -------------------------------------------------------------------------
const dustCount = 75;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 20;
dustPositions[i * 3 + 1] = 0.8 + Math.random() * 7;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 14;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute("position", new THREE.BufferAttribute(dustPositions, 3));
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xe7bc72,
size: 0.045,
transparent: true,
opacity: 0.38,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Camera controls implemented directly, without external addons
// -------------------------------------------------------------------------
function updateCamera() {
const horizontalRadius = cameraRadius * Math.cos(cameraPitch);
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontalRadius,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontalRadius
);
camera.zoom = 22 / cameraRadius;
camera.updateProjectionMatrix();
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraYaw = 0.64;
cameraPitch = 0.67;
cameraRadius = 22;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
pointerDownX = event.clientX;
pointerDownY = event.clientY;
canvas.setPointerCapture(event.pointerId);
tooltip.style.display = "none";
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraYaw -= deltaX * 0.007;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.0055,
0.28,
1.15
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
return;
}
updateTooltip(event);
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
const travel = Math.hypot(
event.clientX - pointerDownX,
event.clientY - pointerDownY
);
if (travel < 5) {
const hit = pickToken(event);
if (hit !== null) selectToken(hit);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("pointerleave", () => {
tooltip.style.display = "none";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
14,
31
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Token hover, selection, and animated count
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const tooltip = document.querySelector("#tooltip");
const status = document.querySelector("#status");
const legendButtons = [...document.querySelectorAll(".token-row")];
let countRun = 0;
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickToken(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(tokenMeshes, false);
if (!intersections.length) return null;
return intersections[0].object.userData.tokenIndex ?? null;
}
function updateTooltip(event) {
const index = pickToken(event);
if (index === null) {
tooltip.style.display = "none";
return;
}
const definition = tokenDefinitions[index];
tooltip.innerHTML = `
<strong>${definition.name}</strong>
<span>Represents ${definition.quantity} measures</span>
`;
tooltip.style.display = "block";
tooltip.style.left = `${Math.min(event.clientX + 18, window.innerWidth - 205)}px`;
tooltip.style.top = `${Math.max(12, event.clientY - 54)}px`;
}
function clearHighlights() {
tokenDefinitions.forEach((definition) => {
definition.material.emissive.setHex(0x000000);
definition.material.emissiveIntensity = 0;
definition.token.scale.set(1, 1, 1);
definition.selection.visible = false;
});
legendButtons.forEach((button) => button.classList.remove("active"));
}
function highlightToken(index) {
const definition = tokenDefinitions[index];
definition.material.emissive.setHex(0x7c2f11);
definition.material.emissiveIntensity = 0.65;
definition.token.scale.set(1.13, 1.13, 1.13);
definition.selection.visible = true;
legendButtons.forEach((button) => {
button.classList.toggle("active", Number(button.dataset.token) === index);
});
}
function selectToken(index) {
clearHighlights();
highlightToken(index);
const definition = tokenDefinitions[index];
status.textContent =
`${definition.name}: ${definition.quantity} ` +
`${definition.quantity === 1 ? "measure" : "measures"} represented.`;
}
const delay = (milliseconds) =>
new Promise((resolve) => setTimeout(resolve, milliseconds));
async function runCount() {
const run = ++countRun;
clearHighlights();
status.textContent = "Counting begins…";
let total = 0;
for (let index = 0; index < tokenDefinitions.length; index++) {
if (run !== countRun) return;
await delay(430);
const definition = tokenDefinitions[index];
highlightToken(index);
total += definition.quantity;
status.textContent =
`${definition.name} added: +${definition.quantity} → ` +
`${total} measures`;
}
await delay(700);
if (run !== countRun) return;
clearHighlights();
status.textContent =
"Ledger complete: 1 + 5 + 10 + 20 + 50 = 86 measures recorded.";
}
legendButtons.forEach((button) => {
button.addEventListener("click", () => {
countRun++;
selectToken(Number(button.dataset.token));
});
});
document.querySelector("#count-button").addEventListener("click", runCount);
document.querySelector("#reset-button").addEventListener("click", () => {
countRun++;
clearHighlights();
resetCamera();
status.textContent = "View reset. Drag to orbit · Scroll to zoom";
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
// Preserve the full tabletop width on narrow portrait screens.
const viewHeight = Math.max(13.5, 22 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
resetCamera();
function animate(time) {
requestAnimationFrame(animate);
dust.rotation.y = time * 0.000018;
dust.position.y = Math.sin(time * 0.00035) * 0.12;
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => {
document.querySelector("#loading").remove();
}, 450);
});
</script>
</body>
</html>
```