voxolith

parseVox()

Read the first model of a MagicaVoxel .vox file, with its RGBA palette (or MagicaVoxel's default palette when the file has none). Later models, the scene graph and materials are ignored; use parseVoxScene for those. Headless: import it from @voxolith/renderer/vox in tools.

function parseVox(buffer: ArrayBuffer): VoxModel;

Defined in: vox.ts:65

Parameters

ParameterTypeDescription
bufferArrayBufferThe whole file.

Returns

VoxModel

The model in the file's Z-up coordinates.

Throws

Error when the magic is not VOX or no SIZE chunk is present.

Example

import { parseVox } from "@voxolith/renderer";

const model = parseVox(await (await fetch("models/cat-sit.vox")).arrayBuffer());
console.log(model.size, model.voxels.length);
// Grid (Y-up) from file (Z-up): (x, y, z) -> (x, z, y).
const size = { x: model.size.x, y: model.size.z, z: model.size.y };
const data = new Uint8Array(size.x * size.y * size.z);
for (const v of model.voxels) data[v.x + v.z * size.x + v.y * size.x * size.y] = v.c;

On this page