createNodeLink#setNodePositions¶
Summary¶
Use setNodePositions, setNodeScalars, setNodeColors and setNodeRadii to replace individual node channels. The corresponding update methods patch values and the buffer setters attach GPU storage. Positions, scalars, colors, and radii can come from CPU arrays or from external GPU buffers.
- Positions and radii accept stride
3or4on the CPU-array path and default to3. GPU buffers for those channels hold four floats per node. - Colors are RGBA float data with four components per node.
- Scalar data length must match
NodeLink.nodeCount. - 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.setNodePositions(data: Float32Array, opts?: { stride?: 3 | 4; keepCPUData?: boolean }): void
NodeLink.updateNodePositions(data: Float32Array, startNode?: number, stride?: 3 | 4): void
NodeLink.setNodePositionsBuffer(buffer: GPUBuffer, nodeCount: number, opts?: { ownBuffer?: boolean }): void
NodeLink.setNodeScalars(data: Float32Array, opts?: { keepCPUData?: boolean }): void
NodeLink.updateNodeScalars(data: Float32Array, startNode?: number): void
NodeLink.setNodeScalarsBuffer(buffer: GPUBuffer | null, opts?: { ownBuffer?: boolean }): void
NodeLink.setNodeColors(data: Float32Array, opts?: { keepCPUData?: boolean }): void
NodeLink.updateNodeColors(data: Float32Array, startNode?: number): void
NodeLink.setNodeColorsBuffer(buffer: GPUBuffer | null, opts?: { ownBuffer?: boolean }): void
NodeLink.setNodeRadii(data: Float32Array, opts?: { stride?: 3 | 4; keepCPUData?: boolean }): void
NodeLink.updateNodeRadii(data: Float32Array, startNode?: number, stride?: 3 | 4): void
NodeLink.setNodeRadiiBuffer(buffer: GPUBuffer | null, opts?: { ownBuffer?: boolean }): void
NodeLink.setWasmNodePositions(source: WasmMemoryView<Float32Array> | null, options?: NodeLinkWasmNodeChannelOptions): void
NodeLink.refreshWasmNodePositions(options?: NodeLinkWasmNodeRefreshOptions): void
NodeLink.setWasmNodeScalars(source: WasmMemoryView<Float32Array> | null, options?: NodeLinkWasmNodeChannelOptions): void
NodeLink.refreshWasmNodeScalars(options?: NodeLinkWasmNodeRefreshOptions): void
NodeLink.setWasmNodeColors(source: WasmMemoryView<Float32Array> | null, options?: NodeLinkWasmNodeChannelOptions): void
NodeLink.refreshWasmNodeColors(options?: NodeLinkWasmNodeRefreshOptions): void
NodeLink.setWasmNodeRadii(source: WasmMemoryView<Float32Array> | null, options?: NodeLinkWasmNodeChannelOptions): void
NodeLink.refreshWasmNodeRadii(options?: NodeLinkWasmNodeRefreshOptions): void
WebAssembly channel setters borrow memory and refresh immediately. Their matching refresh methods re-read the source after producer writes or memory growth. Wasm positions, colors, and radii are fixed vec4 records; Wasm scalars use one float per node. Options control nodeCount, grow-only managed GPU record capacity, CPU retention, and position-only bounds recomputation. Passing null detaches that channel and destroys its managed GPU copy.
CPU setters copy/pack their input. Update methods also copy queued GPU patch bytes and update retained CPU arrays only when present. External buffers must support storage binding and have sufficient capacity; those properties are caller-enforced. Replacing an owned buffer destroys it, while a borrowed replacement is only detached.
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
data |
Float32Array |
Yes | CPU-array payload for node positions, node scalars, node colors, or node radii. |
opts |
Object | No | CPU-array setters accept stride/keepCPUData; GPU-buffer setters accept ownBuffer. Omitting keepCPUData preserves the current setting for the graph, initially false. |
startNode |
number |
No | First node index to patch. Defaults to 0. |
stride |
3 | 4 |
No | CPU tuple width for position or radii data. |
buffer |
GPUBuffer | null |
Yes | External GPU buffer to use for the matching node data category. |
nodeCount |
number |
Yes | Required node count for NodeLink.setNodePositionsBuffer. |
Returns¶
void - No return value. The call updates node-side runtime state and may queue later GPU uploads.
Example¶
const wgpu = await WasmGPU.create(document.querySelector("canvas"));
const graph = wgpu.createNodeLink({ keepCPUData: true });
graph.setNodePositions(new Float32Array([0, 0, 0, 1, 0, 0]));
graph.setNodeScalars(new Float32Array([0.1, 0.5]));
graph.updateNodePositions(new Float32Array([1.25, 0, 0]), 1);
console.log(graph.getNodeRecord(1).position); // [1.25, 0, 0]
graph.destroy();