kevzettler / parse-magica-voxel

Parse MagicaVoxel .vox files to javascript objects works in browser or server
GNU General Public License v3.0
68 stars 14 forks source link

MagicaVoxel 99.6 not working / Skip unknown Chunk Types #8

Closed SamuelVanEgmond closed 2 years ago

SamuelVanEgmond commented 2 years ago

I'm the developer of Smooth Voxels (svox.glitch.me). On my Playground I use parse-magica-voxel to convert MagicaVoxel models 3D models for WebXR. (Works great, thanks!!)

However, parsing no longer works for MagicaVoxel 99.6! (it did work up to 99.4).

The reason is that two new chunk types are now present: rCAM and NOTE. Perhaps these node types could be supported, but I think it would at least be a good idea to skip unknown chunk types.

This change seems to solve the problem for now;

Change function getChunkData to:

function getChunkData(state, id, startIndex, endIndex){
  if(!chunkHandlers[id]){
    console.log("Unsupported chunk type " + id);
    return SKIPHandler(state, startIndex, endIndex);
  }
  return chunkHandlers[id](state, startIndex, endIndex);
};

With SKIPHandler:

function SKIPHandler(state, startIndex, endIndex){
  state.readByteIndex = endIndex;
  return { error: "Unsupported chunk type" };
}
matthewjosephtaylor commented 2 years ago

@SamuelVanEgmond (and others who might be interested) I've forked this project and included the above fix here https://github.com/matthewjosephtaylor/magica-voxels

kevzettler commented 2 years ago

@SamuelVanEgmond thanks for the report. I have added your suggestion in 40ce444ae5f5144b5057a53a5d006da4125c89ef

I have also added support for the new chunks in 40ce444ae5f5144b5057a53a5d006da4125c89ef I believe that should cover 99.7

This has been published on NPM in parse-magica-voxel@2.1.1

Sorry for the late reply for this Github has been eating my notifications and missed some of the issues on this repo