Skip to content

Instantly share code, notes, and snippets.

@seece
Created June 22, 2014 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seece/33fde69960fe0d2a5d01 to your computer and use it in GitHub Desktop.
Save seece/33fde69960fe0d2a5d01 to your computer and use it in GitHub Desktop.
VXL palette extractor
#!/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