# writeVoxel

Function

Source: https://github.com/playcanvas/splat-transform/blob/b6424a5b3b929695fbaafe738a995adb1240d675/src/lib/writers/write-voxel.ts#L420

```ts
writeVoxel(options: WriteVoxelOptions, fs: FileSystem): Promise<void>
```

Voxelizes Gaussian splat data and writes the result as a sparse voxel octree.

This function performs GPU-accelerated voxelization of Gaussian splat data
and outputs two or three files:
- `filename` (.voxel.json) - JSON metadata including bounds, resolution, and array sizes
- Corresponding .voxel.bin - Binary octree data (nodes + leafData as Uint32 arrays)
- Corresponding .collision.glb - Triangle mesh extracted from the voxel output (GLB format, optional)

The binary file layout is:
- Bytes 0 to (nodeCount * 4 - 1): nodes array (Uint32, little-endian)
- Bytes (nodeCount * 4) to end: leafData array (Uint32, little-endian)

**Parameters**

- `options` ([`WriteVoxelOptions`](https://api.playcanvas.com/splat-transform/types/WriteVoxelOptions.md)): Options including filename, data, and voxelization settings.
- `fs` (`FileSystem`): File system for writing output files.

**Returns** `Promise<void>`

**Example**

```ts
import { writeVoxel, MemoryFileSystem } from '@playcanvas/splat-transform';

const fs = new MemoryFileSystem();
await writeVoxel({
    filename: 'scene.voxel.json',
    dataTable: myDataTable,
    voxelResolution: 0.05,
    opacityCutoff: 0.1,
    collisionMesh: true,
    createDevice: async () => myGraphicsDevice
}, fs);
```
