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
| Parameter | Type | Description |
|---|---|---|
buffer | ArrayBuffer | The whole file. |
Returns
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;decodeVoxRotation()
Decode a MagicaVoxel r rotation byte to a signed-permutation matrix (identity = 4).
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.