Prompt specification
Build or customize the Three.js 3D scene "Market inspector checking a measure" 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: Market inspector checking a measure
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/market-inspector-checking-a-measure-x2374
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring local weights and measures in a medieval market. Create a market stall where one vessel is compared with a reference measure. Animate filling both with identical grain tokens to reveal a capacity mismatch. Voxel style.
Working Three.js Starter (market-inspector-checking-a-measure-x2374):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Medieval Market — Measure Audit</title>
<style>
:root {
color-scheme: dark;
--ink: #f7e9c9;
--muted: #cdbb98;
--panel: rgba(28, 22, 18, 0.91);
--border: rgba(231, 194, 119, 0.32);
--gold: #e0b85a;
--red: #d16445;
--green: #83a78e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #91a8ae;
font-family: Georgia, "Times New Roman", serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--border);
box-shadow:
0 12px 36px rgba(0, 0, 0, 0.3),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
backdrop-filter: blur(9px);
}
header {
position: absolute;
top: 22px;
left: 24px;
width: min(440px, calc(100vw - 48px));
padding: 18px 20px 17px;
border-left: 4px solid var(--gold);
border-radius: 4px 12px 12px 4px;
}
.eyebrow {
display: block;
margin-bottom: 6px;
color: var(--gold);
font-family: system-ui, sans-serif;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
header h1 {
margin: 0;
color: var(--ink);
font-size: clamp(24px, 3vw, 36px);
font-weight: 600;
line-height: 1.05;
}
header p {
margin: 9px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.45;
}
.audit-date {
float: right;
margin: -4px -3px 8px 18px;
padding: 7px 9px;
border: 1px solid rgba(224, 184, 90, 0.3);
color: #d9c18b;
font-family: system-ui, sans-serif;
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.measure-label {
position: absolute;
min-width: 154px;
padding: 9px 11px;
transform: translate(-50%, -100%);
border: 1px solid rgba(233, 204, 139, 0.38);
border-radius: 7px;
background: rgba(31, 25, 20, 0.9);
box-shadow: 0 7px 18px rgba(0, 0, 0, 0.26);
color: #fff0cd;
text-align: center;
transition: opacity 150ms ease;
}
.measure-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 12px;
height: 12px;
transform: translateX(-50%) rotate(45deg);
border-right: 1px solid rgba(233, 204, 139, 0.38);
border-bottom: 1px solid rgba(233, 204, 139, 0.38);
background: rgba(31, 25, 20, 0.9);
}
.measure-label.local {
border-top: 3px solid var(--red);
}
.measure-label.reference {
border-top: 3px solid var(--green);
}
.measure-label strong {
display: block;
font-size: 15px;
font-weight: 600;
}
.measure-label .count {
display: block;
margin-top: 3px;
color: #d8c69f;
font-family: system-ui, sans-serif;
font-size: 11px;
}
.measure-label.full {
box-shadow: 0 0 0 2px rgba(224, 184, 90, 0.26), 0 8px 20px rgba(0, 0, 0, 0.32);
}
#result-card {
position: absolute;
top: 24px;
right: 24px;
width: min(330px, calc(100vw - 48px));
padding: 19px;
border-top: 4px solid var(--red);
border-radius: 10px;
opacity: 0;
transform: translateY(-12px) scale(0.97);
transition:
opacity 300ms ease,
transform 300ms ease;
}
#result-card.show {
opacity: 1;
transform: translateY(0) scale(1);
}
.result-main {
display: flex;
gap: 14px;
align-items: center;
}
.result-mark {
display: grid;
flex: 0 0 52px;
width: 52px;
height: 52px;
place-items: center;
border: 2px solid rgba(209, 100, 69, 0.65);
color: #f18763;
font-family: system-ui, sans-serif;
font-size: 34px;
font-weight: 300;
}
#result-card h2 {
margin: 0 0 3px;
color: #fff0cd;
font-size: 20px;
font-weight: 600;
}
#result-card p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.4;
}
.result-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
.result-stat {
padding: 10px;
border: 1px solid rgba(231, 194, 119, 0.17);
background: rgba(0, 0, 0, 0.18);
}
.result-stat span {
display: block;
color: #a99776;
font-family: system-ui, sans-serif;
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.result-stat strong {
display: block;
margin-top: 3px;
color: #f1d697;
font-size: 19px;
}
.difference {
margin-top: 10px;
color: #f18763;
font-family: system-ui, sans-serif;
font-size: 12px;
font-weight: 700;
text-align: center;
}
#controls {
position: absolute;
right: 22px;
bottom: 20px;
left: 22px;
display: grid;
grid-template-columns: minmax(260px, 1fr) auto;
gap: 18px;
align-items: center;
max-width: 1050px;
margin: 0 auto;
padding: 13px 14px 13px 18px;
border-radius: 12px;
pointer-events: auto;
}
.status-row {
display: flex;
gap: 12px;
align-items: center;
}
.token-icon {
position: relative;
flex: 0 0 31px;
width: 31px;
height: 31px;
}
.token-icon::before,
.token-icon::after {
content: "";
position: absolute;
left: 5px;
width: 21px;
height: 11px;
border: 1px solid #f1cf77;
border-radius: 2px;
background: #d8aa42;
box-shadow: inset 0 -3px 0 #aa772c;
}
.token-icon::before {
top: 7px;
}
.token-icon::after {
top: 13px;
left: 9px;
width: 13px;
height: 8px;
}
#status {
min-height: 38px;
color: #e7d8b6;
font-size: 13px;
line-height: 1.4;
}
#status small {
display: block;
margin-top: 2px;
color: #9e8e72;
font-family: system-ui, sans-serif;
font-size: 10px;
}
.progress {
height: 4px;
margin-top: 9px;
overflow: hidden;
border-radius: 5px;
background: rgba(255, 255, 255, 0.08);
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #a84b35, #e0b85a);
transition: width 80ms linear;
}
.button-row {
display: flex;
gap: 8px;
flex-wrap: wrap;
justify-content: flex-end;
}
button {
min-height: 37px;
padding: 8px 13px;
border: 1px solid rgba(226, 193, 122, 0.28);
border-radius: 6px;
background: rgba(255, 255, 255, 0.055);
color: #eedbad;
cursor: pointer;
font-family: system-ui, sans-serif;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(226, 193, 122, 0.65);
background: rgba(224, 184, 90, 0.12);
}
button:active {
transform: translateY(1px);
}
#play-pause {
border-color: rgba(224, 184, 90, 0.48);
background: rgba(224, 184, 90, 0.13);
}
.camera-hint {
position: absolute;
bottom: 25px;
left: 26px;
color: rgba(255, 241, 208, 0.76);
font-family: system-ui, sans-serif;
font-size: 10px;
letter-spacing: 0.05em;
text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
@media (max-width: 760px) {
header {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
header p {
display: none;
}
.audit-date {
display: none;
}
#result-card {
top: 112px;
right: 12px;
width: min(305px, calc(100vw - 24px));
}
#controls {
right: 12px;
bottom: 12px;
left: 12px;
grid-template-columns: 1fr;
gap: 10px;
padding: 12px;
}
.button-row {
justify-content: flex-start;
}
button {
flex: 1 1 auto;
}
.camera-hint {
display: none;
}
.measure-label {
min-width: 125px;
padding: 7px 8px;
}
.measure-label strong {
font-size: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="ui">
<header class="panel">
<span class="audit-date">Market audit</span>
<span class="eyebrow">Weights & Measures</span>
<h1>The Capacity Mismatch</h1>
<p>
A village bushel is tested against the guild’s reference measure using
identical grain tokens.
</p>
</header>
<div id="local-label" class="measure-label local">
<span class="eyebrow">Local measure</span>
<strong>Village bushel</strong>
<span id="local-count" class="count">0 / 12 tokens</span>
</div>
<div id="reference-label" class="measure-label reference">
<span class="eyebrow">Guild reference</span>
<strong>Official bushel</strong>
<span id="reference-count" class="count">0 / 8 tokens</span>
</div>
<section id="result-card" class="panel" aria-live="polite">
<div class="result-main">
<div class="result-mark">≠</div>
<div>
<span class="eyebrow">Mismatch confirmed</span>
<h2>The local measure is larger</h2>
<p>The same tokens reveal that the village vessel is not guild-standard.</p>
</div>
</div>
<div class="result-stats">
<div class="result-stat">
<span>Local capacity</span>
<strong>12 tokens</strong>
</div>
<div class="result-stat">
<span>Guild capacity</span>
<strong>8 tokens</strong>
</div>
</div>
<div class="difference">4 extra tokens · 50% greater capacity</div>
</section>
<section id="controls" class="panel">
<div>
<div class="status-row">
<div class="token-icon" aria-hidden="true"></div>
<div id="status">
Filling both measures with identical grain tokens.
<small>Each token represents one standardized scoop.</small>
</div>
</div>
<div class="progress"><div id="progress-fill"></div></div>
</div>
<div class="button-row">
<button id="play-pause" type="button">Pause</button>
<button id="replay" type="button">Replay filling</button>
<button id="reset-view" type="button">Reset view</button>
</div>
</section>
<div class="camera-hint">DRAG TO ORBIT · WHEEL TO ZOOM · ARROW KEYS TO MOVE</div>
</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 sceneHost = document.getElementById("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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel medieval market scene. Drag to orbit and use the wheel to zoom."
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9eb4b9);
scene.fog = new THREE.Fog(0x9eb4b9, 17, 39);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 2.65, 0.1);
let cameraYaw = 0.47;
let cameraPitch = 0.43;
let cameraRadius = 16.5;
const hemisphere = new THREE.HemisphereLight(0xcde4ee, 0x5d4936, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3ad, 3.2);
sun.position.set(8, 14, 10);
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 = 42;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x9cc9dc, 0.65);
fillLight.position.set(-9, 7, -4);
scene.add(fillLight);
// ------------------------------------------------------------
// Voxel material palette
// ------------------------------------------------------------
const materials = {
wood: new THREE.MeshStandardMaterial({
color: 0x795035,
roughness: 0.86,
flatShading: true
}),
lightWood: new THREE.MeshStandardMaterial({
color: 0xa16c3d,
roughness: 0.82,
flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x3f2b20,
roughness: 0.94,
flatShading: true
}),
seam: new THREE.MeshStandardMaterial({
color: 0x4a3021,
roughness: 1,
flatShading: true
}),
paintedWood: new THREE.MeshStandardMaterial({
color: 0x58776c,
roughness: 0.75,
flatShading: true
}),
brass: new THREE.MeshStandardMaterial({
color: 0xc79b3c,
roughness: 0.48,
metalness: 0.38,
flatShading: true
}),
iron: new THREE.MeshStandardMaterial({
color: 0x41464a,
roughness: 0.58,
metalness: 0.45,
flatShading: true
}),
clothRed: new THREE.MeshStandardMaterial({
color: 0xa74335,
roughness: 0.96,
flatShading: true
}),
clothCream: new THREE.MeshStandardMaterial({
color: 0xd8bb82,
roughness: 0.98,
flatShading: true
}),
clothBlue: new THREE.MeshStandardMaterial({
color: 0x3e6972,
roughness: 0.95,
flatShading: true
}),
sack: new THREE.MeshStandardMaterial({
color: 0xb08a55,
roughness: 1,
flatShading: true
}),
stone: new THREE.MeshStandardMaterial({
color: 0x727976,
roughness: 1,
flatShading: true
}),
stoneDark: new THREE.MeshStandardMaterial({
color: 0x535c5a,
roughness: 1,
flatShading: true
}),
grain: new THREE.MeshStandardMaterial({
color: 0xe3b84d,
roughness: 0.76,
flatShading: true
}),
grainLight: new THREE.MeshStandardMaterial({
color: 0xf0cf72,
roughness: 0.72,
flatShading: true
}),
window: new THREE.MeshStandardMaterial({
color: 0xe7b55d,
emissive: 0x9f5c20,
emissiveIntensity: 0.45,
roughness: 0.8
}),
lantern: new THREE.MeshStandardMaterial({
color: 0xffcb73,
emissive: 0xff9c35,
emissiveIntensity: 2.1,
roughness: 0.45
}),
mismatch: new THREE.MeshStandardMaterial({
color: 0xe9794e,
emissive: 0xa72d1e,
emissiveIntensity: 1.0,
roughness: 0.4,
transparent: true,
opacity: 0.9
})
};
function box(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Cobbled market square
// ------------------------------------------------------------
box(52, 0.12, 52, materials.stoneDark, 0, -0.14, 0);
let seed = 7134;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const cobbleCount = 320;
const cobbleGeometry = new THREE.BoxGeometry(0.78, 0.13, 0.64);
const cobbles = new THREE.InstancedMesh(
cobbleGeometry,
materials.stone,
cobbleCount
);
cobbles.receiveShadow = true;
cobbles.castShadow = false;
const dummy = new THREE.Object3D();
const cobbleColor = new THREE.Color();
for (let i = 0; i < cobbleCount; i++) {
const x = (random() - 0.5) * 34;
const z = (random() - 0.5) * 31;
dummy.position.set(x, -0.045 + random() * 0.035, z);
dummy.rotation.set(0, (random() - 0.5) * 0.16, 0);
dummy.scale.set(0.88 + random() * 0.23, 1, 0.88 + random() * 0.24);
dummy.updateMatrix();
cobbles.setMatrixAt(i, dummy.matrix);
const shade = 0.72 + random() * 0.22;
cobbleColor.setRGB(
0.42 * shade,
0.45 * shade,
0.43 * shade
);
cobbles.setColorAt(i, cobbleColor);
}
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) cobbles.instanceColor.needsUpdate = true;
scene.add(cobbles);
// ------------------------------------------------------------
// Background medieval buildings
// ------------------------------------------------------------
function createHouse(x, z, width, height, colorMaterial) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(width, height, 4.5, colorMaterial, 0, height / 2, 0, group);
const roofA = box(
width * 0.64,
0.28,
5.1,
materials.clothRed,
-width * 0.22,
height + 0.45,
0,
group
);
roofA.rotation.z = 0.58;
const roofB = box(
width * 0.64,
0.28,
5.1,
materials.darkWood,
width * 0.22,
height + 0.45,
0,
group
);
roofB.rotation.z = -0.58;
box(0.65, 1.8, 0.7, materials.stone, width * 0.28, height + 1.05, -0.7, group);
const windowCount = Math.max(2, Math.floor(width / 2));
for (let i = 0; i < windowCount; i++) {
const wx = -width * 0.32 + (i * width * 0.64) / Math.max(1, windowCount - 1);
box(0.55, 0.8, 0.08, materials.darkWood, wx, height * 0.58, 2.29, group);
box(0.39, 0.57, 0.09, materials.window, wx, height * 0.58, 2.35, group);
}
box(0.85, 1.65, 0.12, materials.darkWood, 0, 0.83, 2.3, group);
}
createHouse(-11.5, -11.5, 7.5, 6.6, materials.stoneDark);
createHouse(-3.7, -12.8, 6.2, 7.5, materials.stone);
createHouse(4.2, -12.1, 7.3, 6.2, materials.stoneDark);
createHouse(12.0, -12.8, 7.8, 7.1, materials.stone);
// Distant roof and banner silhouettes.
for (let i = 0; i < 9; i++) {
const x = -15 + i * 3.8;
box(0.16, 2.2 + random(), 0.16, materials.darkWood, x, 6.6, -8.7);
if (i % 2 === 0) {
const flag = box(
0.9,
0.5,
0.08,
i % 4 === 0 ? materials.clothBlue : materials.clothRed,
x + 0.42,
7.35,
-8.7
);
flag.rotation.z = 0.08;
}
}
// ------------------------------------------------------------
// Main market stall
// ------------------------------------------------------------
const stall = new THREE.Group();
scene.add(stall);
const tableTop = 2.35;
// Table top and trestle.
box(11.2, 0.34, 4.1, materials.lightWood, 0, tableTop - 0.17, 0.35, stall);
box(10.9, 0.12, 3.9, materials.wood, 0, tableTop - 0.39, 0.35, stall);
for (const x of [-4.65, 4.65]) {
for (const z of [-1.0, 1.65]) {
box(0.42, 2.2, 0.42, materials.darkWood, x, 1.05, z, stall);
}
box(0.32, 0.32, 3.0, materials.wood, x, 0.55, 0.35, stall);
}
box(9.8, 0.28, 0.34, materials.darkWood, 0, 0.72, 0.35, stall);
// Front cloth with a simple block pattern.
box(7.8, 1.0, 0.08, materials.clothBlue, 0, 1.67, 2.42, stall);
for (let i = 0; i < 7; i++) {
box(0.52, 0.52, 0.05, materials.clothCream, -2.6 + i * 0.87, 1.68, 2.48, stall);
box(0.18, 0.18, 0.06, materials.clothRed, -2.6 + i * 0.87, 1.68, 2.52, stall);
}
// Rear posts and canopy.
for (const x of [-5.65, 5.65]) {
box(0.38, 5.55, 0.38, materials.darkWood, x, 2.77, -2.7, stall);
box(0.76, 0.26, 0.76, materials.stone, x, 0.13, -2.7, stall);
box(0.28, 0.28, 5.1, materials.darkWood, x, 5.35, -0.35, stall);
}
box(11.6, 0.3, 0.35, materials.darkWood, 0, 5.62, -2.7, stall);
for (let i = 0; i < 12; i++) {
const stripe = box(
0.98,
0.17,
3.35,
i % 2 === 0 ? materials.clothCream : materials.clothRed,
-5.4 + i * 0.98,
5.82,
-2.55,
stall
);
stripe.rotation.x = -0.045;
box(
0.98,
0.26,
0.18,
i % 2 === 0 ? materials.clothCream : materials.clothRed,
-5.4 + i * 0.98,
5.56,
-0.92,
stall
);
}
// Back shelf and supplies.
box(10.5, 0.24, 1.15, materials.wood, 0, 3.35, -2.38, stall);
function createSack(x, y, z, scale = 1) {
const sackGroup = new THREE.Group();
sackGroup.position.set(x, y, z);
sackGroup.scale.setScalar(scale);
stall.add(sackGroup);
box(0.85, 0.85, 0.66, materials.sack, 0, 0.43, 0, sackGroup);
box(0.68, 0.32, 0.58, materials.sack, 0, 0.97, 0, sackGroup);
box(0.42, 0.12, 0.38, materials.darkWood, 0, 1.16, 0, sackGroup);
box(0.12, 0.56, 0.05, materials.seam, -0.23, 0.64, 0.35, sackGroup);
}
createSack(-4.55, 3.48, -2.34, 0.82);
createSack(-3.55, 3.48, -2.35, 0.72);
createSack(4.5, 3.48, -2.33, 0.8);
// Hanging guild sign with a geometric balance symbol.
box(2.7, 1.65, 0.18, materials.darkWood, 0, 4.55, -2.58, stall);
box(2.35, 1.32, 0.08, materials.clothBlue, 0, 4.55, -2.47, stall);
box(1.35, 0.11, 0.09, materials.brass, 0, 4.63, -2.39, stall);
box(0.12, 0.75, 0.09, materials.brass, 0, 4.48, -2.39, stall);
box(0.65, 0.08, 0.09, materials.brass, -0.46, 4.19, -2.39, stall);
box(0.65, 0.08, 0.09, materials.brass, 0.46, 4.19, -2.39, stall);
function createLantern(x, y, z) {
box(0.12, 0.55, 0.12, materials.darkWood, x, y + 0.42, z, stall);
box(0.42, 0.62, 0.42, materials.lantern, x, y, z, stall);
box(0.58, 0.12, 0.58, materials.iron, x, y + 0.36, z, stall);
box(0.58, 0.12, 0.58, materials.iron, x, y - 0.36, z, stall);
const light = new THREE.PointLight(0xffa84d, 1.5, 7, 2);
light.position.set(x, y, z + 0.15);
stall.add(light);
}
createLantern(-5.2, 4.75, -1.55);
createLantern(5.2, 4.75, -1.55);
// ------------------------------------------------------------
// Extra market props
// ------------------------------------------------------------
function createBarrel(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(1.25, 1.55, 1.05, materials.wood, 0, 0.78, 0, group);
box(1.37, 0.16, 1.17, materials.iron, 0, 0.28, 0, group);
box(1.37, 0.16, 1.17, materials.iron, 0, 1.27, 0, group);
box(1.05, 0.15, 0.87, materials.darkWood, 0, 1.62, 0, group);
}
createBarrel(-7.2, 0.1, 1.05);
createBarrel(-8.35, -0.7, 0.83);
createBarrel(7.5, -0.4, 1.0);
function createCrate(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
box(1.7, 1.35, 1.5, materials.lightWood, 0, 0.68, 0, group);
for (const side of [-1, 1]) {
box(0.12, 1.4, 1.56, materials.darkWood, side * 0.78, 0.68, 0, group);
}
box(1.75, 0.13, 1.58, materials.darkWood, 0, 0.7, 0, group);
}
createCrate(7.2, 2.2, 0.9);
createCrate(8.4, 3.2, 0.7);
// Balance scale on the left of the table.
const scaleGroup = new THREE.Group();
scaleGroup.position.set(-4.35, tableTop, 0.35);
stall.add(scaleGroup);
box(0.92, 0.16, 0.72, materials.darkWood, 0, 0.08, 0, scaleGroup);
box(0.16, 2.0, 0.16, materials.brass, 0, 1.1, 0, scaleGroup);
box(1.55, 0.13, 0.13, materials.brass, 0, 2.05, 0, scaleGroup);
box(0.22, 0.24, 0.22, materials.brass, 0, 2.1, 0, scaleGroup);
for (const side of [-1, 1]) {
const panX = side * 0.62;
const chainTopY = 1.98;
const chainBottomY = 1.52;
const chain = box(
0.035,
chainTopY - chainBottomY,
0.035,
materials.iron,
panX,
(chainTopY + chainBottomY) / 2,
0,
scaleGroup
);
chain.rotation.z = side * -0.06;
box(0.62, 0.09, 0.48, materials.brass, panX, 1.48, 0, scaleGroup);
}
box(0.32, 0.35, 0.32, materials.iron, -0.62, 1.69, 0, scaleGroup);
box(0.25, 0.25, 0.25, materials.brass, 0.62, 1.65, 0, scaleGroup);
// Sealed guild weights on the right.
box(0.58, 0.42, 0.5, materials.iron, 4.35, tableTop + 0.21, 0.8, stall);
box(0.45, 0.32, 0.4, materials.brass, 4.38, tableTop + 0.59, 0.8, stall);
box(0.20, 0.12, 0.14, materials.clothRed, 4.38, tableTop + 0.8, 0.8, stall);
// ------------------------------------------------------------
// The two measure vessels
// ------------------------------------------------------------
function createVessel({
x,
z,
width,
depth,
height,
wallMaterial,
accentMaterial,
capacity,
baseY
}) {
const group = new THREE.Group();
group.position.set(x, baseY, z);
scene.add(group);
const wall = 0.19;
// Bottom and walls.
box(width + 0.18, 0.2, depth + 0.18, wallMaterial, 0, 0.1, 0, group);
box(width, height, wall, wallMaterial, 0, height / 2, -depth / 2, group);
const frontHeight = height * 0.58;
box(width, frontHeight, wall, wallMaterial, 0, frontHeight / 2, depth / 2, group);
box(wall, height, depth, wallMaterial, -width / 2, height / 2, 0, group);
box(wall, height, depth, wallMaterial, width / 2, height / 2, 0, group);
// Corner uprights.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const postHeight = sz === 1 ? frontHeight : height;
box(
0.28,
postHeight + 0.08,
0.28,
accentMaterial,
sx * (width / 2 - 0.02),
postHeight / 2,
sz * (depth / 2 - 0.02),
group
);
}
}
// Plank seams on the high rear wall.
const plankCount = Math.max(4, Math.round(width / 0.55));
for (let i = 1; i < plankCount; i++) {
const px = -width / 2 + (i * width) / plankCount;
box(0.025, height - 0.08, 0.025, materials.seam, px, height / 2, -depth / 2 - 0.108, group);
}
// Accent bands.
box(width + 0.08, 0.12, 0.08, accentMaterial, 0, height * 0.78, -depth / 2 - 0.12, group);
box(0.08, 0.12, depth + 0.08, accentMaterial, -width / 2 - 0.11, height * 0.78, 0, group);
box(0.08, 0.12, depth + 0.08, accentMaterial, width / 2 + 0.11, height * 0.78, 0, group);
box(width + 0.08, 0.1, 0.08, accentMaterial, 0, frontHeight * 0.82, depth / 2 + 0.11, group);
// Capacity tally pegs on the front lip.
const pegsPerRow = capacity === 12 ? 6 : 4;
for (let i = 0; i < capacity; i++) {
const row = Math.floor(i / pegsPerRow);
const col = i % pegsPerRow;
const countInRow = Math.min(pegsPerRow, capacity - row * pegsPerRow);
const spread = countInRow * 0.13;
box(
0.055,
0.055,
0.055,
accentMaterial,
-spread / 2 + col * 0.13 + (6 - countInRow) * 0.065,
frontHeight + 0.015,
depth / 2 + 0.12,
group
);
}
// Guild-style square seal.
if (capacity === 8) {
box(0.62, 0.62, 0.09, accentMaterial, 0, frontHeight * 0.48, depth / 2 + 0.16, group);
box(0.42, 0.42, 0.11, materials.clothRed, 0, frontHeight * 0.48, depth / 2 + 0.22, group);
box(0.13, 0.42, 0.08, materials.brass, 0, frontHeight * 0.48, depth / 2 + 0.27, group);
box(0.42, 0.13, 0.08, materials.brass, 0, frontHeight * 0.48, depth / 2 + 0.27, group);
}
return group;
}
const localVessel = createVessel({
x: -1.95,
z: 0.58,
width: 3.25,
depth: 2.65,
height: 1.72,
wallMaterial: materials.wood,
accentMaterial: materials.brass,
capacity: 12,
baseY: tableTop
});
// A low guild plinth makes the reference object feel officially mounted.
box(3.0, 0.13, 2.45, materials.darkWood, 2.02, tableTop + 0.065, 0.68, stall);
const referenceVessel = createVessel({
x: 2.02,
z: 0.68,
width: 2.78,
depth: 2.25,
height: 1.45,
wallMaterial: materials.paintedWood,
accentMaterial: materials.brass,
capacity: 8,
baseY: tableTop + 0.13
});
// A glowing block crown appears around the oversized local vessel.
const mismatchCrown = new THREE.Group();
mismatchCrown.position.set(-1.95, tableTop, 0.58);
scene.add(mismatchCrown);
const crownW = 3.6;
const crownD = 3.0;
const crownY = 1.72 + 0.2;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
0.12,
0.52,
0.12,
materials.mismatch,
sx * crownW / 2,
crownY,
sz * crownD / 2,
mismatchCrown
);
}
}
box(crownW + 0.12, 0.11, 0.11, materials.mismatch, 0, crownY + 0.24, -crownD / 2, mismatchCrown);
box(crownW + 0.12, 0.11, 0.11, materials.mismatch, 0, crownY + 0.24, crownD / 2, mismatchCrown);
box(0.11, 0.11, crownD, materials.mismatch, -crownW / 2, crownY + 0.24, 0, mismatchCrown);
box(0.11, 0.11, crownD, materials.mismatch, crownW / 2, crownY + 0.24, 0, mismatchCrown);
mismatchCrown.visible = false;
// ------------------------------------------------------------
// Identical voxel grain tokens
// ------------------------------------------------------------
const tokenMainGeometry = new THREE.BoxGeometry(0.38, 0.2, 0.27);
const tokenRidgeGeometry = new THREE.BoxGeometry(0.13, 0.07, 0.13);
function createToken() {
const group = new THREE.Group();
const main = new THREE.Mesh(tokenMainGeometry, materials.grain);
main.castShadow = true;
main.receiveShadow = true;
group.add(main);
const ridge = new THREE.Mesh(tokenRidgeGeometry, materials.grainLight);
ridge.position.set(0.045, 0.12, 0);
ridge.castShadow = true;
group.add(ridge);
scene.add(group);
return group;
}
function arrangeToken(token, vesselX, vesselZ, baseY, index, capacity) {
const layerSize = 4;
const layer = Math.floor(index / layerSize);
const slot = index % layerSize;
const col = slot % 2;
const row = Math.floor(slot / 2);
const offsetX = col === 0 ? -0.48 : 0.48;
const offsetZ = row === 0 ? -0.39 : 0.39;
const layerHeight = capacity === 12 ? 0.36 : 0.34;
token.userData.target = new THREE.Vector3(
vesselX + offsetX,
baseY + 0.29 + layer * layerHeight,
vesselZ + offsetZ
);
token.userData.index = index;
token.userData.settled = false;
token.visible = false;
}
const localTokens = [];
const referenceTokens = [];
for (let i = 0; i < 12; i++) {
const token = createToken();
arrangeToken(token, -1.95, 0.58, tableTop, i, 12);
localTokens.push(token);
}
for (let i = 0; i < 8; i++) {
const token = createToken();
arrangeToken(token, 2.02, 0.68, tableTop + 0.13, i, 8);
referenceTokens.push(token);
}
// ------------------------------------------------------------
// Filling animation
// ------------------------------------------------------------
const localLabel = document.getElementById("local-label");
const referenceLabel = document.getElementById("reference-label");
const localCount = document.getElementById("local-count");
const referenceCount = document.getElementById("reference-count");
const resultCard = document.getElementById("result-card");
const status = document.getElementById("status");
const progressFill = document.getElementById("progress-fill");
const playPause = document.getElementById("play-pause");
let simulationTime = 0;
let playing = true;
let completed = false;
const tokenDuration = 0.62;
const totalDuration = 4.28;
function tokenStartTime(index, isLocal) {
// The first eight tokens enter both vessels simultaneously.
// The local vessel then accepts four additional tokens.
return 0.75 + index * 0.23 + (isLocal && index >= 8 ? 0.34 : 0);
}
function resetAnimation() {
simulationTime = 0;
completed = false;
playing = true;
playPause.textContent = "Pause";
for (const token of [...localTokens, ...referenceTokens]) {
token.userData.settled = false;
token.visible = false;
token.scale.setScalar(0);
}
resultCard.classList.remove("show");
mismatchCrown.visible = false;
localLabel.classList.remove("full");
referenceLabel.classList.remove("full");
progressFill.style.width = "0%";
status.innerHTML =
"Filling both measures with identical grain tokens." +
"<small>Each token represents one standardized scoop.</small>";
}
function updateToken(token, time, isLocal) {
const start = tokenStartTime(token.userData.index, isLocal);
const p = THREE.MathUtils.clamp(
(time - start) / tokenDuration,
0,
1
);
token.visible = p > 0;
if (p <= 0) return;
const target = token.userData.target;
const startY = 6.35;
// Quadratic fall, followed by a small voxel-style landing bounce.
const fall = p * p;
let y = THREE.MathUtils.lerp(startY, target.y, fall);
if (p > 0.78) {
const bouncePhase = (p - 0.78) / 0.22;
y += Math.sin(bouncePhase * Math.PI) * 0.065 * (1 - bouncePhase);
}
token.position.set(target.x, y, target.z);
token.rotation.x = (1 - p) * p * 7.5;
token.rotation.z = (1 - p) * p * 4.2;
token.rotation.y = token.userData.index * 0.31;
token.scale.setScalar(Math.min(1, p * 5.5));
token.userData.settled = p >= 1;
}
function updateFilling(time) {
for (const token of localTokens) updateToken(token, time, true);
for (const token of referenceTokens) updateToken(token, time, false);
const localSettled = localTokens.filter((t) => t.userData.settled).length;
const referenceSettled = referenceTokens.filter((t) => t.userData.settled).length;
localCount.textContent = `${localSettled} / 12 tokens`;
referenceCount.textContent = `${referenceSettled} / 8 tokens`;
localLabel.classList.toggle("full", localSettled === 12);
referenceLabel.classList.toggle("full", referenceSettled === 8);
progressFill.style.width = `${THREE.MathUtils.clamp(time / totalDuration, 0, 1) * 100}%`;
if (localSettled < 8) {
status.innerHTML =
"The first tokens enter both vessels at the same rate." +
"<small>Watch the lower front wall of each measure.</small>";
} else if (referenceSettled === 8 && localSettled < 12) {
status.innerHTML =
"The guild measure is full, but the local vessel still accepts grain." +
"<small>Four more identical tokens reveal the excess capacity.</small>";
}
if (!completed && time >= totalDuration) {
completed = true;
resultCard.classList.add("show");
mismatchCrown.visible = true;
status.innerHTML =
"Mismatch confirmed: the local bushel holds 12 tokens; the guild bushel holds 8." +
"<small>Local capacity is 50% greater than the official reference.</small>";
}
}
// ------------------------------------------------------------
// Direct camera controls — no external controls module
// ------------------------------------------------------------
function updateCamera() {
const horizontalRadius = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontalRadius,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontalRadius
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraYaw = 0.47;
cameraPitch = 0.43;
cameraRadius = 16.5;
updateCamera();
}
const activePointers = new Map();
let dragging = false;
let previousX = 0;
let previousY = 0;
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1 && dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.005,
0.18,
1.02
);
previousX = event.clientX;
previousY = event.clientY;
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (pinchDistance / Math.max(1, distance)),
10,
25
);
}
pinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
activePointers.delete(event.pointerId);
if (activePointers.size === 0) {
dragging = false;
renderer.domElement.classList.remove("dragging");
}
if (activePointers.size < 2) {
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("pointerleave", (event) => {
if (event.buttons === 0) releasePointer(event);
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
10,
25
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") cameraYaw -= 0.08;
else if (key === "arrowright") cameraYaw += 0.08;
else if (key === "arrowup") cameraPitch = Math.min(1.02, cameraPitch + 0.05);
else if (key === "arrowdown") cameraPitch = Math.max(0.18, cameraPitch - 0.05);
else if (key === "+" || key === "=") cameraRadius = Math.max(10, cameraRadius - 0.7);
else if (key === "-") cameraRadius = Math.min(25, cameraRadius + 0.7);
else if (key === "r") resetCamera();
else return;
event.preventDefault();
updateCamera();
});
// ------------------------------------------------------------
// UI controls and projected labels
// ------------------------------------------------------------
playPause.addEventListener("click", () => {
if (completed) {
resetAnimation();
return;
}
playing = !playing;
playPause.textContent = playing ? "Pause" : "Resume";
});
document.getElementById("replay").addEventListener("click", resetAnimation);
document.getElementById("reset-view").addEventListener("click", resetCamera);
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const localLabelAnchor = new THREE.Vector3(
-1.95,
tableTop + 2.72,
0.58
);
const referenceLabelAnchor = new THREE.Vector3(
2.02,
tableTop + 2.42,
0.68
);
function updateLabels() {
positionLabel(localLabel, localLabelAnchor);
positionLabel(referenceLabel, referenceLabelAnchor);
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetAnimation();
updateCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
simulationTime += delta;
}
updateFilling(simulationTime);
updateCamera();
updateLabels();
if (completed && mismatchCrown.visible) {
const pulse = 1 + Math.sin(performance.now() * 0.004) * 0.025;
mismatchCrown.scale.setScalar(pulse);
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```