vox-saver
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

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

Package Sidebar

Install

npm i vox-saver

Weekly Downloads

18

Version

2.0.3

License

MIT

Unpacked Size

137 kB

Total Files

57

Last publish

Collaborators

  • florianfe