Skip to content

Parse MagicaVoxel .vox files to javascript objects works in browser or server

Notifications You must be signed in to change notification settings

WebBeard/parse-magica-voxel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  • Node.js
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

var parseMagicaVoxel = require('parse-magica-voxel');
var myRequest = new Request('magicavoxel.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
  ],
}       

About

Parse MagicaVoxel .vox files to javascript objects works in browser or server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%