writeVox()
Serialize one model to a MagicaVoxel ".vox" ArrayBuffer (SIZE + XYZI + RGBA). voxels are [x, y, z, colorIndex] with a 1-based colour index; colorFor maps a 1-based index (1..255) to an RGB triple or null (transparent/unused). Pure (no fs) — callers write the returned bytes to disk themselves....
function writeVox(
size: object,
voxels: readonly [number, number, number, number][],
colorFor: (index1: number) => [number, number, number] | null
): ArrayBuffer;Defined in: vox.ts:494
Serialize one model to a MagicaVoxel ".vox" ArrayBuffer (SIZE + XYZI + RGBA).
voxels are [x, y, z, colorIndex] with a 1-based colour index; colorFor
maps a 1-based index (1..255) to an RGB triple or null (transparent/unused).
Pure (no fs) — callers write the returned bytes to disk themselves.
Coordinates are written as bytes, so every axis must fit in 0..255.
Parameters
| Parameter | Type | Description |
|---|---|---|
size | { x: number; y: number; z: number; } | Model extent, Z-up as MagicaVoxel expects. |
size.x | number | - |
size.y | number | - |
size.z | number | - |
voxels | readonly [number, number, number, number][] | Solid voxels only; there is no empty value to write. |
colorFor | (index1: number) => [number, number, number] | null | RGB 0..255 for each palette index that is used. |
Returns
ArrayBuffer
The file's bytes.
Example
import { writeVox } from "@voxolith/renderer/vox";
// A 2×2×1 slab in palette index 1 (red).
const bytes = writeVox(
{ x: 2, y: 2, z: 1 },
[[0, 0, 0, 1], [1, 0, 0, 1], [0, 1, 0, 1], [1, 1, 0, 1]],
(i) => (i === 1 ? [220, 40, 40] : null),
);
await Bun.write("slab.vox", bytes);parseVoxScene()
Read the full extended .vox format: every model, the nTRN/nGRP/nSHP scene graph, MATL materials, LAYR layers and keyframes. A file without a scene graph (the base format) samples as its first model at the origin. Headless: import it from @voxolith/renderer/vox in tools.
Placement
A model placed in the world at a given animation frame (MagicaVoxel Z-up).