@blackbelt-technology/pi-dashboard-deck3d 0.0.0-stage → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. package/.pi/skills/deck3d/SKILL.md +227 -0
  2. package/.pi/skills/deck3d/examples/deck.json +388 -0
  3. package/.pi/skills/deck3d/examples/fixture.md +18 -0
  4. package/.pi/skills/deck3d/examples/snapshot-after.png +0 -0
  5. package/.pi/skills/deck3d/examples/snapshot-before.png +0 -0
  6. package/.pi/skills/deck3d/reference/effects.agent.md +78 -0
  7. package/.pi/skills/deck3d/reference/effects.md +1217 -0
  8. package/.pi/skills/deck3d/reference/ir-fields.agent.md +30 -0
  9. package/.pi/skills/deck3d/reference/ir-fields.md +246 -0
  10. package/README.md +177 -2
  11. package/assets/LICENSE-Poppins.txt +99 -0
  12. package/assets/Poppins-Bold.ttf +0 -0
  13. package/assets/props/LICENSES.txt +4 -0
  14. package/assets/props/brain.glb +0 -0
  15. package/assets/props/cloud.glb +0 -0
  16. package/assets/props/cube.glb +0 -0
  17. package/assets/props/database.glb +0 -0
  18. package/assets/props/laptop.glb +0 -0
  19. package/assets/props/manifest.json +119 -0
  20. package/assets/props/robot.glb +0 -0
  21. package/assets/props/server.glb +0 -0
  22. package/assets/props/shield.glb +0 -0
  23. package/bin/deck3d +49 -0
  24. package/dist/cli.js +10228 -0
  25. package/dist/harvest/harness.js +185718 -0
  26. package/dist/runtime.js +64597 -0
  27. package/fixtures/business-2031/build-deck.mjs +60 -0
  28. package/fixtures/business-2031/build-overrides.mjs +154 -0
  29. package/fixtures/business-2031/deck.json +4220 -0
  30. package/fixtures/business-2031/deck.md +470 -0
  31. package/fixtures/business-2031/fx/closing-mark.js +43 -0
  32. package/fixtures/business-2031/fx/closing-mark.meta.json +26 -0
  33. package/fixtures/business-2031/overrides.json +903 -0
  34. package/fixtures/harvest.md +23 -0
  35. package/fixtures/strategy-lab.json +891 -0
  36. package/fixtures/strategy-lab.md +85 -0
  37. package/package.json +80 -4
  38. package/scripts/build-cli.mjs +29 -0
  39. package/scripts/build-harvest.ts +8 -0
  40. package/scripts/build-runtime.mjs +22 -0
  41. package/scripts/gen-effects.ts +14 -0
  42. package/scripts/gen-ir-fields.ts +34 -0
  43. package/src/check/index.ts +315 -0
  44. package/src/check/rules.ts +393 -0
  45. package/src/cli-io.ts +23 -0
  46. package/src/cli.ts +823 -0
  47. package/src/fx/accent-cycle.meta.json +26 -0
  48. package/src/fx/accent-cycle.ts +8 -0
  49. package/src/fx/agent-depth.meta.json +42 -0
  50. package/src/fx/agent-depth.ts +62 -0
  51. package/src/fx/ascii.meta.json +35 -0
  52. package/src/fx/ascii.ts +4 -0
  53. package/src/fx/aurora.meta.json +26 -0
  54. package/src/fx/aurora.ts +18 -0
  55. package/src/fx/billboards.meta.json +34 -0
  56. package/src/fx/billboards.ts +67 -0
  57. package/src/fx/bloom.meta.json +26 -0
  58. package/src/fx/bloom.ts +4 -0
  59. package/src/fx/camera-drift.meta.json +26 -0
  60. package/src/fx/camera-drift.ts +8 -0
  61. package/src/fx/capital-flows.meta.json +30 -0
  62. package/src/fx/capital-flows.ts +64 -0
  63. package/src/fx/catalogue.ts +89 -0
  64. package/src/fx/chromatic-aberration.meta.json +32 -0
  65. package/src/fx/chromatic-aberration.ts +4 -0
  66. package/src/fx/city-grid.meta.json +37 -0
  67. package/src/fx/city-grid.ts +51 -0
  68. package/src/fx/clipped-solids.meta.json +49 -0
  69. package/src/fx/clipped-solids.ts +171 -0
  70. package/src/fx/cohort-grid.meta.json +48 -0
  71. package/src/fx/cohort-grid.ts +63 -0
  72. package/src/fx/compose.ts +114 -0
  73. package/src/fx/constellation.meta.json +51 -0
  74. package/src/fx/constellation.ts +103 -0
  75. package/src/fx/curve-flow.meta.json +40 -0
  76. package/src/fx/curve-flow.ts +63 -0
  77. package/src/fx/dashed-flow.meta.json +27 -0
  78. package/src/fx/dashed-flow.ts +8 -0
  79. package/src/fx/data-columns.meta.json +30 -0
  80. package/src/fx/data-columns.ts +18 -0
  81. package/src/fx/defaults.ts +92 -0
  82. package/src/fx/depth-of-field.meta.json +40 -0
  83. package/src/fx/depth-of-field.ts +4 -0
  84. package/src/fx/dolly.meta.json +26 -0
  85. package/src/fx/dolly.ts +4 -0
  86. package/src/fx/dot-screen.meta.json +35 -0
  87. package/src/fx/dot-screen.ts +4 -0
  88. package/src/fx/dynamic-instances.meta.json +40 -0
  89. package/src/fx/dynamic-instances.ts +57 -0
  90. package/src/fx/emissive.meta.json +26 -0
  91. package/src/fx/emissive.ts +8 -0
  92. package/src/fx/extruded-shapes.meta.json +62 -0
  93. package/src/fx/extruded-shapes.ts +133 -0
  94. package/src/fx/fab-wafer.meta.json +42 -0
  95. package/src/fx/fab-wafer.ts +72 -0
  96. package/src/fx/fade.meta.json +26 -0
  97. package/src/fx/fade.ts +4 -0
  98. package/src/fx/film.meta.json +26 -0
  99. package/src/fx/film.ts +4 -0
  100. package/src/fx/float.meta.json +26 -0
  101. package/src/fx/float.ts +8 -0
  102. package/src/fx/flythrough.meta.json +26 -0
  103. package/src/fx/flythrough.ts +4 -0
  104. package/src/fx/fog.meta.json +26 -0
  105. package/src/fx/fog.ts +8 -0
  106. package/src/fx/geo-fragments.meta.json +48 -0
  107. package/src/fx/geo-fragments.ts +59 -0
  108. package/src/fx/glass.meta.json +26 -0
  109. package/src/fx/glass.ts +8 -0
  110. package/src/fx/globe-arcs.meta.json +36 -0
  111. package/src/fx/globe-arcs.ts +67 -0
  112. package/src/fx/glow-tube.meta.json +26 -0
  113. package/src/fx/glow-tube.ts +8 -0
  114. package/src/fx/glyph-rain.meta.json +30 -0
  115. package/src/fx/glyph-rain.ts +18 -0
  116. package/src/fx/god-rays.meta.json +40 -0
  117. package/src/fx/god-rays.ts +4 -0
  118. package/src/fx/grid-horizon.meta.json +30 -0
  119. package/src/fx/grid-horizon.ts +18 -0
  120. package/src/fx/hex-grid.meta.json +29 -0
  121. package/src/fx/hex-grid.ts +18 -0
  122. package/src/fx/holo-fresnel.meta.json +26 -0
  123. package/src/fx/holo-fresnel.ts +8 -0
  124. package/src/fx/horizon-gates.meta.json +36 -0
  125. package/src/fx/horizon-gates.ts +60 -0
  126. package/src/fx/index.ts +258 -0
  127. package/src/fx/iridescent.meta.json +26 -0
  128. package/src/fx/iridescent.ts +8 -0
  129. package/src/fx/iris.meta.json +26 -0
  130. package/src/fx/iris.ts +4 -0
  131. package/src/fx/lightformers.meta.json +26 -0
  132. package/src/fx/lightformers.ts +8 -0
  133. package/src/fx/local.ts +200 -0
  134. package/src/fx/market-tape.meta.json +53 -0
  135. package/src/fx/market-tape.ts +97 -0
  136. package/src/fx/matcap.meta.json +26 -0
  137. package/src/fx/matcap.ts +8 -0
  138. package/src/fx/meta.schema.json +49 -0
  139. package/src/fx/metal.meta.json +26 -0
  140. package/src/fx/metal.ts +8 -0
  141. package/src/fx/mirror-floor.meta.json +26 -0
  142. package/src/fx/mirror-floor.ts +8 -0
  143. package/src/fx/neural-mesh.meta.json +54 -0
  144. package/src/fx/neural-mesh.ts +110 -0
  145. package/src/fx/orbit-agents.meta.json +36 -0
  146. package/src/fx/orbit-agents.ts +63 -0
  147. package/src/fx/orbit.meta.json +27 -0
  148. package/src/fx/orbit.ts +8 -0
  149. package/src/fx/outline.meta.json +43 -0
  150. package/src/fx/outline.ts +4 -0
  151. package/src/fx/paper-stack.meta.json +36 -0
  152. package/src/fx/paper-stack.ts +61 -0
  153. package/src/fx/particle-stream.meta.json +27 -0
  154. package/src/fx/particle-stream.ts +8 -0
  155. package/src/fx/particles.meta.json +26 -0
  156. package/src/fx/particles.ts +8 -0
  157. package/src/fx/pixelate.meta.json +28 -0
  158. package/src/fx/pixelate.ts +4 -0
  159. package/src/fx/points-on-geometry.meta.json +61 -0
  160. package/src/fx/points-on-geometry.ts +71 -0
  161. package/src/fx/proof-gate.meta.json +30 -0
  162. package/src/fx/proof-gate.ts +67 -0
  163. package/src/fx/rings.meta.json +27 -0
  164. package/src/fx/rings.ts +8 -0
  165. package/src/fx/room-ibl.meta.json +26 -0
  166. package/src/fx/room-ibl.ts +8 -0
  167. package/src/fx/sao.meta.json +32 -0
  168. package/src/fx/sao.ts +4 -0
  169. package/src/fx/scaffold.ts +172 -0
  170. package/src/fx/scatter.meta.json +49 -0
  171. package/src/fx/scatter.ts +74 -0
  172. package/src/fx/selective-bloom.meta.json +36 -0
  173. package/src/fx/selective-bloom.ts +4 -0
  174. package/src/fx/server-racks.meta.json +36 -0
  175. package/src/fx/server-racks.ts +54 -0
  176. package/src/fx/shader-particles.meta.json +46 -0
  177. package/src/fx/shader-particles.ts +75 -0
  178. package/src/fx/signal-pulse.meta.json +27 -0
  179. package/src/fx/signal-pulse.ts +8 -0
  180. package/src/fx/smaa.meta.json +19 -0
  181. package/src/fx/smaa.ts +4 -0
  182. package/src/fx/sobel.meta.json +24 -0
  183. package/src/fx/sobel.ts +4 -0
  184. package/src/fx/soft-shadows.meta.json +26 -0
  185. package/src/fx/soft-shadows.ts +8 -0
  186. package/src/fx/sprites.meta.json +40 -0
  187. package/src/fx/sprites.ts +57 -0
  188. package/src/fx/stagger-reveal.meta.json +26 -0
  189. package/src/fx/stagger-reveal.ts +8 -0
  190. package/src/fx/starfield.meta.json +32 -0
  191. package/src/fx/starfield.ts +18 -0
  192. package/src/fx/swarm.meta.json +27 -0
  193. package/src/fx/swarm.ts +8 -0
  194. package/src/fx/tessellate.meta.json +39 -0
  195. package/src/fx/tessellate.ts +79 -0
  196. package/src/fx/tokens.meta.json +27 -0
  197. package/src/fx/tokens.ts +8 -0
  198. package/src/fx/trail.meta.json +27 -0
  199. package/src/fx/trail.ts +8 -0
  200. package/src/fx/trust-ledger.meta.json +30 -0
  201. package/src/fx/trust-ledger.ts +47 -0
  202. package/src/fx/types.ts +83 -0
  203. package/src/fx/util.ts +108 -0
  204. package/src/fx/vault-glyphs.meta.json +37 -0
  205. package/src/fx/vault-glyphs.ts +55 -0
  206. package/src/fx/video-screen.meta.json +57 -0
  207. package/src/fx/video-screen.ts +99 -0
  208. package/src/fx/vignette.meta.json +32 -0
  209. package/src/fx/vignette.ts +4 -0
  210. package/src/fx/volume-cloud.meta.json +58 -0
  211. package/src/fx/volume-cloud.ts +87 -0
  212. package/src/fx/volume-perlin.meta.json +46 -0
  213. package/src/fx/volume-perlin.ts +82 -0
  214. package/src/fx/volumetric-spot.meta.json +26 -0
  215. package/src/fx/volumetric-spot.ts +8 -0
  216. package/src/fx/wireframe-overlay.meta.json +27 -0
  217. package/src/fx/wireframe-overlay.ts +8 -0
  218. package/src/ir/defaults.ts +62 -0
  219. package/src/ir/field-reference.ts +96 -0
  220. package/src/ir/hash.ts +34 -0
  221. package/src/ir/ids.ts +65 -0
  222. package/src/ir/merge.ts +155 -0
  223. package/src/ir/schema.json +1211 -0
  224. package/src/ir/types.ts +333 -0
  225. package/src/ir/validate.ts +196 -0
  226. package/src/parse/derive.ts +205 -0
  227. package/src/parse/harvest/bundle.ts +56 -0
  228. package/src/parse/harvest/harness.html +22 -0
  229. package/src/parse/harvest/harness.ts +191 -0
  230. package/src/parse/harvest/index.ts +169 -0
  231. package/src/parse/harvest/shapes.ts +75 -0
  232. package/src/parse/markdown.ts +215 -0
  233. package/src/props/embed.ts +92 -0
  234. package/src/props/fetch.ts +97 -0
  235. package/src/props/generate.ts +152 -0
  236. package/src/props/key.ts +13 -0
  237. package/src/props/search.ts +180 -0
  238. package/src/render/embed-video.ts +80 -0
  239. package/src/render/font.ts +86 -0
  240. package/src/render/index.ts +149 -0
  241. package/src/render/template.html +87 -0
  242. package/src/runtime/backgrounds.ts +146 -0
  243. package/src/runtime/builders.ts +808 -0
  244. package/src/runtime/camera.ts +73 -0
  245. package/src/runtime/hud.ts +887 -0
  246. package/src/runtime/index.ts +1168 -0
  247. package/src/runtime/local-fx.ts +151 -0
  248. package/src/runtime/materials.ts +136 -0
  249. package/src/runtime/measure.ts +73 -0
  250. package/src/runtime/node-geometry.ts +26 -0
  251. package/src/runtime/palette.ts +111 -0
  252. package/src/runtime/post.ts +649 -0
  253. package/src/runtime/props.ts +292 -0
  254. package/src/runtime/quality.ts +20 -0
  255. package/src/runtime/rng.ts +8 -0
  256. package/src/runtime/scene.ts +644 -0
  257. package/src/runtime/text.ts +174 -0
  258. package/src/runtime/types.ts +118 -0
  259. package/src/serve/index.ts +376 -0
  260. package/src/util/paths.ts +35 -0
@@ -0,0 +1,808 @@
1
+ /**
2
+ * 3D diagram builders (ported from the lab). Flowchart + sequence consume the
3
+ * harvested IR; brain/loop/swarm are procedural. Every builder returns
4
+ * `{ g, tick }` so the engine advances all of them from one clock.
5
+ */
6
+ import type { Font } from "opentype.js";
7
+ import * as THREE from "three";
8
+ import type { MergedNode, MergedSlide } from "../ir/types.js";
9
+ import { diagramMaterial } from "./materials.js";
10
+ import { nodeGeometry } from "./node-geometry.js";
11
+ import type { PaletteColors } from "./palette.js";
12
+ import { makeRng } from "./rng.js";
13
+ import { buildLabel } from "./text.js";
14
+ import type { SlideConfig } from "./types.js";
15
+
16
+ export interface BuiltLabel {
17
+ id: string;
18
+ text: string;
19
+ object: THREE.Object3D;
20
+ height: number;
21
+ }
22
+
23
+ export interface DiagramBuild {
24
+ g: THREE.Group;
25
+ tick: (t: number) => void;
26
+ /** Node meshes by id (flowchart) — used by measurement/occlusion. */
27
+ nodes?: Record<string, THREE.Mesh>;
28
+ /** Labelled objects (node/actor/message) for `measure()`. */
29
+ labels?: BuiltLabel[];
30
+ /** Sequence only: id of the currently lifted message group (F7). */
31
+ lifted?: () => string | null;
32
+ }
33
+
34
+ const UP = new THREE.Vector3(0, 1, 0);
35
+ const DIR = new THREE.Vector3();
36
+
37
+ function arrowHead(mat: THREE.Material, r: number): THREE.Mesh {
38
+ const c = new THREE.Mesh(new THREE.ConeGeometry(Math.min(0.07, r * 3), Math.min(0.2, r * 8), 16), mat);
39
+ c.geometry.rotateX(Math.PI / 2);
40
+ return c;
41
+ }
42
+
43
+ function empty(): DiagramBuild {
44
+ return { g: new THREE.Group(), tick: () => {} };
45
+ }
46
+
47
+ /* ---------------------------------------------------------------- *
48
+ * Built topologies (D2). Each renders from `diagram.data` alone — no
49
+ * mermaid harvest — and exposes its parts to `measure()` like flowchart
50
+ * nodes: one `nodes` entry and one `labels` entry per series item, keyed
51
+ * `n<i>` so a check finding can name it.
52
+ * ---------------------------------------------------------------- */
53
+
54
+ /** Series view of a slide: captions always, magnitudes only when complete. */
55
+ function series(slide: MergedSlide, fallback: string[] = []): { labels: string[]; values?: number[] } {
56
+ const data = slide.diagram.data;
57
+ const labels = data?.labels?.length ? data.labels : fallback;
58
+ const values = data?.values?.length === labels.length ? data.values : undefined;
59
+ return { labels, values };
60
+ }
61
+
62
+ interface BuiltParts {
63
+ nodes: Record<string, THREE.Mesh>;
64
+ labels: BuiltLabel[];
65
+ }
66
+
67
+ /**
68
+ * Evenly spaced point on a ring. Captioned members of the cloud topologies are
69
+ * pinned to it: following the cloud's own random positions puts two captions in
70
+ * the same screen region, which `check` correctly reports as overlap/occlusion.
71
+ */
72
+ function ringPoint(i: number, n: number, rx: number, ry = rx): THREE.Vector3 {
73
+ const a = Math.PI / 2 - (i * Math.PI * 2) / Math.max(1, n);
74
+ return new THREE.Vector3(Math.cos(a) * rx, Math.sin(a) * ry, 0);
75
+ }
76
+
77
+ /**
78
+ * Built-topology captions are labels, not prose: the slide card already shows
79
+ * the bullet in full, so a sentence-length caption is clipped here rather than
80
+ * allowed to grow wider than the topology it annotates.
81
+ */
82
+ const CAPTION_MAX = 22;
83
+
84
+ function caption(text: string): string {
85
+ return text.length <= CAPTION_MAX ? text : `${text.slice(0, CAPTION_MAX - 1).trimEnd()}\u2026`;
86
+ }
87
+
88
+ /** Attach a caption plane at `pos`, owned by `id`, and record it for `measure()`. */
89
+ function addPart(
90
+ g: THREE.Group,
91
+ parts: BuiltParts,
92
+ id: string,
93
+ text: string,
94
+ mesh: THREE.Mesh,
95
+ pos: THREE.Vector3,
96
+ P: PaletteColors,
97
+ cfg: SlideConfig,
98
+ ): void {
99
+ const shown = caption(text);
100
+ mesh.userData.ownerId = id;
101
+ mesh.userData.label = shown;
102
+ parts.nodes[id] = mesh;
103
+ const lb = buildLabel(shown, cfg.labels?.size ?? 0.13, P);
104
+ lb.group.position.copy(pos);
105
+ lb.group.userData.ownerId = id;
106
+ g.add(lb.group);
107
+ parts.labels.push({ id, text: shown, object: lb.group, height: lb.height });
108
+ }
109
+
110
+ /** Columns on a plinth, height ∝ value. A zero value keeps a stub so its label stays. */
111
+ function buildBars(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
112
+ const { labels, values } = series(slide, ["A", "B", "C"]);
113
+ if (!labels.length) return empty();
114
+ const g = new THREE.Group();
115
+ const parts: BuiltParts = { nodes: {}, labels: [] };
116
+ const matA = diagramMaterial(P, "accent", cfg);
117
+ const matB = diagramMaterial(P, "second", cfg);
118
+ const MAX_H = 2.4;
119
+ const STUB = 0.12;
120
+ // High enough that BOTH staggered caption rows clear the diagram disc
121
+ // (its top sits at about y = -1.66).
122
+ const BASE = -1.0;
123
+ const DEPTH = 0.12;
124
+ const PLINTH_D = 0.6;
125
+ const peak = Math.max(...(values ?? [1]), Number.EPSILON);
126
+ // Kept inside the diagram disc; a wider spread also costs ratio fidelity,
127
+ // because off-axis columns sit further from the camera.
128
+ const span = 2.2;
129
+ const step = labels.length > 1 ? span / (labels.length - 1) : 0;
130
+ const width = Math.min(0.62, (span / Math.max(1, labels.length)) * 0.7);
131
+
132
+ labels.forEach((text, i) => {
133
+ const v = values?.[i];
134
+ // Heights are exactly proportional so the ratio survives projection; only a
135
+ // genuine zero falls back to the stub.
136
+ const h = v === undefined ? MAX_H : v === 0 ? STUB : (v / peak) * MAX_H;
137
+ const x = labels.length > 1 ? -span / 2 + i * step : 0;
138
+ // Shallow in z on purpose: the projected rect of a deep box picks up a
139
+ // depth term that does not scale with `h`, which would skew the ratio a
140
+ // reader (and `measure()`) is entitled to trust.
141
+ const bar = new THREE.Mesh(new THREE.BoxGeometry(width, h, DEPTH), i === 0 ? matA : matB);
142
+ bar.position.set(x, BASE + h / 2, 0);
143
+ bar.castShadow = true;
144
+ g.add(bar);
145
+ // In front of the plinth, not on it: a caption drawn on the light plinth
146
+ // face loses its contrast and gets clipped by the plinth's front edge.
147
+ // Real captions are words, not letters, so consecutive ones alternate rows
148
+ // — at four columns a single row collides every time.
149
+ const row = labels.length > 2 && i % 2 === 1 ? 0.34 : 0;
150
+ addPart(g, parts, `n${i}`, text, bar, new THREE.Vector3(x, BASE - 0.26 - row, PLINTH_D / 2 + 0.15), P, cfg);
151
+ });
152
+
153
+ const plinth = new THREE.Mesh(new THREE.BoxGeometry(span + 0.9, 0.1, PLINTH_D), diagramMaterial(P, "second", cfg));
154
+ plinth.position.set(0, BASE - 0.05, 0);
155
+ plinth.receiveShadow = true;
156
+ g.add(plinth);
157
+
158
+ return { g, ...parts, tick: (t) => { g.rotation.y = Math.sin(t * 0.25) * 0.18; } };
159
+ }
160
+
161
+ /** Stacked slabs narrowing downward, one per label. */
162
+ function buildFunnel(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
163
+ const { labels } = series(slide, ["Leads", "Qualified", "Won"]);
164
+ if (!labels.length) return empty();
165
+ const g = new THREE.Group();
166
+ const parts: BuiltParts = { nodes: {}, labels: [] };
167
+ const n = labels.length;
168
+ const slabH = Math.min(0.5, 2.6 / n);
169
+ const top = ((n - 1) * slabH) / 2;
170
+
171
+ labels.forEach((text, i) => {
172
+ const rTop = 1.5 * (1 - i / (n + 1));
173
+ const rBottom = 1.5 * (1 - (i + 1) / (n + 1));
174
+ const y = top - i * slabH;
175
+ const slab = new THREE.Mesh(
176
+ new THREE.CylinderGeometry(rTop, rBottom, slabH * 0.82, 6),
177
+ diagramMaterial(P, i === 0 ? "accent" : "second", cfg),
178
+ );
179
+ slab.position.set(0, y, 0);
180
+ slab.castShadow = true;
181
+ g.add(slab);
182
+ addPart(g, parts, `n${i}`, text, slab, new THREE.Vector3(rTop + 0.95, y, 0.2), P, cfg);
183
+ });
184
+
185
+ return { g, ...parts, tick: (t) => { g.rotation.y = t * 0.2; } };
186
+ }
187
+
188
+ /** Milestone pucks along a rail; captions alternate above and below it. */
189
+ function buildTimelineRail(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
190
+ const { labels } = series(slide, ["Now", "Next", "Later"]);
191
+ if (!labels.length) return empty();
192
+ const g = new THREE.Group();
193
+ const parts: BuiltParts = { nodes: {}, labels: [] };
194
+ const span = 3.4;
195
+ const step = labels.length > 1 ? span / (labels.length - 1) : 0;
196
+ const RAIL_Y = 0;
197
+
198
+ const rail = new THREE.Mesh(new THREE.CylinderGeometry(0.05, 0.05, span + 0.6, 12), diagramMaterial(P, "second", cfg));
199
+ rail.rotation.z = Math.PI / 2;
200
+ rail.position.y = RAIL_Y;
201
+ g.add(rail);
202
+
203
+ labels.forEach((text, i) => {
204
+ const x = labels.length > 1 ? -span / 2 + i * step : 0;
205
+ const puck = new THREE.Mesh(new THREE.CylinderGeometry(0.24, 0.24, 0.14, 24), diagramMaterial(P, "accent", cfg));
206
+ puck.rotation.x = Math.PI / 2;
207
+ puck.position.set(x, RAIL_Y, 0);
208
+ puck.castShadow = true;
209
+ g.add(puck);
210
+ // Alternating sides keep captions from colliding on a dense rail.
211
+ const above = i % 2 === 0;
212
+ addPart(g, parts, `n${i}`, text, puck, new THREE.Vector3(x, RAIL_Y + (above ? 0.55 : -0.55), 0.12), P, cfg);
213
+ });
214
+
215
+ return { g, ...parts, tick: (t) => { g.rotation.y = Math.sin(t * 0.3) * 0.25; } };
216
+ }
217
+
218
+ /** Wire sphere with arcs between seeded surface points. */
219
+ function buildGlobe(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
220
+ const { labels } = series(slide, ["EMEA", "AMER", "APAC"]);
221
+ const g = new THREE.Group();
222
+ const parts: BuiltParts = { nodes: {}, labels: [] };
223
+ const R = 1.25;
224
+ const globe = new THREE.Mesh(
225
+ new THREE.SphereGeometry(R, 24, 16),
226
+ new THREE.MeshBasicMaterial({ color: P.second, wireframe: true, transparent: true, opacity: 0.35 }),
227
+ );
228
+ g.add(globe);
229
+
230
+ const rnd = makeRng(7);
231
+ const sites = labels.map((_, i) => {
232
+ const phi = Math.acos(1 - (2 * (i + 0.5)) / Math.max(1, labels.length));
233
+ const theta = rnd() * Math.PI * 2;
234
+ return new THREE.Vector3(Math.sin(phi) * Math.cos(theta), Math.cos(phi), Math.sin(phi) * Math.sin(theta)).multiplyScalar(R);
235
+ });
236
+
237
+ labels.forEach((text, i) => {
238
+ const pin = new THREE.Mesh(new THREE.SphereGeometry(0.1, 16, 16), diagramMaterial(P, "accent", cfg));
239
+ pin.position.copy(sites[i]);
240
+ g.add(pin);
241
+ addPart(g, parts, `n${i}`, text, pin, sites[i].clone().multiplyScalar(1.28), P, cfg);
242
+ });
243
+
244
+ const arcMat = new THREE.MeshBasicMaterial({ color: P.accent, transparent: true, opacity: 0.7 });
245
+ for (let i = 0; i + 1 < sites.length; i++) {
246
+ const mid = sites[i].clone().add(sites[i + 1]).normalize().multiplyScalar(R * 1.45);
247
+ const curve = new THREE.QuadraticBezierCurve3(sites[i], mid, sites[i + 1]);
248
+ g.add(new THREE.Mesh(new THREE.TubeGeometry(curve, 24, 0.02, 8, false), arcMat));
249
+ }
250
+
251
+ return { g, ...parts, tick: (t) => { g.rotation.y = t * 0.18; } };
252
+ }
253
+
254
+ /** Hub sphere with one satellite per label, each on its own tilted ring. */
255
+ function buildOrbitCluster(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
256
+ const { labels } = series(slide, ["Partner", "Reseller", "OEM"]);
257
+ const g = new THREE.Group();
258
+ const parts: BuiltParts = { nodes: {}, labels: [] };
259
+ const hub = new THREE.Mesh(new THREE.SphereGeometry(0.4, 32, 32), diagramMaterial(P, "accent", cfg));
260
+ hub.castShadow = true;
261
+ g.add(hub);
262
+
263
+ const sats = labels.map((text, i) => {
264
+ const radius = 0.9 + (i % 3) * 0.35;
265
+ const tilt = (i / Math.max(1, labels.length)) * Math.PI;
266
+ const ring = new THREE.Mesh(
267
+ new THREE.TorusGeometry(radius, 0.012, 8, 96),
268
+ new THREE.MeshBasicMaterial({ color: P.second, transparent: true, opacity: 0.4 }),
269
+ );
270
+ ring.rotation.set(Math.PI / 2, 0, tilt);
271
+ g.add(ring);
272
+
273
+ const sat = new THREE.Mesh(new THREE.OctahedronGeometry(0.17, 1), diagramMaterial(P, "second", cfg));
274
+ const holder = new THREE.Group();
275
+ holder.rotation.set(Math.PI / 2, 0, tilt);
276
+ holder.add(sat);
277
+ g.add(holder);
278
+
279
+ const phase = (i / Math.max(1, labels.length)) * Math.PI * 2;
280
+ sat.position.set(Math.cos(phase) * radius, Math.sin(phase) * radius, 0);
281
+ // Captions live on an even ring in the GROUP's own space. Following the
282
+ // satellite through `getWorldPosition` reads a stale matrix at build time
283
+ // and projects off-screen.
284
+ const at = ringPoint(i, labels.length, radius + 0.75, radius + 0.55);
285
+ addPart(g, parts, `n${i}`, text, sat, at, P, cfg);
286
+ return { sat, radius, phase };
287
+ });
288
+
289
+ return {
290
+ g,
291
+ ...parts,
292
+ tick(t) {
293
+ for (const s of sats) {
294
+ const a = s.phase + t * 0.35;
295
+ s.sat.position.set(Math.cos(a) * s.radius, Math.sin(a) * s.radius, 0);
296
+ }
297
+ hub.rotation.y = t * 0.4;
298
+ },
299
+ };
300
+ }
301
+
302
+ /** Offset layered slabs, one per label — a compute/infra "stack". */
303
+ function buildStack(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
304
+ const { labels } = series(slide, ["Edge", "Core", "Storage"]);
305
+ if (!labels.length) return empty();
306
+ const g = new THREE.Group();
307
+ const parts: BuiltParts = { nodes: {}, labels: [] };
308
+ const n = labels.length;
309
+ const gap = Math.min(0.46, 2.4 / n);
310
+ const top = ((n - 1) * gap) / 2;
311
+
312
+ labels.forEach((text, i) => {
313
+ const y = top - i * gap;
314
+ const slab = new THREE.Mesh(
315
+ new THREE.BoxGeometry(2.2, gap * 0.55, 1.2),
316
+ diagramMaterial(P, i === 0 ? "accent" : "second", cfg),
317
+ );
318
+ // A small lateral offset per layer reads as depth rather than one block.
319
+ slab.position.set(((i % 2 === 0 ? 1 : -1) * gap) / 3, y, 0);
320
+ slab.castShadow = true;
321
+ g.add(slab);
322
+ addPart(g, parts, `n${i}`, text, slab, new THREE.Vector3(slab.position.x + 1.5, y, 0.62), P, cfg);
323
+ });
324
+
325
+ return { g, ...parts, tick: (t) => { g.rotation.y = -0.35 + Math.sin(t * 0.25) * 0.2; } };
326
+ }
327
+
328
+ /** Abstract network ("brain") — 14 nodes, proximity edges, travelling pulses. */
329
+ function buildBrain(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
330
+ const g = new THREE.Group();
331
+ const matA = diagramMaterial(P, "accent", cfg);
332
+ const matB = diagramMaterial(P, "second", cfg);
333
+ const rnd = makeRng(3);
334
+ const nodes: Array<{ mesh: THREE.Mesh; base: THREE.Vector3; ph: number }> = [];
335
+ const pts: THREE.Vector3[] = [];
336
+ for (let i = 0; i < 14; i++) {
337
+ const v = new THREE.Vector3(rnd() - 0.5, rnd() - 0.5, rnd() - 0.5).normalize().multiplyScalar(0.9 + rnd() * 0.5);
338
+ v.x *= 1.3;
339
+ pts.push(v);
340
+ }
341
+ pts.forEach((p, i) => {
342
+ const s = new THREE.Mesh(new THREE.SphereGeometry(i < 3 ? 0.22 : 0.12, 32, 32), i < 3 ? matA : matB);
343
+ s.position.copy(p);
344
+ s.castShadow = true;
345
+ g.add(s);
346
+ nodes.push({ mesh: s, base: p.clone(), ph: rnd() * 6 });
347
+ });
348
+ const eGeo = new THREE.CylinderGeometry(0.02, 0.02, 1, 8);
349
+ const edges: Array<{ mesh: THREE.Mesh; a: number; b: number }> = [];
350
+ for (let i = 0; i < pts.length; i++) {
351
+ for (let j = i + 1; j < pts.length; j++) {
352
+ if (pts[i].distanceTo(pts[j]) < 1.1) {
353
+ const e = new THREE.Mesh(eGeo, matB);
354
+ g.add(e);
355
+ edges.push({ mesh: e, a: i, b: j });
356
+ }
357
+ }
358
+ }
359
+ const pulses = edges.slice(0, 10).map((e, k) => {
360
+ const m = new THREE.Mesh(new THREE.SphereGeometry(0.05, 12, 12), new THREE.MeshBasicMaterial({ color: P.accent }));
361
+ g.add(m);
362
+ return { m, e, off: k / 10 };
363
+ });
364
+ // Captioned cells are pinned to an even ring inside the cloud so their
365
+ // captions never land on top of each other.
366
+ const parts: BuiltParts = { nodes: {}, labels: [] };
367
+ const captioned = series(slide, []).labels.slice(0, nodes.length);
368
+ captioned.forEach((text, i) => {
369
+ const at = ringPoint(i, captioned.length, 1.05, 0.95);
370
+ nodes[i].base.copy(at);
371
+ nodes[i].mesh.position.copy(at);
372
+ addPart(g, parts, `n${i}`, text, nodes[i].mesh, at.clone().multiplyScalar(1.3), P, cfg);
373
+ });
374
+ return {
375
+ g,
376
+ ...parts,
377
+ tick(t) {
378
+ nodes.forEach((n) => n.mesh.position.copy(n.base).addScaledVector(n.base, Math.sin(t * 1.3 + n.ph) * 0.06));
379
+ captioned.forEach((_, i) => {
380
+ parts.labels[i].object.position.copy(nodes[i].mesh.position).multiplyScalar(1.3);
381
+ });
382
+
383
+ edges.forEach((e) => {
384
+ const a = nodes[e.a].mesh.position;
385
+ const b = nodes[e.b].mesh.position;
386
+ e.mesh.position.lerpVectors(a, b, 0.5);
387
+ e.mesh.scale.y = a.distanceTo(b);
388
+ e.mesh.quaternion.setFromUnitVectors(UP, DIR.subVectors(b, a).normalize());
389
+ });
390
+ pulses.forEach((p) => {
391
+ const k = (t * 0.4 + p.off) % 1;
392
+ p.m.position.lerpVectors(nodes[p.e.a].mesh.position, nodes[p.e.b].mesh.position, k);
393
+ });
394
+ g.rotation.y = t * 0.25;
395
+ },
396
+ };
397
+ }
398
+
399
+ /** Ring of three or more stations with travelling pulses. */
400
+ function buildLoop(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig, font: Font): DiagramBuild {
401
+ const g = new THREE.Group();
402
+ const matA = diagramMaterial(P, "accent", cfg);
403
+ const matB = diagramMaterial(P, "second", cfg);
404
+ const ring = new THREE.Mesh(new THREE.TorusGeometry(1.2, 0.09, 24, 128), matB);
405
+ ring.castShadow = true;
406
+ g.add(ring);
407
+ const labels = series(slide, ["Plan", "Act", "Observe"]).labels;
408
+ const parts: BuiltParts = { nodes: {}, labels: [] };
409
+ const nodes: THREE.Group[] = [];
410
+ labels.forEach((l, i) => {
411
+ const a = Math.PI / 2 - (i * Math.PI * 2) / labels.length;
412
+ const n = new THREE.Group();
413
+ const at = new THREE.Vector3(Math.cos(a) * 1.2, Math.sin(a) * 1.2, 0);
414
+ n.position.copy(at);
415
+ const s = new THREE.Mesh(new THREE.SphereGeometry(0.3, 32, 32), matA);
416
+ s.castShadow = true;
417
+ n.add(s);
418
+ // The caption is drawn ONCE, by `addPart` below: that label is the
419
+ // measurable one, is billboarded, and honours `labels.size`. An extruded
420
+ // copy here rendered the same text a second time at a fixed size.
421
+ g.add(n);
422
+ nodes.push(n);
423
+ addPart(g, parts, `n${i}`, l, s, at.clone().multiplyScalar(1.42), P, cfg);
424
+ });
425
+ const cone = new THREE.ConeGeometry(0.14, 0.32, 16);
426
+ const arrows = labels.map((_, i) => {
427
+ const m = new THREE.Mesh(cone, matA);
428
+ g.add(m);
429
+ return { m, off: i / labels.length };
430
+ });
431
+ return {
432
+ g,
433
+ ...parts,
434
+ tick(t) {
435
+ arrows.forEach((ar) => {
436
+ const a = -Math.PI / 2 + (t * 0.5 + ar.off) * Math.PI * 2 + Math.PI / 3;
437
+ ar.m.position.set(Math.cos(a) * 1.2, Math.sin(a) * 1.2, 0);
438
+ ar.m.rotation.z = a + Math.PI / 2 + Math.PI;
439
+ });
440
+ nodes.forEach((n, i) => n.scale.setScalar(1 + Math.sin(t * 2 + i * 2.1) * 0.06));
441
+ g.rotation.y = Math.sin(t * 0.3) * 0.35;
442
+ },
443
+ };
444
+ }
445
+
446
+ /** Hub with orbiting agents — octahedra with proximity lines. */
447
+ function buildSwarm(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
448
+ const g = new THREE.Group();
449
+ const matA = diagramMaterial(P, "accent", cfg);
450
+ const matB = diagramMaterial(P, "second", cfg);
451
+ const rnd = makeRng(11);
452
+ const hub = new THREE.Mesh(new THREE.SphereGeometry(0.32, 32, 32), matA);
453
+ hub.castShadow = true;
454
+ g.add(hub);
455
+ const agents: Array<{ m: THREE.Mesh; r: number; sp: number; ph: number; tilt: number }> = [];
456
+ for (let i = 0; i < 22; i++) {
457
+ const m = new THREE.Mesh(new THREE.OctahedronGeometry(i % 5 === 0 ? 0.2 : 0.11, 1), i % 5 === 0 ? matA : matB);
458
+ m.castShadow = true;
459
+ g.add(m);
460
+ agents.push({ m, r: 0.5 + rnd() * 1.1, sp: 0.3 + rnd() * 0.6, ph: rnd() * 6, tilt: rnd() * Math.PI });
461
+ }
462
+ const lineGeo = new THREE.BufferGeometry();
463
+ const pos = new Float32Array(agents.length * agents.length * 6);
464
+ lineGeo.setAttribute("position", new THREE.BufferAttribute(pos, 3));
465
+ g.add(new THREE.LineSegments(lineGeo, new THREE.LineBasicMaterial({ color: P.second, transparent: true, opacity: 0.35 })));
466
+ // Captioned agents become fixed stations on an even ring around the hub; the
467
+ // rest keep orbiting. Captions on moving agents cross and occlude each other.
468
+ const parts: BuiltParts = { nodes: {}, labels: [] };
469
+ const captioned = series(slide, []).labels.slice(0, agents.length);
470
+ const pinned = new Set<number>();
471
+ captioned.forEach((text, i) => {
472
+ const at = ringPoint(i, captioned.length, 1.1, 0.95);
473
+ agents[i].m.position.copy(at);
474
+ pinned.add(i);
475
+ addPart(g, parts, `n${i}`, text, agents[i].m, at.clone().add(new THREE.Vector3(0, 0.3, 0)), P, cfg);
476
+ });
477
+ return {
478
+ g,
479
+ ...parts,
480
+ tick(t) {
481
+ agents.forEach((a, i) => {
482
+ if (pinned.has(i)) {
483
+ a.m.rotation.set(t * 0.5, t * 0.35, 0);
484
+ return;
485
+ }
486
+ const th = t * a.sp + a.ph;
487
+ a.m.position.set(Math.cos(th) * a.r, Math.sin(th * 1.3 + a.tilt) * a.r * 0.5, Math.sin(th) * a.r);
488
+ a.m.rotation.set(t, t * 0.7, 0);
489
+ });
490
+ let k = 0;
491
+ for (let i = 0; i < agents.length; i++) {
492
+ for (let j = i + 1; j < agents.length; j++) {
493
+ const pa = agents[i].m.position;
494
+ const pb = agents[j].m.position;
495
+ if (pa.distanceTo(pb) < 0.75) {
496
+ pos.set([pa.x, pa.y, pa.z, pb.x, pb.y, pb.z], k);
497
+ k += 6;
498
+ }
499
+ }
500
+ }
501
+ lineGeo.setDrawRange(0, k / 3);
502
+ lineGeo.attributes.position.needsUpdate = true;
503
+ },
504
+ };
505
+ }
506
+
507
+ interface FlowLayout {
508
+ sc: number;
509
+ scale: number;
510
+ toW: (x: number, y: number) => THREE.Vector3;
511
+ horiz: boolean;
512
+ minX: number;
513
+ maxX: number;
514
+ minY: number;
515
+ maxY: number;
516
+ }
517
+
518
+ function computeLayout(nodes: MergedNode[], slide: MergedSlide): FlowLayout {
519
+ const minX = Math.min(...nodes.map((n) => n.x - n.w / 2));
520
+ const maxX = Math.max(...nodes.map((n) => n.x + n.w / 2));
521
+ const minY = Math.min(...nodes.map((n) => n.y - n.h / 2));
522
+ const maxY = Math.max(...nodes.map((n) => n.y + n.h / 2));
523
+ const sc = Math.min(4.4 / Math.max(0.001, maxX - minX), 2.9 / Math.max(0.001, maxY - minY));
524
+ const cx = (minX + maxX) / 2;
525
+ const cy = (minY + maxY) / 2;
526
+ const scale = slide.diagram.scale ?? 1;
527
+ const off = slide.diagram.offset ?? {};
528
+ const horiz = slide.diagram.dir === "LR" || slide.diagram.dir === "RL";
529
+ const rank = (x: number, y: number) => (horiz ? (x - minX) / (maxX - minX || 1) : (y - minY) / (maxY - minY || 1));
530
+ const toW = (x: number, y: number) =>
531
+ new THREE.Vector3((x - cx) * sc * scale + (off.x ?? 0), -(y - cy) * sc * scale + (off.y ?? 0), (rank(x, y) - 0.5) * 0.7);
532
+ return { sc, scale, toW, horiz, minX, maxX, minY, maxY };
533
+ }
534
+
535
+ function meshForNode(n: MergedNode, degree: Record<string, number>, layout: FlowLayout, P: PaletteColors, cfg: SlideConfig): THREE.Mesh {
536
+ const w = (n.size?.w ?? n.w) * layout.sc * layout.scale;
537
+ const h = (n.size?.h ?? n.h) * layout.sc * layout.scale;
538
+ const hub = (degree[n.id] ?? 0) >= 3 || n.shape === "diamond" || n.shape === "hexagon";
539
+ const cfgN = n.material ? { ...cfg, material: n.material } : cfg;
540
+ const m = new THREE.Mesh(nodeGeometry(n.shape, w, h), diagramMaterial(P, hub ? "accent" : "second", cfgN));
541
+ const pos = layout.toW(n.x, n.y);
542
+ if (n.position) pos.add(new THREE.Vector3(n.position.x ?? 0, n.position.y ?? 0, n.position.z ?? 0));
543
+ m.position.copy(pos);
544
+ m.castShadow = true;
545
+ m.userData.label = n.label;
546
+ m.userData.ownerId = n.id;
547
+ return m;
548
+ }
549
+
550
+ function placeFlowNodes(
551
+ nodes: MergedNode[],
552
+ layout: FlowLayout,
553
+ edges: NonNullable<MergedSlide["diagram"]["edges"]>,
554
+ P: PaletteColors,
555
+ cfg: SlideConfig,
556
+ g: THREE.Group,
557
+ ): { meshes: Record<string, THREE.Mesh>; labels: BuiltLabel[] } {
558
+ const degree: Record<string, number> = {};
559
+ for (const e of edges) {
560
+ degree[e.from] = (degree[e.from] ?? 0) + 1;
561
+ degree[e.to] = (degree[e.to] ?? 0) + 1;
562
+ }
563
+ const meshes: Record<string, THREE.Mesh> = {};
564
+ const labels: BuiltLabel[] = [];
565
+ for (const n of nodes) {
566
+ const m = meshForNode(n, degree, layout, P, cfg);
567
+ g.add(m);
568
+ meshes[n.id] = m;
569
+ const h = (n.size?.h ?? n.h) * layout.sc * layout.scale;
570
+ const round = n.shape === "circle" || n.shape === "doublecircle" || n.shape === "round" || n.shape === "stadium";
571
+ const lb = buildLabel(n.label, cfg.labels?.size ?? Math.min(0.13, h * 0.45), P);
572
+ lb.group.position.set(m.position.x, m.position.y, m.position.z + (round ? h / 2 : 0.09) + 0.01);
573
+ lb.group.userData.ownerId = n.id;
574
+ g.add(lb.group);
575
+ labels.push({ id: n.id, text: n.label, object: lb.group, height: lb.height });
576
+ }
577
+ return { meshes, labels };
578
+ }
579
+
580
+ function buildFlowEdges(
581
+ edges: NonNullable<MergedSlide["diagram"]["edges"]>,
582
+ layout: FlowLayout,
583
+ P: PaletteColors,
584
+ cfg: SlideConfig,
585
+ g: THREE.Group,
586
+ ): Array<{ m: THREE.Mesh; curve: THREE.CatmullRomCurve3; off: number }> {
587
+ const matA = diagramMaterial(P, "accent", cfg);
588
+ const matB = diagramMaterial(P, "second", cfg);
589
+ const rnd = makeRng(31);
590
+ const pulses: Array<{ m: THREE.Mesh; curve: THREE.CatmullRomCurve3; off: number }> = [];
591
+ for (const e of edges) {
592
+ if (e.path.length < 2) continue;
593
+ const curve = new THREE.CatmullRomCurve3(e.path.map(([x, y]) => layout.toW(x, y)));
594
+ const thick = e.kind === "thick";
595
+ const r = thick ? 0.04 : 0.024;
596
+ const mat =
597
+ e.kind === "dotted"
598
+ ? new THREE.MeshStandardMaterial({ color: P.second, transparent: true, opacity: 0.45, metalness: 0.6, roughness: 0.3 })
599
+ : thick
600
+ ? matA
601
+ : matB;
602
+ const tube = new THREE.Mesh(new THREE.TubeGeometry(curve, 32, r, 10, false), mat);
603
+ tube.castShadow = true;
604
+ g.add(tube);
605
+ const end = curve.getPoint(1);
606
+ const pre = curve.getPoint(0.94);
607
+ const tn = end.clone().sub(pre).normalize();
608
+ const head = arrowHead(thick ? matA : matB, r);
609
+ head.position.copy(end).addScaledVector(tn, -r * 4.5);
610
+ head.lookAt(end.clone().add(tn));
611
+ g.add(head);
612
+ if (e.label) {
613
+ const lb = buildLabel(e.label, cfg.labels?.size ?? 0.09, P);
614
+ lb.group.position.copy(curve.getPoint(0.5)).add(new THREE.Vector3(0, 0.14, 0.05));
615
+ lb.group.userData.ownerId = e.id;
616
+ g.add(lb.group);
617
+ }
618
+ const pm = new THREE.Mesh(new THREE.SphereGeometry(r * 2.2, 12, 12), new THREE.MeshBasicMaterial({ color: P.accent }));
619
+ g.add(pm);
620
+ pulses.push({ m: pm, curve, off: rnd() });
621
+ }
622
+ return pulses;
623
+ }
624
+
625
+ function buildGroupPlates(
626
+ groups: NonNullable<MergedSlide["diagram"]["groups"]>,
627
+ meshes: Record<string, THREE.Mesh>,
628
+ P: PaletteColors,
629
+ cfg: SlideConfig,
630
+ g: THREE.Group,
631
+ ): void {
632
+ for (const sg of groups) {
633
+ const mem = sg.nodes.map((id) => meshes[id]).filter(Boolean);
634
+ if (!mem.length) continue;
635
+ const bb = new THREE.Box3();
636
+ mem.forEach((m) => bb.expandByObject(m));
637
+ bb.expandByScalar(0.22);
638
+ const sz = bb.getSize(new THREE.Vector3());
639
+ const c = bb.getCenter(new THREE.Vector3());
640
+ const plate = new THREE.Mesh(
641
+ new THREE.BoxGeometry(sz.x, sz.y, 0.05),
642
+ new THREE.MeshPhysicalMaterial({
643
+ color: P.card,
644
+ transmission: cfg.material === "glass" ? 0.6 : 0,
645
+ transparent: true,
646
+ opacity: 0.75,
647
+ roughness: 0.3,
648
+ envMapIntensity: cfg.envReflections !== false ? 0.8 : 0,
649
+ }),
650
+ );
651
+ plate.position.set(c.x, c.y, bb.min.z - 0.08);
652
+ g.add(plate);
653
+ const lb = buildLabel(sg.title, cfg.labels?.size ?? 0.09, P);
654
+ lb.group.position.set(c.x, bb.max.y + 0.02, bb.min.z - 0.05);
655
+ g.add(lb.group);
656
+ }
657
+ }
658
+
659
+ /** Harvested flowchart → 3D staircase with tubes, arrow-heads and group plates. */
660
+ function buildFlowchart(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
661
+ const ir = slide.diagram;
662
+ const g = new THREE.Group();
663
+ const nodes = ir.nodes ?? [];
664
+ if (!nodes.length) return empty();
665
+ const layout = computeLayout(nodes, slide);
666
+ const edges = ir.edges ?? [];
667
+ const { meshes, labels } = placeFlowNodes(nodes, layout, edges, P, cfg, g);
668
+ const pulses = buildFlowEdges(edges, layout, P, cfg, g);
669
+ buildGroupPlates(ir.groups ?? [], meshes, P, cfg, g);
670
+ return {
671
+ g,
672
+ nodes: meshes,
673
+ labels,
674
+ tick(t) {
675
+ pulses.forEach((p) => p.m.position.copy(p.curve.getPoint((t * 0.35 + p.off) % 1)));
676
+ g.rotation.y = Math.sin(t * 0.25) * 0.28;
677
+ },
678
+ };
679
+ }
680
+
681
+ /** Harvested sequence → actor slabs, time staircase, messages lighting in order. */
682
+ function buildSequence(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig): DiagramBuild {
683
+ const ir = slide.diagram;
684
+ const g = new THREE.Group();
685
+ const matB = diagramMaterial(P, "second", cfg);
686
+ const actors = ir.actors ?? [];
687
+ const messages = ir.messages ?? [];
688
+ const n = actors.length;
689
+ const m = messages.length;
690
+ const X: Record<string, number> = {};
691
+ const labels: BuiltLabel[] = [];
692
+ actors.forEach((a, i) => {
693
+ X[a.id] = (i - (n - 1) / 2) * (3.8 / Math.max(1, n - 1 || 1));
694
+ });
695
+ const yz = (k: number): [number, number] => [0.9 - k * (2.0 / Math.max(1, m - 1 || 1)), 0.7 - k * (2.0 / Math.max(1, m - 1 || 1))];
696
+ actors.forEach((a) => {
697
+ const head = new THREE.Mesh(new THREE.BoxGeometry(1.05, 0.38, 0.14), matB);
698
+ head.position.set(X[a.id], 1.4, 0.9);
699
+ head.castShadow = true;
700
+ g.add(head);
701
+ const lb = buildLabel(a.label, cfg.labels?.size ?? 0.13, P);
702
+ lb.group.position.set(X[a.id], 1.4, 0.98);
703
+ lb.group.userData.ownerId = a.id;
704
+ g.add(lb.group);
705
+ labels.push({ id: a.id, text: a.label, object: lb.group, height: lb.height });
706
+ const [y0, z0] = yz(-0.5);
707
+ const [y1, z1] = yz(m - 0.5);
708
+ const life = new THREE.Mesh(
709
+ new THREE.TubeGeometry(
710
+ new THREE.LineCurve3(new THREE.Vector3(X[a.id], y0 + 0.2, z0 + 0.2), new THREE.Vector3(X[a.id], y1, z1)),
711
+ 1,
712
+ 0.015,
713
+ 8,
714
+ false,
715
+ ),
716
+ new THREE.MeshStandardMaterial({ color: P.second, transparent: true, opacity: 0.5 }),
717
+ );
718
+ g.add(life);
719
+ });
720
+ const msgs = messages.map((msg, k) => {
721
+ const [y, z] = yz(k);
722
+ // A self-message has no horizontal span; give it a short stub so the tube
723
+ // is not zero-length (degenerate geometry would poison measurement/raycast).
724
+ const same = msg.from === msg.to;
725
+ const a = new THREE.Vector3(X[msg.from] ?? 0, y, z);
726
+ const b = new THREE.Vector3((X[msg.to] ?? 0) + (same ? 0.35 : 0), y, z);
727
+ const dir = b.clone().sub(a).normalize();
728
+ const dotted = msg.kind === "dotted";
729
+ const mat = new THREE.MeshStandardMaterial({
730
+ color: dotted ? P.second : P.accent,
731
+ metalness: 0.7,
732
+ roughness: 0.3,
733
+ transparent: dotted,
734
+ opacity: dotted ? 0.55 : 1,
735
+ emissive: P.accent,
736
+ emissiveIntensity: 0,
737
+ });
738
+ const mg = new THREE.Group();
739
+ mg.userData.ownerId = msg.id;
740
+ g.add(mg);
741
+ const tube = new THREE.Mesh(new THREE.TubeGeometry(new THREE.LineCurve3(a, b.clone().addScaledVector(dir, -0.14)), 1, 0.03, 10, false), mat);
742
+ tube.castShadow = true;
743
+ mg.add(tube);
744
+ const head = arrowHead(mat, 0.03);
745
+ head.position.copy(b).addScaledVector(dir, -0.11);
746
+ head.lookAt(b);
747
+ mg.add(head);
748
+ const lb = buildLabel(msg.text, cfg.labels?.size ?? 0.105, P);
749
+ lb.group.position.copy(a).lerp(b, 0.5).add(new THREE.Vector3(0, 0.15, 0.02));
750
+ lb.group.userData.ownerId = msg.id;
751
+ mg.add(lb.group);
752
+ labels.push({ id: msg.id, text: msg.text, object: lb.group, height: lb.height });
753
+ const pulse = new THREE.Mesh(new THREE.SphereGeometry(0.07, 12, 12), new THREE.MeshBasicMaterial({ color: P.accent }));
754
+ pulse.visible = false;
755
+ mg.add(pulse);
756
+ return { mat, mg, pulse, a, b };
757
+ });
758
+ const period = 1.1;
759
+ let active: string | null = null;
760
+ return {
761
+ g,
762
+ labels,
763
+ lifted: () => active,
764
+ tick(t) {
765
+ const act = Math.floor(t / period) % Math.max(1, m);
766
+ active = messages[act]?.id ?? null;
767
+ const ph = (t / period) % 1;
768
+ msgs.forEach((x, k) => {
769
+ const on = k === act;
770
+ x.mat.emissiveIntensity += ((on ? 0.7 : 0) - x.mat.emissiveIntensity) * 0.15;
771
+ x.mg.position.z += ((on ? 0.12 : 0) - x.mg.position.z) * 0.15;
772
+ x.pulse.visible = on;
773
+ if (on) x.pulse.position.lerpVectors(x.a, x.b, ph);
774
+ });
775
+ g.rotation.y = -0.22 + Math.sin(t * 0.25) * 0.1;
776
+ },
777
+ };
778
+ }
779
+
780
+ export function buildDiagram(slide: MergedSlide, P: PaletteColors, cfg: SlideConfig, font: Font): DiagramBuild {
781
+ const kind = slide.diagram.kind;
782
+ switch (kind) {
783
+ case "flowchart":
784
+ return buildFlowchart(slide, P, cfg);
785
+ case "sequence":
786
+ return buildSequence(slide, P, cfg);
787
+ case "brain":
788
+ return buildBrain(slide, P, cfg);
789
+ case "loop":
790
+ return buildLoop(slide, P, cfg, font);
791
+ case "swarm":
792
+ return buildSwarm(slide, P, cfg);
793
+ case "bars":
794
+ return buildBars(slide, P, cfg);
795
+ case "funnel":
796
+ return buildFunnel(slide, P, cfg);
797
+ case "timeline-rail":
798
+ return buildTimelineRail(slide, P, cfg);
799
+ case "globe":
800
+ return buildGlobe(slide, P, cfg);
801
+ case "orbit-cluster":
802
+ return buildOrbitCluster(slide, P, cfg);
803
+ case "stack":
804
+ return buildStack(slide, P, cfg);
805
+ default:
806
+ return empty();
807
+ }
808
+ }