Skip to content

voxel-toolMagicaVoxel .vox 工具集

纯 JS 核心库 + Three.js 真实 3D 查看器(React / Vue / Solid / Preact / Svelte / Qwik)

voxel-tool
voxel-tool — P4 新功能一览

这是什么? ​

voxel-tool 是一套用于 MagicaVoxel .vox 体素模型的 JavaScript 工具集:

  • @voxel-tool/core — 纯 JS 核心库:.vox 文件读写、调色板工具、VoxelGrid 体素容器。
  • @voxel-tool/mesh — 共享体素几何核心 (Three.js):面剔除 + greedy meshing 的 buildVoxelGeometry 单一实现,被 @voxel-tool/viewer 与 @voxel-tool/exporter 共用;颜色空间与材质差异通过参数表达。
  • @voxel-tool/viewer — 框架无关的 Three.js 查看器核心(createVoxelViewer + buildVoxelGeometry),所有框架组件都复用它。
  • @voxel-tool/exporter — 独立导出库:体素模型 → GLB / glTF / OBJ / STL / PLY / USDZ / FBX,并支持 .vox 无损往返与 glTF/GLB 动画烘焙。
  • @voxel-tool/cli — 无头 Node CLI:.vox ↔ GLB/glTF/OBJ/STL/PLY/USDZ/FBX 双向转换、网格体素化、布尔 CSG,以及 Minecraft Schematic 往返——无需浏览器。
  • @voxel-tool/react — React 3D 查看器组件(基于 Three.js)。
  • @voxel-tool/vue — Vue 3 3D 查看器组件(同一套渲染原理)。
  • @voxel-tool/solid — SolidJS 3D 查看器组件。
  • @voxel-tool/preact — Preact 3D 查看器组件。
  • @voxel-tool/svelte — Svelte 5 3D 查看器组件。
  • @voxel-tool/qwik — Qwik 3D 查看器组件。

渲染采用主流 .vox viewer 的原理:真实 3D 立方体 + 深度缓冲 + 面剔除 + 正交等距相机 + OrbitControls, 告别 Canvas 2D 画家算法的排序瑕疵。所有框架组件共享 @voxel-tool/viewer 同一份实现, 不存在「每个框架重写一遍渲染」的重复代码。

bash
npm install @voxel-tool/core @voxel-tool/react
jsx
import { VoxViewer } from '@voxel-tool/react';
import { parseVox } from '@voxel-tool/core';

const buf = await fetch('/model.vox').then((r) => r.arrayBuffer());
const { models, palette } = parseVox(buf);

export default function App() {
  return <VoxViewer model={models[0]} palette={palette} />;
}

MIT Licensed © 2026 Maicarons