gromgull / py-vox-io

Python module for parsing and writing MagicaVoxel vox file
MIT License
102 stars 26 forks source link

Palette has an off-by-one index issue #2

Open alexhunsley opened 6 years ago

alexhunsley commented 6 years ago

Hi, thanks for the lib!

I was generating a very simple vox scene with 2 colours in it and have realised py-vox-io seems to have an off-by-one error in it when creating the palette information because it inserts a black colour entry at index 0 when in fact it shouldn't be doing so.

In models.py there is a line:

palette = [ Color(0,0,0,0) ] + [ Color(*c, 255) for c in chunks(palette, 3) ]

I believe the line should actually read:

palette = [ Color(*c, 255) for c in chunks(palette, 3) ]

After I make this change, my palette indexes are correct.

I can make a pull request if you think this sounds correct.

P.S. I think I can see how this came about. The spec for the vox format says:

color [0-254] are mapped to palette index [1-255], e.g :

... but I don't think this means that you actually have to have your own entry for black at index 0 when you generate palette information.