Skip to content

@voxel-tool/preact ​

Preact 3D viewer component (built on @voxel-tool/viewer + Three.js). Real 3D cubes + depth buffer + face culling + orthographic isometric camera + OrbitControls.

jsx
import { VoxViewer } from '@voxel-tool/preact';

<VoxViewer /> Props ​

PropTypeDefaultDescription
srcArrayBuffer | Uint8Arraynull.vox binary; when provided, parseVox is called internally
model{ size, voxels }nullA parsed model (from parseVox's models[0])
paletteArray<[r,g,b,a]>nullA 256-entry palette; pairs with model
backgroundstring'#16181e'Canvas background color
widthnumber480Canvas width (px)
heightnumber480Canvas height (px)

Provide either src or model; if both are given, model wins.

Interaction ​

  • Left-drag: rotate the view
  • Scroll: zoom
  • Right-drag: pan

The component auto-frames the model (Box3 bounding-box centering + zoom-to-fit) and shows voxel count · face count at the bottom-left.

Example ​

jsx
import { useState } from 'preact/hooks';
import { VoxViewer } from '@voxel-tool/preact';
import { parseVox } from '@voxel-tool/core';

export function App() {
  const [data, setData] = useState(null);
  const onFile = async (e) => {
    const buf = new Uint8Array(await e.target.files[0].arrayBuffer());
    setData(parseVox(buf));
  };
  return (
    <div>
      <input type="file" accept=".vox" onChange={onFile} />
      {data && <VoxViewer model={data.models[0]} palette={data.palette} />}
    </div>
  );
}

See Component Examples · Preact.

MIT Licensed © 2026 Maicarons