Prompt specification
Build or customize the Three.js 3D scene "Left of the Bench From Two Views" 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: Left of the Bench From Two Views
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/left-of-the-bench-from-two-views-x3414
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: left of the bench from two views. Place a ball and bench between two observers facing opposite directions. Compare observer-relative left with a fixed world direction using labeled reference frames. Return one self-contained HTML file.
Working Three.js Starter (left-of-the-bench-from-two-views-x3414):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Same Ball, Different Left — Voxel Reference Frames</title>
<style>
:root {
--ink: #10212b;
--muted: #5d6d75;
--panel: #ffffff;
--line: #d7e0e3;
--a: #12b9bd;
--a-soft: #d9f6f5;
--b: #ef527f;
--b-soft: #ffe1ea;
--world: #58b96b;
--world-soft: #e0f5e4;
--gold: #f3b61f;
--shadow: 0 10px 30px rgba(25, 47, 57, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
overflow: hidden;
color: var(--ink);
background: #e8eef0;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
header {
position: relative;
z-index: 10;
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 18px 24px;
background: rgba(255, 255, 255, 0.94);
border-bottom: 1px solid var(--line);
box-shadow: 0 4px 18px rgba(34, 55, 64, 0.06);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 4px;
color: #728188;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.3vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 7px 0 0;
max-width: 720px;
color: var(--muted);
font-size: 13px;
line-height: 1.4;
}
.controls {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
button {
appearance: none;
border: 1px solid #cfdadd;
border-radius: 9px;
padding: 9px 12px;
color: #34454d;
background: #fff;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: #9eafb5;
}
button:focus-visible {
outline: 3px solid rgba(18, 185, 189, 0.25);
outline-offset: 2px;
}
button.active {
color: #fff;
background: #17323d;
border-color: #17323d;
}
#labelsButton.active {
color: #17323d;
background: #eaf1f3;
border-color: #9fb1b8;
}
#stage {
position: relative;
flex: 1 1 auto;
min-height: 320px;
overflow: hidden;
background: #dce5e8;
isolation: isolate;
}
#stage.overview {
cursor: grab;
touch-action: none;
}
#stage.overview.dragging {
cursor: grabbing;
}
#stage canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
}
.viewport-label {
position: absolute;
z-index: 3;
top: 16px;
left: 18px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 11px;
color: #fff;
background: rgba(16, 33, 43, 0.84);
box-shadow: var(--shadow);
pointer-events: none;
backdrop-filter: blur(8px);
}
.viewport-label b {
display: block;
font-size: 12px;
letter-spacing: 0.04em;
}
.viewport-label small {
display: block;
margin-top: 2px;
color: #dbe4e8;
font-size: 11px;
}
.dot {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--a);
box-shadow: 0 0 0 4px rgba(18, 185, 189, 0.18);
}
#labelB {
left: calc(50% + 18px);
}
#labelB .dot {
background: var(--b);
box-shadow: 0 0 0 4px rgba(239, 82, 127, 0.18);
}
.divider {
position: absolute;
z-index: 2;
top: 0;
bottom: 0;
left: 50%;
width: 2px;
background: rgba(31, 54, 64, 0.24);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45);
pointer-events: none;
}
.stage-hint {
position: absolute;
z-index: 3;
bottom: 13px;
left: 50%;
transform: translateX(-50%);
padding: 7px 11px;
border-radius: 999px;
color: #53666f;
background: rgba(255, 255, 255, 0.82);
font-size: 11px;
font-weight: 700;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(6px);
}
#loading {
position: absolute;
z-index: 8;
inset: 0;
display: grid;
place-items: center;
color: #51656e;
background: #dce5e8;
font-size: 14px;
font-weight: 750;
}
footer {
position: relative;
z-index: 10;
flex: 0 0 auto;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
padding: 12px 18px 16px;
background: #f7fafb;
border-top: 1px solid var(--line);
}
.conclusion {
grid-column: 1 / -1;
padding: 1px 3px 4px;
color: #52656e;
font-size: 12px;
text-align: center;
}
.conclusion strong {
color: var(--ink);
}
.frame-card {
position: relative;
min-height: 116px;
overflow: hidden;
padding: 14px 15px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 5px 15px rgba(28, 50, 60, 0.05);
}
.frame-card::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 5px;
background: var(--accent);
}
.frame-card.world {
--accent: var(--world);
background: linear-gradient(135deg, #fff 40%, var(--world-soft));
}
.frame-card.a {
--accent: var(--a);
background: linear-gradient(135deg, #fff 40%, var(--a-soft));
}
.frame-card.b {
--accent: var(--b);
background: linear-gradient(135deg, #fff 40%, var(--b-soft));
}
.frame-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.frame-heading strong {
font-size: 13px;
letter-spacing: 0.035em;
}
.frame-heading span {
padding: 4px 7px;
border-radius: 6px;
color: #fff;
background: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.06em;
}
.axes {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 9px;
}
.axis-chip {
padding: 5px 7px;
border: 1px solid #d7e1e4;
border-radius: 6px;
color: #4d6069;
background: rgba(255, 255, 255, 0.82);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.result {
color: #394c55;
font-size: 12px;
line-height: 1.35;
}
.result b {
color: var(--accent);
font-size: 14px;
}
.note {
margin-top: 4px;
color: #708087;
font-size: 10px;
}
@media (max-width: 900px) {
header {
align-items: flex-start;
}
.controls {
max-width: 340px;
}
footer {
grid-template-columns: 1fr 1fr;
}
.frame-card.world {
grid-column: 1 / -1;
}
}
@media (max-width: 720px) {
body {
height: auto;
min-height: 100vh;
overflow: auto;
}
header {
flex-direction: column;
gap: 13px;
padding: 16px;
}
.controls {
max-width: none;
justify-content: flex-start;
}
#stage {
flex: none;
height: 72vh;
min-height: 610px;
}
.divider {
top: 50%;
right: 0;
bottom: auto;
left: 0;
width: auto;
height: 2px;
}
#labelB {
top: calc(50% + 14px);
left: 14px;
}
.viewport-label {
top: 14px;
left: 14px;
}
.stage-hint {
bottom: 10px;
max-width: calc(100% - 24px);
overflow: hidden;
text-overflow: ellipsis;
}
footer {
grid-template-columns: 1fr;
padding: 12px;
}
.frame-card.world,
.frame-card.a,
.frame-card.b {
grid-column: auto;
}
.conclusion {
grid-column: 1;
line-height: 1.45;
}
}
</style>
</head>
<body>
<header>
<div>
<p class="eyebrow">Voxel reference-frame experiment</p>
<h1>Same ball. Different “left.”</h1>
<p class="subtitle">
Two observers face opposite directions across the same bench. The ball never moves,
but observer-relative left and right reverse.
</p>
</div>
<nav class="controls" aria-label="Scene controls">
<button id="pairedButton" class="active" type="button">Paired views</button>
<button id="overviewButton" type="button">Overview</button>
<button id="labelsButton" class="active" type="button">Labels on</button>
<button id="resetButton" type="button">Reset</button>
</nav>
</header>
<main id="stage" aria-label="Interactive 3D voxel comparison">
<div id="loading">Building the voxel scene…</div>
<div id="labelA" class="viewport-label">
<span class="dot"></span>
<div>
<b>OBSERVER A · LOOKING +X</b>
<small>Ball appears to the RIGHT</small>
</div>
</div>
<div id="labelB" class="viewport-label">
<span class="dot"></span>
<div>
<b>OBSERVER B · LOOKING −X</b>
<small>Ball appears to the LEFT</small>
</div>
</div>
<div class="divider"></div>
<div id="stageHint" class="stage-hint">One world · two opposite headings</div>
</main>
<footer>
<div class="conclusion">
Same world position, opposite answers:
<strong style="color: var(--a)">RIGHT for A</strong> ·
<strong style="color: var(--b)">LEFT for B</strong>.
</div>
<section class="frame-card world">
<div class="frame-heading">
<strong>FIXED WORLD FRAME</strong>
<span>DOES NOT ROTATE</span>
</div>
<div class="axes">
<span class="axis-chip">+X EAST</span>
<span class="axis-chip">+Y UP</span>
<span class="axis-chip">+Z NORTH</span>
</div>
<div class="result">Ball offset from bench: <b>+Z</b></div>
<div class="note">Its world-side classification stays unchanged.</div>
</section>
<section class="frame-card a">
<div class="frame-heading">
<strong>OBSERVER A FRAME</strong>
<span>FACING +X</span>
</div>
<div class="axes">
<span class="axis-chip">FORWARD +X</span>
<span class="axis-chip">UP +Y</span>
<span class="axis-chip">LEFT −Z</span>
</div>
<div class="result">Ball on +Z is <b>RIGHT</b></div>
<div class="note">A’s left points toward −Z.</div>
</section>
<section class="frame-card b">
<div class="frame-heading">
<strong>OBSERVER B FRAME</strong>
<span>FACING −X</span>
</div>
<div class="axes">
<span class="axis-chip">FORWARD −X</span>
<span class="axis-chip">UP +Y</span>
<span class="axis-chip">LEFT +Z</span>
</div>
<div class="result">Ball on +Z is <b>LEFT</b></div>
<div class="note">B’s left points toward +Z.</div>
</section>
</footer>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const pairedButton = document.getElementById("pairedButton");
const overviewButton = document.getElementById("overviewButton");
const labelsButton = document.getElementById("labelsButton");
const resetButton = document.getElementById("resetButton");
const stageHint = document.getElementById("stageHint");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.setAttribute(
"aria-label",
"A voxel bench and yellow ball viewed by two observers facing opposite directions"
);
stage.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5e8);
scene.fog = new THREE.Fog(0xdce5e8, 16, 29);
const cameraA = new THREE.PerspectiveCamera(42, 1, 0.1, 60);
cameraA.position.set(-7.2, 2.45, 0);
cameraA.lookAt(0, 0.82, 0);
const cameraB = new THREE.PerspectiveCamera(42, 1, 0.1, 60);
cameraB.position.set(7.2, 2.45, 0);
cameraB.lookAt(0, 0.82, 0);
const overviewCamera = new THREE.PerspectiveCamera(45, 1, 0.1, 70);
const overviewTarget = new THREE.Vector3(0, 0.85, 0);
const orbit = {
radius: 11.2,
theta: 0.58,
phi: 1.13
};
function updateOverviewCamera() {
const sinPhi = Math.sin(orbit.phi);
overviewCamera.position.set(
overviewTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
overviewTarget.y + orbit.radius * Math.cos(orbit.phi),
overviewTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
overviewCamera.lookAt(overviewTarget);
}
updateOverviewCamera();
scene.add(new THREE.HemisphereLight(0xffffff, 0x6c7d82, 2.25));
const sun = new THREE.DirectionalLight(0xfff4dc, 3.0);
sun.position.set(-6, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 28;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8ddff, 0.85);
fill.position.set(8, 6, -7);
scene.add(fill);
const materialCache = new Map();
function material(color, roughness = 0.82, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
flatShading: true
})
);
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
options.material || material(color, options.roughness ?? 0.82, options.metalness ?? 0)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
function makeLabel(text, color = "#ffffff", accent = "#12b9bd") {
const canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
const font = "700 34px system-ui, sans-serif";
ctx.font = font;
const measured = ctx.measureText(text).width;
canvas.width = Math.ceil(measured + 52);
canvas.height = 66;
ctx = canvas.getContext("2d");
ctx.font = font;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
const r = 15;
const w = canvas.width;
const h = canvas.height;
ctx.beginPath();
ctx.moveTo(r, 0);
ctx.lineTo(w - r, 0);
ctx.quadraticCurveTo(w, 0, w, r);
ctx.lineTo(w, h - r);
ctx.quadraticCurveTo(w, h, w - r, h);
ctx.lineTo(r, h);
ctx.quadraticCurveTo(0, h, 0, h - r);
ctx.lineTo(0, r);
ctx.quadraticCurveTo(0, 0, r, 0);
ctx.closePath();
ctx.fillStyle = "rgba(16, 33, 43, 0.90)";
ctx.fill();
ctx.lineWidth = 4;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = color;
ctx.fillText(text, w / 2, h / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
})
);
const worldWidth = THREE.MathUtils.clamp(text.length * 0.125 + 0.72, 1.3, 3.65);
sprite.scale.set(worldWidth, worldWidth * canvas.height / canvas.width, 1);
sprite.renderOrder = 20;
return sprite;
}
const labelGroup = new THREE.Group();
scene.add(labelGroup);
function addLabel(text, position, color = "#ffffff", accent = "#12b9bd") {
const sprite = makeLabel(text, color, accent);
sprite.position.set(position[0], position[1], position[2]);
labelGroup.add(sprite);
return sprite;
}
function addArrow(origin, direction, length, color, text, labelPosition) {
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(...direction).normalize(),
new THREE.Vector3(...origin),
length,
new THREE.Color(color),
0.38,
0.24
);
scene.add(arrow);
if (text && labelPosition) {
addLabel(text, labelPosition, "#ffffff", color);
}
return arrow;
}
// Floor and grid.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(18, 12),
material(0xcbd6d9, 0.95)
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x84969b, 0xb7c4c7);
grid.position.y = 0.003;
grid.scale.z = 12 / 18;
grid.material.transparent = true;
grid.material.opacity = 0.6;
scene.add(grid);
// Low voxel border pieces give the floor a constructed, diorama-like edge.
const border = new THREE.Group();
scene.add(border);
for (const x of [-8.6, 8.6]) {
for (const z of [-5.6, -1.9, 1.9, 5.6]) {
box(border, [0.32, 0.22, 1.35], [x, 0.08, z], 0x96a8ad);
}
}
for (const z of [-5.6, 5.6]) {
for (const x of [-6.5, -3.2, 3.2, 6.5]) {
box(border, [1.35, 0.22, 0.32], [x, 0.08, z], 0x96a8ad);
}
}
// Bench centered between the observers.
const bench = new THREE.Group();
scene.add(bench);
const woodColors = [0xb9793f, 0xc98a4c, 0xae6e38];
for (let i = 0; i < 3; i++) {
box(
bench,
[0.38, 0.23, 3.0],
[-0.42 + i * 0.42, 1.05, 0],
woodColors[i]
);
}
for (const x of [-0.42, 0.42]) {
for (const z of [-1.1, 1.1]) {
box(bench, [0.23, 1.0, 0.23], [x, 0.5, z], 0x33474f, {
metalness: 0.25,
roughness: 0.55
});
box(bench, [0.34, 0.12, 0.34], [x, 0.08, z], 0x26383f);
}
}
box(bench, [1.22, 0.13, 0.16], [0, 0.67, -1.1], 0x42575f, {
metalness: 0.3,
roughness: 0.55
});
box(bench, [1.22, 0.13, 0.16], [0, 0.67, 1.1], 0x42575f, {
metalness: 0.3,
roughness: 0.55
});
addLabel("BENCH", [0, 1.55, 0], "#ffffff", "#b9793f");
// Ball is on the +Z side of the bench in the fixed world frame.
const ballGroup = new THREE.Group();
scene.add(ballGroup);
box(ballGroup, [1.06, 0.035, 1.06], [0, 0.025, 1.85], 0xe1b64a);
const ball = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.57, 1),
new THREE.MeshStandardMaterial({
color: 0xf3b61f,
roughness: 0.58,
metalness: 0.03,
flatShading: true
})
);
ball.position.set(0, 0.62, 1.85);
ball.castShadow = true;
ball.receiveShadow = true;
ballGroup.add(ball);
const ballRing = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.035, 8, 40),
new THREE.MeshBasicMaterial({
color: 0xf3b61f,
transparent: true,
opacity: 0.75,
depthWrite: false
})
);
ballRing.rotation.x = Math.PI / 2;
ballRing.position.set(0, 0.06, 1.85);
ballGroup.add(ballRing);
addLabel("BALL · +Z SIDE", [0, 1.52, 1.85], "#ffffff", "#f3b61f");
const relationGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.055, 0.55),
new THREE.Vector3(0, 0.055, 1.32)
]);
const relationLine = new THREE.Line(
relationGeometry,
new THREE.LineDashedMaterial({
color: 0xd99c10,
dashSize: 0.13,
gapSize: 0.09,
linewidth: 1
})
);
relationLine.computeLineDistances();
scene.add(relationLine);
// Voxel observers. Their noses explicitly show the facing direction.
function createObserver(primary, secondary, facing) {
const group = new THREE.Group();
scene.add(group);
box(group, [0.48, 0.82, 0.56], [0, 1.28, 0], primary);
box(group, [0.12, 0.42, 0.58], [facing * 0.29, 1.35, 0], secondary);
box(group, [0.28, 0.80, 0.21], [0, 0.42, -0.15], 0x33444d);
box(group, [0.28, 0.80, 0.21], [0, 0.42, 0.15], 0x33444d);
box(group, [0.45, 0.16, 0.27], [facing * 0.09, 0.08, -0.15], 0x223039);
box(group, [0.45, 0.16, 0.27], [facing * 0.09, 0.08, 0.15], 0x223039);
box(group, [0.43, 0.43, 0.46], [0, 1.92, 0], 0xe6b58c);
box(group, [0.48, 0.17, 0.50], [0, 2.15, 0], 0x493c38);
box(group, [0.18, 0.17, 0.15], [facing * 0.29, 1.91, 0], 0xe6b58c);
// Eyes on the face.
box(group, [0.055, 0.065, 0.065], [facing * 0.225, 2.00, -0.115], 0x1c272c);
box(group, [0.055, 0.065, 0.065], [facing * 0.225, 2.00, 0.115], 0x1c272c);
// Arms extend along the forward/back axis.
box(group, [0.56, 0.18, 0.18], [facing * 0.08, 1.12, -0.39], secondary);
box(group, [0.56, 0.18, 0.18], [facing * 0.08, 1.12, 0.39], secondary);
box(group, [0.17, 0.20, 0.18], [facing * 0.35, 1.12, -0.39], 0xe6b58c);
box(group, [0.17, 0.20, 0.18], [facing * 0.35, 1.12, 0.39], 0xe6b58c);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.82, 0.035, 8, 40),
new THREE.MeshBasicMaterial({
color: primary,
transparent: true,
opacity: 0.75
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.045;
group.add(ring);
return group;
}
const observerA = createObserver(0x12b9bd, 0x087f84, 1);
observerA.position.x = -4.45;
const observerB = createObserver(0xef527f, 0xb52f5b, -1);
observerB.position.x = 4.45;
const observerALabel = addLabel("OBSERVER A", [-4.45, 2.68, 0], "#ffffff", "#12b9bd");
const observerBLabel = addLabel("OBSERVER B", [4.45, 2.68, 0], "#ffffff", "#ef527f");
// Fixed world direction: +Z.
addArrow(
[-1.25, 0.075, -4.0],
[0, 0, 1],
8.0,
0x58b96b,
"FIXED WORLD +Z",
[-1.25, 0.47, 4.18]
);
// Observer A frame: faces +X, so left is -Z.
addArrow(
[-3.55, 0.08, 1.25],
[0, 0, -1],
3.15,
0x12b9bd,
"A LEFT = −Z",
[-3.55, 0.48, -2.42]
);
addArrow(
[-3.75, 0.08, 0],
[1, 0, 0],
1.55,
0x12b9bd,
"A FORWARD +X",
[-2.10, 0.38, 0]
);
// Observer B frame: faces -X, so left is +Z.
addArrow(
[3.55, 0.08, -1.25],
[0, 0, 1],
3.15,
0xef527f,
"B LEFT = +Z",
[3.55, 0.48, 2.42]
);
addArrow(
[3.75, 0.08, 0],
[-1, 0, 0],
1.55,
0xef527f,
"B FORWARD −X",
[2.10, 0.38, 0]
);
// Small fixed-world X/Y axes near the back-left corner.
const worldOrigin = [-2.35, 0.07, -2.55];
addArrow(worldOrigin, [1, 0, 0], 1.45, 0xe45f5f, null, null);
addArrow(worldOrigin, [0, 1, 0], 1.45, 0x4c83d7, null, null);
addLabel("WORLD +X", [-0.80, 0.34, -2.55], "#ffffff", "#e45f5f");
addLabel("WORLD +Y", [-2.35, 1.63, -2.55], "#ffffff", "#4c83d7");
let mode = "paired";
let labelsOn = true;
let stacked = false;
let width = 1;
let height = 1;
function resize() {
width = Math.max(1, stage.clientWidth);
height = Math.max(1, stage.clientHeight);
stacked = width < 720;
stage.classList.toggle("stacked", stacked);
renderer.setSize(width, height, false);
if (stacked) {
const topHeight = Math.floor(height / 2);
const bottomHeight = height - topHeight;
cameraA.aspect = width / topHeight;
cameraB.aspect = width / bottomHeight;
} else {
const halfWidth = Math.floor(width / 2);
cameraA.aspect = halfWidth / height;
cameraB.aspect = (width - halfWidth) / height;
}
cameraA.updateProjectionMatrix();
cameraB.updateProjectionMatrix();
overviewCamera.aspect = width / height;
overviewCamera.updateProjectionMatrix();
}
function setMode(nextMode) {
mode = nextMode;
pairedButton.classList.toggle("active", mode === "paired");
overviewButton.classList.toggle("active", mode === "overview");
stage.classList.toggle("overview", mode === "overview");
stageHint.textContent =
mode === "overview"
? "Drag to orbit · wheel or pinch to zoom"
: "One world · two opposite headings";
}
function resetOverview() {
orbit.radius = 11.2;
orbit.theta = 0.58;
orbit.phi = 1.13;
updateOverviewCamera();
}
pairedButton.addEventListener("click", () => setMode("paired"));
overviewButton.addEventListener("click", () => setMode("overview"));
labelsButton.addEventListener("click", () => {
labelsOn = !labelsOn;
labelGroup.visible = labelsOn;
labelsButton.classList.toggle("active", labelsOn);
labelsButton.textContent = labelsOn ? "Labels on" : "Labels off";
});
resetButton.addEventListener("click", () => {
resetOverview();
setMode("paired");
});
// Direct, dependency-free orbit controls for the overview camera.
let dragging = false;
let lastX = 0;
let lastY = 0;
stage.addEventListener("pointerdown", (event) => {
if (mode !== "overview") return;
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
stage.classList.add("dragging");
stage.setPointerCapture(event.pointerId);
});
stage.addEventListener("pointermove", (event) => {
if (!dragging || mode !== "overview") return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.22, Math.PI - 0.22);
updateOverviewCamera();
});
function stopDragging(event) {
dragging = false;
stage.classList.remove("dragging");
if (event && stage.hasPointerCapture(event.pointerId)) {
stage.releasePointerCapture(event.pointerId);
}
}
stage.addEventListener("pointerup", stopDragging);
stage.addEventListener("pointercancel", stopDragging);
stage.addEventListener(
"wheel",
(event) => {
if (mode !== "overview") return;
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
6.2,
17.5
);
updateOverviewCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "1") setMode("paired");
if (event.key === "2") setMode("overview");
if (event.key.toLowerCase() === "r") {
resetOverview();
setMode("paired");
}
});
function prepareSplitView(view) {
observerA.visible = view === "B";
observerB.visible = view === "A";
observerALabel.visible = view !== "A";
observerBLabel.visible = view !== "B";
}
function renderScene() {
if (mode === "overview") {
renderer.setScissorTest(false);
renderer.setViewport(0, 0, width, height);
observerA.visible = true;
observerB.visible = true;
observerALabel.visible = true;
observerBLabel.visible = true;
renderer.render(scene, overviewCamera);
return;
}
renderer.setScissorTest(true);
if (stacked) {
const topHeight = Math.floor(height / 2);
const bottomHeight = height - topHeight;
renderer.setViewport(0, topHeight, width, topHeight);
renderer.setScissor(0, topHeight, width, topHeight);
prepareSplitView("A");
renderer.render(scene, cameraA);
renderer.setViewport(0, 0, width, bottomHeight);
renderer.setScissor(0, 0, width, bottomHeight);
prepareSplitView("B");
renderer.render(scene, cameraB);
} else {
const leftWidth = Math.floor(width / 2);
const rightWidth = width - leftWidth;
renderer.setViewport(0, 0, leftWidth, height);
renderer.setScissor(0, 0, leftWidth, height);
prepareSplitView("A");
renderer.render(scene, cameraA);
renderer.setViewport(leftWidth, 0, rightWidth, height);
renderer.setScissor(leftWidth, 0, rightWidth, height);
prepareSplitView("B");
renderer.render(scene, cameraB);
}
renderer.setScissorTest(false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
window.addEventListener("resize", resize);
resize();
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
if (!reduceMotion) {
const pulse = 1 + Math.sin(clock.getElapsedTime() * 2.4) * 0.035;
ballRing.scale.set(pulse, pulse, pulse);
ballRing.material.opacity = 0.65 + Math.sin(clock.getElapsedTime() * 2.4) * 0.12;
}
renderScene();
}
renderScene();
loading.style.display = "none";
animate();
</script>
</body>
</html>
```