Prompt specification
Build or customize the Three.js 3D scene "Two players moving counters by a rule" 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: Two players moving counters by a rule
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-players-moving-counters-by-a-rule-x2242
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a voxel tabletop race game in an ancient-style household setting. Place a small marked board between two seated figures, with counters stored in shallow dishes beside it. Use one documented ruleset or clearly label an authored modern reconstruction, and show its movement rule on a compact card. Animate a single legal turn by moving the chosen counter across the actual counted squares, leaving all other pieces in their previous states. Use clay-colored counters, a wood or stone board, and a woven mat to frame the vignette, without inventing an archaeological claim for the surrounding household details.
Working Three.js Starter (two-players-moving-counters-by-a-rule-x2242):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rosette Race — A Voxel Household Vignette</title>
<style>
:root {
--ink: #2b211b;
--paper: #ead8b6;
--paper-deep: #d7bf94;
--clay: #b86445;
--gold: #d8a94d;
--teal: #547c78;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #211914;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
#title {
top: 22px;
left: 24px;
max-width: 430px;
color: #f0dfbc;
text-shadow: 0 2px 12px rgba(0, 0, 0, 0.65);
}
#title .eyebrow {
display: block;
margin-bottom: 5px;
color: #d9ad61;
font-family: system-ui, sans-serif;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
#title h1 {
margin: 0;
font-size: clamp(27px, 4vw, 49px);
font-weight: 500;
line-height: 0.96;
}
#title p {
max-width: 360px;
margin: 10px 0 0;
color: #d8c9aa;
font-family: system-ui, sans-serif;
font-size: 12px;
line-height: 1.45;
}
#rules {
top: 22px;
right: 24px;
width: 306px;
padding: 16px 17px 15px;
pointer-events: auto;
background:
linear-gradient(rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0)),
var(--paper);
border: 1px solid rgba(66, 43, 29, 0.5);
border-radius: 3px;
box-shadow:
0 14px 34px rgba(0, 0, 0, 0.35),
inset 0 0 0 4px rgba(104, 73, 43, 0.08);
transform: rotate(0.35deg);
}
#rules .card-label {
margin: 0 0 6px;
color: #835038;
font-family: system-ui, sans-serif;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#rules h2 {
margin: 0 0 8px;
font-size: 22px;
font-weight: 600;
}
#rules .rule {
margin: 9px 0 0;
padding-top: 9px;
border-top: 1px solid rgba(64, 43, 28, 0.19);
font-family: system-ui, sans-serif;
font-size: 12px;
line-height: 1.43;
}
#rules .rule strong {
color: #78432f;
}
#rules .disclaimer {
margin-top: 11px;
padding-top: 9px;
border-top: 1px solid rgba(64, 43, 28, 0.19);
color: #69584b;
font-family: system-ui, sans-serif;
font-size: 10px;
line-height: 1.4;
}
#dice-readout {
display: flex;
align-items: center;
gap: 9px;
margin-top: 12px;
}
.dice {
width: 22px;
height: 22px;
border: 2px solid #594335;
border-radius: 3px;
background:
radial-gradient(circle at 6px 6px, #30251e 0 2.5px, transparent 3px),
#f2dfb4;
box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32);
}
#dice-readout span {
margin-left: 3px;
font-family: system-ui, sans-serif;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
}
#status {
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 12px;
min-width: 350px;
max-width: calc(100vw - 32px);
padding: 11px 15px 11px 11px;
color: #f4e7cc;
background: rgba(35, 27, 22, 0.88);
border: 1px solid rgba(231, 204, 151, 0.24);
border-radius: 4px;
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
transform: translateX(-50%);
}
#roll-badge {
display: grid;
flex: 0 0 43px;
height: 43px;
place-items: center;
color: #2c2119;
background: #e4c37d;
border-radius: 3px;
font-size: 25px;
font-weight: 700;
box-shadow: inset 0 0 0 3px rgba(84, 56, 35, 0.17);
}
#status strong {
display: block;
font-family: system-ui, sans-serif;
font-size: 12px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#status small {
display: block;
margin-top: 4px;
color: #cdbb9c;
font-family: system-ui, sans-serif;
font-size: 11px;
}
#controls {
right: 24px;
bottom: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 39px;
padding: 0 14px;
color: #f4e5c7;
background: rgba(44, 32, 24, 0.9);
border: 1px solid rgba(232, 201, 139, 0.42);
border-radius: 3px;
font-family: system-ui, sans-serif;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
cursor: pointer;
}
button:hover {
background: #684433;
}
button:disabled {
cursor: wait;
opacity: 0.55;
}
#camera-hint {
left: 24px;
bottom: 26px;
color: rgba(241, 226, 196, 0.73);
font-family: system-ui, sans-serif;
font-size: 10px;
letter-spacing: 0.04em;
text-shadow: 0 1px 6px #000;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: #e5cda0;
background: #211914;
font-family: system-ui, sans-serif;
font-size: 13px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#loading.hidden {
display: none;
}
@media (max-width: 760px) {
#title {
top: 15px;
left: 15px;
}
#title p {
display: none;
}
#rules {
top: auto;
right: 12px;
bottom: 91px;
width: 270px;
padding: 12px 14px;
}
#rules .disclaimer {
display: none;
}
#status {
bottom: 12px;
min-width: 0;
width: calc(100vw - 24px);
}
#controls {
right: 12px;
bottom: 88px;
}
#camera-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="A voxel tabletop race game in an imagined ancient-style household"></main>
<header id="title" class="hud">
<span class="eyebrow">An authored modern reconstruction</span>
<h1>Rosette Race</h1>
<p>
One legal four-square turn on a numbered board, staged in a generic
ancient-style household. No archaeological reconstruction is claimed.
</p>
</header>
<aside id="rules" class="hud" aria-label="Rules card">
<p class="card-label">Movement rule</p>
<h2>Rosette Race</h2>
<p class="rule">
<strong>Four binary dice.</strong> Each marked corner scores 1,
giving a roll from 1 to 4. The illustrated roll is
<strong>4</strong>.
</p>
<p class="rule">
<strong>Count forward.</strong> On an entry turn, square 1 is the first
counted square:
<strong>off board → 1 → 2 → 3 → 4</strong>.
On a later turn, advance exactly the number rolled.
</p>
<p class="rule">
<strong>Rosettes</strong> at squares 4, 8, 14, and 20 grant another turn.
This vignette deliberately animates only the first turn.
</p>
<div id="dice-readout" aria-label="Four binary dice, all marked">
<i class="dice"></i>
<i class="dice"></i>
<i class="dice"></i>
<i class="dice"></i>
<span>ROLL 4 / 4</span>
</div>
<p class="disclaimer">
The route, rosette rewards, board arrangement, and household setting are
an authored modern scene, not a reconstruction of an excavated game.
</p>
</aside>
<section id="status" class="hud" aria-live="polite">
<div id="roll-badge">4</div>
<div>
<strong id="status-main">Preparing the legal turn</strong>
<small id="status-sub">The chosen counter enters on square 1.</small>
</div>
</section>
<nav id="controls" class="hud" aria-label="Scene controls">
<button id="replay" type="button" disabled>Replay legal turn</button>
<button id="reset-view" type="button">Reset view</button>
</nav>
<div id="camera-hint" class="hud">Drag to orbit · Scroll to zoom</div>
<div id="loading">Building the household vignette…</div>
<noscript>This scene requires JavaScript and WebGL.</noscript>
<script type="module">
// Only Three.js core is imported. Camera controls are implemented below.
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const mount = document.querySelector("#scene");
const replayButton = document.querySelector("#replay");
const resetViewButton = document.querySelector("#reset-view");
const statusMain = document.querySelector("#status-main");
const statusSub = document.querySelector("#status-sub");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x251b15);
scene.fog = new THREE.Fog(0x251b15, 18, 34);
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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.setAttribute("role", "img");
renderer.domElement.setAttribute(
"aria-label",
"Voxel tabletop game with a numbered board, clay counters, two seated figures, and dishes."
);
mount.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const orbit = {
yaw: 0.66,
pitch: 0.61,
radius: 14.8,
target: new THREE.Vector3(0, 1.05, 0)
};
function updateCamera() {
const horizontal = orbit.radius * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontal,
orbit.target.y + Math.sin(orbit.pitch) * orbit.radius,
orbit.target.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(orbit.target);
}
updateCamera();
// Custom orbit controls: drag to rotate, wheel to zoom.
const pointer = {
active: false,
id: null,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.005,
0.28,
1.13
);
pointer.x = event.clientX;
pointer.y = event.clientY;
updateCamera();
});
function stopPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
}
renderer.domElement.addEventListener("pointerup", stopPointer);
renderer.domElement.addEventListener("pointercancel", stopPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.009,
9.2,
21
);
updateCamera();
},
{ passive: false }
);
resetViewButton.addEventListener("click", () => {
orbit.yaw = 0.66;
orbit.pitch = 0.61;
orbit.radius = 14.8;
orbit.target.set(0, 1.05, 0);
updateCamera();
});
// Lighting.
const hemisphere = new THREE.HemisphereLight(0xffe5bd, 0x4b3324, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffdfad, 3.3);
keyLight.position.set(5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const warmLamp = new THREE.PointLight(0xffa657, 15, 10, 2);
warmLamp.position.set(-5.6, 3.1, -4.2);
scene.add(warmLamp);
const fillLight = new THREE.PointLight(0x789a9a, 5, 14, 2);
fillLight.position.set(6, 5, 3);
scene.add(fillLight);
// Materials.
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x66503b,
roughness: 1
}),
plaster: new THREE.MeshStandardMaterial({
color: 0xc6ad82,
roughness: 0.96
}),
plasterAlt: new THREE.MeshStandardMaterial({
color: 0xb89b70,
roughness: 1
}),
plasterDark: new THREE.MeshStandardMaterial({
color: 0x9d805e,
roughness: 1
}),
wood: new THREE.MeshStandardMaterial({
color: 0x66432d,
roughness: 0.88
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0x8b603c,
roughness: 0.9
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x3f2b22,
roughness: 0.95
}),
stone: new THREE.MeshStandardMaterial({
color: 0xb8aa8e,
roughness: 0.96
}),
stoneDark: new THREE.MeshStandardMaterial({
color: 0x8d816d,
roughness: 1
}),
clay: new THREE.MeshStandardMaterial({
color: 0xb96545,
roughness: 0.82
}),
clayDark: new THREE.MeshStandardMaterial({
color: 0x8d4937,
roughness: 0.88
}),
clayLight: new THREE.MeshStandardMaterial({
color: 0xc57a54,
roughness: 0.82
}),
linen: new THREE.MeshStandardMaterial({
color: 0xdfc99e,
roughness: 1
}),
indigo: new THREE.MeshStandardMaterial({
color: 0x405f64,
roughness: 0.92
}),
reed: new THREE.MeshStandardMaterial({
color: 0xa17d4e,
roughness: 1
}),
reedLight: new THREE.MeshStandardMaterial({
color: 0xc09a62,
roughness: 1
}),
skin: new THREE.MeshStandardMaterial({
color: 0xa96f4c,
roughness: 0.9
}),
hair: new THREE.MeshStandardMaterial({
color: 0x2b211d,
roughness: 1
}),
black: new THREE.MeshStandardMaterial({
color: 0x241d19,
roughness: 0.9
}),
ivory: new THREE.MeshStandardMaterial({
color: 0xe2ce9d,
roughness: 0.8
}),
gold: new THREE.MeshStandardMaterial({
color: 0xc7953f,
roughness: 0.68
}),
teal: new THREE.MeshStandardMaterial({
color: 0x527a76,
roughness: 0.8
})
};
function addBox(
parent,
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
material,
x = 0,
y = 0,
z = 0,
segments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Generic floor and block-built plaster walls.
addBox(scene, 22, 0.5, 17, materials.floor, 0, -0.4, 0, false);
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 13; col++) {
const material =
(row + col) % 4 === 0
? materials.plasterAlt
: materials.plaster;
addBox(
scene,
1.55,
1.55,
0.32,
material,
-9.2 + col * 1.58 + (row % 2) * 0.18,
0.34 + row * 1.5,
-6.25,
false
);
}
}
addBox(scene, 0.35, 5.1, 10, materials.plasterDark, -10, 2.1, -1.2, false);
addBox(scene, 0.55, 0.35, 10, materials.woodDark, -9.75, 0.08, -1.2, false);
// Woven mat: alternating reed strips and darker cross-weaving.
const matGroup = new THREE.Group();
scene.add(matGroup);
for (let i = 0; i < 30; i++) {
const material = i % 3 === 0 ? materials.reedLight : materials.reed;
addBox(
matGroup,
11.2,
0.06,
0.19,
material,
0,
-0.12,
-3.55 + i * 0.245,
false
);
}
for (let i = 0; i < 21; i++) {
addBox(
matGroup,
0.12,
0.025,
7.1,
i % 2 === 0 ? materials.woodLight : materials.reedLight,
-5.1 + i * 0.51,
-0.075,
0,
false
);
}
// Low table.
const table = new THREE.Group();
scene.add(table);
addBox(table, 10.8, 0.3, 4.8, materials.wood, 0, 1.05, 0);
addBox(table, 10.4, 0.13, 4.42, materials.woodLight, 0, 1.22, 0);
for (const x of [-4.55, 4.55]) {
for (const z of [-1.75, 1.75]) {
addBox(table, 0.38, 1.0, 0.38, materials.woodDark, x, 0.43, z);
}
}
addBox(table, 9.3, 0.24, 0.32, materials.woodDark, 0, 0.38, -1.7);
addBox(table, 9.3, 0.24, 0.32, materials.woodDark, 0, 0.38, 1.7);
// Board base and frame.
const board = new THREE.Group();
scene.add(board);
addBox(board, 7.05, 0.22, 2.5, materials.woodDark, 0, 1.32, 0);
addBox(board, 6.87, 0.08, 2.33, materials.woodLight, 0, 1.44, 0);
const pitch = 0.62;
const tileSize = 0.58;
const route = [
[1, 0],
[0, 0],
[0, 1],
[0, 2],
[0, 3],
[1, 3],
[1, 2],
[1, 1],
[2, 1],
[2, 2],
[2, 3],
[2, 4],
[2, 5],
[2, 6],
[1, 6],
[0, 6],
[0, 7],
[0, 8],
[0, 9],
[1, 9]
];
const rosetteSquares = new Set([4, 8, 14, 20]);
const routeLookup = new Map();
route.forEach(([row, col], index) => {
routeLookup.set(`${row},${col}`, index + 1);
});
function tilePosition(row, col) {
return new THREE.Vector3(
(col - 4.5) * pitch,
1.535,
(row - 1) * pitch
);
}
function makeNumberTexture(number, rosette) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
context.clearRect(0, 0, 128, 128);
context.fillStyle = "#30261e";
context.textAlign = "center";
context.textBaseline = "middle";
context.font =
number >= 10
? "bold 43px Georgia, serif"
: "bold 53px Georgia, serif";
context.fillText(String(number), 64, 67);
if (rosette) {
context.fillStyle = "#a66836";
context.beginPath();
context.arc(104, 22, 7, 0, Math.PI * 2);
context.fill();
context.fillStyle = "#ead7aa";
context.beginPath();
context.arc(104, 22, 2.4, 0, Math.PI * 2);
context.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addRosette(position) {
const group = new THREE.Group();
group.position.set(position.x + 0.19, 1.525, position.z - 0.19);
for (let i = 0; i < 5; i++) {
const angle = (i / 5) * Math.PI * 2;
const petal = addBox(
group,
0.105,
0.035,
0.065,
materials.clayDark,
Math.cos(angle) * 0.067,
0,
Math.sin(angle) * 0.067
);
petal.rotation.y = -angle;
}
addBox(group, 0.065, 0.042, 0.065, materials.gold, 0, 0.005, 0);
board.add(group);
}
const validCells = [];
for (let row = 0; row < 3; row++) {
for (let col = 0; col < 10; col++) {
const isBridge = col === 4 || col === 5;
if (isBridge && row !== 2) continue;
validCells.push([row, col]);
const position = tilePosition(row, col);
const routeNumber = routeLookup.get(`${row},${col}`);
const material = routeNumber ? materials.stone : materials.stoneDark;
addBox(
board,
tileSize,
0.09,
tileSize,
material,
position.x,
1.48,
position.z
);
if (routeNumber) {
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.43, 0.43),
new THREE.MeshBasicMaterial({
map: makeNumberTexture(
routeNumber,
rosetteSquares.has(routeNumber)
),
transparent: true,
depthWrite: false,
toneMapped: false
})
);
label.rotation.x = -Math.PI / 2;
label.position.set(position.x, 1.529, position.z);
label.renderOrder = 3;
board.add(label);
if (rosetteSquares.has(routeNumber)) {
addRosette(position);
}
}
}
}
// Thin inlaid route line connecting the actual counted squares.
for (let i = 0; i < route.length - 1; i++) {
const a = tilePosition(...route[i]);
const b = tilePosition(...route[i + 1]);
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz) - 0.16;
const link = addBox(
board,
length,
0.014,
0.027,
materials.teal,
(a.x + b.x) / 2,
1.535,
(a.z + b.z) / 2,
false
);
link.rotation.y = -Math.atan2(dz, dx);
link.renderOrder = 1;
}
// Small front plaque.
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 512;
plaqueCanvas.height = 96;
const plaqueContext = plaqueCanvas.getContext("2d");
plaqueContext.fillStyle = "#c9a66b";
plaqueContext.fillRect(0, 0, 512, 96);
plaqueContext.fillStyle = "#3d2b21";
plaqueContext.textAlign = "center";
plaqueContext.textBaseline = "middle";
plaqueContext.font = "bold 31px Georgia";
plaqueContext.fillText("ROSES RACE · 20 COUNTED SQUARES", 256, 50);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(2.55, 0.36),
new THREE.MeshBasicMaterial({ map: plaqueTexture, toneMapped: false })
);
plaque.position.set(0, 1.32, 1.258);
board.add(plaque);
// Shallow dishes and clay counters.
function createDish(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const bowlMaterial = materials.woodLight.clone();
bowlMaterial.side = THREE.DoubleSide;
const bowl = new THREE.Mesh(
new THREE.CylinderGeometry(0.58, 0.64, 0.17, 16, 1, true),
bowlMaterial
);
bowl.position.y = 1.31;
bowl.castShadow = true;
bowl.receiveShadow = true;
group.add(bowl);
addCylinder(
group,
0.61,
0.61,
0.045,
materials.wood,
0,
1.235,
0,
16
);
return group;
}
const leftDish = createDish(-4.48, 0.52);
const rightDish = createDish(4.48, 0.52);
function createCounter(color, accentColor) {
const group = new THREE.Group();
addCylinder(
group,
0.17,
0.19,
0.14,
new THREE.MeshStandardMaterial({
color,
roughness: 0.8
}),
0,
0,
0,
12
);
addCylinder(
group,
0.125,
0.125,
0.025,
new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.76
}),
0,
0.083,
0,
12
);
scene.add(group);
return group;
}
const selectedHome = new THREE.Vector3(-4.49, 1.44, 0.43);
const selectedCounter = createCounter(0xb86445, 0xd2956d);
selectedCounter.position.copy(selectedHome);
selectedCounter.userData.home = selectedHome.clone();
const leftReserve = [
new THREE.Vector3(-4.25, 1.44, 0.81),
new THREE.Vector3(-4.68, 1.44, 0.79)
];
const leftReserveCounters = leftReserve.map((position) => {
const counter = createCounter(0xb86445, 0xd2956d);
counter.position.copy(position);
counter.userData.home = position.clone();
return counter;
});
const rightReserve = [
new THREE.Vector3(4.28, 1.44, 0.43),
new THREE.Vector3(4.48, 1.44, 0.81),
new THREE.Vector3(4.70, 1.44, 0.80)
];
rightReserve.forEach((position) => {
const counter = createCounter(0xa9533b, 0xc77b58);
counter.position.copy(position);
});
// Stationary pieces are never touched by the turn animation.
const stationarySquare8 = tilePosition(...route[7]);
const stationarySquare15 = tilePosition(...route[14]);
const stationaryCounterA = createCounter(0x9a4c37, 0xbe7354);
stationaryCounterA.position.set(
stationarySquare8.x,
1.605,
stationarySquare8.z
);
const stationaryCounterB = createCounter(0x9a4c37, 0xbe7354);
stationaryCounterB.position.set(
stationarySquare15.x,
1.605,
stationarySquare15.z
);
// Binary dice in a small tray. All four are marked, so the roll is 4.
const diceTray = new THREE.Group();
diceTray.position.set(3.35, 0, -1.47);
scene.add(diceTray);
addBox(diceTray, 1.1, 0.08, 0.57, materials.woodDark, 0, 1.24, 0);
const diceGroups = [];
for (let i = 0; i < 4; i++) {
const die = new THREE.Group();
die.position.set(-0.36 + i * 0.24, 1.4, (i % 2) * 0.07 - 0.035);
die.rotation.y = Math.PI / 4 + i * 0.16;
const pyramid = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.25, 4),
materials.ivory
);
pyramid.castShadow = true;
pyramid.receiveShadow = true;
die.add(pyramid);
const marker = addBox(
die,
0.055,
0.012,
0.055,
materials.black,
0,
0.015,
0.095,
false
);
marker.rotation.x = -0.55;
diceTray.add(die);
diceGroups.push(die);
}
// Highlight under the currently counted square.
const highlightMaterial = new THREE.MeshBasicMaterial({
color: 0xe3b85a,
transparent: true,
opacity: 0,
depthWrite: false,
toneMapped: false
});
const highlight = new THREE.Mesh(
new THREE.PlaneGeometry(0.52, 0.52),
highlightMaterial
);
highlight.rotation.x = -Math.PI / 2;
highlight.position.y = 1.54;
highlight.renderOrder = 4;
scene.add(highlight);
function squareWorldPosition(squareNumber) {
const [row, col] = route[squareNumber - 1];
const position = tilePosition(row, col);
position.y = 1.605;
return position;
}
function setHighlight(squareNumber, opacity = 0.22) {
const position = squareWorldPosition(squareNumber);
highlight.position.set(position.x, 1.541, position.z);
highlightMaterial.opacity = opacity;
}
// Seated voxel figures. Their costumes are generic and make no archaeological claim.
function createFigure(x, z, rotationY, tunicMaterial, hairColor) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotationY;
scene.add(group);
const skinMaterial = materials.skin.clone();
const hairMaterial = new THREE.MeshStandardMaterial({
color: hairColor,
roughness: 1
});
// Crossed legs.
addBox(group, 0.34, 0.28, 1.05, materials.linen, -0.23, 0.34, -0.08);
addBox(group, 0.34, 0.28, 1.05, materials.linen, 0.23, 0.34, 0.08);
addBox(group, 0.31, 0.26, 0.78, materials.linen, -0.24, 0.18, 0.54);
addBox(group, 0.31, 0.26, 0.78, materials.linen, 0.24, 0.18, -0.54);
// Torso and shoulders.
addBox(group, 0.83, 1.08, 0.54, tunicMaterial, 0, 1.08, 0);
addBox(group, 1.03, 0.25, 0.58, tunicMaterial, 0, 1.53, 0);
addBox(group, 0.86, 0.13, 0.57, materials.linen, 0, 0.64, 0);
// Arms reaching toward the table.
const leftArm = addBox(
group,
0.25,
0.72,
0.28,
tunicMaterial,
-0.53,
1.11,
-0.22
);
leftArm.rotation.x = -0.48;
const rightArm = addBox(
group,
0.25,
0.72,
0.28,
tunicMaterial,
0.53,
1.11,
-0.22
);
rightArm.rotation.x = -0.48;
addBox(group, 0.23, 0.22, 0.68, materials.linen, -0.52, 0.72, -0.55);
addBox(group, 0.23, 0.22, 0.68, materials.linen, 0.52, 0.72, -0.55);
addBox(group, 0.22, 0.18, 0.25, skinMaterial, -0.52, 0.64, -0.89);
addBox(group, 0.22, 0.18, 0.25, skinMaterial, 0.52, 0.64, -0.89);
// Neck, head, hair, and simple face.
addBox(group, 0.25, 0.22, 0.25, skinMaterial, 0, 1.72, 0);
addBox(group, 0.62, 0.66, 0.58, skinMaterial, 0, 2.06, -0.02);
addBox(group, 0.66, 0.19, 0.61, hairMaterial, 0, 2.35, 0.015);
addBox(group, 0.65, 0.40, 0.17, hairMaterial, 0, 2.12, 0.25);
addBox(group, 0.075, 0.075, 0.025, materials.black, -0.15, 2.08, -0.321);
addBox(group, 0.075, 0.075, 0.025, materials.black, 0.15, 2.08, -0.321);
addBox(group, 0.17, 0.04, 0.025, materials.clayDark, 0, 1.91, -0.322);
return group;
}
addBox(
scene,
1.8,
0.24,
1.35,
materials.indigo,
-0.9,
0.03,
3.65
);
addBox(
scene,
1.8,
0.24,
1.35,
materials.linen,
0.9,
0.03,
-3.68
);
createFigure(-0.9, 3.65, 0, materials.linen, 0x2d211c);
createFigure(0.9, -3.68, Math.PI, materials.indigo, 0x443027);
// Generic shelf and household vessels.
addBox(scene, 4.5, 0.2, 0.65, materials.wood, 3.3, 2.55, -5.82);
function makeVessel(x, y, z, scale, material) {
const vessel = new THREE.Group();
vessel.position.set(x, y, z);
vessel.scale.setScalar(scale);
scene.add(vessel);
addCylinder(vessel, 0.19, 0.27, 0.48, material, 0, 0.24, 0, 8);
addCylinder(vessel, 0.105, 0.17, 0.20, material, 0, 0.57, 0, 8);
addCylinder(vessel, 0.13, 0.13, 0.035, materials.woodDark, 0, 0.69, 0, 8);
}
makeVessel(2.0, 2.66, -5.8, 1, materials.clayDark);
makeVessel(2.75, 2.66, -5.8, 0.72, materials.stone);
makeVessel(4.45, 2.66, -5.8, 0.92, materials.clayLight);
// A simple block lamp with an emissive flame.
addBox(scene, 0.18, 2.2, 0.18, materials.woodDark, -5.6, 1.15, -4.4);
addBox(scene, 0.85, 0.12, 0.85, materials.wood, -5.6, 2.22, -4.4);
addBox(scene, 0.62, 0.07, 0.62, materials.woodDark, -5.6, 2.32, -4.4);
const flameMaterial = new THREE.MeshStandardMaterial({
color: 0xffa331,
emissive: 0xff6a12,
emissiveIntensity: 2.6,
roughness: 0.5
});
addBox(scene, 0.18, 0.32, 0.18, flameMaterial, -5.6, 2.51, -4.4, false);
// Animation helpers.
const sleep = (milliseconds) =>
new Promise((resolve) => setTimeout(resolve, milliseconds));
function tweenArc(from, to, duration, height) {
return new Promise((resolve) => {
const startTime = performance.now();
function frame(now) {
const t = Math.min((now - startTime) / duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
selectedCounter.position.x = THREE.MathUtils.lerp(
from.x,
to.x,
eased
);
selectedCounter.position.y =
THREE.MathUtils.lerp(from.y, to.y, eased) +
Math.sin(Math.PI * t) * height;
selectedCounter.position.z = THREE.MathUtils.lerp(
from.z,
to.z,
eased
);
selectedCounter.rotation.y += 0.055;
if (t < 1) {
requestAnimationFrame(frame);
} else {
selectedCounter.position.copy(to);
resolve();
}
}
requestAnimationFrame(frame);
});
}
function animateDice() {
const original = diceGroups.map((die) => ({
x: die.position.x,
y: die.position.y,
z: die.position.z,
rotationY: die.rotation.y
}));
return new Promise((resolve) => {
const startTime = performance.now();
const duration = 520;
function frame(now) {
const t = Math.min((now - startTime) / duration, 1);
diceGroups.forEach((die, index) => {
const base = original[index];
const bounce = Math.abs(Math.sin(t * Math.PI * 3 + index * 0.35));
die.position.set(
base.x,
base.y + bounce * 0.085,
base.z
);
die.rotation.y = base.rotationY + t * 0.6;
});
if (t < 1) {
requestAnimationFrame(frame);
} else {
diceGroups.forEach((die, index) => {
const base = original[index];
die.position.set(base.x, base.y, base.z);
die.rotation.y = base.rotationY + 0.6;
});
resolve();
}
}
requestAnimationFrame(frame);
});
}
let playing = false;
async function playTurn() {
if (playing) return;
playing = true;
replayButton.disabled = true;
replayButton.textContent = "Playing turn…";
// Only the chosen counter is reset. Every other piece remains untouched.
selectedCounter.position.copy(selectedCounter.userData.home);
selectedCounter.rotation.set(0, 0, 0);
selectedCounter.scale.setScalar(1);
highlightMaterial.opacity = 0;
statusMain.textContent = "Rolling four binary dice";
statusSub.textContent = "All four marked corners give a legal roll of 4.";
await animateDice();
await sleep(260);
statusMain.textContent = "Roll 4 · entering the route";
statusSub.textContent = "Square 1 is the first counted square.";
const square1 = squareWorldPosition(1);
await tweenArc(
selectedCounter.position.clone(),
square1,
850,
0.68
);
setHighlight(1, 0.3);
statusMain.textContent = "Count 1 of 4";
statusSub.textContent = "The chosen counter is on counted square 1.";
await sleep(220);
for (let square = 2; square <= 4; square++) {
const from = squareWorldPosition(square - 1);
const to = squareWorldPosition(square);
await tweenArc(from, to, 540, 0.27);
setHighlight(square, 0.32);
statusMain.textContent = `Count ${square} of 4`;
statusSub.textContent =
square === 4
? "Landed on rosette square 4; an extra turn is earned."
: `The chosen counter is on counted square ${square}.`;
await sleep(square === 4 ? 320 : 180);
}
await sleep(240);
highlightMaterial.opacity = 0.22;
statusMain.textContent = "Turn complete · rosette square 4";
statusSub.textContent =
"Exactly one legal turn was animated; all other pieces stayed fixed.";
playing = false;
replayButton.disabled = false;
replayButton.textContent = "Replay legal turn";
}
replayButton.addEventListener("click", playTurn);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function render() {
requestAnimationFrame(render);
const elapsed = clock.getElapsedTime();
if (!playing && highlightMaterial.opacity > 0) {
highlightMaterial.opacity =
0.17 + (Math.sin(elapsed * 3.5) + 1) * 0.035;
}
flameMaterial.emissiveIntensity =
2.45 + Math.sin(elapsed * 8.2) * 0.22;
renderer.render(scene, camera);
}
render();
loading.classList.add("hidden");
setTimeout(() => {
playTurn();
}, 650);
</script>
</body>
</html>
```