Python script for the extraction of Polygons from World.dat type files:
#!/usr/local/bin/python3
import sys
from pprint import pprint
#- load WORLD.DAT as binary
#- .DAT is a sequence of x1, y1, x2, y2, x3, y3, x4, y4, tex values
#- coordinates are 16-bit int, texture is 32-bit int
#- multiply coordinates by 0.125
#- output as - [x1, y1, x2, y2, x3, y3, x4, y4, tex] for yaml
#- if x4 == -1, don't output x4, y4
def readOneRecord(f):
record = []
for i in range(0, 8):
readValue = f.read(2)
if not readValue:
return record
intCoord = int.from_bytes(readValue, byteorder='little', signed=True)
if i == 6 and intCoord == -1:
f.read(2)
break
record.append(intCoord * 0.125)
tex = int.from_bytes(f.read(4), byteorder='little', signed=True)
record.insert(0,tex)
return record
if len(sys.argv) > 1:
path = sys.argv[1]
with open(path,"rb") as f:
nextRecord = readOneRecord(f)
while len(nextRecord) > 0:
pprint(nextRecord)
nextRecord = readOneRecord(f)