dust-engine / dot_vox

Rust parser for MagicaVoxel .vox files.
MIT License
51 stars 20 forks source link

pallete loading from .vox fails after upgrading from 0.4.0 to 0.5.0 #10

Closed jice-nospam closed 7 years ago

jice-nospam commented 7 years ago

I just upgraded dot_vox to the last version (from commit 8aeb367) and my .vox file loading fails because my DotVoxData.pallete field only has 255 elements (where 256 expected).

Seems the culprit is this change :

-named!(parse_pallete <&[u8], Vec<u32> >, complete!(do_parse!(
-    take!(8) >>
-    colors: many_m_n!(256, 256, le_u32) >>
+named!(pub extract_pallete <&[u8], Vec<u32> >, complete!(do_parse!(
+    take!(12) >>
+    colors: many_m_n!(255, 255, le_u32) >>
davidedmonds commented 7 years ago

Hey - I'll take a look at this as soon as I get a chance. In the meanwhile, have you got a .vox file I can use for a test case (to prevent me from breaking things again)?

jice-nospam commented 7 years ago

This is the file I'm using. It contains 6 models and a custom pallete :

elf.zip

There might be something wrong in the file instead. It seems there's a voxel with color 255 in there. Yet the color index 255 is not selectable in MagicaVoxel...

jice-nospam commented 7 years ago

mmh something weird in the spec. There should be 256 ints in the chunk, yet we should only read 255 of them (color index 0 being hardcoded as black?)

4 x 256  | int        | (R, G, B, A) : 1 byte for each component
                      | * <NOTICE>
                      | * color [0-254] are mapped to palette index [1-255], e.g : 
                      | 
                      | for ( int i = 0; i <= 254; i++ ) {
                      |     palette[i + 1] = ReadRGBA(); 
                      | }
jice-nospam commented 7 years ago

ok this is not an issue. I simply had to index pallete using voxel.i -1 instead of voxel.i. Magica Voxel color indices range from 1 to 255, actually resulting in a 255 colors pallete.

davidedmonds commented 7 years ago

Ah - thanks very much for digging into that 👍