RichysHub / MagicaVoxel-VOX-importer

Blender import script for MagicaVoxel .vox format as cube primitives.
MIT License
227 stars 56 forks source link

No default palette #5

Closed RichysHub closed 5 years ago

RichysHub commented 7 years ago

Default palette is well defined in the specification of the format, yet currently we do not use this, we simply expect a palette chunk to be present in the .vox file

RichysHub commented 7 years ago

Have added support for this. Need to perform a proper test on the code though, ensure palette is used . This probably needs me to write a palette stripper, to get hold of a .vox file with no RGBA chunk

RichysHub commented 7 years ago

In testing if the default palette was used, a bug was found causing colors to be different to expectations. This has been fixed in https://github.com/RichysHub/MagicaVoxel-VOX-importer/commit/9e792920fc9c91ec0d07a8226c96ce5a9ea17e52

vox importer color fix

wizardgsz commented 5 years ago

Loading this sample chr_cat.vox, I have to correct the palette.updatein:

if not palette:  # no palette provided, use default
        for col in range(256):
            palette.update({col + 1: struct.unpack('<4B', struct.pack('<I', DEFAULT_PALETTE[col]))})

Please note the "<I" packing DEFAULT_PALETTE (it is ">I" now)

RichysHub commented 5 years ago

Okay, I was hesitant to agree, given the above changes, and therefore how confident I was.

However, I have thrown together a quick script (something I clearly never did back in 2017) to visualize the palettes, and I am happy to agree that it is currently incorrect.

struct.unpack('<4B', struct.pack('>I', DEFAULT_PALETTE[col])) produces:

>I

struct.unpack('<4B', struct.pack('<I', DEFAULT_PALETTE[col])) produces:

<I

I think there are some slight issues in gamma correction maths currently, and in #8, but I'll detail those there.