https://github.com/kevzettler/parse-magica-voxel
Parse MagicaVoxel .vox files to javascript objects works in browser or server
https://github.com/kevzettler/parse-magica-voxel
magicavoxel voxel voxels webgl
Last synced: about 22 hours ago
JSON representation
Parse MagicaVoxel .vox files to javascript objects works in browser or server
- Host: GitHub
- URL: https://github.com/kevzettler/parse-magica-voxel
- Owner: kevzettler
- License: gpl-3.0
- Created: 2016-12-05T01:12:33.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-10-02T23:49:46.000Z (about 2 years ago)
- Last Synced: 2024-04-14T05:16:42.377Z (over 1 year ago)
- Topics: magicavoxel, voxel, voxels, webgl
- Language: JavaScript
- Homepage:
- Size: 70.3 KB
- Stars: 64
- Watchers: 3
- Forks: 16
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Parse MagicaVoxel .vox file format
Javascript parser for MagicaVoxel .vox file format:https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt
Works in Browser and Node.js server environments
## Install
```
npm install parse-magica-voxel
```## Usage
see [examples](/example)* Node.js
```javascript
var fs = require('fs');
var parseMagicaVoxel = require('parse-magica-voxel');fs.readFile("./chr_old.vox", function (err, Buffer) {
if (err) throw err;
console.log(JSON.stringify(parseMagicaVoxel(Buffer)));
});
```* Browser
You will have to bundle the module with Webpack or Browserify and load the voxel file using `fetch` or another `XMLHttpRequest` utility
```javascript
var parseMagicaVoxel = require('parse-magica-voxel');
var myRequest = new Request('/example/path/to/your-vox-file.vox');
fetch(myRequest).then(function(response) {
return response.arrayBuffer();
}).then(function(buffer) {
console.log(JSON.stringify(parseMagicaVoxel(buffer));
});
```### Result
```
{
"VOX ": 150,
"PACK": 1,
"SIZE": {
"x": 20,
"y": 21,
"z": 20
},
"XYZI": [
{x, y, z, c},
//... more voxels
],
"RGBA": [
{r,g,b,a},
//... more rgba values
],
}
```