API

Interface MeshFromStorageOptions

Describes a mesh whose vertices are produced on the GPU.

interface MeshFromStorageOptions {
    arrayStride: number;
    attributeOffsets?: Partial<
        Record<
            "position"
            | "normal"
            | "tangent"
            | "uv"
            | "uv2"
            | "color",
            number,
        >,
    >;
    baseVertex?: number;
    boundMax?: readonly [number, number, number];
    boundMin?: readonly [number, number, number];
    indexCount?: number;
    indexFormat?: GPUIndexFormat;
    indices:
        | StorageBuffer
        | Uint32Array<ArrayBufferLike>
        | Uint16Array<ArrayBufferLike>;
    storage: StorageBuffer;
    vertexCount: number;
}
Index
arrayStride: number

Byte stride of one vertex inside storage. A positive multiple of four within the device's vertex-stride limit.

attributeOffsets?: Partial<
    Record<
        "position"
        | "normal"
        | "tangent"
        | "uv"
        | "uv2"
        | "color",
        number,
    >,
>

Own-property byte offsets inside one vertex. Values must be non-negative integers smaller than arrayStride. Omitted position, normal, and UV attributes sit at offset 0, which is the right default when a single float32x4 position is the whole vertex.

Only the six streams MeshVbLayout describes can be offset (position, normal, tangent, uv, uv2, color); skinning attributes are not supported from a slab.

baseVertex?: number

First vertex of this mesh within a shared allocation.

This is how many meshes share ONE slab: each takes a slot and addresses it through the draw call's baseVertex, rather than a non-zero setVertexBuffer bind offset (which corrupts vertex fetch on some AMD/Dawn paths). Default 0.

boundMax?: readonly [number, number, number]

Analytic upper bound of the produced geometry, in mesh-local space.

boundMin?: readonly [number, number, number]

Analytic lower bound of the produced geometry, in mesh-local space.

indexCount?: number

Number of indices to draw. Required when indices is a shared allocation, since its byte length is padded and need not equal the draw count. Defaults to the typed array's length. Must be a positive integer within the source capacity. Every used typed-array index must be less than vertexCount.

indexFormat?: GPUIndexFormat

Index format. Derived from the typed array's element size when indices is one (an explicit format must match); REQUIRED when indices is a shared allocation, whose element size is not recoverable from the allocation. A 16-bit topology declared as 32-bit fails WebGPU validation with a size complaint that points at the buffer rather than at the format.

indices:
    | StorageBuffer
    | Uint32Array<ArrayBufferLike>
    | Uint16Array<ArrayBufferLike>

Triangle indices.

A Uint16Array or Uint32Array is snapshotted and uploaded into a fresh index buffer owned by this mesh. The used prefix is validated for the initial upload; later changes to the caller's array do not change the uploaded topology.

A StorageBuffer created with { index: true } is used in place, SHARED with every other mesh given the same allocation. That is the right form for a slab of uniform slots, where every slot's indices are byte-identical and uploading them per mesh would duplicate the same kilobytes thousands of times. A shared allocation is NOT freed with the mesh; it outlives the meshes and the caller disposes it.

storage: StorageBuffer

Vertex source. Must be vertex: true; GPU-written sources also require writable: true.

vertexCount: number

Logical vertex count in this mesh's slot, used for range validation and missing-stream defaults.