Created
June 22, 2014 15:07
-
-
Save pekkavaa/33fde69960fe0d2a5d01 to your computer and use it in GitHub Desktop.
VXL palette extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
from struct import * | |
""" | |
http://xhp.xwis.net/documents/VXL_Format.txt | |
The header is fixed length, 802 bytes, and contains a few fixed size records and a colour palette. | |
struct vxl_header | |
{ | |
char filetype[16]; /* ASCIIZ string - "Voxel Animation" */ | |
long unknown; /* Always 1 - number of animation frames? */ | |
long n_limbs; /* Number of limb headers/bodies/tailers */ | |
long n_limbs2; /* Always the same as n_limbs */ | |
long bodysize; /* Total size in bytes of all limb bodies */ | |
short int unknown2; /* Always 0x1f10 - ID or end of header code? */ | |
char palette[256][3]; /* 256 colour palette for the voxel in RGB format */ | |
}; | |
""" | |
parser = argparse.ArgumentParser(description= | |
""" | |
Reads Westwood VXL files and outputs the palette in csv. | |
""" | |
) | |
parser.add_argument('vxl', help="Target VXL file.") | |
parser.add_argument('csv', help="Palette CSV file.") | |
args = parser.parse_args() | |
output_path = args.csv | |
palette = [] | |
with open(args.vxl, "rb") as f: | |
f.seek(0x22) # Palette data always starts at offset 0x24 | |
byte = f.read(1) | |
for entry in range(0,256): | |
r = ord(f.read(1)) | |
g = ord(f.read(1)) | |
b = ord(f.read(1)) | |
palette.append((r,g,b)) | |
with open(args.csv, "w") as f: | |
for color in palette: | |
f.write("%d,%d,%d\n" % (color)) | |
print "Saved %d colors." % (len(palette)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment