Skip to content

WasmGPU.createLatticeSpace

Summary

WasmGPU.createLatticeSpace creates a regular 2D or 3D cell lattice. Flat data uses X-fastest indexing: x + width * y in 2D and x + width * (y + height * z) in 3D.

The renderer draws procedural quads for 2D cells and cubes for 3D cells. This is a surface-cell renderer, not raymarched participating-media volume rendering.

Syntax

WasmGPU.createLatticeSpace(descriptor: LatticeSpaceDescriptor): LatticeSpace
const lattice = wgpu.createLatticeSpace(descriptor);

Parameters

Name Type Required Description
descriptor LatticeSpaceDescriptor Yes Structural dimensions plus optional data, mask, layout, appearance, and ownership settings.

Returns

LatticeSpace - Scene object with immutable dimensions/component count and mutable layout, appearance, and data sources.

Descriptor

type LatticeSpaceDimensions =
    | [number, number]
    | [number, number, number];

type LatticeSpaceIndex =
    | [number, number]
    | [number, number, number];

type LatticeSpaceIndexRange = {
    min: LatticeSpaceIndex;
    max: LatticeSpaceIndex;
};

type LatticeSpaceColorMode = "scalar" | "rgba" | "solid";
type LatticeSpaceColorSpace = "linear" | "srgb";
type LatticeSpaceColormap = BuiltinColormapName | "custom";
type LatticeSpaceVisualChangeKind = "scale" | "colormap" | "visual";

type LatticeSpaceDescriptor = {
    dimensions: LatticeSpaceDimensions;
    componentCount?: 1 | 2 | 3 | 4;
    data?: Float32Array;
    wasmData?: WasmMemoryView<Float32Array>;
    dataBuffer?: GPUBuffer | { buffer: GPUBuffer };
    mask?: Uint32Array;
    wasmMask?: WasmMemoryView<Uint32Array>;
    maskBuffer?: GPUBuffer | { buffer: GPUBuffer };
    wasmCapacity?: number;
    origin?: [number, number, number];
    spacing?: [number, number, number];
    cellScale?: number | [number, number, number];
    indexRange?: LatticeSpaceIndexRange;
    valueRange?: [number, number] | null;
    colorMode?: LatticeSpaceColorMode;
    colorSpace?: LatticeSpaceColorSpace;
    solidColor?: [number, number, number, number];
    colormap?: LatticeSpaceColormap | Colormap;
    colormapStops?: Color4[];
    scaleTransform?: ScaleTransformDescriptor;
    opacity?: number; lit?: boolean;
    blendMode?: BlendMode; cullMode?: CullMode;
    depthWrite?: boolean; depthTest?: boolean;
    visible?: boolean; name?: string;
    keepCPUData?: boolean; ownBuffers?: boolean;
};

dimensions, dimensionCount, cellCount, and componentCount are structural and do not change after construction. data.length must equal cellCount * componentCount; mask.length must equal cellCount.

data, wasmData, and dataBuffer are mutually exclusive. The same rule applies independently to mask, wasmMask, and maskBuffer. Data buffers store packed f32 components and must cover cellCount * componentCount values; mask buffers store one u32 per cell. External GPU buffers are borrowed unless ownBuffers: true transfers destruction responsibility; WebAssembly views always remain borrowed.

Defaults include componentCount: 1, origin: [0, 0, 0], spacing: [1, 1, 1], cellScale: 1, the full half-open index range, scalar/linear color interpretation, "viridis" colormap, full opacity, unlit shading, opaque blending, back-face culling, and enabled depth testing/writing. The "rgba" color mode requires four components.

Example

const lattice = wgpu.createLatticeSpace({
    dimensions: [64, 64],
    data: values,
    origin: [-3.2, -3.2, 0],
    spacing: [0.1, 0.1, 1],
    cellScale: 0.92,
    colorMode: "scalar",
    scaleTransform: { mode: "linear", domainMin: -1, domainMax: 1 },
    keepCPUData: true
});
scene.add(lattice);

Member Reference

See Also