(paths: readonly EdgePulsePath[])
| 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. */ |
| 50 | export function edgeArrowGeometry(paths: readonly EdgePulsePath[]): BufferGeometry { |
| 51 | const position: number[] = [], starts: number[] = [], ends: number[] = [], colors: number[] = [], flows: number[] = []; |
| 52 | for (const path of paths) { |
| 53 | if (!isDirectedEdge(path.type, path.types) || path.points.length < 2 || (path.opacity ?? 1) <= 0) continue; |
| 54 | if (path.points.some(point => ![point.x, point.y, point.z].every(Number.isFinite))) continue; |
| 55 | const distances = [0]; |
| 56 | for (let i = 1; i < path.points.length; i++) { |
| 57 | const a = path.points[i - 1], b = path.points[i]; |
| 58 | distances.push(distances[i - 1] + Math.hypot(b.x - a.x, b.y - a.y, b.z - a.z)); |
| 59 | } |
| 60 | const total = distances.at(-1)!; |
| 61 | if (!total) continue; |
| 62 | const color = new Color(path.color ?? edgeColor(path.type, path.types)); |
| 63 | for (let i = 1; i < path.points.length; i++) { |
| 64 | if (distances[i] === distances[i - 1]) continue; |
| 65 | const a = path.points[i - 1], b = path.points[i]; |
| 66 | for (const [x, y] of [[1, 0], [-.65, .4], [-.65, -.4]]) { |
| 67 | position.push(x, y, 0); starts.push(a.x, a.y, a.z); ends.push(b.x, b.y, b.z); |
| 68 | colors.push(color.r, color.g, color.b); |
| 69 | flows.push(distances[i - 1] / total, distances[i] / total, edgePhase(path.id), Math.min(1, path.opacity ?? .7) * .3); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | const geometry = new BufferGeometry(); |
| 74 | geometry.setAttribute('position', new Float32BufferAttribute(position, 3)); |
| 75 | geometry.setAttribute('arrowStart', new Float32BufferAttribute(starts, 3)); |
| 76 | geometry.setAttribute('arrowEnd', new Float32BufferAttribute(ends, 3)); |
| 77 | geometry.setAttribute('color', new Float32BufferAttribute(colors, 3)); |
| 78 | geometry.setAttribute('arrowFlow', new Float32BufferAttribute(flows, 4)); |
| 79 | return geometry; |
| 80 | } |
| 81 | |
| 82 | const vertexShader = ` |
| 83 | uniform float uTime; |
no test coverage detected