API REFERENCE · 2.2.0

wgpu-kit/three

Three.js CPU-snapshot adapter, with explicit ownership and current-version limits.

Auxiliary inputs, dispatch counts, managed batches and typed kernels are released in 2.1.0. The original API retains the published npm 2.0.0 declarations and implementation as its historical audit baseline; Additions in 2.1.0 and 2.2.0 are identified on affected APIs and cite src files, without claiming a fresh audit of the entire API. Only actual public exports of this entry point are listed.

Source reference: 1 ↗ 2 ↗

threePointsfunction

Create a Three.js Points object driven by CPU snapshots of a particle position buffer.

threePoints(
  sim: ParticlesSim,
  THREE: ThreeAPI,
  opts?: { size?: number; color?: number },
): ThreePointsHandle;

Parameters

NameTypeRequiredDefaultMeaning
simParticlesSimYes—Particle simulation; its position-buffer length determines point count. The handle dispose() also destroys this simulation.
THREEThreeAPIYes—Injected Three.js constructors; no hard Three.js dependency is installed by this adapter.
opts{ size?: number; color?: number }No{}Point material options.
opts.sizenumberNo0.015Passed to PointsMaterial.size with sizeAttenuation=true.
opts.colornumberNo0x8fb4ffUniform material color; this adapter does not copy per-species colors.

Returns

ThreePointsHandle A Points handle with asynchronous update and disposal. positions initially contain zeroes until update() completes.

Behavior & constraints

  • Each update reads GPU data back to CPU and marks a Three BufferAttribute dirty; it is not a zero-copy WebGPU/TSL bridge. z is fixed at 0.
  • Version 2.0.0 captures sim.buffers().pos only once at construction. Particle simulation ping-pong changes the current buffer after tick(), so update() may read the previous step on alternating ticks. Do not promise every update is the newest step.
  • The geometry must provide setAttribute at runtime although ThreeAPI types BufferGeometry as returning unknown. There is no automatic resize, render loop, scene removal, geometry disposal, or material disposal.

Examples

Create an accurate initial snapshot and explicitly dispose Three resources.
import * as THREE from 'three';
import { particles } from 'wgpu-kit/particles';
import { threePoints, type ThreeAPI } from 'wgpu-kit/three';
const sim = await particles({ count: 1024 });
const handle = threePoints(sim, THREE as unknown as ThreeAPI, { size: 0.02 });
const points = handle.points as THREE.Points;
const scene = new THREE.Scene();
scene.add(points);
await handle.update(); // Initial snapshot; no tick has changed the buffer.
// Render scene with your camera and renderer.
function dispose() {
  scene.remove(points);
  points.geometry.dispose();
  const materials = Array.isArray(points.material)
    ? points.material
    : [points.material];
  materials.forEach((material) => material.dispose());
  handle.dispose(); // Also destroys sim.
}

ThreeAPIinterface

Minimal structural constructor surface injected into threePoints.

interface ThreeAPI

Pointsconstructor property

Construct the returned point cloud.

Points: new (geometry: unknown, material: unknown) => unknown;

Parameters

NameTypeRequiredDefaultMeaning
geometryunknownYes—Geometry constructed below, with a position attribute.
materialunknownYes—Constructed point material.

Returns

unknown Usually THREE.Points; retain/cast its concrete type in the application.

BufferGeometryconstructor property

Construct a geometry; runtime must support setAttribute(name, attribute).

BufferGeometry: new () => unknown;

Parameters

This call takes no arguments.

Returns

unknown Geometry object.

BufferAttributeconstructor property

Construct a position attribute backed by a Float32Array.

BufferAttribute: new (
  array: Float32Array,
  itemSize: number,
) => { set: (arr: ArrayLike<number>) => void; needsUpdate: boolean };

Parameters

NameTypeRequiredDefaultMeaning
arrayFloat32ArrayYes—Backing positions array of count*3 components.
itemSizenumberYes—Components per item; adapter passes 3.

Returns

{ set: (arr: ArrayLike<number>) => void; needsUpdate: boolean } Attribute whose needsUpdate is set true after each snapshot. The declared set(arr) method is not called by this adapter.

Fields & related types

NameTypeRequiredDefaultMeaning
set(arr)(arr: ArrayLike<number>) => void——Required by the structural declaration; array-like numbers to copy. Unused internally.
needsUpdateboolean——Writable flag set true after snapshot copy.

PointsMaterialconstructor property

Construct the point material.

PointsMaterial: new (params: {
  size?: number;
  color?: number;
  sizeAttenuation?: boolean;
}) => unknown;

Parameters

NameTypeRequiredDefaultMeaning
params{ size?: number; color?: number; sizeAttenuation?: boolean }Yes—Material option object.
params.sizenumberNo—Point size; adapter supplies opts.size ?? 0.015.
params.colornumberNo—Color; adapter supplies opts.color ?? 0x8fb4ff.
params.sizeAttenuationbooleanNo—Perspective size attenuation; adapter explicitly passes true.

Returns

unknown Material object.

ThreePointsHandleinterface

Point object and lifecycle returned by threePoints.

interface ThreePointsHandle

pointsproperty

Constructed THREE.Points instance, ready to add to a scene.

points: unknown;

Returns

unknown Concrete object from injected THREE.Points.

updatemethod

Read the captured position buffer and copy x/y into the attribute; z=0.

update(): Promise<void>;

Parameters

This call takes no arguments.

Returns

Promise<void> Resolves after readback and attribute update. It does not render the scene.

Behavior & constraints

  • Await updates serially; Buffer.read mapping and captured-buffer limitations apply.

Errors & failure cases

  • GPU readback failures propagate as rejected promises.

disposemethod

Calls sim.destroy().

dispose(): void;

Parameters

This call takes no arguments.

Returns

void No return value.

Behavior & constraints

  • This destroys the supplied simulation, but does not remove points from its scene or call geometry/material.dispose(). Clean those up separately.

Search concepts, APIs, and examples