Prompt specification
Build or customize the Three.js 3D scene "Two Identical Target Courses" 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 Identical Target Courses
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-identical-target-courses-x3645
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing fair comparisons under explicit game rules. Build two matched tabletop target courses with equal distances and obstacle layouts. Show the controlled dimensions before placing different player tokens at the starts. Stylized solid forms.
Working Three.js Starter (two-identical-target-courses-x3645):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Matched Course Lab</title>
<style>
:root {
--paper: #f6f1e8;
--paper-dark: #e9e1d4;
--ink: #21313b;
--muted: #66757c;
--line: #d6cdbf;
--orange: #ee9c3b;
--red: #e85d52;
--blue: #3689b8;
--green: #347d6d;
--shadow: 0 12px 35px rgba(30, 44, 50, 0.14);
}
* {
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
display: flex;
width: 100%;
height: 100%;
}
.panel {
width: clamp(320px, 28vw, 380px);
flex: 0 0 auto;
height: 100%;
overflow-y: auto;
padding: 25px 24px 22px;
background:
radial-gradient(circle at 15% 0%, rgba(255,255,255,.8), transparent 32%),
var(--paper);
border-right: 1px solid var(--line);
z-index: 5;
}
.eyebrow {
margin: 0 0 7px;
color: var(--orange);
font-size: 11px;
font-weight: 850;
letter-spacing: .16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 29px;
line-height: 1.05;
letter-spacing: -.045em;
}
.subtitle {
margin: 10px 0 20px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.stepper {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-bottom: 17px;
}
.step {
min-height: 67px;
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255,255,255,.38);
color: #849097;
transition: .25s ease;
}
.step b {
display: block;
margin-bottom: 3px;
font-size: 15px;
}
.step span {
display: block;
font-size: 10px;
line-height: 1.25;
}
.step.active {
color: var(--ink);
border-color: var(--orange);
background: #fff8ec;
box-shadow: 0 4px 15px rgba(238,156,59,.12);
}
.step.done {
color: var(--green);
border-color: rgba(52,125,109,.35);
background: rgba(52,125,109,.08);
}
.notice {
padding: 12px 13px;
margin-bottom: 16px;
border-left: 3px solid var(--orange);
border-radius: 7px;
background: rgba(238,156,59,.09);
color: #705126;
font-size: 12px;
line-height: 1.5;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin: 0 0 18px;
}
.metric {
padding: 11px 9px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255,255,255,.52);
}
.metric b {
display: block;
font-size: 19px;
line-height: 1;
letter-spacing: -.03em;
}
.metric span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
font-weight: 750;
line-height: 1.25;
text-transform: uppercase;
letter-spacing: .05em;
}
.section-title {
display: flex;
align-items: center;
gap: 8px;
margin: 18px 0 9px;
font-size: 12px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
}
.section-title::after {
content: "";
height: 1px;
flex: 1;
background: var(--line);
}
.rules {
margin: 0;
padding: 0 0 0 20px;
color: #4f6069;
font-size: 12px;
line-height: 1.5;
}
.rules li {
margin: 0 0 7px;
padding-left: 2px;
}
.rules strong {
color: var(--ink);
}
.controls {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 18px;
}
button {
border: 0;
border-radius: 10px;
cursor: pointer;
font-weight: 800;
transition: transform .15s ease, opacity .15s ease, box-shadow .15s ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
}
button:active:not(:disabled) {
transform: translateY(1px);
}
button:disabled {
cursor: not-allowed;
opacity: .42;
}
.primary {
padding: 12px 15px;
color: #fff;
background: var(--ink);
box-shadow: 0 6px 16px rgba(33,49,59,.18);
}
.secondary {
padding: 11px 13px;
color: var(--ink);
background: var(--paper-dark);
}
.fairness {
margin-top: 12px;
padding: 10px 12px;
border-radius: 10px;
color: #285e54;
background: rgba(52,125,109,.09);
font-size: 11px;
line-height: 1.45;
}
.log {
display: grid;
gap: 7px;
margin-top: 9px;
}
.log-entry {
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255,255,255,.4);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.log-entry b {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-size: 11px;
}
#stage {
position: relative;
flex: 1 1 auto;
min-width: 0;
height: 100%;
overflow: hidden;
background: #e7e4dc;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: absolute;
top: 18px;
left: 18px;
right: 18px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
pointer-events: none;
}
.course-chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.chip {
display: flex;
align-items: center;
gap: 7px;
padding: 8px 11px;
border: 1px solid rgba(255,255,255,.55);
border-radius: 999px;
background: rgba(250,247,240,.78);
box-shadow: var(--shadow);
backdrop-filter: blur(8px);
font-size: 11px;
font-weight: 800;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
}
.dot.red {
background: var(--red);
}
.dot.blue {
background: var(--blue);
}
.audit {
padding: 8px 11px;
border-radius: 999px;
color: #285e54;
background: rgba(231,247,239,.86);
box-shadow: var(--shadow);
font-size: 10px;
font-weight: 850;
letter-spacing: .05em;
text-transform: uppercase;
}
.view-tools {
position: absolute;
top: 67px;
left: 18px;
display: flex;
gap: 7px;
}
.view-tools button {
padding: 8px 10px;
color: var(--ink);
background: rgba(250,247,240,.83);
box-shadow: 0 5px 15px rgba(30,44,50,.08);
backdrop-filter: blur(8px);
font-size: 10px;
}
.status-card {
position: absolute;
left: 50%;
bottom: 113px;
width: min(570px, calc(100% - 36px));
padding: 11px 16px;
transform: translateX(-50%);
border: 1px solid rgba(255,255,255,.65);
border-radius: 12px;
background: rgba(248,245,238,.88);
box-shadow: var(--shadow);
backdrop-filter: blur(9px);
color: #4c5d65;
text-align: center;
font-size: 12px;
line-height: 1.4;
pointer-events: none;
}
.dock {
position: absolute;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 13px;
padding: 10px 11px 10px 10px;
transform: translateX(-50%);
border: 1px solid rgba(255,255,255,.7);
border-radius: 16px;
background: rgba(248,245,238,.91);
box-shadow: 0 16px 40px rgba(30,44,50,.19);
backdrop-filter: blur(10px);
}
.die {
display: grid;
place-items: center;
width: 48px;
height: 48px;
border-radius: 12px;
color: #fff;
background: var(--ink);
box-shadow: inset 0 -3px 0 rgba(0,0,0,.18);
font-size: 23px;
font-weight: 900;
transition: transform .18s ease;
}
.die.rolling {
transform: rotate(-13deg) scale(1.08);
}
.dock-copy {
min-width: 126px;
}
.dock-copy b {
display: block;
margin-bottom: 2px;
font-size: 12px;
}
.dock-copy span {
color: var(--muted);
font-size: 10px;
}
.roll-button {
min-width: 126px;
padding: 12px 15px;
color: #fff;
background: var(--orange);
box-shadow: 0 6px 14px rgba(238,156,59,.25);
font-size: 12px;
}
.hint {
position: absolute;
right: 18px;
bottom: 20px;
color: rgba(33,49,59,.58);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 900px) {
.hint {
display: none;
}
.audit {
display: none;
}
}
@media (max-width: 740px) {
html, body {
overflow: hidden;
}
#app {
flex-direction: column;
}
#stage {
order: 0;
width: 100%;
height: 61%;
min-height: 390px;
}
.panel {
order: 1;
width: 100%;
height: 39%;
padding: 18px;
border-right: 0;
border-top: 1px solid var(--line);
}
h1 {
font-size: 24px;
}
.subtitle {
margin-bottom: 13px;
}
.stepper {
margin-bottom: 12px;
}
.step {
min-height: 54px;
}
.metrics {
margin-bottom: 12px;
}
.status-card {
bottom: 102px;
font-size: 11px;
}
.dock {
bottom: 14px;
}
.dock-copy {
min-width: 105px;
}
.roll-button {
min-width: 108px;
}
.hud {
top: 10px;
left: 10px;
right: 10px;
}
.view-tools {
top: 55px;
left: 10px;
}
}
</style>
</head>
<body>
<div id="app">
<aside class="panel">
<p class="eyebrow">Tabletop fairness lab</p>
<h1>Matched<br>Course Run</h1>
<p class="subtitle">
Two independent target courses. One controlled layout, one shared die,
and two cosmetic player tokens.
</p>
<div class="stepper">
<div class="step active" id="step1">
<b>01</b>
<span>Inspect controlled dimensions</span>
</div>
<div class="step" id="step2">
<b>02</b>
<span>Place both tokens</span>
</div>
<div class="step" id="step3">
<b>03</b>
<span>Run shared rounds</span>
</div>
</div>
<div class="notice" id="setupNotice">
The amber measurement lines are visible on the tabletop.
No player tokens have been placed yet.
</div>
<div class="metrics">
<div class="metric">
<b>20.0</b>
<span>Course length / u</span>
</div>
<div class="metric">
<b>4.8</b>
<span>Lane width / u</span>
</div>
<div class="metric">
<b>4</b>
<span>Matched obstacles</span>
</div>
</div>
<div class="section-title">Explicit game rules</div>
<ol class="rules">
<li>Both courses run from <strong>0 to 20 game units</strong>.</li>
<li>
Each course has the same lane width, obstacle count, obstacle order,
obstacle sizes, and relative obstacle offsets.
</li>
<li>
Obstacle landing footprints begin at
<strong>3.6, 7.4, 11.5, and 15.4 u</strong>.
</li>
<li>
Every round uses <strong>one d6 for both players</strong>.
Each token advances by that exact result.
</li>
<li>
If a token lands inside an obstacle footprint, it stops before the
footprint and loses <strong>1 additional unit</strong>.
</li>
<li>
The first token to reach 20 u wins. A simultaneous finish is a tie.
Token color and shape have <strong>no gameplay effect</strong>.
</li>
</ol>
<div class="controls">
<button class="primary" id="setupButton">Lock layout & place tokens</button>
<button class="secondary" id="resetButton" title="Return to the controlled setup">
Reset
</button>
</div>
<div class="fairness">
<strong>Controlled variables:</strong> course length, lane width,
obstacle positions, obstacle footprints, die sequence, collision rule,
and target distance. Only the token appearance differs.
</div>
<div class="section-title">Round log</div>
<div class="log" id="log"></div>
</aside>
<main id="stage">
<canvas id="scene"></canvas>
<div class="hud">
<div class="course-chips">
<div class="chip"><span class="dot red"></span> Player A · Block token</div>
<div class="chip"><span class="dot blue"></span> Player B · Orb token</div>
</div>
<div class="audit">0 unmatched gameplay variables</div>
</div>
<div class="view-tools">
<button id="measureButton">Hide measurements</button>
<button id="viewButton">Reset view</button>
</div>
<div class="status-card" id="status">
Inspect the amber dimensions, then lock the layout to place both tokens.
</div>
<div class="dock">
<div class="die" id="die">—</div>
<div class="dock-copy">
<b id="roundLabel">Shared die</b>
<span id="dieLabel">Waiting for setup</span>
</div>
<button class="roll-button" id="rollButton" disabled>Roll shared d6</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Controlled experiment constants
// -------------------------------------------------------------------------
const COURSE_LENGTH = 20;
const LANE_WIDTH = 4.8;
const START_Z = 10;
const TARGET_Z = START_Z - COURSE_LENGTH;
const LANE_CENTERS = [-3.6, 3.6];
const TOKEN_RADIUS = 0.43;
// Distances are measured from each lane's start. The same array is used
// for both courses without per-player modification.
const OBSTACLES = [
{ distance: 3.6, offsetX: -0.58, radius: 0.72, type: "block" },
{ distance: 7.4, offsetX: 0.58, radius: 0.50, type: "post" },
{ distance: 11.5, offsetX: -0.25, radius: 0.78, type: "bar" },
{ distance: 15.4, offsetX: 0.62, radius: 0.58, type: "bumper" }
];
const $ = id => document.getElementById(id);
const stage = $("stage");
const canvas = $("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e4dc);
scene.fog = new THREE.Fog(0xe7e4dc, 39, 68);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
// Direct camera controls: no examples/addons are used.
const cameraTarget = new THREE.Vector3(0, 0, -0.5);
const cameraState = {
theta: 0,
phi: 0.86,
radius: 31
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(phi) * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let dragX = 0;
let dragY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.46,
1.25
);
updateCamera();
});
function stopDragging() {
dragging = false;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
22,
48
);
updateCamera();
}, { passive: false });
$("viewButton").addEventListener("click", () => {
cameraState.theta = 0;
cameraState.phi = 0.86;
cameraState.radius = 31;
updateCamera();
});
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(stage);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Lighting and materials
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff8e9, 0x657478, 2.1));
const keyLight = new THREE.DirectionalLight(0xfff1d9, 3.0);
keyLight.position.set(-10, 19, 13);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -20;
keyLight.shadow.camera.right = 20;
keyLight.shadow.camera.top = 22;
keyLight.shadow.camera.bottom = -22;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 55;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb9d9e8, 1.15);
rimLight.position.set(12, 10, -12);
scene.add(rimLight);
function material(color, roughness = 0.78, metalness = 0.03) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const materials = {
ground: material(0xd9d4c9, 0.95),
base: material(0x22313a, 0.82),
trim: material(0x34464f, 0.74),
laneA: material(0x3b596d, 0.9),
laneB: material(0x3b625b, 0.9),
cream: material(0xf0e8d8, 0.88),
targetA: material(0xe85d52, 0.72),
targetB: material(0x3689b8, 0.72),
obstacle: material(0xe3ae4f, 0.7),
obstacleDark: material(0x8d6931, 0.82),
footprint: new THREE.MeshBasicMaterial({
color: 0xf4c35d,
transparent: true,
opacity: 0.2,
depthWrite: false,
side: THREE.DoubleSide
})
};
function mesh(geometry, mat, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(parent, width, height, depth, mat, x, y, z) {
const object = mesh(new THREE.BoxGeometry(width, height, depth), mat, parent);
object.position.set(x, y, z);
return object;
}
// Rounded billboard labels generated entirely inside this file.
function createLabel(text, {
background = "#263943",
foreground = "#ffffff",
width = 3.6,
height = width / 4
} = {}) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
const radius = 24;
context.beginPath();
context.moveTo(radius, 4);
context.lineTo(508 - radius, 4);
context.quadraticCurveTo(508, 4, 508, 4 + radius);
context.lineTo(508, 124 - radius);
context.quadraticCurveTo(508, 124, 508 - radius, 124);
context.lineTo(radius, 124);
context.quadraticCurveTo(4, 124, 4, 124 - radius);
context.lineTo(4, 4 + radius);
context.quadraticCurveTo(4, 4, radius, 4);
context.closePath();
context.fillStyle = background;
context.fill();
context.fillStyle = foreground;
context.font = "800 43px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 67);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
sprite.scale.set(width, height, 1);
sprite.renderOrder = 12;
return sprite;
}
// -------------------------------------------------------------------------
// Tabletop and matched courses
// -------------------------------------------------------------------------
const ground = mesh(
new THREE.PlaneGeometry(100, 100),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.25;
ground.castShadow = false;
box(scene, 13.8, 0.18, 26.4, materials.trim, 0, -0.72, 0);
box(scene, 13.4, 0.62, 26.0, materials.base, 0, -0.30, 0);
// Four small solid feet reinforce the tabletop-object styling.
for (const x of [-5.5, 5.5]) {
for (const z of [-10.8, 10.8]) {
box(scene, 1.1, 0.5, 1.1, materials.trim, x, -0.93, z);
}
}
function createLane(laneX, laneMaterial, targetMaterial, labelText) {
box(scene, LANE_WIDTH, 0.12, 23.2, laneMaterial, laneX, 0.09, 0);
// Raised lane-edge strips.
for (const edge of [-1, 1]) {
box(
scene,
0.10,
0.17,
23.2,
materials.cream,
laneX + edge * (LANE_WIDTH / 2),
0.18,
0
);
}
// Start platform and finish line.
box(scene, 4.35, 0.05, 0.55, materials.cream, laneX, 0.185, 10.55);
box(scene, 4.35, 0.05, 0.10, materials.cream, laneX, 0.185, TARGET_Z);
// Solid concentric target.
const target = new THREE.Group();
target.position.set(laneX, 0, TARGET_Z);
scene.add(target);
const outer = mesh(
new THREE.CylinderGeometry(1.30, 1.30, 0.07, 48),
targetMaterial,
target
);
outer.position.y = 0.215;
const middle = mesh(
new THREE.CylinderGeometry(0.92, 0.92, 0.08, 48),
materials.cream,
target
);
middle.position.y = 0.265;
const inner = mesh(
new THREE.CylinderGeometry(0.56, 0.56, 0.09, 48),
targetMaterial,
target
);
inner.position.y = 0.315;
const bullseye = mesh(
new THREE.CylinderGeometry(0.22, 0.22, 0.10, 32),
materials.cream,
target
);
bullseye.position.y = 0.37;
const label = createLabel(labelText, {
background: "#263943",
foreground: "#ffffff",
width: 4.25
});
label.position.set(laneX, 0.75, 11.85);
scene.add(label);
// Flat direction arrows.
const arrowMaterial = material(0x9fb1b5, 0.95);
for (const z of [8.6, 3.8, -3.7, -7.7]) {
const arrow = mesh(
new THREE.ConeGeometry(0.24, 0.52, 3),
arrowMaterial
);
arrow.rotation.x = -Math.PI / 2;
arrow.scale.y = 0.22;
arrow.position.set(laneX, 0.205, z);
arrow.castShadow = false;
}
}
createLane(LANE_CENTERS[0], materials.laneA, materials.targetA, "COURSE A");
createLane(LANE_CENTERS[1], materials.laneB, materials.targetB, "COURSE B");
function createObstacle(obstacle, laneX, index) {
const group = new THREE.Group();
group.position.set(
laneX + obstacle.offsetX,
0,
START_Z - obstacle.distance
);
scene.add(group);
// Visible landing footprint includes the token radius.
const footprintRadius = obstacle.radius + TOKEN_RADIUS;
const footprint = mesh(
new THREE.RingGeometry(
footprintRadius - 0.055,
footprintRadius,
48
),
materials.footprint,
group
);
footprint.rotation.x = -Math.PI / 2;
footprint.position.y = 0.177;
footprint.castShadow = false;
footprint.receiveShadow = false;
if (obstacle.type === "block") {
box(group, 1.18, 0.92, 0.88, materials.obstacle, 0, 0.63, 0);
box(group, 0.82, 0.12, 0.94, materials.obstacleDark, 0, 1.13, 0);
} else if (obstacle.type === "post") {
const post = mesh(
new THREE.CylinderGeometry(0.48, 0.55, 1.15, 16),
materials.obstacle,
group
);
post.position.y = 0.75;
const cap = mesh(
new THREE.CylinderGeometry(0.53, 0.53, 0.13, 16),
materials.obstacleDark,
group
);
cap.position.y = 1.36;
} else if (obstacle.type === "bar") {
box(group, 1.55, 0.68, 0.58, materials.obstacle, 0, 0.51, 0);
box(group, 0.16, 0.74, 0.66, materials.obstacleDark, 0, 0.52, 0);
} else {
const bumper = mesh(
new THREE.CylinderGeometry(0.57, 0.66, 0.78, 6),
materials.obstacle,
group
);
bumper.position.y = 0.56;
bumper.rotation.y = Math.PI / 6;
const cap = mesh(
new THREE.CylinderGeometry(0.38, 0.45, 0.13, 6),
materials.obstacleDark,
group
);
cap.position.y = 1.01;
cap.rotation.y = Math.PI / 6;
}
const number = createLabel(String(index + 1), {
background: "#8d6931",
foreground: "#fff7e8",
width: 0.72,
height: 0.28
});
number.position.set(0, 1.65, 0);
group.add(number);
}
OBSTACLES.forEach((obstacle, index) => {
createObstacle(obstacle, LANE_CENTERS[0], index);
createObstacle(obstacle, LANE_CENTERS[1], index);
});
// -------------------------------------------------------------------------
// Controlled-dimension overlays
// -------------------------------------------------------------------------
const measurementGroup = new THREE.Group();
scene.add(measurementGroup);
const measurementMaterial = new THREE.LineBasicMaterial({
color: 0xf2a13d,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
});
function measurementLine(points) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry, measurementMaterial);
line.renderOrder = 20;
measurementGroup.add(line);
return line;
}
function measurementTick(x, y, z, alongX, length = 0.38) {
const dx = alongX ? length : 0;
const dz = alongX ? 0 : length;
measurementLine([
new THREE.Vector3(x - dx, y, z - dz),
new THREE.Vector3(x + dx, y, z + dz)
]);
}
// Overall 20-unit course length.
const lengthX = -6.28;
measurementLine([
new THREE.Vector3(lengthX, 0.43, START_Z),
new THREE.Vector3(lengthX, 0.43, TARGET_Z)
]);
measurementTick(lengthX, 0.43, START_Z, true);
measurementTick(lengthX, 0.43, TARGET_Z, true);
const lengthLabel = createLabel("20.0 u course", {
background: "#ef9c3b",
foreground: "#273640",
width: 3.8
});
lengthLabel.position.set(lengthX, 1.02, 0);
measurementGroup.add(lengthLabel);
// Lane width.
const widthZ = 11.30;
measurementLine([
new THREE.Vector3(LANE_CENTERS[0] - LANE_WIDTH / 2, 0.43, widthZ),
new THREE.Vector3(LANE_CENTERS[0] + LANE_WIDTH / 2, 0.43, widthZ)
]);
measurementTick(LANE_CENTERS[0] - LANE_WIDTH / 2, 0.43, widthZ, false);
measurementTick(LANE_CENTERS[0] + LANE_WIDTH / 2, 0.43, widthZ, false);
const widthLabel = createLabel("4.8 u lane", {
background: "#ef9c3b",
foreground: "#273640",
width: 2.9
});
widthLabel.position.set(LANE_CENTERS[0], 1.00, widthZ + 0.18);
measurementGroup.add(widthLabel);
// Obstacle distance ruler.
const rulerX = 6.28;
measurementLine([
new THREE.Vector3(rulerX, 0.43, START_Z),
new THREE.Vector3(rulerX, 0.43, TARGET_Z)
]);
measurementTick(rulerX, 0.43, START_Z, true);
measurementTick(rulerX, 0.43, TARGET_Z, true);
OBSTACLES.forEach((obstacle, index) => {
const z = START_Z - obstacle.distance;
measurementTick(rulerX, 0.43, z, true, 0.30);
const label = createLabel(`${obstacle.distance.toFixed(1)} u`, {
background: "#ef9c3b",
foreground: "#273640",
width: 1.65,
height: 0.42
});
label.position.set(rulerX + 0.78, 0.83, z);
measurementGroup.add(label);
});
const rulerLabel = createLabel("OBSTACLE STOPS", {
background: "#ef9c3b",
foreground: "#273640",
width: 3.25
});
rulerLabel.position.set(rulerX, 1.10, 0);
measurementGroup.add(rulerLabel);
// -------------------------------------------------------------------------
// Cosmetic player tokens
// -------------------------------------------------------------------------
function createPlayerToken(kind, color, labelText) {
const group = new THREE.Group();
scene.add(group);
const tokenMaterial = material(color, 0.58, 0.08);
const baseMaterial = material(0x263943, 0.8);
const base = mesh(
new THREE.CylinderGeometry(0.50, 0.55, 0.12, 24),
baseMaterial,
group
);
base.position.y = 0.06;
if (kind === "block") {
const body = box(group, 0.78, 0.73, 0.78, tokenMaterial, 0, 0.48, 0);
body.rotation.y = Math.PI / 4;
const cap = mesh(
new THREE.ConeGeometry(0.40, 0.36, 4),
tokenMaterial,
group
);
cap.position.y = 1.01;
cap.rotation.y = Math.PI / 4;
} else {
const body = mesh(
new THREE.IcosahedronGeometry(0.49, 1),
tokenMaterial,
group
);
body.position.y = 0.56;
const top = mesh(
new THREE.CylinderGeometry(0.17, 0.23, 0.24, 12),
baseMaterial,
group
);
top.position.y = 1.04;
}
const label = createLabel(labelText, {
background: color,
foreground: "#ffffff",
width: 2.15,
height: 0.54
});
label.position.set(0, 1.60, 0);
group.add(label);
group.visible = false;
group.scale.setScalar(0.001);
group.position.y = 0.17;
return group;
}
const playerA = createPlayerToken("block", 0xe85d52, "PLAYER A");
const playerB = createPlayerToken("orb", 0x3689b8, "PLAYER B");
playerA.position.x = LANE_CENTERS[0];
playerB.position.x = LANE_CENTERS[1];
playerA.position.z = START_Z;
playerB.position.z = START_Z;
// -------------------------------------------------------------------------
// Game state and rules
// -------------------------------------------------------------------------
let phase = "setup";
let busy = false;
let completed = false;
let round = 0;
let progress = [0, 0];
let moveAnimation = null;
let placementAnimation = null;
let measurementsVisible = true;
function setStatus(message) {
$("status").textContent = message;
}
function addLog(title, message) {
const entry = document.createElement("div");
entry.className = "log-entry";
const heading = document.createElement("b");
heading.textContent = title;
const body = document.createElement("span");
body.textContent = message;
entry.append(heading, body);
$("log").prepend(entry);
while ($("log").children.length > 5) {
$("log").lastElementChild.remove();
}
}
function updateSteps() {
$("step1").className = phase === "setup" ? "step active" : "step done";
$("step2").className =
phase === "setup" ? "step" : "step done";
$("step3").className =
phase === "setup" ? "step" : "step active";
}
function setMeasurementsVisible(visible) {
measurementsVisible = visible;
measurementGroup.visible = visible;
$("measureButton").textContent =
visible ? "Hide measurements" : "Show measurements";
}
$("measureButton").addEventListener("click", () => {
setMeasurementsVisible(!measurementsVisible);
});
function placeTokens() {
phase = "race";
progress = [0, 0];
round = 0;
completed = false;
busy = false;
playerA.visible = true;
playerB.visible = true;
playerA.scale.setScalar(0.001);
playerB.scale.setScalar(0.001);
playerA.position.set(LANE_CENTERS[0], 0.17, START_Z);
playerB.position.set(LANE_CENTERS[1], 0.17, START_Z);
placementAnimation = performance.now();
setMeasurementsVisible(false);
updateSteps();
$("setupNotice").textContent =
"The controlled layout is locked. Both tokens now begin at identical starts.";
$("setupButton").disabled = true;
$("setupButton").textContent = "Layout locked";
$("rollButton").disabled = false;
$("rollButton").textContent = "Roll shared d6";
$("roundLabel").textContent = "Round 0";
$("dieLabel").textContent = "One die for both players";
$("die").textContent = "—";
setStatus(
"Both racers are at identical starts. Roll one shared die; both tokens receive exactly the same movement."
);
addLog(
"Controlled layout locked",
"Both courses use 20.0 u length, 4.8 u width, and the same four obstacle footprints."
);
}
$("setupButton").addEventListener("click", placeTokens);
function resetExperiment() {
phase = "setup";
busy = false;
completed = false;
round = 0;
progress = [0, 0];
moveAnimation = null;
placementAnimation = null;
playerA.visible = false;
playerB.visible = false;
setMeasurementsVisible(true);
updateSteps();
$("setupNotice").textContent =
"The amber measurement lines are visible on the tabletop. No player tokens have been placed yet.";
$("setupButton").disabled = false;
$("setupButton").textContent = "Lock layout & place tokens";
$("rollButton").disabled = true;
$("rollButton").textContent = "Roll shared d6";
$("roundLabel").textContent = "Shared die";
$("dieLabel").textContent = "Waiting for setup";
$("die").textContent = "—";
setStatus(
"Inspect the amber dimensions, then lock the layout to place both tokens."
);
addLog(
"Experiment reset",
"The dimension-controlled setup has been restored and both tokens were removed."
);
}
$("resetButton").addEventListener("click", resetExperiment);
// Resolve the landing result from the controlled course.
// The same function and constants are used for both players.
function resolveLanding(currentProgress, rollValue) {
const landing = Math.min(
COURSE_LENGTH,
currentProgress + rollValue
);
if (landing >= COURSE_LENGTH) {
return {
to: COURSE_LENGTH,
hit: null,
goal: true
};
}
for (const obstacle of OBSTACLES) {
const footprintRadius = obstacle.radius + TOKEN_RADIUS;
// The token travels down the center of its lane.
const dx = -obstacle.offsetX;
const dz = landing - obstacle.distance;
const centerDistance = Math.hypot(dx, dz);
if (
Math.abs(obstacle.offsetX) <= footprintRadius &&
centerDistance <= footprintRadius
) {
// Find the near edge of the circular landing footprint along
// the lane centerline.
const halfChord = Math.sqrt(
footprintRadius * footprintRadius -
obstacle.offsetX * obstacle.offsetX
);
const stopBefore = Math.max(
currentProgress,
obstacle.distance - halfChord - 0.04
);
return {
to: Math.max(0, stopBefore - 1),
hit: obstacle,
goal: false
};
}
}
return {
to: landing,
hit: null,
goal: false
};
}
function finishRound() {
const resultA = resolveLanding(progress[0], lastRoll);
const resultB = resolveLanding(progress[1], lastRoll);
progress[0] = resultA.to;
progress[1] = resultB.to;
moveAnimation = {
start: performance.now(),
duration: 920,
fromA: playerA.position.z,
fromB: playerB.position.z,
toA: resultA.to,
toB: resultB.to,
hitA: resultA.hit,
hitB: resultB.hit
};
busy = true;
$("rollButton").disabled = true;
}
let lastRoll = 1;
function handleRoll() {
if (phase !== "race" || busy) return;
if (completed) {
resetRace();
return;
}
lastRoll = 1 + Math.floor(Math.random() * 6);
round += 1;
$("die").textContent = String(lastRoll);
$("die").classList.add("rolling");
$("roundLabel").textContent = `Round ${round}`;
$("dieLabel").textContent = "Shared result for A and B";
setTimeout(() => {
$("die").classList.remove("rolling");
}, 170);
finishRound();
}
$("rollButton").addEventListener("click", handleRoll);
function resetRace() {
progress = [0, 0];
round = 0;
completed = false;
busy = false;
moveAnimation = null;
playerA.position.set(LANE_CENTERS[0], 0.17, START_Z);
playerB.position.set(LANE_CENTERS[1], 0.17, START_Z);
playerA.rotation.set(0, 0, 0);
playerB.rotation.set(0, 0, 0);
$("rollButton").disabled = false;
$("rollButton").textContent = "Roll shared d6";
$("roundLabel").textContent = "Round 0";
$("dieLabel").textContent = "One die for both players";
$("die").textContent = "—";
setStatus(
"Rematch ready. The same controlled courses and shared-die rule will be used again."
);
addLog(
"Rematch reset",
"Both tokens returned to their matched starts."
);
}
function completeMoveAnimation(now) {
const animation = moveAnimation;
const t = Math.min(1, (now - animation.start) / animation.duration);
const eased = 1 - Math.pow(1 - t, 3);
const hop = Math.sin(Math.PI * t);
playerA.position.z = THREE.MathUtils.lerp(
animation.fromA,
START_Z - animation.toA,
eased
);
playerB.position.z = THREE.MathUtils.lerp(
animation.fromB,
START_Z - animation.toB,
eased
);
playerA.position.y = 0.17 + hop * 0.78;
playerB.position.y = 0.17 + hop * 0.78;
if (t < 1) return;
playerA.position.y = 0.17;
playerB.position.y = 0.17;
const resultA = resolveLanding(progress[0], lastRoll);
const resultB = resolveLanding(progress[1], lastRoll);
progress[0] = resultA.to;
progress[1] = resultB.to;
moveAnimation = null;
busy = false;
const bothHit = resultA.hit && resultB.hit;
const oneHit = resultA.hit || resultB.hit;
if (bothHit) {
addLog(
`Round ${round} · shared roll ${lastRoll}`,
`Both tokens landed inside matched obstacle footprints, stopped before impact, and lost 1 unit.`
);
setStatus(
`Shared roll ${lastRoll}: both tokens hit the same matched obstacle footprint and received the same 1-unit penalty.`
);
} else if (oneHit) {
addLog(
`Round ${round} · shared roll ${lastRoll}`,
"A shared roll produced one footprint collision. The differing result is shown in the log."
);
setStatus(
`Shared roll ${lastRoll}: one token landed in an obstacle footprint and received the 1-unit penalty.`
);
} else {
addLog(
`Round ${round} · shared roll ${lastRoll}`,
`Both tokens advanced exactly ${lastRoll} unit${lastRoll === 1 ? "" : "s"} with no footprint collision.`
);
setStatus(
`Shared roll ${lastRoll}: both tokens advanced exactly ${lastRoll} unit${lastRoll === 1 ? "" : "s"}.`
);
}
const goalA = progress[0] >= COURSE_LENGTH;
const goalB = progress[1] >= COURSE_LENGTH;
if (goalA || goalB) {
completed = true;
if (goalA && goalB) {
addLog(
"Result · tie",
"Both players reached the 20-unit target on the same shared roll."
);
setStatus(
"Dead heat: both players reached the target on the same shared roll, as expected from fully matched inputs."
);
} else if (goalA) {
addLog(
"Result · Player A",
"Player A reached the target first."
);
setStatus("Player A reaches the target first.");
} else {
addLog(
"Result · Player B",
"Player B reached the target first."
);
setStatus("Player B reaches the target first.");
}
$("rollButton").disabled = false;
$("rollButton").textContent = "Rematch";
} else {
$("rollButton").disabled = false;
$("rollButton").textContent = "Roll shared d6";
}
}
// -------------------------------------------------------------------------
// Initial UI and animation loop
// -------------------------------------------------------------------------
updateSteps();
addLog(
"Controlled setup",
"Both courses are visible with their dimensions. Player tokens are intentionally not placed yet."
);
function animate(now) {
requestAnimationFrame(animate);
if (placementAnimation !== null) {
const t = Math.min(1, (now - placementAnimation) / 650);
const c1 = 1.70158;
const c3 = c1 + 1;
const ease = 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
playerA.scale.setScalar(Math.max(0.001, ease));
playerB.scale.setScalar(Math.max(0.001, ease));
if (t >= 1) {
playerA.scale.setScalar(1);
playerB.scale.setScalar(1);
placementAnimation = null;
}
}
if (moveAnimation !== null) {
completeMoveAnimation(now);
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```