Prompt specification
Build or customize the Three.js 3D scene "Tissue connectivity exploration table" 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: Tissue connectivity exploration table
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tissue-connectivity-exploration-table-x0816
Scene Description Prompt:
Explore barrier, mechanical, and signaling connections between low-poly toy cells, with each junction function displayed separately. Three.js from cdnjs in one HTML file.
Working Three.js Starter (tissue-connectivity-exploration-table-x0816):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Junction Workshop — Toy Cell Connections</title>
<style>
:root {
--ink: #24343b;
--muted: #6d7e84;
--paper: rgba(255, 255, 255, 0.9);
--line: rgba(54, 76, 83, 0.13);
--barrier: #ef7d5b;
--mechanical: #dfa92f;
--signaling: #25a4b5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #edf3f1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 3px solid rgba(37, 164, 181, 0.34);
outline-offset: 2px;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.hero {
position: fixed;
z-index: 8;
top: 24px;
left: 26px;
max-width: 470px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 7px;
color: #60747b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 3px;
border-radius: 999px;
background: var(--signaling);
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 42px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 850;
}
.hero p {
margin: 10px 0 0;
color: #6c7c82;
font-size: 12px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 15px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(51, 72, 79, 0.1);
border-radius: 999px;
background: rgba(255, 255, 255, 0.68);
color: #61737a;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.03em;
backdrop-filter: blur(12px);
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 0 3px color-mix(in srgb, var(--dot), transparent 78%);
}
.view-tools {
position: fixed;
z-index: 12;
top: 24px;
right: 24px;
display: flex;
gap: 7px;
padding: 6px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.84);
box-shadow: 0 14px 40px rgba(57, 76, 81, 0.11);
backdrop-filter: blur(18px);
}
.tool-button {
min-height: 34px;
padding: 0 11px;
border: 0;
border-radius: 9px;
background: transparent;
color: #52666d;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: 160ms ease;
}
.tool-button:hover {
background: #eef4f2;
color: #1f3238;
}
.tool-button.primary {
background: #263b42;
color: white;
}
.tool-button.primary:hover {
background: #35515a;
}
#inspector {
position: fixed;
z-index: 10;
top: 88px;
right: 24px;
bottom: 24px;
width: 360px;
padding: 22px;
overflow: auto;
border: 1px solid var(--line);
border-radius: 22px;
background: var(--paper);
box-shadow: 0 24px 70px rgba(57, 76, 81, 0.16);
backdrop-filter: blur(22px);
scrollbar-width: thin;
}
.inspector-kicker {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.type-pill {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--type-color);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.type-pill::before {
content: "";
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--type-color);
transform: rotate(45deg);
}
.junction-code {
color: #95a2a6;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
}
#detail-title {
margin: 0;
font-size: 29px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.route {
display: flex;
align-items: center;
gap: 8px;
margin: 17px 0;
}
.route-cell {
flex: 1;
min-width: 0;
padding: 9px 10px;
border: 1px solid #e1e9e7;
border-radius: 11px;
background: #f7faf9;
}
.route-cell small {
display: block;
margin-bottom: 2px;
color: #9aa8ac;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
}
.route-cell strong {
display: block;
overflow: hidden;
color: #3f555d;
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.route-arrow {
color: var(--type-color);
font-size: 20px;
font-weight: 800;
}
#detail-function {
margin: 0;
color: #596c73;
font-size: 13px;
line-height: 1.62;
}
.section-label {
margin: 21px 0 9px;
color: #8a999e;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.function-path {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 6px;
}
.function-step {
position: relative;
min-height: 92px;
padding: 10px;
border: 1px solid #e3ebe9;
border-radius: 11px;
background: #f8faf9;
}
.function-step:not(:last-child)::after {
content: "›";
position: absolute;
top: 36px;
right: -7px;
z-index: 2;
width: 14px;
height: 18px;
border-radius: 50%;
background: white;
color: var(--type-color);
font-size: 16px;
font-weight: 900;
text-align: center;
}
.function-step small {
display: block;
margin-bottom: 6px;
color: var(--type-color);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.function-step span {
display: block;
color: #53666d;
font-size: 10px;
line-height: 1.42;
}
.analogy {
margin-top: 14px;
padding: 13px 14px;
border-left: 3px solid var(--type-color);
border-radius: 4px 11px 11px 4px;
background: color-mix(in srgb, var(--type-color), white 91%);
color: #5b6e74;
font-size: 11px;
line-height: 1.55;
}
.meta-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.meta-item {
padding: 10px;
border: 1px solid #e5ecea;
border-radius: 10px;
background: rgba(247, 250, 249, 0.75);
}
.meta-item small {
display: block;
margin-bottom: 3px;
color: #9aa7ab;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.meta-item strong {
color: #485f66;
font-size: 10px;
font-weight: 750;
}
.state-line {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 15px 0 11px;
padding: 10px 12px;
border: 1px solid #e2eae8;
border-radius: 11px;
background: #f8faf9;
}
.state-line span:first-child {
color: #8a999e;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#junction-state {
color: #52666d;
font-size: 11px;
font-weight: 850;
}
#junction-state.active {
color: var(--type-color);
}
.inspector-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.inspector-actions button {
min-height: 42px;
border-radius: 11px;
font-size: 11px;
font-weight: 850;
cursor: pointer;
transition: 160ms ease;
}
.inspector-actions .primary {
border: 0;
background: var(--type-color);
color: white;
box-shadow: 0 7px 18px color-mix(in srgb, var(--type-color), transparent 72%);
}
.inspector-actions .primary:hover {
filter: brightness(0.94);
transform: translateY(-1px);
}
.inspector-actions .secondary {
border: 1px solid #dce6e3;
background: white;
color: #50666d;
}
.inspector-actions .secondary:hover {
background: #f2f7f5;
}
#dock {
position: fixed;
z-index: 9;
right: 408px;
bottom: 24px;
left: 24px;
max-width: 1180px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 20px;
background: rgba(255, 255, 255, 0.82);
box-shadow: 0 20px 55px rgba(57, 76, 81, 0.13);
backdrop-filter: blur(20px);
}
.dock-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-bottom: 11px;
}
.dock-title {
display: flex;
align-items: baseline;
gap: 8px;
white-space: nowrap;
}
.dock-title strong {
font-size: 13px;
letter-spacing: -0.01em;
}
.dock-title span {
color: #93a1a5;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.filters {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 5px;
}
.filter-button {
min-height: 29px;
padding: 0 10px;
border: 1px solid transparent;
border-radius: 999px;
background: #f0f5f3;
color: #76868b;
font-size: 9px;
font-weight: 850;
cursor: pointer;
transition: 160ms ease;
}
.filter-button:hover,
.filter-button.active {
border-color: var(--filter-color, #455f67);
background: var(--filter-color, #455f67);
color: white;
}
.cards {
display: flex;
gap: 9px;
overflow-x: auto;
padding: 1px 1px 5px;
scrollbar-width: thin;
scrollbar-color: #c6d2cf transparent;
}
.junction-card {
flex: 0 0 178px;
min-height: 123px;
padding: 12px;
border: 1px solid #e2eae8;
border-radius: 13px;
background: #fbfcfc;
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 180ms ease;
}
.junction-card:hover {
transform: translateY(-2px);
border-color: color-mix(in srgb, var(--card-color), white 48%);
box-shadow: 0 8px 20px rgba(58, 77, 82, 0.08);
}
.junction-card.selected {
border-color: var(--card-color);
background: color-mix(in srgb, var(--card-color), white 91%);
box-shadow: inset 3px 0 0 var(--card-color);
}
.junction-card[hidden] {
display: none;
}
.card-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
}
.card-id {
color: var(--card-color);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
}
.card-type {
color: #9aa7ab;
font-size: 8px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.junction-card h3 {
margin: 0 0 5px;
font-size: 12px;
letter-spacing: -0.015em;
}
.card-function {
margin: 0;
color: #72838a;
font-size: 9px;
line-height: 1.48;
}
.junction-tag {
position: absolute;
z-index: 4;
min-width: 29px;
height: 29px;
padding: 0 7px;
border: 2px solid white;
border-radius: 999px;
background: var(--tag-color);
color: white;
box-shadow: 0 5px 15px color-mix(in srgb, var(--tag-color), transparent 64%);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.04em;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -50%);
transition: 160ms ease;
}
.junction-tag:hover,
.junction-tag.selected {
box-shadow: 0 0 0 5px color-mix(in srgb, var(--tag-color), transparent 83%),
0 6px 16px color-mix(in srgb, var(--tag-color), transparent 64%);
}
.cell-label {
position: absolute;
z-index: 2;
padding: 4px 7px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.72);
color: #64767d;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.13em;
pointer-events: none;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #edf3f1;
color: #62777e;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 1120px) {
#inspector {
width: 330px;
}
#dock {
right: 378px;
}
.hero {
max-width: 410px;
}
}
@media (max-width: 820px) {
.hero {
top: 17px;
left: 16px;
}
.hero p,
.legend {
display: none;
}
.view-tools {
top: 76px;
right: auto;
left: 12px;
}
#inspector {
top: 77px;
right: 12px;
bottom: auto;
width: min(350px, calc(100vw - 24px));
max-height: 46vh;
padding: 18px;
}
#dock {
right: 12px;
bottom: 12px;
left: 12px;
padding: 11px;
}
.dock-head {
align-items: flex-start;
flex-direction: column;
gap: 8px;
}
.filters {
justify-content: flex-start;
}
.cell-label {
display: none;
}
}
@media (max-width: 520px) {
h1 {
font-size: 27px;
}
#inspector {
top: 122px;
max-height: 35vh;
}
.view-tools {
top: 76px;
left: 12px;
}
.tool-button {
padding: 0 8px;
font-size: 9px;
}
.junction-card {
flex-basis: 164px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D toy-cell junction network"></canvas>
<div id="labels"></div>
<header class="hero">
<div class="eyebrow">Cellular Toy Lab / Junction Study</div>
<h1>Junction Workshop</h1>
<p>Drag to orbit · Scroll to zoom · Select a numbered junction to inspect its function.</p>
<div class="legend" aria-label="Connection types">
<div class="legend-item" style="--dot: var(--barrier)">
<span class="legend-dot"></span>Barrier
</div>
<div class="legend-item" style="--dot: var(--mechanical)">
<span class="legend-dot"></span>Mechanical
</div>
<div class="legend-item" style="--dot: var(--signaling)">
<span class="legend-dot"></span>Signaling
</div>
</div>
</header>
<div class="view-tools" aria-label="View controls">
<button class="tool-button" id="reset-view" type="button">Reset view</button>
<button class="tool-button" id="top-view" type="button">Top view</button>
<button class="tool-button primary" id="run-all" type="button">Run all</button>
</div>
<aside id="inspector" aria-live="polite">
<div class="inspector-kicker">
<span class="type-pill" id="type-pill">Barrier</span>
<span class="junction-code" id="junction-code">J01 / BARRIER</span>
</div>
<h2 id="detail-title">Dock seal</h2>
<div class="route" style="--type-color: var(--barrier)">
<div class="route-cell">
<small>From</small>
<strong id="from-cell">Sensor</strong>
</div>
<div class="route-arrow">→</div>
<div class="route-cell">
<small>To</small>
<strong id="to-cell">Launcher</strong>
</div>
</div>
<p id="detail-function"></p>
<div class="section-label">Function path</div>
<div class="function-path" id="function-path"></div>
<div class="analogy" id="analogy"></div>
<div class="section-label">Connection properties</div>
<div class="meta-grid">
<div class="meta-item">
<small>Transfer mode</small>
<strong id="transfer-mode"></strong>
</div>
<div class="meta-item">
<small>Response</small>
<strong id="response-mode"></strong>
</div>
<div class="meta-item">
<small>Span</small>
<strong id="junction-span"></strong>
</div>
<div class="meta-item">
<small>Dependency</small>
<strong id="junction-dependency"></strong>
</div>
</div>
<div class="state-line">
<span>Current state</span>
<strong id="junction-state"></strong>
</div>
<div class="inspector-actions">
<button class="primary" id="actuate" type="button">Actuate</button>
<button class="secondary" id="focus-junction" type="button">Focus junction</button>
</div>
</aside>
<section id="dock" aria-label="Junction atlas">
<div class="dock-head">
<div class="dock-title">
<strong>Junction atlas</strong>
<span id="visible-count">7 connections</span>
</div>
<div class="filters" role="group" aria-label="Filter junction type">
<button class="filter-button active" data-filter="all" type="button">All</button>
<button
class="filter-button"
data-filter="barrier"
style="--filter-color: var(--barrier)"
type="button"
>Barrier · 2</button>
<button
class="filter-button"
data-filter="mechanical"
style="--filter-color: var(--mechanical)"
type="button"
>Mechanical · 3</button>
<button
class="filter-button"
data-filter="signaling"
style="--filter-color: var(--signaling)"
type="button"
>Signaling · 3</button>
</div>
</div>
<div class="cards" id="cards"></div>
</section>
<div id="loading">Assembling toy cells…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const TYPE = {
barrier: {
label: "Barrier",
color: "#ef7d5b",
glyph: "▥"
},
mechanical: {
label: "Mechanical",
color: "#dfa92f",
glyph: "↔"
},
signaling: {
label: "Signaling",
color: "#25a4b5",
glyph: "≋"
}
};
const CELL_SPECS = [
{
id: "A",
name: "Sensor",
role: "input cell",
color: "#f3a58f",
accent: "#bd5c49",
position: [-4.5, 0, -2.8]
},
{
id: "B",
name: "Launcher",
role: "signal cell",
color: "#f4cf79",
accent: "#b98a18",
position: [0, 0, -2.8]
},
{
id: "C",
name: "Receiver",
role: "target cell",
color: "#72cbd5",
accent: "#238f9d",
position: [4.5, 0, -2.8]
},
{
id: "D",
name: "Actuator",
role: "moving cell",
color: "#85d5a4",
accent: "#3a9b64",
position: [-4.5, 0, 2.8]
},
{
id: "E",
name: "Coupler",
role: "middle cell",
color: "#b6a2e8",
accent: "#7057b5",
position: [0, 0, 2.8]
},
{
id: "F",
name: "Builder",
role: "output cell",
color: "#f3ad70",
accent: "#b8662e",
position: [4.5, 0, 2.8]
}
];
const JUNCTION_SPECS = [
{
id: "J01",
type: "barrier",
from: "A",
to: "B",
title: "Dock seal",
function: "Blocks cargo until a matched latch opens.",
input: "Cargo tile arrives at Sensor.",
transfer: "Opposing teeth form a physical stop.",
output: "The tile cannot enter Launcher.",
analogy: "A little orange gate that clicks shut between two toy rooms.",
transferMode: "Physical contact",
responseMode: "Binary / gated",
span: "2.3 toy units",
dependency: "Aligned latches",
offState: "Sealed",
onState: "Gate open",
startAction: "Open gate",
stopAction: "Close gate"
},
{
id: "J02",
type: "signaling",
from: "B",
to: "C",
title: "Ligand bead",
function: "Carries a released signal across the gap without direct contact.",
input: "Launcher releases a tagged signal bead.",
transfer: "The bead follows a soluble path.",
output: "Receiver captures it and changes state.",
analogy: "Rolling a blue marble from one room into a catch cup.",
transferMode: "Diffusion / ligand",
responseMode: "Chemical trigger",
span: "2.3 toy units",
dependency: "Matching receptor",
offState: "Quiet",
onState: "Pulse active",
startAction: "Send pulse",
stopAction: "Stop pulse"
},
{
id: "J03",
type: "mechanical",
from: "D",
to: "E",
title: "Push beam",
function: "Transfers force directly so both cells move in lockstep.",
input: "Actuator rotates its drive cam.",
transfer: "A rigid beam carries the push.",
output: "Coupler pivots at the same moment.",
analogy: "Two blocks joined by a stiff yellow plastic rod.",
transferMode: "Rigid force",
responseMode: "Continuous motion",
span: "2.3 toy units",
dependency: "Physical linkage",
offState: "Resting",
onState: "Extended",
startAction: "Extend piston",
stopAction: "Retract piston"
},
{
id: "J04",
type: "barrier",
from: "E",
to: "F",
title: "Pressure hatch",
function: "Stays shut until force crosses a preset threshold.",
input: "Cargo presses against the Coupler.",
transfer: "A spring-loaded hatch holds its stop.",
output: "Builder remains isolated under pressure.",
analogy: "A pressure-sensitive trapdoor that waits for a firm push.",
transferMode: "Threshold lock",
responseMode: "Gated",
span: "2.3 toy units",
dependency: "Applied pressure",
offState: "Locked",
onState: "Hatch released",
startAction: "Release hatch",
stopAction: "Lock hatch"
},
{
id: "J05",
type: "signaling",
from: "A",
to: "D",
title: "Cascade ping",
function: "Passes a local signal to start a downstream response.",
input: "Sensor becomes activated.",
transfer: "A second messenger relays the event.",
output: "Actuator begins its response program.",
analogy: "One bell rings and makes the bell beside it answer.",
transferMode: "Second messenger",
responseMode: "Cascade",
span: "2.3 toy units",
dependency: "Relay molecule",
offState: "Quiet",
onState: "Cascade active",
startAction: "Trigger cascade",
stopAction: "Stop cascade"
},
{
id: "J06",
type: "signaling",
from: "B",
to: "E",
title: "Remote relay",
function: "Sends a longer-lived signal to a nonadjacent cell.",
input: "Launcher emits a persistent signal.",
transfer: "The signal follows a curved soluble route.",
output: "Coupler amplifies the received response.",
analogy: "A glowing bead travels down a bent clear tube.",
transferMode: "Diffusion / relay",
responseMode: "Amplified",
span: "2.3 toy units",
dependency: "Signal lifetime",
offState: "Quiet",
onState: "Relay active",
startAction: "Emit relay",
stopAction: "Stop relay"
},
{
id: "J07",
type: "mechanical",
from: "C",
to: "F",
title: "Piston rail",
function: "Converts pressure into a precise sliding movement.",
input: "Receiver pumps its cylinder.",
transfer: "A piston pushes along the rail.",
output: "Builder's slider advances in sync.",
analogy: "A pump connected to a yellow sliding platform.",
transferMode: "Pressure to travel",
responseMode: "Linear motion",
span: "2.3 toy units",
dependency: "Sealed piston",
offState: "Resting",
onState: "Sliding",
startAction: "Run piston",
stopAction: "Stop piston"
}
];
const canvas = document.querySelector("#scene");
const labelsLayer = document.querySelector("#labels");
const cardsContainer = document.querySelector("#cards");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#edf3f1");
scene.fog = new THREE.Fog("#edf3f1", 19, 36);
const camera = new THREE.PerspectiveCamera(
44,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const hemisphere = new THREE.HemisphereLight("#ffffff", "#a6b8b1", 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff7e8", 3.1);
keyLight.position.set(-7, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight("#bdebf1", 1.25);
rimLight.position.set(9, 7, -8);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 26),
new THREE.MeshStandardMaterial({
color: "#e8efec",
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, "#bfcfca", "#d8e2df");
grid.position.y = -0.018;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
const orbit = {
theta: 0.43,
thetaGoal: 0.43,
phi: 1.02,
phiGoal: 1.02,
radius: 17.5,
radiusGoal: 17.5,
target: new THREE.Vector3(0, 0.65, 0),
targetGoal: new THREE.Vector3(0, 0.65, 0)
};
const cellMap = new Map();
const junctionMap = [];
const hitMeshes = [];
let selectedIndex = 0;
let filter = "all";
function roundedGeometry(w, h, d, radius = 0.16, bevel = 0.1) {
const b = Math.min(bevel, h * 0.24, w * 0.12, d * 0.12);
const sw = w - 2 * b;
const sd = d - 2 * b;
const r = Math.max(0.02, radius - b);
const shape = new THREE.Shape();
shape.moveTo(-sw / 2 + r, -sd / 2);
shape.lineTo(sw / 2 - r, -sd / 2);
shape.quadraticCurveTo(sw / 2, -sd / 2, sw / 2, -sd / 2 + r);
shape.lineTo(sw / 2, sd / 2 - r);
shape.quadraticCurveTo(sw / 2, sd / 2, sw / 2 - r, sd / 2);
shape.lineTo(-sw / 2 + r, sd / 2);
shape.quadraticCurveTo(-sw / 2, sd / 2, -sw / 2, sd / 2 - r);
shape.lineTo(-sw / 2, -sd / 2 + r);
shape.quadraticCurveTo(-sw / 2, -sd / 2, -sw / 2 + r, -sd / 2);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: Math.max(0.025, h - 2 * b),
steps: 1,
curveSegments: 2,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: b,
bevelThickness: b
});
geometry.center();
geometry.rotateX(-Math.PI / 2);
return geometry;
}
function cylinderBetween(a, b, radius, material, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
return mesh;
}
function makeStandard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.58,
metalness: 0.02,
emissive: color,
emissiveIntensity: 0.08,
transparent: true,
...options
});
}
function createCell(spec) {
const group = new THREE.Group();
group.position.set(...spec.position);
scene.add(group);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(1.48, 1.58, 0.13, 8),
makeStandard("#f7faf8", { roughness: 0.82 })
);
platform.position.y = 0.035;
platform.receiveShadow = true;
platform.castShadow = true;
group.add(platform);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.32, 0.035, 6, 48),
new THREE.MeshBasicMaterial({
color: "#ffffff",
transparent: true,
opacity: 0.95
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.13;
ring.visible = false;
group.add(ring);
const body = new THREE.Mesh(
roundedGeometry(1.9, 1.02, 1.55, 0.25, 0.13),
makeStandard(spec.color, { roughness: 0.64 })
);
body.position.y = 0.64;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const capColor = new THREE.Color(spec.color).lerp(
new THREE.Color("#ffffff"),
0.32
);
const cap = new THREE.Mesh(
roundedGeometry(1.64, 0.12, 1.29, 0.18, 0.035),
makeStandard(capColor, { roughness: 0.74 })
);
cap.position.y = 1.18;
cap.castShadow = true;
group.add(cap);
const nucleus = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.32, 1),
makeStandard(spec.accent, { roughness: 0.42 })
);
nucleus.position.set(0, 1.34, 0);
nucleus.scale.set(1, 0.72, 0.9);
nucleus.rotation.set(0.18, 0.32, -0.12);
nucleus.castShadow = true;
group.add(nucleus);
const organellePositions = [
[-0.54, 1.28, 0.31],
[0.51, 1.28, 0.22],
[-0.33, 1.28, -0.43],
[0.35, 1.28, -0.39]
];
organellePositions.forEach((position, index) => {
const organelle = new THREE.Mesh(
new THREE.IcosahedronGeometry(index === 0 ? 0.11 : 0.085, 0),
makeStandard(spec.accent, { roughness: 0.6 })
);
organelle.position.set(...position);
organelle.rotation.set(index, index * 0.7, index * 0.3);
organelle.castShadow = true;
group.add(organelle);
});
const poreGeometry = new THREE.SphereGeometry(0.055, 8, 6);
[-0.32, 0, 0.32].forEach((x) => {
const pore = new THREE.Mesh(
poreGeometry,
makeStandard(spec.accent, { roughness: 0.5 })
);
pore.position.set(x, 0.86, 0.79);
group.add(pore);
});
const footGeometry = roundedGeometry(0.3, 0.16, 0.3, 0.06, 0.03);
const footMaterial = makeStandard(
new THREE.Color(spec.color).multiplyScalar(0.72),
{ roughness: 0.72 }
);
[
[-0.56, -0.45],
[0.56, -0.45],
[-0.56, 0.45],
[0.56, 0.45]
].forEach(([x, z]) => {
const foot = new THREE.Mesh(footGeometry, footMaterial);
foot.position.set(x, 0.09, z);
foot.castShadow = true;
group.add(foot);
});
const label = document.createElement("div");
label.className = "cell-label";
label.textContent = `${spec.id} · ${spec.name.toUpperCase()}`;
labelsLayer.appendChild(label);
const cell = {
...spec,
group,
ring,
label,
labelPosition: new THREE.Vector3(
spec.position[0],
1.94,
spec.position[2]
)
};
cellMap.set(spec.id, cell);
return cell;
}
CELL_SPECS.forEach(createCell);
function trackMaterial(junction, material) {
material.transparent = true;
material.userData.baseOpacity = material.opacity;
junction.materials.push(material);
return material;
}
function addPort(junction, position, direction, color) {
const ringMaterial = trackMaterial(
junction,
makeStandard(color, {
roughness: 0.38,
metalness: 0.12,
emissiveIntensity: 0.12
})
);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.052, 6, 16),
ringMaterial
);
ring.position.copy(position);
ring.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction
);
ring.castShadow = true;
junction.group.add(ring);
const stubMaterial = trackMaterial(
junction,
makeStandard("#aab9b8", { roughness: 0.45, metalness: 0.18 })
);
const stub = new THREE.Mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.34, 8),
stubMaterial
);
stub.position.copy(position).addScaledVector(direction, -0.08);
stub.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
);
stub.castShadow = true;
junction.group.add(stub);
}
function createArrow(junction, position, direction, color) {
const material = trackMaterial(
junction,
makeStandard(color, {
roughness: 0.4,
emissiveIntensity: 0.15
})
);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.095, 0.27, 6),
material
);
arrow.position.copy(position);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
junction.group.add(arrow);
}
function createMarker(junction) {
const markerGroup = new THREE.Group();
markerGroup.position.copy(junction.hotspot).add(
new THREE.Vector3(0, 0.5, 0)
);
const markerMaterial = trackMaterial(
junction,
makeStandard(TYPE[junction.type].color, {
roughness: 0.28,
metalness: 0.12,
emissiveIntensity: 0.28
})
);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.17, 0),
markerMaterial
);
marker.castShadow = true;
markerGroup.add(marker);
const haloMaterial = trackMaterial(
junction,
new THREE.MeshBasicMaterial({
color: TYPE[junction.type].color,
transparent: true,
opacity: 0.55,
depthWrite: false
})
);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.28, 0.026, 6, 24),
haloMaterial
);
markerGroup.add(halo);
junction.marker = markerGroup;
junction.markerHalo = halo;
junction.group.add(markerGroup);
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const hit = new THREE.Mesh(
new THREE.SphereGeometry(0.7, 12, 8),
hitMaterial
);
hit.position.copy(junction.hotspot);
hit.userData.junctionIndex = junction.index;
junction.group.add(hit);
hitMeshes.push(hit);
}
function createJunction(spec, index) {
const source = cellMap.get(spec.from);
const target = cellMap.get(spec.to);
const sourcePosition = new THREE.Vector3(
source.position[0],
0,
source.position[2]
);
const targetPosition = new THREE.Vector3(
target.position[0],
0,
target.position[2]
);
const midpoint = sourcePosition.clone().add(targetPosition).multiplyScalar(0.5);
const sourceDirection = midpoint.clone().sub(sourcePosition).setY(0).normalize();
const targetDirection = midpoint.clone().sub(targetPosition).setY(0).normalize();
const start = sourcePosition.clone().addScaledVector(sourceDirection, 1.17);
start.y = 0.98;
const end = targetPosition.clone().addScaledVector(targetDirection, 1.17);
end.y = 0.98;
const junction = {
...spec,
index,
start,
end,
center: midpoint.clone().setY(0.98),
direction: end.clone().sub(start).setY(0).normalize(),
group: new THREE.Group(),
materials: [],
active: false,
openAmount: 0
};
scene.add(junction.group);
addPort(
junction,
start,
junction.direction,
TYPE[junction.type].color
);
addPort(
junction,
end,
junction.direction,
TYPE[junction.type].color
);
if (junction.type === "barrier") {
const trackMaterialValue = trackMaterial(
junction,
makeStandard("#a7b5b2", {
roughness: 0.5,
metalness: 0.15,
emissiveIntensity: 0.02
})
);
const track = cylinderBetween(
start.clone().setY(0.78),
end.clone().setY(0.78),
0.045,
trackMaterialValue,
6
);
junction.group.add(track);
const perpendicular = new THREE.Vector3(
-junction.direction.z,
0,
junction.direction.x
);
junction.gateAxis = perpendicular.clone();
junction.gateHome = junction.center.clone();
const postGeometry = roundedGeometry(
0.27,
0.72,
0.3,
0.07,
0.045
);
const postMaterial = trackMaterial(
junction,
makeStandard("#d46f50", {
roughness: 0.48,
metalness: 0.05
})
);
[-0.47, 0.47].forEach((offset) => {
const post = new THREE.Mesh(postGeometry, postMaterial);
post.position
.copy(junction.center)
.addScaledVector(perpendicular, offset);
post.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
perpendicular
);
post.castShadow = true;
junction.group.add(post);
});
const gateGroup = new THREE.Group();
gateGroup.position.copy(junction.center);
gateGroup.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
perpendicular
);
const gateMaterial = trackMaterial(
junction,
makeStandard(TYPE.barrier.color, {
roughness: 0.4,
metalness: 0.08
})
);
const gate = new THREE.Mesh(
roundedGeometry(0.82, 0.53, 0.15, 0.07, 0.04),
gateMaterial
);
gate.castShadow = true;
gateGroup.add(gate);
const toothMaterial = trackMaterial(
junction,
makeStandard("#a84835", { roughness: 0.52 })
);
[-0.25, 0, 0.25].forEach((x) => {
const tooth = new THREE.Mesh(
roundedGeometry(0.17, 0.25, 0.21, 0.03, 0.02),
toothMaterial
);
tooth.position.set(x, -0.09, 0);
tooth.castShadow = true;
gateGroup.add(tooth);
});
junction.gate = gateGroup;
junction.group.add(gateGroup);
junction.hotspot = junction.center.clone().setY(1.08);
createArrow(
junction,
start.clone().lerp(end, 0.76).setY(1.03),
junction.direction,
TYPE.barrier.color
);
}
if (junction.type === "mechanical") {
const shaftMaterial = trackMaterial(
junction,
makeStandard("#7d8f8c", {
roughness: 0.35,
metalness: 0.45,
emissiveIntensity: 0.02
})
);
const shaft = cylinderBetween(
start.clone().setY(0.94),
end.clone().setY(0.94),
0.075,
shaftMaterial,
10
);
junction.group.add(shaft);
const couplingMaterial = trackMaterial(
junction,
makeStandard("#b28b24", {
roughness: 0.34,
metalness: 0.38
})
);
[-0.32, 0.32].forEach((offset) => {
const disc = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.25, 0.13, 12),
couplingMaterial
);
disc.position
.copy(junction.center)
.addScaledVector(junction.direction, offset);
disc.position.y = 0.98;
disc.castShadow = true;
junction.group.add(disc);
});
const gear = new THREE.Group();
gear.position.copy(junction.center);
gear.position.y = 1.11;
const gearMaterial = trackMaterial(
junction,
makeStandard(TYPE.mechanical.color, {
roughness: 0.35,
metalness: 0.28
})
);
const gearBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.3, 0.3, 0.13, 12),
gearMaterial
);
gearBody.castShadow = true;
gear.add(gearBody);
const toothMaterial = trackMaterial(
junction,
makeStandard("#bd8f1c", {
roughness: 0.38,
metalness: 0.24
})
);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const tooth = new THREE.Mesh(
new THREE.BoxGeometry(0.14, 0.14, 0.24),
toothMaterial
);
tooth.position.set(
Math.cos(angle) * 0.33,
0,
Math.sin(angle) * 0.33
);
tooth.rotation.y = -angle;
tooth.castShadow = true;
gear.add(tooth);
}
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.16, 10),
couplingMaterial
);
cap.position.y = 0.06;
gear.add(cap);
junction.gear = gear;
junction.group.add(gear);
const sliderMaterial = trackMaterial(
junction,
makeStandard("#efd069", {
roughness: 0.3,
metalness: 0.2
})
);
const slider = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.13, 1),
sliderMaterial
);
slider.position.copy(junction.center).setY(1.16);
slider.castShadow = true;
junction.slider = slider;
junction.group.add(slider);
junction.hotspot = junction.center.clone().setY(1.08);
createArrow(
junction,
start.clone().lerp(end, 0.76).setY(1.06),
junction.direction,
TYPE.mechanical.color
);
}
if (junction.type === "signaling") {
const p1 = start.clone().lerp(end, 0.28);
p1.y += 0.35;
const p2 = start.clone().lerp(end, 0.72);
p2.y += 0.55;
const curve = new THREE.CatmullRomCurve3([
start.clone(),
p1,
p2,
end.clone()
]);
junction.curve = curve;
const pathMaterial = trackMaterial(
junction,
makeStandard(TYPE.signaling.color, {
roughness: 0.32,
metalness: 0.05,
transparent: true,
opacity: 0.38,
emissiveIntensity: 0.2
})
);
const path = new THREE.Mesh(
new THREE.TubeGeometry(curve, 48, 0.035, 6, false),
pathMaterial
);
junction.group.add(path);
const dotMaterial = trackMaterial(
junction,
makeStandard(TYPE.signaling.color, {
roughness: 0.3,
transparent: true,
opacity: 0.45,
emissiveIntensity: 0.25
})
);
for (let i = 0; i < 10; i++) {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.038, 7, 5),
dotMaterial
);
dot.position.copy(curve.getPoint(i / 9));
junction.group.add(dot);
}
const particleMaterial = trackMaterial(
junction,
makeStandard("#83e5ec", {
roughness: 0.2,
metalness: 0.02,
emissive: "#32bbc9",
emissiveIntensity: 0.75
})
);
junction.particles = [];
for (let i = 0; i < 5; i++) {
const particle = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.095, 1),
particleMaterial
);
particle.position.copy(curve.getPoint(i / 5));
particle.castShadow = true;
junction.particles.push(particle);
junction.group.add(particle);
}
const midpoint = curve.getPoint(0.5);
junction.hotspot = midpoint.clone();
const tangent = curve.getTangent(0.66).normalize();
createArrow(
junction,
curve.getPoint(0.66),
tangent,
TYPE.signaling.color
);
}
createMarker(junction);
const tag = document.createElement("button");
tag.className = "junction-tag";
tag.type = "button";
tag.style.setProperty("--tag-color", TYPE[junction.type].color);
tag.textContent = junction.id;
tag.setAttribute(
"aria-label",
`${junction.id}, ${junction.title}, ${TYPE[junction.type].label}`
);
tag.addEventListener("click", () => selectJunction(index));
labelsLayer.appendChild(tag);
junction.tag = tag;
junction.tagPosition = junction.hotspot.clone().add(
new THREE.Vector3(0, 0.62, 0)
);
junctionMap.push(junction);
}
JUNCTION_SPECS.forEach(createJunction);
function createCards() {
JUNCTION_SPECS.forEach((spec, index) => {
const card = document.createElement("button");
card.type = "button";
card.className = "junction-card";
card.style.setProperty("--card-color", TYPE[spec.type].color);
card.innerHTML = `
<span class="card-top">
<span class="card-id">${spec.id}</span>
<span class="card-type">${TYPE[spec.type].label}</span>
</span>
<h3>${spec.title}</h3>
<p class="card-function">${spec.function}</p>
`;
card.addEventListener("click", () => selectJunction(index));
cardsContainer.appendChild(card);
spec.card = card;
});
}
createCards();
function updateCellRings() {
cellMap.forEach((cell) => {
cell.ring.visible = false;
});
if (selectedIndex < 0) return;
const junction = junctionMap[selectedIndex];
const source = cellMap.get(junction.from);
const target = cellMap.get(junction.to);
[source, target].forEach((cell) => {
cell.ring.visible = true;
cell.ring.material.color.set(TYPE[junction.type].color);
});
}
function applyFilter() {
junctionMap.forEach((junction) => {
const matches = filter === "all" || junction.type === filter;
junction.group.visible = matches;
junction.materials.forEach((material) => {
material.opacity = material.userData.baseOpacity;
if (material.emissive) {
material.emissiveIntensity =
junction.index === selectedIndex ? 0.62 : 0.1;
}
});
const selected = junction.index === selectedIndex;
junction.marker.scale.setScalar(selected ? 1.18 : 1);
});
JUNCTION_SPECS.forEach((spec) => {
spec.card.hidden = !(filter === "all" || spec.type === filter);
spec.card.classList.toggle(
"selected",
spec.id === junctionMap[selectedIndex]?.id
);
});
const count = JUNCTION_SPECS.filter(
(spec) => filter === "all" || spec.type === filter
).length;
document.querySelector("#visible-count").textContent =
`${count} connection${count === 1 ? "" : "s"}`;
updateCellRings();
}
function renderInspector() {
const junction = junctionMap[selectedIndex];
const source = cellMap.get(junction.from);
const target = cellMap.get(junction.to);
const color = TYPE[junction.type].color;
document.documentElement.style.setProperty("--type-color", color);
document.querySelector("#type-pill").textContent = TYPE[junction.type].label;
document.querySelector("#junction-code").textContent =
`${junction.id} / ${junction.type.toUpperCase()}`;
document.querySelector("#detail-title").textContent = junction.title;
document.querySelector("#from-cell").textContent = source.name;
document.querySelector("#to-cell").textContent = target.name;
document.querySelector("#detail-function").textContent = junction.function;
document.querySelector("#function-path").innerHTML = `
<div class="function-step">
<small>Input</small>
<span>${junction.input}</span>
</div>
<div class="function-step">
<small>Transfer</small>
<span>${junction.transfer}</span>
</div>
<div class="function-step">
<small>Output</small>
<span>${junction.output}</span>
</div>
`;
document.querySelector("#analogy").textContent =
`Toy analogy — ${junction.analogy}`;
document.querySelector("#transfer-mode").textContent = junction.transferMode;
document.querySelector("#response-mode").textContent = junction.responseMode;
document.querySelector("#junction-span").textContent = junction.span;
document.querySelector("#junction-dependency").textContent =
junction.dependency;
const state = document.querySelector("#junction-state");
state.textContent = junction.active ? junction.onState : junction.offState;
state.classList.toggle("active", junction.active);
const actuate = document.querySelector("#actuate");
actuate.textContent = junction.active
? junction.stopAction
: junction.startAction;
JUNCTION_SPECS.forEach((spec) => {
spec.card.classList.toggle(
"selected",
spec.id === junction.id
);
});
junctionMap.forEach((item) => {
item.tag.classList.toggle(
"selected",
item.index === selectedIndex
);
});
}
function selectJunction(index, focus = false) {
if (!junctionMap[index]) return;
selectedIndex = index;
applyFilter();
renderInspector();
if (focus) {
const junction = junctionMap[index];
orbit.targetGoal.copy(junction.hotspot).setY(0.72);
orbit.radiusGoal = 9;
}
}
document.querySelectorAll(".filter-button").forEach((button) => {
button.addEventListener("click", () => {
filter = button.dataset.filter;
document.querySelectorAll(".filter-button").forEach((item) => {
item.classList.toggle("active", item === button);
});
const current = junctionMap[selectedIndex];
if (filter !== "all" && current.type !== filter) {
const firstMatch = junctionMap.findIndex(
(junction) => junction.type === filter
);
if (firstMatch >= 0) {
selectedIndex = firstMatch;
}
}
applyFilter();
renderInspector();
});
});
document.querySelector("#actuate").addEventListener("click", () => {
const junction = junctionMap[selectedIndex];
junction.active = !junction.active;
renderInspector();
});
document.querySelector("#focus-junction").addEventListener("click", () => {
selectJunction(selectedIndex, true);
});
document.querySelector("#reset-view").addEventListener("click", () => {
orbit.thetaGoal = 0.43;
orbit.phiGoal = 1.02;
orbit.radiusGoal = 17.5;
orbit.targetGoal.set(0, 0.65, 0);
});
document.querySelector("#top-view").addEventListener("click", () => {
orbit.thetaGoal = 0;
orbit.phiGoal = 0.1;
orbit.radiusGoal = 17;
orbit.targetGoal.set(0, 0.4, 0);
});
document.querySelector("#run-all").addEventListener("click", () => {
const allActive = junctionMap.every((junction) => junction.active);
junctionMap.forEach((junction) => {
junction.active = !allActive;
});
document.querySelector("#run-all").textContent =
allActive ? "Run all" : "Pause all";
renderInspector();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let shiftPanning = false;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
pointerDown = true;
pointerMoved = false;
shiftPanning = event.shiftKey || event.button === 2;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 2) {
pointerMoved = true;
}
if (shiftPanning) {
const right = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, new THREE.Vector3(), new THREE.Vector3());
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
orbit.targetGoal.addScaledVector(
right,
-dx * orbit.radius * 0.0015
);
orbit.targetGoal.addScaledVector(
forward,
-dy * orbit.radius * 0.0015
);
} else {
orbit.thetaGoal -= dx * 0.006;
orbit.phiGoal = THREE.MathUtils.clamp(
orbit.phiGoal - dy * 0.005,
0.08,
1.43
);
}
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerMoved) {
const rect = canvas.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 visibleHits = hitMeshes.filter(
(hit) => hit.visible && hit.parent.visible
);
const intersections = raycaster.intersectObjects(
visibleHits,
false
);
if (intersections.length) {
selectJunction(intersections[0].object.userData.junctionIndex);
}
}
pointerDown = false;
shiftPanning = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
shiftPanning = false;
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radiusGoal = THREE.MathUtils.clamp(
orbit.radiusGoal * Math.exp(event.deltaY * 0.001),
7.5,
27
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
orbit.thetaGoal = 0.43;
orbit.phiGoal = 1.02;
orbit.radiusGoal = 17.5;
orbit.targetGoal.set(0, 0.65, 0);
}
if (event.key === "+" || event.key === "=") {
orbit.radiusGoal = Math.max(7.5, orbit.radiusGoal - 1);
}
if (event.key === "-") {
orbit.radiusGoal = Math.min(27, orbit.radiusGoal + 1);
}
if (event.key === "ArrowLeft") orbit.thetaGoal -= 0.12;
if (event.key === "ArrowRight") orbit.thetaGoal += 0.12;
if (event.key === "ArrowUp") {
orbit.phiGoal = Math.max(0.08, orbit.phiGoal - 0.1);
}
if (event.key === "ArrowDown") {
orbit.phiGoal = Math.min(1.43, orbit.phiGoal + 0.1);
}
});
function updateCamera(dt) {
const smoothing = 1 - Math.exp(-8 * dt);
orbit.theta = THREE.MathUtils.lerp(
orbit.theta,
orbit.thetaGoal,
smoothing
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi,
orbit.phiGoal,
smoothing
);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
orbit.radiusGoal,
smoothing
);
orbit.target.lerp(orbit.targetGoal, smoothing);
camera.position
.setFromSphericalCoords(orbit.radius, orbit.phi, orbit.theta)
.add(orbit.target);
camera.lookAt(orbit.target);
}
function updateJunctions(elapsed, dt) {
junctionMap.forEach((junction) => {
if (junction.type === "barrier") {
const target = junction.active ? 1 : 0;
junction.openAmount = THREE.MathUtils.lerp(
junction.openAmount,
target,
1 - Math.exp(-7 * dt)
);
junction.gate.position
.copy(junction.gateHome)
.addScaledVector(
junction.gateAxis,
junction.openAmount * 0.72
);
}
if (junction.type === "mechanical") {
const speed = junction.active ? 1.8 : 0.16;
junction.gear.rotation.y += dt * speed;
const travel = junction.active
? Math.sin(elapsed * 3.3) * 0.48
: Math.sin(elapsed * 0.7) * 0.07;
junction.slider.position
.copy(junction.center)
.addScaledVector(junction.direction, travel);
junction.slider.position.y = 1.16;
}
if (junction.type === "signaling") {
const speed = junction.active ? 0.26 : 0.052;
junction.particles.forEach((particle, index) => {
const t = (elapsed * speed + index / junction.particles.length) % 1;
particle.position.copy(junction.curve.getPoint(t));
const pulse = 1 + Math.sin(elapsed * 5 + index) * 0.08;
particle.scale.setScalar(pulse);
});
}
junction.markerHalo.rotation.y = elapsed * 0.65;
junction.markerHalo.rotation.z = elapsed * 0.4;
});
}
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition, visible = true) {
if (!visible) {
element.style.display = "none";
return;
}
projected.copy(worldPosition).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
if (!onScreen) {
element.style.display = "none";
return;
}
element.style.display = "";
element.style.left = `${(projected.x * 0.5 + 0.5) * innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * innerHeight}px`;
}
function updateLabels() {
cellMap.forEach((cell) => {
positionLabel(cell.label, cell.labelPosition);
});
junctionMap.forEach((junction) => {
const visible =
filter === "all" || junction.type === filter;
positionLabel(junction.tag, junction.tagPosition, visible);
});
}
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(dt);
updateJunctions(elapsed, dt);
updateLabels();
cellMap.forEach((cell, index) => {
if (cell.ring.visible) {
const pulse = 1 + Math.sin(elapsed * 2.2 + index) * 0.025;
cell.ring.scale.setScalar(pulse);
}
});
renderer.render(scene, camera);
});
selectJunction(0);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```