Prompt specification
Build or customize the Three.js 3D scene "Context Changes Expression Interpretation" 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: Context Changes Expression Interpretation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/context-changes-expression-interpretation-x3720
Scene Description Prompt:
Reuse one voxel facial pose in two fictional situations; surrounding actions reveal why expression alone leaves ambiguity. One HTML scene using Three.js from cdnjs.
Working Three.js Starter (context-changes-expression-interpretation-x3720):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>One Face, Two Stories</title>
<style>
:root {
--ink: #f3ead7;
--muted: #b6beb8;
--gold: #e6ad67;
--panel: rgba(14, 24, 25, 0.82);
--line: rgba(235, 225, 203, 0.2);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101a1c;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.masthead {
position: absolute;
top: 28px;
left: 32px;
max-width: 430px;
text-shadow: 0 2px 18px #071011;
}
.eyebrow {
margin-bottom: 8px;
color: var(--gold);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 3.6vw, 54px);
font-weight: 760;
letter-spacing: -0.045em;
line-height: 0.96;
}
.masthead p {
max-width: 370px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.identity {
position: absolute;
top: 28px;
left: 50%;
display: flex;
align-items: center;
gap: 13px;
padding: 10px 14px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel);
backdrop-filter: blur(12px);
transform: translateX(-50%);
white-space: nowrap;
}
.identity span {
color: #d7ddd6;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.pixel {
width: 7px;
height: 7px;
background: var(--gold);
box-shadow:
14px 0 var(--gold),
0 7px var(--gold),
14px 14px #111b1d,
-14px 14px #111b1d,
-7px 28px #111b1d,
0 28px #111b1d,
7px 28px #111b1d,
14px 28px #111b1d;
transform: scale(1.15);
}
.scene-label {
position: absolute;
width: 250px;
padding: 13px 15px 14px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel);
box-shadow: 0 14px 36px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(12px);
transform: translate(-50%, -100%);
transition: opacity 160ms ease;
}
.scene-label::after {
content: "";
position: absolute;
bottom: -18px;
left: 50%;
width: 1px;
height: 18px;
background: linear-gradient(var(--gold), transparent);
}
.label-number {
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
}
.scene-label h2 {
margin: 5px 0 7px;
font-size: 19px;
letter-spacing: -0.02em;
}
.scene-label p {
margin: 0;
color: #bdc7c1;
font-size: 12px;
line-height: 1.45;
}
.reading {
display: block;
margin-top: 8px;
color: #efe2c9;
font-size: 11px;
font-weight: 650;
}
.caption {
position: absolute;
left: 50%;
bottom: 26px;
width: min(680px, calc(100vw - 40px));
padding: 13px 18px;
border: 1px solid var(--line);
border-radius: 10px;
background: var(--panel);
backdrop-filter: blur(12px);
transform: translateX(-50%);
text-align: center;
}
.caption strong {
color: var(--gold);
font-size: 11px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.caption p {
margin: 5px 0 0;
color: #cbd1ca;
font-size: 12px;
line-height: 1.45;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.buttons {
display: flex;
padding: 4px;
border: 1px solid var(--line);
border-radius: 9px;
background: var(--panel);
backdrop-filter: blur(12px);
}
button {
border: 0;
border-radius: 6px;
padding: 8px 11px;
background: transparent;
color: #c8cec7;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
}
button:hover { color: white; }
button.active {
background: #e5ab66;
color: #172123;
}
.hint {
color: rgba(230, 235, 225, 0.58);
font-size: 10px;
letter-spacing: 0.04em;
text-shadow: 0 1px 8px #000;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #101a1c;
transition: opacity 350ms ease, visibility 350ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
color: #d9ddd5;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.loader::before {
content: "";
width: 14px;
height: 14px;
background: var(--gold);
box-shadow: 14px 0 #b67346;
animation: load 700ms steps(2) infinite alternate;
}
@keyframes load {
to { transform: translateY(-8px); }
}
@media (max-width: 900px) {
.identity { display: none; }
.controls { bottom: 105px; }
.scene-label { width: 210px; }
}
@media (max-width: 620px) {
.masthead {
top: 18px;
left: 18px;
right: 18px;
}
.masthead p { display: none; }
.scene-label { width: 180px; padding: 10px 11px; }
.scene-label h2 { font-size: 16px; }
.scene-label p { font-size: 10px; }
.reading { font-size: 9px; }
.caption { bottom: 14px; }
.caption p { font-size: 10px; }
.controls { right: 12px; bottom: 98px; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="loading">
<div class="loader">Building the dioramas</div>
</div>
<div id="hud">
<header class="masthead">
<div class="eyebrow">A study in contextual expression</div>
<h1>One face.<br>Two stories.</h1>
<p>
The same voxel expression appears in two invented situations.
Only the surrounding actions reveal how it should be read.
</p>
</header>
<div class="identity">
<span>Identical facial pose</span>
<i class="pixel" aria-hidden="true"></i>
</div>
<section id="leftLabel" class="scene-label">
<div class="label-number">01 / THE TOLL</div>
<h2>A coin offered under threat</h2>
<p>A blade waits behind the traveler while payment passes forward.</p>
<span class="reading">Context reads the face as nervous compliance.</span>
</section>
<section id="rightLabel" class="scene-label">
<div class="label-number">02 / THE WAGER</div>
<h2>A token pushed into danger</h2>
<p>A revealed hand makes the same expression look like calculated nerve.</p>
<span class="reading">Context reads the face as deliberate bravado.</span>
</section>
<section class="caption">
<strong>The expression is fixed. The stakes are not.</strong>
<p>Context supplies the missing verb: fear, resolve, compliance, or bluff.</p>
</section>
<nav class="controls" aria-label="Camera controls">
<div class="buttons">
<button class="active" data-view="overview">Both</button>
<button data-view="left">The Toll</button>
<button data-view="right">The Wager</button>
</div>
<div class="hint">Drag to orbit · scroll to zoom · click a vignette</div>
</nav>
</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 renderer = new THREE.WebGLRenderer({
antialias: true,
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;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101a1c);
scene.fog = new THREE.Fog(0x101a1c, 19, 38);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const world = new THREE.Group();
scene.add(world);
const hemisphere = new THREE.HemisphereLight(0xc6e0df, 0x30231c, 1.9);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe2b6, 3.4);
keyLight.position.set(-7, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const coolFill = new THREE.DirectionalLight(0x8ed9e1, 1.25);
coolFill.position.set(9, 7, 5);
scene.add(coolFill);
const leftLight = new THREE.PointLight(0xff8a55, 20, 8, 2);
leftLight.position.set(-4.8, 4.2, 1.2);
scene.add(leftLight);
const rightLight = new THREE.PointLight(0x61dce8, 18, 8, 2);
rightLight.position.set(4.8, 4.1, 1.1);
scene.add(rightLight);
// ---------------------------------------------------------------------
// Shared voxel construction helpers
// ---------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function makeMaterial(color, options = {}) {
const key = color + JSON.stringify(options);
if (!materialCache.has(key)) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0
});
if (options.emissive !== undefined) {
material.emissive.set(options.emissive);
material.emissiveIntensity = options.emissiveIntensity ?? 1;
}
if (options.transparent) {
material.transparent = true;
material.opacity = options.opacity ?? 1;
}
materialCache.set(key, material);
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
cubeGeometry,
makeMaterial(color, options.materialOptions ?? {})
);
mesh.scale.set(...size);
mesh.position.set(...position);
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function group(parent, position = [0, 0, 0]) {
const result = new THREE.Group();
result.position.set(...position);
parent.add(result);
return result;
}
// ---------------------------------------------------------------------
// Stage
// ---------------------------------------------------------------------
box(world, [40, 0.25, 28], [0, -0.28, 0], 0x111c1d);
function makePlatform(cx, sideColor, floorColor) {
box(world, [7.15, 0.46, 5.9], [cx, -0.02, 0], sideColor);
box(world, [6.85, 0.14, 5.62], [cx, 0.27, 0], floorColor);
for (let z = -2.25; z <= 2.25; z += 0.75) {
box(
world,
[6.6, 0.025, 0.025],
[cx, 0.35, z],
0x000000,
{ castShadow: false }
);
}
}
makePlatform(-4.6, 0x513332, 0x806852);
makePlatform(4.6, 0x214c50, 0x486c69);
function makeArch(cx, postColor, accentColor) {
box(world, [0.42, 3.6, 0.48], [cx - 2.65, 2.05, -2.45], postColor);
box(world, [0.42, 3.6, 0.48], [cx + 2.65, 2.05, -2.45], postColor);
box(world, [5.75, 0.42, 0.56], [cx, 3.72, -2.45], postColor);
box(world, [0.68, 0.18, 0.66], [cx - 2.65, 3.98, -2.45], accentColor);
box(world, [0.68, 0.18, 0.66], [cx + 2.65, 3.98, -2.45], accentColor);
for (let i = -2; i <= 2; i++) {
box(
world,
[0.36, 0.18, 0.62],
[cx + i * 0.78, 4.02, -2.45],
accentColor
);
}
}
makeArch(-4.6, 0x49332f, 0x8c513b);
makeArch(4.6, 0x23464a, 0x36777a);
// Left vignette: a key-shaped toll sign.
box(world, [1.42, 0.58, 0.16], [-4.6, 3.72, -2.12], 0x2b2422);
box(world, [0.42, 0.42, 0.08], [-4.8, 3.72, -2.01], 0xdba663);
box(world, [0.18, 0.62, 0.08], [-4.48, 3.72, -2.01], 0xdba663);
box(world, [0.18, 0.16, 0.08], [-4.48, 3.56, -2.01], 0xdba663);
// Right vignette: a card-shaped wager sign.
box(world, [1.42, 0.58, 0.16], [4.6, 3.72, -2.12], 0x1c3134);
box(world, [0.48, 0.68, 0.07], [4.42, 3.72, -2.02], 0xe9dcc0);
box(world, [0.48, 0.68, 0.07], [4.78, 3.72, -2.02], 0xe9dcc0);
box(world, [0.09, 0.09, 0.08], [4.42, 3.72, -1.96], 0xc95d50);
box(world, [0.09, 0.09, 0.08], [4.78, 3.72, -1.96], 0xc95d50);
// ---------------------------------------------------------------------
// The repeated traveler and facial pose
// ---------------------------------------------------------------------
function makeArm(parent, side, sleeveColor, skinColor) {
const arm = group(parent, [side * 0.57, 1.94, 0]);
box(arm, [0.31, 0.68, 0.35], [0, -0.34, 0], sleeveColor);
box(arm, [0.27, 0.28, 0.29], [0, -0.78, 0], skinColor);
box(arm, [0.33, 0.12, 0.37], [0, -0.56, 0], 0x34484a);
return arm;
}
function makeTravelerFace(head) {
const skin = 0xd7a176;
const skinLight = 0xe1ae82;
// A five-by-five voxel face plate.
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 5; col++) {
const shade =
row === 0 || col === 0 || col === 4 ? skinLight : skin;
box(
head,
[0.215, 0.215, 0.085],
[(col - 2) * 0.225, (2 - row) * 0.225, 0.445],
shade
);
}
}
// The exact same narrowed eyes, asymmetric brow and crooked mouth
// are used for both situations.
box(head, [0.22, 0.075, 0.07], [-0.245, 0.29, 0.515], 0x3a2823);
box(
head,
[0.22, 0.075, 0.07],
[0.245, 0.225, 0.515],
0x3a2823,
{ rotation: [0, 0, -0.12] }
);
box(head, [0.15, 0.13, 0.07], [-0.245, 0.08, 0.515], 0x172124);
box(head, [0.15, 0.13, 0.07], [0.245, 0.08, 0.515], 0x172124);
box(head, [0.045, 0.045, 0.035], [-0.22, 0.105, 0.56], 0xf5ead7);
box(head, [0.045, 0.045, 0.035], [0.27, 0.105, 0.56], 0xf5ead7);
box(head, [0.1, 0.12, 0.07], [0, -0.04, 0.515], 0xc68b63);
box(head, [0.13, 0.08, 0.07], [-0.12, -0.25, 0.515], 0x56302b);
box(head, [0.13, 0.08, 0.07], [0, -0.28, 0.515], 0x56302b);
box(head, [0.13, 0.08, 0.07], [0.12, -0.23, 0.515], 0x56302b);
}
function makeTraveler() {
const traveler = group(world);
const coat = 0xc1843f;
const trousers = 0x30464b;
const skin = 0xd7a176;
box(traveler, [0.36, 0.82, 0.4], [-0.25, 0.72, 0], trousers);
box(traveler, [0.36, 0.82, 0.4], [0.25, 0.72, 0], trousers);
box(traveler, [0.44, 0.24, 0.58], [-0.25, 0.21, 0.08], 0x202a2c);
box(traveler, [0.44, 0.24, 0.58], [0.25, 0.21, 0.08], 0x202a2c);
box(traveler, [0.98, 1.08, 0.6], [0, 1.59, 0], coat);
box(traveler, [1.05, 0.13, 0.64], [0, 1.08, 0], 0x364546);
box(traveler, [0.17, 0.17, 0.08], [0, 1.08, 0.35], 0xd5a655);
box(traveler, [0.88, 0.18, 0.65], [0, 2.06, 0], 0xd8b36b);
box(traveler, [0.23, 0.63, 0.12], [-0.22, 1.76, 0.36], 0xb8693d);
box(traveler, [0.23, 0.63, 0.12], [0.22, 1.76, 0.36], 0xb8693d);
const head = group(traveler, [0, 2.77, 0]);
box(head, [1.18, 1.18, 0.78], [0, 0, 0], skin);
makeTravelerFace(head);
// The same hair silhouette in both worlds.
box(head, [1.29, 0.24, 0.92], [0, 0.67, -0.01], 0x312825);
box(head, [1.28, 1.05, 0.2], [0, 0.08, -0.43], 0x312825);
box(head, [0.22, 0.78, 0.3], [-0.57, 0.15, -0.24], 0x312825);
box(head, [0.22, 0.78, 0.3], [0.57, 0.15, -0.24], 0x312825);
box(head, [0.44, 0.18, 0.44], [0.29, 0.58, 0.27], 0x312825);
const leftArm = makeArm(traveler, -1, coat, skin);
const rightArm = makeArm(traveler, 1, coat, skin);
const token = box(
rightArm,
[0.27, 0.085, 0.27],
[0, -0.92, 0.045],
0xe7b761,
{ materialOptions: { metalness: 0.55, roughness: 0.34 } }
);
token.name = "traveler-token";
return { group: traveler, leftArm, rightArm, token };
}
const travelerLeft = makeTraveler();
travelerLeft.group.position.set(-4.7, 0.36, -0.35);
travelerLeft.rightArm.rotation.z = 1.24;
const travelerRight = makeTraveler();
travelerRight.group.position.set(4.0, 0.36, -1.05);
travelerRight.rightArm.rotation.x = -0.62;
// ---------------------------------------------------------------------
// Supporting characters
// ---------------------------------------------------------------------
function makeTollkeeper() {
const keeper = group(world);
const coat = 0x496a68;
box(keeper, [0.38, 0.8, 0.42], [-0.24, 0.68, 0], 0x26383a);
box(keeper, [0.38, 0.8, 0.42], [0.24, 0.68, 0], 0x26383a);
box(keeper, [0.96, 1.05, 0.58], [0, 1.58, 0], coat);
box(keeper, [0.34, 0.32, 0.36], [0, 2.2, 0], 0xc99169);
const head = group(keeper, [0, 2.73, 0]);
box(head, [1.05, 1.08, 0.72], [0, 0, 0], 0xc99169);
box(head, [1.08, 0.22, 0.78], [0, 0.56, -0.02], 0x283438);
box(head, [0.17, 0.13, 0.07], [-0.24, 0.08, 0.4], 0x172124);
box(head, [0.17, 0.13, 0.07], [0.24, 0.08, 0.4], 0x172124);
box(head, [0.48, 0.09, 0.07], [0, -0.26, 0.4], 0x50312c);
const arm = makeArm(keeper, -1, coat, 0xc99169);
arm.rotation.x = -1.12;
keeper.position.set(-2.86, 0.36, -0.48);
keeper.rotation.y = -1.48;
return { group: keeper, arm };
}
const tollkeeper = makeTollkeeper();
function makeGuard() {
const guard = group(world);
const cloak = 0x252b30;
box(guard, [1.06, 1.25, 0.64], [0, 1.1, 0], cloak);
box(guard, [0.86, 0.72, 0.56], [0, 1.97, 0], cloak);
box(guard, [0.68, 0.7, 0.65], [0, 2.6, 0.02], cloak);
box(guard, [0.52, 0.44, 0.1], [0, 2.57, 0.39], 0x111719);
box(
guard,
[0.11, 0.08, 0.04],
[-0.13, 2.62, 0.46],
0xff7558,
{ materialOptions: { emissive: 0xff3d25, emissiveIntensity: 2 } }
);
box(
guard,
[0.11, 0.08, 0.04],
[0.13, 2.62, 0.46],
0xff7558,
{ materialOptions: { emissive: 0xff3d25, emissiveIntensity: 2 } }
);
const daggerArm = makeArm(guard, 1, cloak, 0x9b765d);
daggerArm.rotation.x = -1.27;
box(daggerArm, [0.13, 0.88, 0.1], [0, -1.15, 0], 0xd8ddd7, {
materialOptions: { metalness: 0.7, roughness: 0.25 }
});
box(daggerArm, [0.38, 0.1, 0.13], [0, -0.77, 0], 0x9a6a3d);
guard.position.set(-6.05, 0.36, -0.72);
guard.rotation.y = 1.14;
return { group: guard, daggerArm };
}
const guard = makeGuard();
function makeRobotDealer() {
const robot = group(world);
box(robot, [0.95, 1.15, 0.72], [0, 1.2, 0], 0x426a6c);
box(robot, [1.12, 0.22, 0.82], [0, 0.7, 0], 0x29494c);
box(robot, [0.82, 0.8, 0.72], [0, 2.18, 0], 0x4b7779);
box(
robot,
[0.66, 0.18, 0.08],
[0, 2.22, 0.4],
0x75eced,
{ materialOptions: { emissive: 0x37dfe4, emissiveIntensity: 2.4 } }
);
box(robot, [0.17, 0.18, 0.17], [-0.58, 1.7, 0], 0x29494c);
box(robot, [0.17, 0.18, 0.17], [0.58, 1.7, 0], 0x29494c);
const arm = makeArm(robot, -1, 0x426a6c, 0x29494c);
arm.rotation.x = -0.96;
robot.position.set(5.83, 0.36, -0.66);
robot.rotation.y = -0.12;
return { group: robot, arm };
}
const robot = makeRobotDealer();
// ---------------------------------------------------------------------
// Wager table, cards, chips, and target marker
// ---------------------------------------------------------------------
const table = group(world, [4.55, 0, 0.55]);
box(table, [0.34, 1.18, 0.34], [-1.32, 0.83, -0.76], 0x223a3c);
box(table, [0.34, 1.18, 0.34], [1.32, 0.83, -0.76], 0x223a3c);
box(table, [0.34, 1.18, 0.34], [-1.32, 0.83, 0.76], 0x223a3c);
box(table, [0.34, 1.18, 0.34], [1.32, 0.83, 0.76], 0x223a3c);
box(table, [3.35, 0.2, 2.35], [0, 1.32, 0], 0x284a4d);
box(table, [3.05, 0.06, 2.05], [0, 1.45, 0], 0x356466);
function makeCard(parent, x, z, angle, markColor) {
const card = group(parent, [x, 1.52, z]);
card.rotation.y = angle;
box(card, [0.46, 0.045, 0.68], [0, 0, 0], 0xf1e4c9);
box(card, [0.085, 0.055, 0.085], [0, 0.045, 0], markColor);
box(card, [0.085, 0.055, 0.085], [-0.11, 0.045, -0.2], markColor);
box(card, [0.085, 0.055, 0.085], [0.11, 0.045, 0.2], markColor);
return card;
}
const cards = [
makeCard(table, 0.18, 0.12, -0.22, 0xb84742),
makeCard(table, 0.48, 0.22, 0.08, 0xb84742),
makeCard(table, 0.78, 0.1, 0.31, 0xb84742)
];
function chipStack(x, z, color) {
for (let i = 0; i < 5; i++) {
box(table, [0.27, 0.09, 0.27], [x, 1.55 + i * 0.095, z], color);
}
}
chipStack(-0.95, -0.2, 0xd7a653);
chipStack(-0.62, 0.52, 0x8e4c48);
chipStack(1.08, 0.48, 0xc88748);
// Four voxels mark where the token is being pushed.
const targetMarker = group(world, [4.58, 1.51, -0.48]);
box(targetMarker, [0.13, 0.035, 0.13], [-0.25, 0, -0.25], 0xe4b56b);
box(targetMarker, [0.13, 0.035, 0.13], [0.25, 0, -0.25], 0xe4b56b);
box(targetMarker, [0.13, 0.035, 0.13], [-0.25, 0, 0.25], 0xe4b56b);
box(targetMarker, [0.13, 0.035, 0.13], [0.25, 0, 0.25], 0xe4b56b);
// Small tollbooth lantern.
box(world, [0.45, 0.62, 0.45], [-6.7, 3.25, -2.15], 0xffa45d, {
materialOptions: {
emissive: 0xff7733,
emissiveIntensity: 1.8
}
});
// ---------------------------------------------------------------------
// Invisible clickable vignette zones
// ---------------------------------------------------------------------
const zones = [];
const zoneMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
for (const [cx, name] of [[-4.6, "left"], [4.6, "right"]]) {
const zone = new THREE.Mesh(
new THREE.BoxGeometry(7.1, 4.4, 5.9),
zoneMaterial
);
zone.position.set(cx, 2.15, 0);
zone.userData.view = name;
world.add(zone);
zones.push(zone);
}
// ---------------------------------------------------------------------
// Custom camera controls — no addons
// ---------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.7, 0),
theta: 0.25,
phi: 1.03,
radius: 16.7
};
const cameraGoal = {
target: cameraState.target.clone(),
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius
};
let activeView = "overview";
function overviewRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.9) return 25;
if (aspect < 1.4) return 20;
return 16.7;
}
function setView(name) {
activeView = name;
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
if (name === "overview") {
cameraGoal.target.set(0, 1.7, 0);
cameraGoal.theta = 0.25;
cameraGoal.phi = 1.03;
cameraGoal.radius = overviewRadius();
} else if (name === "left") {
cameraGoal.target.set(-4.45, 1.8, -0.25);
cameraGoal.theta = 0.18;
cameraGoal.phi = 1.06;
cameraGoal.radius = window.innerWidth < 700 ? 13 : 10.4;
} else {
cameraGoal.target.set(4.45, 1.8, -0.05);
cameraGoal.theta = 0.12;
cameraGoal.phi = 1.04;
cameraGoal.radius = window.innerWidth < 700 ? 13 : 10.4;
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let dragDistance = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragDistance = 0;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
cameraGoal.theta -= dx * 0.006;
cameraGoal.phi = THREE.MathUtils.clamp(
cameraGoal.phi + dy * 0.005,
0.65,
1.32
);
if (dragDistance > 4) {
activeView = "free";
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.remove("active");
});
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (dragDistance < 7) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(zones, false)[0];
if (hit) setView(hit.object.userData.view);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
cameraGoal.radius = THREE.MathUtils.clamp(
cameraGoal.radius + event.deltaY * 0.012,
7.5,
27
);
}, { passive: false });
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function updateCamera() {
cameraState.target.lerp(cameraGoal.target, 0.085);
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraGoal.theta,
0.085
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraGoal.phi,
0.085
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraGoal.radius,
0.085
);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const leftLabel = document.getElementById("leftLabel");
const rightLabel = document.getElementById("rightLabel");
const labelAnchors = [
{
element: leftLabel,
point: new THREE.Vector3(-4.6, 4.58, -2.25)
},
{
element: rightLabel,
point: new THREE.Vector3(4.6, 4.58, -2.25)
}
];
function updateLabels() {
for (const label of labelAnchors) {
const projected = label.point.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity =
projected.z > -1 && projected.z < 1 ? "1" : "0";
}
}
// ---------------------------------------------------------------------
// Ambient action and animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
const leftGlint = new THREE.PointLight(0xffc36e, 2.4, 2.2, 2);
const rightGlint = new THREE.PointLight(0xffc36e, 1.8, 1.8, 2);
scene.add(leftGlint, rightGlint);
const tokenWorld = new THREE.Vector3();
function animate() {
const t = clock.getElapsedTime();
// The toll payment trembles under pressure.
travelerLeft.rightArm.rotation.z =
1.24 + Math.sin(t * 7.2) * 0.012;
travelerLeft.token.position.y =
-0.92 + Math.sin(t * 6.5) * 0.008;
travelerLeft.token.rotation.y = t * 0.8;
travelerLeft.token.scale.setScalar(1 + Math.sin(t * 4) * 0.035);
// The wager is a slower, more deliberate push.
travelerRight.rightArm.rotation.x =
-0.62 + Math.sin(t * 1.55) * 0.035;
travelerRight.token.position.y =
-0.92 + Math.sin(t * 1.55) * 0.006;
travelerRight.token.rotation.y = -t * 0.55;
// Threatening arm and cards have restrained secondary motion.
guard.daggerArm.rotation.x =
-1.27 + Math.sin(t * 1.2) * 0.025;
robot.arm.rotation.x =
-0.96 + Math.sin(t * 1.1 + 1) * 0.025;
cards.forEach((card, index) => {
card.rotation.z = Math.sin(t * 1.4 + index) * 0.015;
});
travelerLeft.token.getWorldPosition(tokenWorld);
leftGlint.position.copy(tokenWorld);
leftGlint.intensity = 1.7 + Math.sin(t * 4) * 0.55;
travelerRight.token.getWorldPosition(tokenWorld);
rightGlint.position.copy(tokenWorld);
rightGlint.intensity = 1.2 + Math.sin(t * 2.8) * 0.35;
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (activeView === "overview") {
cameraGoal.radius = overviewRadius();
}
});
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```