https://github.com/florianfe/vox-saver.js
inverse to vox-reader
https://github.com/florianfe/vox-saver.js
Last synced: about 2 months ago
JSON representation
inverse to vox-reader
- Host: GitHub
- URL: https://github.com/florianfe/vox-saver.js
- Owner: FlorianFe
- License: mit
- Created: 2021-12-19T12:27:16.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-01T18:41:33.000Z (about 2 years ago)
- Last Synced: 2025-03-29T00:24:57.507Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 454 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vox-saver
npm module for writing [.vox](https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt) files which are exported in [MagickaVoxel](https://ephtracy.github.io/). It's the inverse function to [vox-reader.js](https://github.com/FlorianFe/vox-reader.js)
## 💾 Installation
```bash
npm install --save vox-saver
```## 🚀 Usage
Example for generating a voxel sphere
```js
const SIZE = 20;
const RADIUS = 8;const checkIfInsideSphere = (x : number, y : number, z : number) => {
const cx = x - SIZE / 2;
const cy = y - SIZE / 2;
const cz = z - SIZE / 2;return cx * cx + cy * cy + cz * cz < RADIUS * RADIUS;
}const xyziValues =
flatten(range(0, SIZE).map((z : number) =>
range(0, SIZE).map((y : number) =>
range(0, SIZE).map((x : number) =>
({ x, y, z, i: 1 })
)
)
))
.filter((v : any) => checkIfInsideSphere(v.x, v.y, v.z))const vox = {
size: { x: SIZE, y: SIZE, z: SIZE },
xyzi: {
numVoxels: xyziValues.length,
values: xyziValues
},
rgba: {
values: range(0, 255).map(() => ({r: 255, g: 255, b: 255, a: 255}))
}
}const writtenVox = writeVox(vox)
fs.writeFileSync('./sphere.vox', Buffer.from(writtenVox))```
## 📖 License
(c) 2022 Florian Fechner. [MIT License](https://github.com/FlorianFe/vox-saver.js/blob/master/LICENSE)