createNodeLink#setEdges¶
Summary¶
Use setEdges, setEdgeScalars and setEdgeColors to replace edge pairs and their scalar or RGBA channels.
NodeLink.setEdgesandNodeLink.updateEdgesuse source/destination node-index pairs.- CPU-backed edge pairs can be
Uint16ArrayorUint32Array. Both indices in each pair must name existing nodes. A GPU edge buffer holds pairs ofu32indices. - Edge scalar length must match
NodeLink.edgeCount. - Edge colors are RGBA float data with four components per edge.
- GPU-buffer setters replace CPU-backed data for that category.
- GPU buffers are borrowed by default. Pass
{ ownBuffer: true }to a GPU-buffer setter to transfer destruction responsibility for that replacement. - Update methods patch subranges and validate bounds before writing. Use
GPUBufferUsage.STORAGEon external channel buffers and includeGPUBufferUsage.COPY_DSTwhen patching them through these methods.
Syntax¶
NodeLink.setEdges(data: Uint16Array | Uint32Array, opts?: { keepCPUData?: boolean }): void
NodeLink.updateEdges(data: Uint16Array | Uint32Array, startEdge?: number): void
NodeLink.setEdgesBuffer(buffer: GPUBuffer, edgeCount: number, opts?: { ownBuffer?: boolean }): void
NodeLink.setEdgeScalars(data: Float32Array, opts?: { keepCPUData?: boolean }): void
NodeLink.updateEdgeScalars(data: Float32Array, startEdge?: number): void
NodeLink.setEdgeScalarsBuffer(buffer: GPUBuffer | null, opts?: { ownBuffer?: boolean }): void
NodeLink.setEdgeColors(data: Float32Array, opts?: { keepCPUData?: boolean }): void
NodeLink.updateEdgeColors(data: Float32Array, startEdge?: number): void
NodeLink.setEdgeColorsBuffer(buffer: GPUBuffer | null, opts?: { ownBuffer?: boolean }): void
NodeLink.setWasmEdges(source: WasmMemoryView<Uint32Array> | null, options?: NodeLinkWasmEdgeChannelOptions): void
NodeLink.refreshWasmEdges(options?: NodeLinkWasmEdgeRefreshOptions): void
NodeLink.setWasmEdgeScalars(source: WasmMemoryView<Float32Array> | null, options?: NodeLinkWasmEdgeChannelOptions): void
NodeLink.refreshWasmEdgeScalars(options?: NodeLinkWasmEdgeRefreshOptions): void
NodeLink.setWasmEdgeColors(source: WasmMemoryView<Float32Array> | null, options?: NodeLinkWasmEdgeChannelOptions): void
NodeLink.refreshWasmEdgeColors(options?: NodeLinkWasmEdgeRefreshOptions): void
WebAssembly channel setters borrow memory and refresh immediately. Their matching refresh methods re-read the source after producer writes or memory growth. Wasm edges are u32 endpoint pairs, scalars are one f32 per edge, and colors are vec4<f32>. Options control edgeCount, grow-only managed GPU record capacity, and retained CPU snapshots. Passing null detaches that channel and destroys its managed GPU copy.
Every edge endpoint must be an integer in [0, nodeCount), regardless of source family. Validate producer-owned WebAssembly views and external GPU buffers before supplying them. Update methods copy queued patch bytes and update retained CPU arrays only when present. External buffers must support storage binding and have sufficient capacity.
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
data |
Uint16Array | Uint32Array | Float32Array |
Yes | CPU-array payload for edges, edge scalars, or edge colors. |
opts |
Object | No | CPU-array setters accept keepCPUData; GPU-buffer setters accept ownBuffer. Omitting keepCPUData preserves the current setting for the graph, initially false. |
startEdge |
number |
No | First edge index to patch. Defaults to 0. |
buffer |
GPUBuffer | null |
Yes | External GPU buffer to use for the matching edge data category. |
edgeCount |
number |
Yes | Required edge count for NodeLink.setEdgesBuffer. |
Returns¶
void - No return value. The call updates edge-side runtime state and may queue later GPU uploads.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const graph = wgpu.createNodeLink({
nodePositions: new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0]),
keepCPUData: true
});
graph.setEdges(new Uint16Array([0, 1, 1, 2]));
graph.setEdgeScalars(new Float32Array([0.2, 0.8]));
graph.updateEdges(new Uint16Array([2, 0]), 1);
console.log(graph.getEdgeRecord(1).dst); // 0
graph.destroy();