Prompt specification
Build or customize the Three.js 3D scene "Confounder intervention explorer" 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: Confounder intervention explorer
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/confounder-intervention-explorer-x1784
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts confounding by a common causal variable. Use a declared toy causal model to compare observational filtering with intervening on one variable; label the model assumptions and avoid implying causation can be read directly from scatterplots. Low-poly.
Working Three.js Starter (confounder-intervention-explorer-x1784):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Common Cause, Two Worlds — Three.js Causal Model</title>
<style>
:root {
color-scheme: dark;
--bg: #07121b;
--panel: rgba(8, 24, 34, 0.92);
--line: rgba(137, 190, 207, 0.2);
--text: #edf7fa;
--muted: #91aeba;
--cyan: #50d5c0;
--orange: #ff865e;
--yellow: #ffd166;
--purple: #ad91ff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
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;
}
.hud {
position: fixed;
z-index: 10;
inset: 0 0 auto 0;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 24px;
padding: 24px 28px 60px;
pointer-events: none;
background: linear-gradient(180deg, rgba(7, 18, 27, 0.98), rgba(7, 18, 27, 0));
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 720px;
font-size: clamp(25px, 3.2vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 780;
}
.subtitle {
margin: 10px 0 0;
max-width: 680px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
pointer-events: auto;
}
button {
border: 1px solid var(--line);
border-radius: 7px;
padding: 9px 12px;
background: rgba(10, 30, 42, 0.88);
color: var(--muted);
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.035em;
cursor: pointer;
transition: 160ms ease;
}
button:hover,
button.active {
border-color: rgba(80, 213, 192, 0.7);
background: rgba(80, 213, 192, 0.13);
color: var(--text);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.contract {
position: fixed;
z-index: 10;
inset: auto 0 0;
min-height: 184px;
display: grid;
grid-template-columns: 1.12fr 1fr 0.86fr;
border-top: 1px solid var(--line);
background:
linear-gradient(90deg, rgba(80, 213, 192, 0.035), transparent 35%),
rgba(6, 18, 27, 0.96);
backdrop-filter: blur(14px);
}
.contract > section {
min-width: 0;
padding: 18px 24px 19px;
border-right: 1px solid var(--line);
}
.contract > section:last-child { border-right: 0; }
.section-title {
display: flex;
align-items: center;
gap: 9px;
margin: 0 0 11px;
color: var(--text);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title::before {
width: 7px;
height: 7px;
content: "";
border-radius: 2px;
background: var(--cyan);
transform: rotate(45deg);
}
.equation {
margin: 3px 0;
color: #dcebf0;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: clamp(10px, 0.88vw, 13px);
line-height: 1.55;
white-space: nowrap;
}
.equation b {
color: var(--cyan);
font-weight: 750;
}
.small {
margin: 8px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.assumptions {
margin: 0;
padding-left: 17px;
color: #b8ccd5;
font-size: 10.5px;
line-height: 1.52;
}
.assumptions li { margin: 2px 0; }
.readout {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.metric {
padding: 8px 9px;
border: 1px solid rgba(137, 190, 207, 0.13);
border-radius: 6px;
background: rgba(255, 255, 255, 0.025);
}
.metric .value {
display: block;
margin-bottom: 2px;
color: var(--text);
font-size: 19px;
font-weight: 800;
letter-spacing: -0.035em;
}
.metric .label {
display: block;
color: var(--muted);
font-size: 8.5px;
line-height: 1.25;
}
.metric.observed .value { color: var(--orange); }
.metric.intervention .value { color: var(--purple); }
.metric.effect .value { color: var(--yellow); }
.caution {
grid-column: 1 / -1;
margin-top: 2px;
padding: 8px 10px;
border-left: 2px solid var(--yellow);
background: rgba(255, 209, 102, 0.055);
color: #d8d1bd;
font-size: 9.5px;
line-height: 1.42;
}
.caution strong { color: var(--yellow); }
.hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 199px;
transform: translateX(-50%);
color: rgba(181, 209, 219, 0.58);
font-size: 9px;
letter-spacing: 0.08em;
pointer-events: none;
text-transform: uppercase;
}
.loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: var(--bg);
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 900px) {
.hud {
padding: 17px 17px 48px;
}
.subtitle { max-width: 500px; }
.controls {
max-width: 180px;
}
.contract {
max-height: 42vh;
grid-template-columns: 1fr;
overflow-y: auto;
}
.contract > section {
padding: 14px 17px;
border-right: 0;
border-bottom: 1px solid var(--line);
}
.hint { display: none; }
}
@media (max-width: 580px) {
.hud {
display: block;
}
.controls {
justify-content: flex-start;
margin-top: 14px;
}
.subtitle { font-size: 11px; }
}
</style>
</head>
<body>
<div class="loading" id="loading">Building the causal worlds…</div>
<header class="hud">
<div>
<div class="eyebrow">Causal inference lab · declared toy model</div>
<h1>Common cause,<br />two different questions.</h1>
<p class="subtitle">
Conditioning on <b>X = 1</b> selects a different mix of hidden causes.
The intervention <b>do(X = 1)</b> changes X’s mechanism instead.
</p>
</div>
<div class="controls" aria-label="Scene controls">
<button class="active" data-mode="compare">Compare</button>
<button data-mode="observe">Observed filter</button>
<button data-mode="intervene">Intervention</button>
<button id="resetCamera">Reset view</button>
</div>
</header>
<footer class="contract" aria-label="Declared model and assumptions">
<section>
<h2 class="section-title">Declared structural model</h2>
<div class="equation"><b>C</b> ~ Bernoulli(0.50)</div>
<div class="equation"><b>X</b> | C ~ Bernoulli(logit⁻¹(−2.20 + 4.39C))</div>
<div class="equation"><b>Y</b> = 4.00 + 1.10X + 1.80C + ε, ε ~ N(0,1)</div>
<p class="small">
Edges: C → X, C → Y, X → Y. Synthetic samples: n = 5,000.
</p>
</section>
<section>
<h2 class="section-title">Model assumptions</h2>
<ol class="assumptions">
<li>The causal graph is specified before examining the data.</li>
<li>C contains every common cause of X and Y in this toy model.</li>
<li>The structural equations remain stable across regimes.</li>
<li>do(X = 1) replaces X’s equation and cuts the incoming C → X edge.</li>
<li>Positivity holds: P(X = 1 | C = 0) = 0.10 and P(X = 1 | C = 1) = 0.90.</li>
</ol>
</section>
<section>
<h2 class="section-title">Model readouts</h2>
<div class="readout">
<div class="metric observed">
<span class="value">6.72</span>
<span class="label">E[Y | X = 1]<br />observational filter</span>
</div>
<div class="metric intervention">
<span class="value">6.00</span>
<span class="label">E[Y | do(X = 1)]<br />intervention</span>
</div>
<div class="metric effect">
<span class="value">+1.10</span>
<span class="label">assumed effect of X<br />holding C fixed</span>
</div>
<div class="metric">
<span class="value">0.90 / 0.50</span>
<span class="label">P(C = 1): filtered / do-world</span>
</div>
<div class="caution">
<strong>Do not read causality from the picture.</strong>
The visuals are descriptive simulations. The +1.10 effect comes from the
declared equations—not from association in a histogram or scatterplot.
The 0.72 observed-vs-do gap reflects a different C mixture.
</div>
</div>
</section>
</footer>
<div class="hint">Drag to orbit · scroll to zoom · double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.querySelector("#loading");
// ---------------------------------------------------------------------
// Renderer, camera, lighting
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07121b);
scene.fog = new THREE.Fog(0x07121b, 18, 38);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, -0.05, 0);
let yaw = -0.055;
let pitch = 0.115;
let radius = 12.8;
let userZoomed = false;
function updateCamera() {
const horizontal = radius * Math.cos(pitch);
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + radius * Math.sin(pitch),
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
}
function resetCamera() {
yaw = -0.055;
pitch = 0.115;
radius = window.innerWidth / window.innerHeight < 0.9 ? 25 : 12.8;
userZoomed = false;
updateCamera();
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xbdefff, 0x10202b, 2.1));
const key = new THREE.DirectionalLight(0xfff1db, 3.2);
key.position.set(-5, 10, 8);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -12;
key.shadow.camera.right = 12;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 1;
key.shadow.camera.far = 30;
scene.add(key);
const rim = new THREE.DirectionalLight(0x6ee7d5, 1.25);
rim.position.set(8, 3, -8);
scene.add(rim);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(48, 32),
new THREE.MeshStandardMaterial({
color: 0x081923,
roughness: 0.95,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.76;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x245062, 0x17313e);
grid.position.y = -2.745;
grid.material.transparent = true;
grid.material.opacity = 0.35;
scene.add(grid);
// ---------------------------------------------------------------------
// Low-poly helpers
// ---------------------------------------------------------------------
const allLabels = [];
function roundedRectPath(ctx, x, y, w, h, r) {
r = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(
text,
{
width = 2.5,
color = "#edf7fa",
background = "rgba(7,18,27,0.80)",
border = "rgba(137,190,207,0.18)",
fontSize = 48,
weight = 700,
align = "center"
} = {}
) {
const lines = text.split("\n");
const font = `${weight} ${fontSize}px Inter, Arial, sans-serif`;
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
ctx.font = font;
const textWidth = Math.max(
...lines.map((line) => ctx.measureText(line).width)
);
const lineHeight = fontSize * 1.18;
const paddingX = 24;
const paddingY = 16;
canvas.width = Math.ceil(textWidth + paddingX * 2);
canvas.height = Math.ceil(lines.length * lineHeight + paddingY * 2);
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (background) {
roundedRectPath(
ctx, 2, 2, canvas.width - 4, canvas.height - 4, 15
);
ctx.fillStyle = background;
ctx.fill();
if (border) {
ctx.strokeStyle = border;
ctx.lineWidth = 2;
ctx.stroke();
}
}
ctx.font = font;
ctx.fillStyle = color;
ctx.textBaseline = "middle";
ctx.textAlign = align;
lines.forEach((line, i) => {
const x = align === "center"
? canvas.width / 2
: align === "left"
? paddingX
: canvas.width - paddingX;
const y = paddingY + lineHeight * (i + 0.5);
ctx.fillText(line, x, y);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(
width,
width * canvas.height / canvas.width,
1
);
sprite.renderOrder = 20;
allLabels.push(sprite);
return sprite;
}
function makePanel(width, height, accent) {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.BoxGeometry(width, height, 0.18),
new THREE.MeshStandardMaterial({
color: 0x0d2532,
emissive: 0x07151e,
emissiveIntensity: 0.35,
roughness: 0.84,
metalness: 0.05
})
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
new THREE.LineBasicMaterial({
color: accent,
transparent: true,
opacity: 0.34
})
);
group.add(edges);
const topRule = new THREE.Mesh(
new THREE.BoxGeometry(width - 0.18, 0.055, 0.22),
new THREE.MeshStandardMaterial({
color: accent,
emissive: accent,
emissiveIntensity: 0.35,
roughness: 0.5
})
);
topRule.position.set(0, height / 2 - 0.11, 0.12);
group.add(topRule);
return group;
}
function makeArrow(start, control, end, color, radius = 0.027) {
const curve = new THREE.QuadraticBezierCurve3(start, control, end);
const group = new THREE.Group();
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 14, radius, 5, false),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.18,
roughness: 0.65
})
);
tube.castShadow = true;
group.add(tube);
const tip = new THREE.Mesh(
new THREE.ConeGeometry(radius * 4.3, radius * 10, 6),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.12,
roughness: 0.55
})
);
tip.position.copy(end);
tip.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
curve.getTangent(1).normalize()
);
group.add(tip);
return group;
}
function makeNode(color, radius = 0.34) {
const group = new THREE.Group();
const node = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 0),
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.2,
flatShading: true,
roughness: 0.48,
metalness: 0.08
})
);
node.castShadow = true;
group.add(node);
const collar = new THREE.Mesh(
new THREE.TorusGeometry(radius * 1.22, 0.025, 5, 16),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.42
})
);
group.add(collar);
return group;
}
// ---------------------------------------------------------------------
// Deterministic synthetic data from the declared model
// ---------------------------------------------------------------------
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = mulberry32(20250308);
function normal() {
let u = 0;
let v = 0;
while (u === 0) u = random();
while (v === 0) v = random();
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
}
const observational = [];
const interventional = [];
for (let i = 0; i < 5000; i++) {
const c = random() < 0.5 ? 0 : 1;
const probabilityX1 = c === 1 ? 0.9 : 0.1;
const x = random() < probabilityX1 ? 1 : 0;
const y = 4 + 1.1 * x + 1.8 * c + normal();
if (x === 1) observational.push({ c, y });
// do(X = 1): preserve C's distribution and replace X's equation.
const doY = 4 + 1.1 + 1.8 * c + normal();
interventional.push({ c, y: doY });
}
function histogram(data, bins = 12, min = 2.5, max = 8.5) {
const result = Array.from({ length: bins }, () => ({ c0: 0, c1: 0 }));
const width = (max - min) / bins;
for (const row of data) {
const index = Math.max(
0,
Math.min(bins - 1, Math.floor((row.y - min) / width))
);
result[index][row.c === 1 ? "c1" : "c0"]++;
}
return result;
}
// ---------------------------------------------------------------------
// Declared causal graph
// ---------------------------------------------------------------------
const graphGroup = new THREE.Group();
graphGroup.position.x = -5.25;
scene.add(graphGroup);
const graphPanel = makePanel(3.95, 4.72, 0x50d5c0);
graphGroup.add(graphPanel);
const graphTitle = makeLabel("DECLARED GRAPH", {
width: 2.95,
color: "#eaf7f8",
fontSize: 46
});
graphTitle.position.set(0, 1.92, 0.32);
graphGroup.add(graphTitle);
const graphSubtitle = makeLabel("arrows come from the model, not the data", {
width: 3.3,
color: "#91aeba",
background: "rgba(7,18,27,0.25)",
border: null,
fontSize: 35,
weight: 550
});
graphSubtitle.position.set(0, 1.49, 0.34);
graphGroup.add(graphSubtitle);
const cPosition = new THREE.Vector3(-0.93, 0.55, 0.38);
const xPosition = new THREE.Vector3(0.95, -0.05, 0.38);
const yPosition = new THREE.Vector3(-0.93, -1.18, 0.38);
const cNode = makeNode(0x50d5c0);
cNode.position.copy(cPosition);
graphGroup.add(cNode);
const xNode = makeNode(0xff865e);
xNode.position.copy(xPosition);
graphGroup.add(xNode);
const yNode = makeNode(0xffd166);
yNode.position.copy(yPosition);
graphGroup.add(yNode);
graphGroup.add(
makeArrow(
cPosition,
new THREE.Vector3(-0.08, 0.62, 0.3),
xPosition,
0x79aebe,
0.025
)
);
graphGroup.add(
makeArrow(
cPosition,
new THREE.Vector3(-0.93, -0.31, 0.3),
yPosition,
0x50d5c0,
0.025
)
);
graphGroup.add(
makeArrow(
xPosition,
new THREE.Vector3(0.24, -1.25, 0.3),
yPosition,
0xff865e,
0.025
)
);
const cLabel = makeLabel("C\ncommon cause", {
width: 1.38,
color: "#71ead9",
fontSize: 40
});
cLabel.position.set(-1.30, 1.03, 0.56);
graphGroup.add(cLabel);
const xLabel = makeLabel("X\nexposure", {
width: 1.32,
color: "#ff9c7b",
fontSize: 40
});
xLabel.position.set(1.08, 0.42, 0.56);
graphGroup.add(xLabel);
const yLabel = makeLabel("Y\noutcome", {
width: 1.35,
color: "#ffe08e",
fontSize: 40
});
yLabel.position.set(-1.28, -1.62, 0.56);
graphGroup.add(yLabel);
const graphFoot = makeLabel("C → X → Y + C → Y", {
width: 2.75,
color: "#c6dbe2",
background: "rgba(7,18,27,0.3)",
border: null,
fontSize: 39
});
graphFoot.position.set(0, -2.03, 0.55);
graphGroup.add(graphFoot);
// ---------------------------------------------------------------------
// Outcome card construction
// ---------------------------------------------------------------------
function buildOutcomeCard({
x,
title,
subtitle,
accent,
data,
probabilityC1,
modelMean,
meanText,
positionName
}) {
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
const panel = makePanel(4.3, 4.72, accent);
group.add(panel);
const titleSprite = makeLabel(title, {
width: 3.5,
color: "#eef8fa",
fontSize: 45
});
titleSprite.position.set(0, 1.93, 0.34);
group.add(titleSprite);
const subtitleSprite = makeLabel(subtitle, {
width: 3.55,
color: "#9bb4c0",
background: "rgba(7,18,27,0.24)",
border: null,
fontSize: 34,
weight: 550
});
subtitleSprite.position.set(0, 1.5, 0.35);
group.add(subtitleSprite);
// Composition of C within the displayed population.
const barWidth = 3.42;
const barY = 1.12;
const c0Width = barWidth * (1 - probabilityC1);
const c0Bar = new THREE.Mesh(
new THREE.BoxGeometry(c0Width, 0.16, 0.22),
new THREE.MeshStandardMaterial({
color: 0x2d6577,
roughness: 0.75
})
);
c0Bar.position.set(-barWidth / 2 + c0Width / 2, barY, 0.28);
group.add(c0Bar);
const c1Bar = new THREE.Mesh(
new THREE.BoxGeometry(barWidth - c0Width, 0.16, 0.22),
new THREE.MeshStandardMaterial({
color: 0x50d5c0,
emissive: 0x174d48,
emissiveIntensity: 0.2,
roughness: 0.7
})
);
c1Bar.position.set(
-barWidth / 2 + c0Width + (barWidth - c0Width) / 2,
barY,
0.28
);
group.add(c1Bar);
const c0Text = makeLabel(`C = 0 ${Math.round((1 - probabilityC1) * 100)}%`, {
width: 1.45,
color: "#8eb4c1",
background: "rgba(7,18,27,0.22)",
border: null,
fontSize: 34,
weight: 650
});
c0Text.position.set(-1.08, 0.82, 0.4);
group.add(c0Text);
const c1Text = makeLabel(`C = 1 ${Math.round(probabilityC1 * 100)}%`, {
width: 1.45,
color: "#71ead9",
background: "rgba(7,18,27,0.22)",
border: null,
fontSize: 34,
weight: 650
});
c1Text.position.set(1.05, 0.82, 0.4);
group.add(c1Text);
// Stacked low-poly histogram. Bar color identifies the latent C group.
const bins = histogram(data);
const maxCount = Math.max(...bins.map((b) => b.c0 + b.c1));
const baseline = -1.63;
const chartHeight = 1.62;
const barSpacing = 0.32;
const barWidthLocal = 0.255;
bins.forEach((bin, i) => {
const total = bin.c0 + bin.c1;
const totalHeight = total / maxCount * chartHeight;
const h0 = total ? bin.c0 / total * totalHeight : 0;
const h1 = total ? bin.c1 / total * totalHeight : 0;
const localX = (i - (bins.length - 1) / 2) * barSpacing;
if (h0 > 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(barWidthLocal, h0, 0.24),
new THREE.MeshStandardMaterial({
color: 0x2d6577,
roughness: 0.8
})
);
mesh.position.set(localX, baseline + h0 / 2, 0.27);
mesh.castShadow = true;
group.add(mesh);
}
if (h1 > 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(barWidthLocal, h1, 0.24),
new THREE.MeshStandardMaterial({
color: 0x50d5c0,
emissive: 0x123f3c,
emissiveIntensity: 0.22,
roughness: 0.72
})
);
mesh.position.set(localX, baseline + h0 + h1 / 2, 0.27);
mesh.castShadow = true;
group.add(mesh);
}
});
// Baseline and mean marker.
const baselineMesh = new THREE.Mesh(
new THREE.BoxGeometry(3.82, 0.025, 0.26),
new THREE.MeshBasicMaterial({ color: 0x557482 })
);
baselineMesh.position.set(0, baseline, 0.31);
group.add(baselineMesh);
const outcomeMin = 2.5;
const outcomeMax = 8.5;
const meanY = baseline + (modelMean - outcomeMin) / (outcomeMax - outcomeMin) * chartHeight;
const meanLine = new THREE.Mesh(
new THREE.BoxGeometry(3.78, 0.035, 0.30),
new THREE.MeshBasicMaterial({ color: accent })
);
meanLine.position.set(0, meanY, 0.40);
group.add(meanLine);
const meanLabel = makeLabel(meanText, {
width: 1.65,
color: accent === 0xff865e ? "#ffac91" : "#c6b5ff",
background: "rgba(7,18,27,0.92)",
border: `rgba(${accent === 0xff865e ? "255,134,94" : "173,145,255"},0.45)`,
fontSize: 34,
weight: 750
});
meanLabel.position.set(1.0, meanY + 0.17, 0.52);
group.add(meanLabel);
const legend = makeLabel("bar color = latent C · descriptive only", {
width: 3.35,
color: "#8eaab7",
background: "rgba(7,18,27,0.18)",
border: null,
fontSize: 31,
weight: 550
});
legend.position.set(0, -2.05, 0.52);
group.add(legend);
const axisLabel = makeLabel("Y", {
width: 0.42,
color: "#d8e8ed",
background: null,
border: null,
fontSize: 45
});
axisLabel.position.set(-1.93, -1.35, 0.46);
group.add(axisLabel);
const question = makeLabel(positionName, {
width: 3.15,
color: "#bdd2d9",
background: "rgba(7,18,27,0.22)",
border: null,
fontSize: 33,
weight: 600
});
question.position.set(0, -2.34, 0.53);
group.add(question);
return group;
}
const observedGroup = buildOutcomeCard({
x: -0.25,
title: "OBSERVE / FILTER",
subtitle: "condition on the observed rows X = 1",
accent: 0xff865e,
data: observational,
probabilityC1: 0.90,
modelMean: 6.72,
meanText: "model mean\n6.72",
positionName: "P(Y | X = 1) — selection changed C"
});
const interventionGroup = buildOutcomeCard({
x: 5.05,
title: "INTERVENE / do(X = 1)",
subtitle: "replace X’s equation and cut C → X",
accent: 0xad91ff,
data: interventional,
probabilityC1: 0.50,
modelMean: 6.00,
meanText: "model mean\n6.00",
positionName: "P(Y | do(X = 1)) — C keeps its prior"
});
// A small divider reinforces that these are different estimands.
const divider = new THREE.Mesh(
new THREE.OctahedronGeometry(0.14, 0),
new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x5a4211,
emissiveIntensity: 0.4,
flatShading: true
})
);
divider.position.set(2.39, 0.05, 0.45);
scene.add(divider);
const dividerLabel = makeLabel("≠", {
width: 0.48,
color: "#ffd166",
background: "rgba(7,18,27,0.85)",
border: null,
fontSize: 52
});
dividerLabel.position.set(2.39, -0.37, 0.55);
scene.add(dividerLabel);
// ---------------------------------------------------------------------
// Direct camera controls: pointer drag and wheel zoom
// ---------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
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;
yaw -= dx * 0.0045;
pitch = THREE.MathUtils.clamp(pitch + dy * 0.0035, -0.12, 0.5);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius + event.deltaY * 0.008,
8.5,
38
);
userZoomed = true;
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
document.querySelector("#resetCamera").addEventListener("click", resetCamera);
// View buttons change which stations are shown.
const modeButtons = [...document.querySelectorAll("[data-mode]")];
modeButtons.forEach((button) => {
button.addEventListener("click", () => {
modeButtons.forEach((b) => b.classList.remove("active"));
button.classList.add("active");
const mode = button.dataset.mode;
graphGroup.visible = mode === "compare";
observedGroup.visible = mode !== "intervene";
interventionGroup.visible = mode !== "observe";
if (mode === "observe") {
target.set(-2.7, -0.05, 0);
} else if (mode === "intervene") {
target.set(5.05, -0.05, 0);
} else {
target.set(0, -0.05, 0);
}
updateCamera();
});
});
// ---------------------------------------------------------------------
// Resize and animation
// ---------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
if (!userZoomed) {
radius = width / height < 0.9 ? 25 : 12.8;
updateCamera();
}
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
const t = clock.getElapsedTime();
// Subtle low-poly idle motion; no animated arrows imply inferred causality.
cNode.rotation.y = t * 0.22;
cNode.rotation.x = t * 0.09;
xNode.rotation.y = -t * 0.18;
yNode.rotation.y = t * 0.15;
divider.rotation.y = t * 0.45;
divider.position.y = 0.05 + Math.sin(t * 1.3) * 0.045;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
animate();
</script>
</body>
</html>
```