Prompt specification
Build or customize the Three.js 3D scene "Shared Gaze Across an Occluding Wall" 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: Shared Gaze Across an Occluding Wall
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shared-gaze-across-an-occluding-wall-x3728
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing gaze direction, head movement, and visual attention. Create two characters with different sight lines to objects behind a partition. Display what each can geometrically see and distinguish visibility from knowledge or belief. Low-poly.
Working Three.js Starter (shared-gaze-across-an-occluding-wall-x3728):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gaze, Attention & Epistemic States</title>
<style>
:root {
--ink: #14232d;
--muted: #60717c;
--paper: rgba(249, 247, 240, 0.92);
--line: rgba(20, 35, 45, 0.13);
--cyan: #148da8;
--orange: #df743d;
--green: #278a61;
--red: #cb4e56;
--purple: #7654a5;
--shadow: 0 16px 50px rgba(21, 36, 44, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5e5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
touch-action: none;
}
#title {
position: fixed;
z-index: 5;
top: 20px;
left: 22px;
width: min(520px, calc(100vw - 450px));
pointer-events: none;
}
.eyebrow {
display: inline-block;
margin-bottom: 8px;
padding: 5px 9px;
border: 1px solid rgba(20, 35, 45, 0.16);
border-radius: 999px;
background: rgba(249, 247, 240, 0.7);
color: #53656f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
h1 {
margin: 0;
max-width: 520px;
font-size: clamp(26px, 3.2vw, 45px);
line-height: 0.98;
letter-spacing: -0.045em;
}
#title p {
max-width: 490px;
margin: 12px 0 0;
color: #4d606b;
font-size: 13px;
line-height: 1.45;
text-wrap: balance;
}
#legend {
position: fixed;
z-index: 5;
top: 22px;
left: 22px;
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 128px;
pointer-events: none;
}
.legend-item,
.status,
.mini-tag {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border-radius: 999px;
font-size: 10px;
font-weight: 750;
line-height: 1;
white-space: nowrap;
backdrop-filter: blur(12px);
}
.legend-item {
border: 1px solid rgba(20, 35, 45, 0.12);
background: rgba(249, 247, 240, 0.78);
color: #4b5f6a;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
}
#panel {
position: fixed;
z-index: 10;
top: 18px;
right: 18px;
width: 390px;
max-height: calc(100vh - 100px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(20, 35, 45, 0.13);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
}
#panel h2 {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 0 10px;
font-size: 12px;
letter-spacing: 0.075em;
text-transform: uppercase;
}
#panel h2:not(:first-child) {
margin-top: 19px;
padding-top: 17px;
border-top: 1px solid var(--line);
}
#clock {
color: var(--muted);
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.section-note {
margin: -3px 0 11px;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.observer-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.observer {
padding: 12px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.55);
}
.observer.a {
border-top: 3px solid var(--cyan);
}
.observer.b {
border-top: 3px solid var(--orange);
}
.observer-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
}
.observer-name {
font-size: 12px;
font-weight: 850;
}
.mini-tag {
padding: 4px 6px;
background: #edf0ed;
color: #617078;
}
.observer dl {
display: grid;
grid-template-columns: auto 1fr;
gap: 5px 8px;
margin: 0;
font-size: 10px;
line-height: 1.35;
}
.observer dt {
color: #7a8990;
font-weight: 650;
}
.observer dd {
margin: 0;
color: #263b46;
font-weight: 720;
text-align: right;
}
.table-wrap {
overflow: hidden;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.47);
}
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
th {
padding: 8px 7px;
border-bottom: 1px solid var(--line);
color: #718087;
font-size: 9px;
letter-spacing: 0.08em;
text-align: left;
text-transform: uppercase;
}
th:nth-child(2),
th:nth-child(3) {
text-align: center;
}
td {
padding: 9px 7px;
border-bottom: 1px solid var(--line);
vertical-align: top;
}
tr:last-child td {
border-bottom: 0;
}
tr.selected td {
background: rgba(21, 141, 168, 0.07);
}
.object-button {
width: 100%;
padding: 0;
border: 0;
background: transparent;
color: #233944;
cursor: pointer;
font: inherit;
font-size: 10.5px;
font-weight: 800;
line-height: 1.25;
text-align: left;
}
.object-button span {
display: block;
margin-top: 4px;
color: #8a969b;
font-size: 9px;
font-weight: 600;
}
.sight-cell {
text-align: center;
}
.status {
justify-content: center;
min-width: 74px;
padding: 5px 6px;
}
.status.visible {
background: rgba(39, 138, 97, 0.12);
color: var(--green);
}
.status.blocked {
background: rgba(203, 78, 86, 0.12);
color: var(--red);
}
.status.clear {
background: rgba(96, 113, 124, 0.11);
color: #63747d;
}
.cell-detail {
display: block;
margin-top: 5px;
color: #7b888e;
font-size: 8.5px;
line-height: 1.25;
}
#selectedTitle {
margin-bottom: 10px;
font-size: 14px;
font-weight: 850;
}
.epistemic-card {
margin-top: 8px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.53);
}
.epistemic-card .person {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
font-size: 11px;
font-weight: 850;
}
.person.a {
color: var(--cyan);
}
.person.b {
color: var(--orange);
}
.epistemic-row {
display: grid;
grid-template-columns: 65px 1fr;
gap: 8px;
margin-top: 6px;
font-size: 9.5px;
line-height: 1.35;
}
.epistemic-row strong {
color: #76858c;
font-weight: 700;
}
.epistemic-row span {
color: #263b46;
font-weight: 700;
}
.epistemic-row small {
display: block;
margin-top: 2px;
color: #89959a;
font-size: 8.5px;
font-weight: 550;
}
.knowledge {
color: var(--green) !important;
}
.belief {
color: var(--purple) !important;
}
.epistemic-warning {
margin: 10px 0 0;
padding: 9px 10px;
border-left: 3px solid var(--purple);
border-radius: 0 8px 8px 0;
background: rgba(118, 84, 165, 0.08);
color: #625679;
font-size: 9.5px;
line-height: 1.45;
}
#controls {
position: fixed;
z-index: 12;
left: 50%;
bottom: 18px;
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 7px;
max-width: calc(100vw - 36px);
padding: 7px;
border: 1px solid rgba(20, 35, 45, 0.13);
border-radius: 14px;
background: rgba(249, 247, 240, 0.9);
box-shadow: var(--shadow);
transform: translateX(-50%);
backdrop-filter: blur(16px);
}
button {
border: 1px solid rgba(20, 35, 45, 0.12);
border-radius: 9px;
background: #fffefa;
color: #344a55;
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
transition: transform 120ms ease, background 120ms ease, opacity 120ms ease;
}
button:hover {
background: #eef4f2;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#controls button {
padding: 8px 11px;
}
#controls button.off {
opacity: 0.46;
}
#hint {
position: fixed;
z-index: 5;
left: 20px;
bottom: 21px;
max-width: 300px;
color: rgba(37, 56, 65, 0.72);
font-size: 9.5px;
line-height: 1.4;
pointer-events: none;
}
#hint strong {
color: rgba(37, 56, 65, 0.94);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #e2e9e8;
color: #536770;
font-size: 12px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 850px) {
#title {
width: calc(100vw - 40px);
}
#title p {
max-width: 420px;
}
#legend {
display: none;
}
#panel {
top: auto;
right: 12px;
bottom: 78px;
width: calc(100vw - 24px);
max-height: 43vh;
padding: 14px;
}
#hint {
display: none;
}
#controls {
bottom: 12px;
}
}
@media (max-width: 520px) {
#title {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
h1 {
font-size: 29px;
}
#title p {
font-size: 11px;
}
.observer-grid {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<div id="loading">Loading Three.js scene…</div>
<header id="title">
<div class="eyebrow">Low-poly epistemic vision study</div>
<h1>Gaze is not the same as seeing—or knowing.</h1>
<p>
Two observers share a partitioned room. Optical visibility, gaze alignment,
knowledge, and belief are displayed as separate layers.
</p>
</header>
<div id="legend" aria-label="Legend">
<div class="legend-item"><span class="dot" style="color:var(--cyan)"></span>A · Ari</div>
<div class="legend-item"><span class="dot" style="color:var(--orange)"></span>B · Bo</div>
<div class="legend-item"><span class="dot" style="color:var(--green)"></span>Clear sight ray</div>
<div class="legend-item"><span class="dot" style="color:var(--red)"></span>Blocked sight ray</div>
<div class="legend-item"><span class="dot" style="color:var(--purple)"></span>Belief</div>
</div>
<aside id="panel">
<section>
<h2>
Live observers
<span id="clock">t = 0.0 s</span>
</h2>
<div class="observer-grid">
<div class="observer a">
<div class="observer-heading">
<span class="observer-name">A · Ari</span>
<span class="mini-tag">cyan</span>
</div>
<dl>
<dt>Head yaw</dt><dd id="a-yaw">—</dd>
<dt>Gaze goal</dt><dd id="a-focus">—</dd>
<dt>Visible</dt><dd id="a-visible">—</dd>
<dt>Attending</dt><dd id="a-attention">—</dd>
</dl>
</div>
<div class="observer b">
<div class="observer-heading">
<span class="observer-name">B · Bo</span>
<span class="mini-tag">orange</span>
</div>
<dl>
<dt>Head yaw</dt><dd id="b-yaw">—</dd>
<dt>Gaze goal</dt><dd id="b-focus">—</dd>
<dt>Visible</dt><dd id="b-visible">—</dd>
<dt>Attending</dt><dd id="b-attention">—</dd>
</dl>
</div>
</div>
</section>
<section>
<h2>Geometric visibility</h2>
<p class="section-note">
<strong>VISIBLE</strong> = unobstructed ray inside the 52° gaze field.
<strong>CLEAR / TURN</strong> = unobstructed, but outside the current field.
<strong>BLOCKED</strong> = the partition intersects the ray.
</p>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Object</th>
<th>A</th>
<th>B</th>
</tr>
</thead>
<tbody id="objectRows"></tbody>
</table>
</div>
</section>
<section>
<h2>Epistemic ledger</h2>
<div id="selectedTitle">Coral icosahedron</div>
<div class="epistemic-card">
<div class="person a"><span>A · Ari</span><span>epistemic state</span></div>
<div id="a-knowledge"></div>
<div id="a-belief"></div>
</div>
<div class="epistemic-card">
<div class="person b"><span>B · Bo</span><span>epistemic state</span></div>
<div id="b-knowledge"></div>
<div id="b-belief"></div>
</div>
<p class="epistemic-warning">
Knowledge and belief are independent, preloaded evidence records.
A clear line of sight does not automatically create knowledge, recognition,
or a true belief.
</p>
</section>
</aside>
<div id="controls">
<button id="pauseBtn" type="button">Pause</button>
<button id="restartBtn" type="button">Restart cycle</button>
<button id="raysBtn" type="button">Sight rays</button>
<button id="conesBtn" type="button">Gaze cones</button>
<button id="viewBtn" type="button">Reset view</button>
</div>
<div id="hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom ·
<strong>Click an object</strong> to inspect its knowledge and belief records.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene and renderer
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5e5);
scene.fog = new THREE.Fog(0xdce5e5, 18, 37);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D scene showing two observers, gaze directions, sight rays, and objects"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf4fbff, 0x8e806d, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d9, 3.2);
sun.position.set(6, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa7d7e7, 0.7);
fill.position.set(-8, 6, -5);
scene.add(fill);
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
const COLORS = {
a: 0x148da8,
b: 0xdf743d,
blocked: 0xcb4e56,
selection: 0xf8f4dc
};
const FOV_DEGREES = 52;
const HALF_FOV = THREE.MathUtils.degToRad(FOV_DEGREES / 2);
const ATTENTION_ANGLE = THREE.MathUtils.degToRad(7.5);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.02,
flatShading: true,
...options
});
}
function makeLabel(text, background = "#f8f5e9", foreground = "#213844") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 144;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(25,45,55,0.16)";
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
ctx.fillStyle = foreground;
ctx.font = "800 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(2.65, 0.6, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeCircle(radius, color, opacity = 0.3) {
const mesh = new THREE.Mesh(
new THREE.CircleGeometry(radius, 32),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = 0.012;
return mesh;
}
function damp(current, target, lambda, dt) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * dt)
);
}
function dampAngle(current, target, lambda, dt) {
const delta = Math.atan2(
Math.sin(target - current),
Math.cos(target - current)
);
return current + delta * (1 - Math.exp(-lambda * dt));
}
function segmentBoxIntersection(start, end, min, max) {
const direction = end.clone().sub(start);
let tMin = 0;
let tMax = 1;
for (const axis of ["x", "y", "z"]) {
const d = direction[axis];
const s = start[axis];
if (Math.abs(d) < 1e-8) {
if (s < min[axis] || s > max[axis]) return null;
continue;
}
const t1 = (min[axis] - s) / d;
const t2 = (max[axis] - s) / d;
const near = Math.min(t1, t2);
const far = Math.max(t1, t2);
tMin = Math.max(tMin, near);
tMax = Math.min(tMax, far);
if (tMin > tMax) return null;
}
if (tMax < 0 || tMin > 1) return null;
if (tMin <= 0 || tMin >= 1) return null;
return tMin;
}
// -------------------------------------------------------------------------
// Floor, room, and partition
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(28, 28),
standardMaterial(0xd5d0c3)
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(26, 26, 0x8d9b9d, 0xaeb8b7);
grid.material.transparent = true;
grid.material.opacity = 0.28;
grid.position.y = 0.018;
scene.add(grid);
const partitionMin = new THREE.Vector3(-2.1, 0, -0.22);
const partitionMax = new THREE.Vector3(2.1, 3.4, 0.22);
const partition = new THREE.Mesh(
new THREE.BoxGeometry(4.2, 3.4, 0.44),
standardMaterial(0x66737a)
);
partition.position.set(0, 1.7, 0);
partition.castShadow = true;
partition.receiveShadow = true;
scene.add(partition);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(4.35, 0.14, 0.54),
standardMaterial(0x45545b)
);
cap.position.set(0, 3.42, 0);
cap.castShadow = true;
scene.add(cap);
const stripeMaterial = standardMaterial(0xb49a58);
for (let i = -4; i <= 4; i++) {
const stripe = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 2.75, 0.025),
stripeMaterial
);
stripe.position.set(i * 0.47, 1.72, 0.232);
stripe.rotation.z = -0.43;
scene.add(stripe);
}
const partitionLabel = makeLabel(
"OPAQUE PARTITION",
"#45545b",
"#f4f0df"
);
partitionLabel.scale.set(2.8, 0.63, 1);
partitionLabel.position.set(0, 3.95, 0);
scene.add(partitionLabel);
const backWall = new THREE.Mesh(
new THREE.BoxGeometry(13.5, 2.7, 0.18),
standardMaterial(0xc7d1cf)
);
backWall.position.set(0, 1.35, -6.35);
backWall.receiveShadow = true;
scene.add(backWall);
// -------------------------------------------------------------------------
// Objects behind the partition
// -------------------------------------------------------------------------
const objects = [];
function registerObject(config) {
const group = new THREE.Group();
group.position.set(config.x, 0, config.z);
scene.add(group);
const mesh = new THREE.Mesh(config.geometry, config.material);
mesh.position.y = config.centerY;
mesh.rotation.y = config.rotation || 0;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.objectId = config.id;
group.add(mesh);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.83, 0.83, 0.07, 12),
standardMaterial(0xabb6b2)
);
pedestal.position.y = 0.035;
pedestal.receiveShadow = true;
group.add(pedestal);
const label = makeLabel(config.name);
label.position.set(0, config.labelY, 0);
group.add(label);
const object = {
id: config.id,
name: config.name,
shortName: config.shortName,
group,
mesh,
label,
radius: config.radius
};
objects.push(object);
return object;
}
registerObject({
id: "cylinder",
name: "Cobalt cylinder",
shortName: "Cylinder",
x: -4.45,
z: -3.15,
centerY: 0.67,
labelY: 2.05,
radius: 0.82,
geometry: new THREE.CylinderGeometry(0.55, 0.55, 1.3, 6),
material: standardMaterial(0x4964df)
});
registerObject({
id: "cube",
name: "Amber cube",
shortName: "Cube",
x: 3.55,
z: -3.1,
centerY: 0.54,
labelY: 1.95,
radius: 0.8,
rotation: 0.38,
geometry: new THREE.BoxGeometry(1.05, 1.05, 1.05),
material: standardMaterial(0xf1b13b)
});
registerObject({
id: "sphere",
name: "Coral icosahedron",
shortName: "Icosahedron",
x: 0.65,
z: -3.25,
centerY: 0.72,
labelY: 2.05,
radius: 0.82,
geometry: new THREE.IcosahedronGeometry(0.67, 1),
material: standardMaterial(0xef476f)
});
const objectById = Object.fromEntries(objects.map((o) => [o.id, o]));
// -------------------------------------------------------------------------
// Characters
// -------------------------------------------------------------------------
const characters = [];
function createCharacter(config) {
const root = new THREE.Group();
root.position.set(config.x, 0, config.z);
scene.add(root);
root.add(makeCircle(1.05, config.color, 0.3));
const bodyMaterial = standardMaterial(config.color);
const darkMaterial = standardMaterial(0x26343b);
const skinMaterial = standardMaterial(config.skin);
const legGeometry = new THREE.BoxGeometry(0.24, 0.72, 0.27);
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(legGeometry, darkMaterial);
leg.position.set(side * 0.19, 0.37, 0);
leg.castShadow = true;
root.add(leg);
const shoe = new THREE.Mesh(
new THREE.BoxGeometry(0.3, 0.16, 0.45),
darkMaterial
);
shoe.position.set(side * 0.19, 0.09, -0.08);
shoe.castShadow = true;
root.add(shoe);
}
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.55, 1.18, 6),
bodyMaterial
);
torso.position.y = 1.26;
torso.castShadow = true;
root.add(torso);
const chestBadge = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.14, 0.025, 8),
standardMaterial(0xf6f1dc)
);
chestBadge.rotation.x = Math.PI / 2;
chestBadge.position.set(0, 1.35, -0.48);
root.add(chestBadge);
const armGeometry = new THREE.CylinderGeometry(0.1, 0.14, 0.82, 5);
for (const side of [-1, 1]) {
const arm = new THREE.Mesh(armGeometry, bodyMaterial);
arm.position.set(side * 0.52, 1.28, 0);
arm.rotation.z = side * -0.12;
arm.castShadow = true;
root.add(arm);
const hand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.14, 0),
skinMaterial
);
hand.position.set(side * 0.57, 0.84, -0.02);
hand.castShadow = true;
root.add(hand);
}
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.16, 0.25, 6),
skinMaterial
);
neck.position.y = 1.98;
root.add(neck);
const headPivot = new THREE.Group();
headPivot.position.set(0, 2.24, 0);
headPivot.rotation.order = "YXZ";
root.add(headPivot);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.44, 1),
skinMaterial
);
head.scale.set(0.94, 1.05, 0.93);
head.castShadow = true;
headPivot.add(head);
const hair = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.46, 0.18, 7),
standardMaterial(config.hair)
);
hair.position.y = 0.29;
hair.castShadow = true;
headPivot.add(hair);
const eyes = [];
for (const side of [-1, 1]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 8, 6),
standardMaterial(0xf8f3df)
);
eye.position.set(side * 0.145, 0.06, -0.365);
eye.scale.z = 0.55;
headPivot.add(eye);
eyes.push(eye);
const pupil = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 7, 5),
standardMaterial(0x10232b)
);
pupil.position.set(side * 0.145, 0.06, -0.415);
pupil.scale.z = 0.5;
headPivot.add(pupil);
}
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.2, 4),
standardMaterial(config.skin)
);
nose.rotation.x = -Math.PI / 2;
nose.position.set(0, -0.015, -0.455);
headPivot.add(nose);
const gazeOrigin = new THREE.Object3D();
gazeOrigin.position.set(0, 0.06, -0.39);
headPivot.add(gazeOrigin);
const label = makeLabel(
`${config.id} · ${config.name}`,
config.id === "A" ? "#d9f1f4" : "#fae4d6",
"#213844"
);
label.position.set(0, 3.18, 0);
root.add(label);
const gazeGroup = new THREE.Group();
scene.add(gazeGroup);
const coneGeometry = new THREE.ConeGeometry(
1,
5.8,
16,
1,
true
);
const cone = new THREE.Mesh(
coneGeometry,
new THREE.MeshBasicMaterial({
color: config.color,
transparent: true,
opacity: 0.075,
depthWrite: false,
side: THREE.DoubleSide
})
);
gazeGroup.add(cone);
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(),
2.7,
config.color,
0.34,
0.18
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.95;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.95;
gazeGroup.add(arrow);
const character = {
id: config.id,
name: config.name,
color: config.color,
root,
headPivot,
eyes,
gazeOrigin,
gazeGroup,
cone,
arrow,
desiredYaw: 0,
desiredPitch: 0,
headYaw: 0,
headPitch: 0,
gazeDir: new THREE.Vector3(0, 0, -1),
focusId: null,
status: {},
rings: {}
};
for (const object of objects) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.73, 0.035, 6, 28),
new THREE.MeshBasicMaterial({
color: config.color,
transparent: true,
opacity: 0,
depthWrite: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(object.group.position.x, 0.09, object.group.position.z);
ring.scale.setScalar(object.radius / 0.73);
scene.add(ring);
character.rings[object.id] = ring;
}
characters.push(character);
return character;
}
createCharacter({
id: "A",
name: "Ari",
x: -4.7,
z: 4.7,
color: COLORS.a,
skin: 0xb97854,
hair: 0x25303a
});
createCharacter({
id: "B",
name: "Bo",
x: 4.7,
z: 4.7,
color: COLORS.b,
skin: 0xe0a276,
hair: 0x5b3829
});
const characterById = Object.fromEntries(
characters.map((character) => [character.id, character])
);
// -------------------------------------------------------------------------
// Sight rays and state markers
// -------------------------------------------------------------------------
function createSightLine(character) {
const solid = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]),
new THREE.LineBasicMaterial({
color: character.color,
transparent: true,
opacity: 0.72,
depthTest: false,
depthWrite: false
})
);
solid.frustumCulled = false;
solid.renderOrder = 8;
const dashed = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]),
new THREE.LineDashedMaterial({
color: COLORS.blocked,
dashSize: 0.2,
gapSize: 0.14,
transparent: true,
opacity: 0.55,
depthTest: false,
depthWrite: false
})
);
dashed.frustumCulled = false;
dashed.renderOrder = 8;
dashed.visible = false;
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.1),
new THREE.MeshBasicMaterial({
color: COLORS.blocked,
depthTest: false,
depthWrite: false
})
);
marker.renderOrder = 9;
marker.visible = false;
const group = new THREE.Group();
group.add(solid, dashed, marker);
scene.add(group);
return { group, solid, dashed, marker };
}
for (const character of characters) {
character.sightLines = {};
for (const object of objects) {
character.sightLines[object.id] = createSightLine(character);
}
}
const selectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.88, 0.045, 6, 36),
new THREE.MeshBasicMaterial({
color: COLORS.selection,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
selectionRing.rotation.x = Math.PI / 2;
scene.add(selectionRing);
let selectedObjectId = "sphere";
// -------------------------------------------------------------------------
// Independent epistemic records
// -------------------------------------------------------------------------
const epistemic = {
A: {
cylinder: {
knowledge: {
text: "Cobalt cylinder",
source: "Prior team briefing"
},
belief: {
text: "Cobalt cylinder · 90%",
source: "Consistent with the briefing"
}
},
cube: {
knowledge: null,
belief: {
text: "Coral icosahedron · 65%",
source: "Misheard object label"
}
},
sphere: {
knowledge: null,
belief: {
text: "Amber cube · 40%",
source: "Uncertain inference"
}
}
},
B: {
cylinder: {
knowledge: null,
belief: {
text: "Cobalt cylinder · 70%",
source: "Secondhand report"
}
},
cube: {
knowledge: {
text: "Amber cube",
source: "Direct earlier observation"
},
belief: {
text: "Amber cube · 95%",
source: "Supported by direct observation"
}
},
sphere: {
knowledge: null,
belief: {
text: "Coral icosahedron · 60%",
source: "Tentative verbal report"
}
}
}
};
// -------------------------------------------------------------------------
// Animation schedule
// -------------------------------------------------------------------------
let elapsed = 0;
let paused = false;
let showRays = true;
let showCones = true;
function focusFor(character, time) {
const cycle = time % 16;
if (character.id === "A") {
if (cycle < 4.5) return "cylinder";
if (cycle < 8.5) return "cube";
if (cycle < 11) return null;
return "cylinder";
}
if (cycle < 4) return "cube";
if (cycle < 8) return "sphere";
if (cycle < 10.5) return null;
return "cube";
}
const tmpQuaternion = new THREE.Quaternion();
const tmpVector = new THREE.Vector3();
const targetVector = new THREE.Vector3();
const startVector = new THREE.Vector3();
const endVector = new THREE.Vector3();
const hitVector = new THREE.Vector3();
function updateCharacters(dt) {
for (const character of characters) {
character.focusId = focusFor(character, elapsed);
character.gazeOrigin.getWorldPosition(startVector);
if (character.focusId) {
objectById[character.focusId].mesh.getWorldPosition(targetVector);
} else {
targetVector.set(
character.root.position.x,
2.2,
character.root.position.z - 6
);
}
tmpVector.copy(targetVector).sub(startVector);
const distance = tmpVector.length();
const targetYaw = Math.atan2(-tmpVector.x, -tmpVector.z);
const targetPitch = Math.asin(THREE.MathUtils.clamp(tmpVector.y / distance, -1, 1));
character.desiredYaw = dampAngle(
character.desiredYaw,
targetYaw,
5.2,
dt
);
character.desiredPitch = damp(
character.desiredPitch,
targetPitch,
5.2,
dt
);
// The head follows more slowly than the eyes.
character.headYaw = dampAngle(
character.headYaw,
character.desiredYaw,
1.35,
dt
);
character.headPitch = damp(
character.headPitch,
character.desiredPitch * 0.55,
1.45,
dt
);
// Local eye rotation compensates for the lagging head.
const localYaw = character.desiredYaw + character.headYaw;
const localPitch = character.desiredPitch - character.headPitch;
character.headPivot.rotation.set(
character.headPitch,
character.headYaw,
0,
"YXZ"
);
character.headPivot.updateWorldMatrix(true, true);
character.headPivot.getWorldQuaternion(tmpQuaternion);
character.gazeDir
.set(
Math.sin(localYaw) * Math.cos(localPitch),
Math.sin(localPitch),
-Math.cos(localYaw) * Math.cos(localPitch)
)
.applyQuaternion(tmpQuaternion)
.normalize();
character.gazeOrigin.getWorldPosition(startVector);
const coneLength = 5.8;
const coneRadius = Math.tan(HALF_FOV) * coneLength;
character.cone.position
.copy(startVector)
.addScaledVector(character.gazeDir, coneLength / 2);
character.cone.quaternion.setFromUnitVectors(
new THREE.Vector3(0, -1, 0),
character.gazeDir
);
character.cone.scale.set(coneRadius, 1, coneRadius);
character.arrow.position.copy(startVector);
character.arrow.setDirection(character.gazeDir);
}
}
function updateLine(line, a, b) {
const positions = line.geometry.getAttribute("position");
positions.setXYZ(0, a.x, a.y, a.z);
positions.setXYZ(1, b.x, b.y, b.z);
positions.needsUpdate = true;
line.geometry.computeBoundingSphere();
if (line.isLineSegments || line.material.isLineDashedMaterial) {
line.computeLineDistances();
}
}
function updateSightStates() {
scene.updateMatrixWorld(true);
for (const character of characters) {
character.gazeOrigin.getWorldPosition(startVector);
for (const object of objects) {
object.mesh.getWorldPosition(endVector);
hitVector.copy(endVector);
const t = segmentBoxIntersection(
startVector,
endVector,
partitionMin,
partitionMax
);
const blocked = t !== null;
if (blocked) hitVector.lerpVectors(startVector, endVector, t);
const direction = endVector.clone().sub(startVector);
const distance = direction.length();
direction.normalize();
const angle = Math.acos(
THREE.MathUtils.clamp(
direction.dot(character.gazeDir),
-1,
1
)
);
const inField = angle <= HALF_FOV + 0.015;
const clear = !blocked;
const visible = clear && inField;
const attended = clear && angle <= ATTENTION_ANGLE;
character.status[object.id] = {
blocked,
clear,
inField,
visible,
attended,
angle
};
const lineSet = character.sightLines[object.id];
if (blocked) {
lineSet.solid.material.color.setHex(COLORS.blocked);
lineSet.solid.material.opacity = 0.72;
lineSet.dashed.visible = true;
lineSet.marker.visible = true;
updateLine(lineSet.solid, startVector, hitVector);
updateLine(lineSet.dashed, hitVector, endVector);
lineSet.marker.position.copy(hitVector);
} else {
lineSet.solid.material.color.setHex(character.color);
lineSet.solid.material.opacity = character.id === "A" ? 0.7 : 0.62;
lineSet.dashed.visible = false;
lineSet.marker.visible = false;
updateLine(lineSet.solid, startVector, endVector);
}
lineSet.group.visible = showRays;
const ring = character.rings[object.id];
ring.visible = visible;
ring.material.opacity = attended ? 0.95 : 0.28;
ring.scale.setScalar(
(object.radius / 0.73) * (attended ? 1.09 : 1)
);
}
}
const selected = objectById[selectedObjectId];
selectionRing.position.set(
selected.group.position.x,
0.105,
selected.group.position.z
);
selectionRing.scale.setScalar(selected.radius / 0.88);
}
// -------------------------------------------------------------------------
// Interface
// -------------------------------------------------------------------------
const objectRows = document.getElementById("objectRows");
objectRows.innerHTML = objects
.map(
(object) => `
<tr id="row-${object.id}">
<td>
<button class="object-button" data-object="${object.id}" type="button">
${object.shortName}
<span>behind partition</span>
</button>
</td>
<td class="sight-cell" id="cell-A-${object.id}"></td>
<td class="sight-cell" id="cell-B-${object.id}"></td>
</tr>
`
)
.join("");
objectRows.addEventListener("click", (event) => {
const button = event.target.closest("[data-object]");
if (!button) return;
selectedObjectId = button.dataset.object;
updateUI();
});
function renderCell(state) {
if (state.blocked) {
return `
<span class="status blocked">BLOCKED</span>
<span class="cell-detail">
partition intersects ray${state.inField ? " · in field" : ""}
</span>
`;
}
if (state.visible) {
return `
<span class="status visible">VISIBLE</span>
<span class="cell-detail">
clear ray · ${state.attended ? "attending now" : "in gaze field"}
</span>
`;
}
return `
<span class="status clear">CLEAR / TURN</span>
<span class="cell-detail">
clear ray · outside current field
</span>
`;
}
function epistemicMarkup(record, kind) {
if (!record) {
return `
<div class="epistemic-row">
<strong>${kind === "knowledge" ? "Knowledge" : "Belief"}</strong>
<span style="color:#849197">No record</span>
</div>
`;
}
return `
<div class="epistemic-row">
<strong>${kind === "knowledge" ? "Knowledge" : "Belief"}</strong>
<span class="${kind}">
${record.text}
<small>${record.source}</small>
</span>
</div>
`;
}
function updateUI() {
document.getElementById("clock").textContent =
`t = ${elapsed.toFixed(1)} s`;
for (const character of characters) {
const id = character.id;
const lowerId = id.toLowerCase();
const visible = objects.filter(
(object) => character.status[object.id]?.visible
);
const attended = objects.filter(
(object) => character.status[object.id]?.attended
);
document.getElementById(`${lowerId}-yaw`).textContent =
`${THREE.MathUtils.radToDeg(character.headYaw).toFixed(0)}°`;
document.getElementById(`${lowerId}-focus`).textContent =
character.focusId
? objectById[character.focusId].shortName
: "Forward scan";
document.getElementById(`${lowerId}-visible`).textContent =
visible.length
? visible.map((object) => object.shortName).join(", ")
: "None";
document.getElementById(`${lowerId}-attention`).textContent =
attended.length
? attended.map((object) => object.shortName).join(", ")
: "None";
}
for (const object of objects) {
for (const character of characters) {
const cell = document.getElementById(
`cell-${character.id}-${object.id}`
);
cell.innerHTML = renderCell(
character.status[object.id]
);
}
document
.getElementById(`row-${object.id}`)
.classList.toggle("selected", object.id === selectedObjectId);
}
const selected = objectById[selectedObjectId];
document.getElementById("selectedTitle").textContent =
`${selected.name} · epistemic records`;
for (const character of characters) {
const lowerId = character.id.toLowerCase();
const record = epistemic[character.id][selectedObjectId];
document.getElementById(`${lowerId}-knowledge`).innerHTML =
epistemicMarkup(record.knowledge, "knowledge");
document.getElementById(`${lowerId}-belief`).innerHTML =
epistemicMarkup(record.belief, "belief");
}
}
// -------------------------------------------------------------------------
// Manual camera controls: orbit, zoom, keyboard, double-click reset
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.56,
phi: 0.98,
radius: 18.5,
target: new THREE.Vector3(0, 1.05, 0)
};
const defaultCamera = {
theta: 0.56,
phi: 0.98,
radius: 18.5
};
function updateCamera() {
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);
}
function resetCamera() {
cameraState.theta = defaultCamera.theta;
cameraState.phi = defaultCamera.phi;
cameraState.radius = defaultCamera.radius;
}
let dragging = false;
let pointerDown = null;
let pointerMoved = false;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerMoved = false;
pointerDown = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging && pointerDown) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 4) pointerMoved = true;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.45,
1.38
);
pointerDown = { x: event.clientX, y: event.clientY };
renderer.domElement.style.cursor = "grabbing";
} else {
renderer.domElement.style.cursor = hoverObject(event) ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
pointerDown = null;
renderer.domElement.style.cursor = "grab";
if (!pointerMoved) {
const object = pickObject(event);
if (object) {
selectedObjectId = object.id;
updateUI();
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerDown = null;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
27
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.theta -= 0.08;
if (event.key === "ArrowRight") cameraState.theta += 0.08;
if (event.key === "ArrowUp") {
cameraState.phi = Math.max(0.45, cameraState.phi - 0.06);
}
if (event.key === "ArrowDown") {
cameraState.phi = Math.min(1.38, cameraState.phi + 0.06);
}
if (event.key === "+" || event.key === "=") {
cameraState.radius = Math.max(10, cameraState.radius - 1);
}
if (event.key === "-") {
cameraState.radius = Math.min(27, cameraState.radius + 1);
}
if (event.key.toLowerCase() === "r") resetCamera();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const clickTargets = objects.map((object) => object.mesh);
function pickObject(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(clickTargets, false)[0];
return hit ? objectById[hit.object.userData.objectId] : null;
}
function hoverObject(event) {
return !!pickObject(event);
}
// -------------------------------------------------------------------------
// Buttons
// -------------------------------------------------------------------------
const pauseButton = document.getElementById("pauseBtn");
const raysButton = document.getElementById("raysBtn");
const conesButton = document.getElementById("conesBtn");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
document.getElementById("restartBtn").addEventListener("click", () => {
elapsed = 0;
for (const character of characters) {
character.desiredYaw = 0;
character.desiredPitch = 0;
character.headYaw = 0;
character.headPitch = 0;
}
updateUI();
});
raysButton.addEventListener("click", () => {
showRays = !showRays;
raysButton.classList.toggle("off", !showRays);
for (const character of characters) {
for (const object of objects) {
character.sightLines[object.id].group.visible = showRays;
}
}
});
conesButton.addEventListener("click", () => {
showCones = !showCones;
conesButton.classList.toggle("off", !showCones);
for (const character of characters) {
character.gazeGroup.visible = showCones;
}
});
document.getElementById("viewBtn").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
let lastTime = performance.now();
let lastUI = 0;
function animate(now) {
const dt = Math.min(0.05, (now - lastTime) / 1000);
lastTime = now;
if (!paused) elapsed += dt;
updateCharacters(dt);
updateSightStates();
updateCamera();
const pulse = 1 + Math.sin(now * 0.004) * 0.035;
selectionRing.scale.multiplyScalar(1);
const selected = objectById[selectedObjectId];
selectionRing.scale.setScalar((selected.radius / 0.88) * pulse);
if (now - lastUI > 100) {
updateUI();
lastUI = now;
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCharacters(1 / 60);
updateSightStates();
updateCamera();
updateUI();
document.getElementById("loading").remove();
requestAnimationFrame(animate);
</script>
</body>
</html>
```