vox-saver
v2.0.3
Published
Takes a JavaScript Object of .vox file data and returns a Byte Array with all the containing informations
Downloads
131
Maintainers
Readme
vox-saver
npm module for writing .vox files which are exported in MagickaVoxel. It's the inverse function to vox-reader.js
💾 Installation
npm install --save vox-saver
🚀 Usage
Example for generating a voxel sphere
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