Socket
Socket
Sign inDemoInstall

vox-saver

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vox-saver

Takes a JavaScript Object of .vox file data and returns a Byte Array with all the containing informations


Version published
Weekly downloads
21
decreased by-41.67%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 01 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc