(paths: readonly EdgePulsePath[])
| 19 | } |
| 20 | /** One line batch for every curve; progress is measured from semantic source to target. */ |
| 21 | export function edgePulseGeometry(paths: readonly EdgePulsePath[]): BufferGeometry { |
| 22 | const positions: number[] = [], colors: number[] = [], flow: number[] = []; |
| 23 | for (const path of paths) { |
| 24 | if (!isDirectedEdge(path.type, path.types) || path.points.length < 2 || (path.opacity ?? 1) <= 0) continue; |
| 25 | if (path.points.some(point => ![point.x, point.y, point.z].every(Number.isFinite))) continue; |
| 26 | const distances = [0]; |
| 27 | for (let i = 1; i < path.points.length; i++) { |
| 28 | const a = path.points[i - 1], b = path.points[i]; |
| 29 | distances.push(distances[i - 1] + Math.hypot(b.x - a.x, b.y - a.y, b.z - a.z)); |
| 30 | } |
| 31 | const total = distances.at(-1)!; |
| 32 | if (!total) continue; |
| 33 | const color = new Color(path.color ?? edgeColor(path.type, path.types)), phase = edgePhase(path.id); |
| 34 | for (let i = 1; i < path.points.length; i++) for (const index of [i - 1, i]) { |
| 35 | const point = path.points[index]; |
| 36 | positions.push(point.x, point.y, point.z); colors.push(color.r, color.g, color.b); |
| 37 | flow.push(distances[index] / total, phase, Math.max(0, Math.min(1, path.opacity ?? .7))); |
| 38 | } |
| 39 | } |
| 40 | const geometry = new BufferGeometry(); |
| 41 | geometry.setAttribute('position', new Float32BufferAttribute(positions, 3)); |
| 42 | geometry.setAttribute('color', new Float32BufferAttribute(colors, 3)); |
| 43 | geometry.setAttribute('edgeFlow', new Float32BufferAttribute(flow, 3)); |
| 44 | geometry.computeBoundingSphere(); |
| 45 | return geometry; |
| 46 | } |
| 47 | |
| 48 | /** One screen-facing triangle per curve segment; only the segment under the |
| 49 | * travelling head is visible. This keeps every arrow in one GPU draw call. */ |
no test coverage detected