I'm sorry...
I guess I should have been a little more clear on how the DNA strip sequence works...
it starts out with a selection of 3 face offsets
then checks to make sure the offsets are valad (no duplicate data)Code:|06 46| |06 47| |06 48| 06 3A 06 48 06 3B 06 48 06 3C
if the offset is valad, the face is logged to a temporary file "faces.txt"
if the offset is invalad, the face is skipped...
then the offset is moved down by 1 (or 4)
then that face is checked...Code:06 46 |06 47| |06 48| |06 3A| 06 48 06 3B 06 48 06 3C
import struct as S
dat = open("import.dat", 'rb')
obj = open("export.obj", 'w')
#mtl = open("export.mtl", 'w')
def HexToDec(h):
return float(S.unpack("<h", S.pack("<H", int((h.encode('hex')), 16)))[0])
def vert(v):
return (HexToDec(v)* 0.01).__str__()
def face(f):
return int(HexToDec(f)+1).__str__()+"/"
def UV(uv):
return int(HexToDec(uv)+1).__str__()+"/"
def normal(nor):
return +int(HexToDec(nor)/32767).__str__()
t0 = dat.read(32)#header
a = 0
while (a == 0):
v = "v "+vert(dat.read(2))+" "+vert(dat.read(2))+" "+vert(dat.read(2))
if (v == 'v 0.0 0.0 0.0'):
a = 1#main loop
while (a == 1):
h = dat.read(1).encode('hex')+dat.read(1).encode('hex')
if (h == 'B800' or h == 'A800' or h == 'B000' or h == '9000' or h == '9800' or h == 'A000' or h == '8000'):
a = 2
s = dat.seek(-1,1)
index = HexToDec(dat.read(2))#index count
while (a == 2):
if (h == 'B800'): #point
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
index = index - 1
print "f "+f0+uv0+"1"
obj.write("f "+f0+uv0+"1"+"\n")
a = 1
if (h == 'A800'): #line
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
index = index - 2
print "f "+f0+uv0+"1 "+f1+uv1+"1"
obj.write("f "+f0+uv0+"1 "+f1+uv1+"1"+"\n")
a = 1
if (h == 'B000'): #line strip
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
index = index - 2
seek = dat.seek(-10,1)
index = index + 1
print "f "+f0+uv0+"1 "+f1+uv1+"1"
obj.write("f "+f0+uv0+"1 "+f1+uv1+"1"+"\n")
a = 1
if (h == '9000'): #triangle
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 3
print "f "+f0+uv0+"1 "+f1+uv1+"1 "+f2+uv2+"1"
obj.write("f "+f0+uv0+"1 "+f1+uv1+"1 "+f2+uv2+"1"+"\n")
a = 1
if (h == '9800'): #triangle strip
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 3
seek = dat.seek(-15,1)
index = index + 2
print "f "+f0+uv0+"1 "+f1+uv1+"1 "+f2+uv2+"1"
obj.write("f "+f0+uv0+"1 "+f1+uv1+"1 "+f2+uv2+"1"+"\n")
a = 1
if (h == 'A000'): #triangle fan
while (index > 0):
index = 0
a = 1
if (h == '8000'): #quad
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
f3 = face(dat.read(2))
uv3 = UV(dat.read(2))
nor3 = dat.read(2)#normal(dat.read(2))
index = index - 4
print "f "+f0+uv0+"1 "+f1+uv1+"1 "+f2+uv2+"1 "+f3+uv3+"1"
obj.write("f "+f0+uv0+"1 "+f1+uv1+"1 "+f2+uv2+"1 "+f3+uv3+"1"+"\n")
a = 1
else:
#print v
obj.write(v+"\n")
thax alotTriangle fans are similar to how triangle strips are handled, except that the first index is always used, along with the previous/last index and the current index.
0 1 2 3 4 5 6
becomes
[0 1 2] [0 2 3] [0 3 4] [0 4 5] [0 5 6]
that's why I asked about bone data earlier...i am currently looking into various flag values associated with the internal data structures of this format. Once those are deciphered the data should be a bit more manageable as the actual type and intended sizes will be known. A lot of the vertex data in Pl*.dat file will not always appear correctly until the joint data within the file is handled properly (which can also be indexed as well, though i am not sure if this format makes use of it yet, but probably).
import struct as S
dat = open("import.dat", 'rb')
obj = open("export.obj", 'w')
#mtl = open("export.mtl", 'w')
def HexToDec(h):
return float(S.unpack("<h", S.pack("<H", int((h.encode('hex')), 16)))[0])
def vert(v):
return (HexToDec(v)* 0.01).__str__()
def face(f):
return int(HexToDec(f)+1).__str__()+"/"
def UV(uv):
return int(HexToDec(uv)+1).__str__()+"/"
def normal(nor):
return int(HexToDec(nor)/32767).__str__()
t0 = dat.read(32)#header
a = 0
while (a == 0):
v = "v "+vert(dat.read(2))+" "+vert(dat.read(2))+" "+vert(dat.read(2))
if (v == 'v 0.0 0.0 0.0'):
a = 1#main loop
obj.write("\n")
while (a == 1):
h = dat.read(1).encode('hex')+dat.read(1).encode('hex')
if (h == 'B800' or h == 'A800' or h == 'B000' or h == '9000' or h == '9800' or h == 'A000' or h == '8000'):
a = 2
s = dat.seek(-1,1)
index = HexToDec(dat.read(2))#index count
while (a == 2):
if (h == 'B800'): #point
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
index = index - 1
print "f "+f0+uv0+"1"
obj.write("f "+f0+uv0+"1"+"\n")
if (h == 'A800'): #line
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
index = index - 2
print "f "+f0+uv0+"1"+' '+f1+uv1+"1"
obj.write("f "+f0+uv0+"1"+' '+f1+uv1+"1"+"\n")
if (h == 'B000'): #line strip
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
index = index - 1
seek = dat.seek(-6,1)
if (f0 != f1 or f1 != '00'):
print "f "+f0+uv0+"1"+' '+f1+uv1+"1"
obj.write("f "+f0+uv0+"1"+' '+f1+uv1+"1"+"\n")
if (h == '9000'): #triangle
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 3
print "f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"
obj.write("f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"+"\n")
if (h == '9800'): #triangle strip
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 1
seek = dat.seek(-12,1)
if (f0 != f1 and f1 != f2 and f2 != f0 or f2 != '00'):
print "f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"
obj.write("f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"+"\n")
if (h == 'A000'): #triangle fan
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
while (index > 0):
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 1
seek = dat.seek(-6,1)
if (f0 != f1 and f1 != f2 and f2 != f0 or f2 != '00'):
print "f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"
obj.write("f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"+"\n")
if (h == '8000'): #quad
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
f3 = face(dat.read(2))
uv3 = UV(dat.read(2))
nor3 = dat.read(2)#normal(dat.read(2))
index = index - 4
print "f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"+' '+f3+uv3+"1"
obj.write("f "+f0+uv0+"1"+' '+f1+uv1+"1"+' '+f2+uv2+"1"+' '+f3+uv3+"1"+"\n")
a = 1
else:
#print v
obj.write(v+"\n")
import struct as S
dat = open("import.dat", 'rb')
obj = open("export.obj", 'w')
#mtl = open("export.mtl", 'w')
def HexToDec(h):
return float(S.unpack("<h", S.pack("<H", int((h.encode('hex')), 16)))[0])
def vert(v):
return (HexToDec(v)* 0.01).__str__()
def face(f):
return int(HexToDec(f)+1).__str__()
def UV(uv):
return int(HexToDec(uv)+1).__str__()
def normal(nor):
return int(HexToDec(nor)/32767).__str__()
t0 = dat.read(32)#header
a = 0
while (a == 0):
v = "v "+vert(dat.read(2))+" "+vert(dat.read(2))+" "+vert(dat.read(2))
if (v == 'v 0.0 0.0 0.0'):
a = 1#main loop
obj.write("\n")
while (a == 1):
# attempt to ensure processing starts at the beginning of a data section
#h = dat.read(1).encode('hex')+dat.read(1).encode('hex')+dat.read(1).encode('hex')
#if (h == '0000B8' or h == '0000A8' or h == '0000B0' or h == '000090' or h == '000098' or h == '0000A0' or h == '000080'): #this may also work and find even more matches, need to update backtrack offset if used
h = dat.read(1).encode('hex')+dat.read(1).encode('hex')+dat.read(1).encode('hex')+dat.read(1).encode('hex')
if (h == '0000B800' or h == '0000A800' or h == '0000B000' or h == '00009000' or h == '00009800' or h == '0000A000' or h == '00008000'):
a = 2
s = dat.seek(-2,1)
pos = dat.tell()
print pos.__str__()+": "+h
while (a == 2):
pos = dat.tell()
h = dat.read(1).encode('hex') #+dat.read(1).encode('hex')
print pos.__str__()+": "+h
if (h == 'B8' or h == 'A8' or h == 'B0' or h == '90' or h == '98' or h == 'A0' or h == '80'):
#s = dat.seek(-1,1)
index = HexToDec(dat.read(2))#index count
if (h == 'B8'): #point
while (index > 0):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
index = index - 1
print "f "+f0+"/"+uv0+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+"\n")
elif (h == 'A8'): #line
while (index > 1):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
index = index - 2
print "f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+"\n")
elif (h == 'B0'): #line strip
while (index > 1):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
index = index - 1
if (index > 1):
seek = dat.seek(-6,1)
if (f0 != f1):
print "f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+"\n")
elif (h == '90'): #triangle
while (index > 2):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 3
if (int(f0, 10) >= 0 and int(f1, 10) >= 0 and int(f2, 10) >= 0):
print "f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"+"\n")
elif (h == '98'): #triangle strip
flip = 1
while (index > 2):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 1
if (index > 2):
seek = dat.seek(-12,1)
if (f0 != f1 and f1 != f2 and f2 != f0):
if (int(f0, 10) >= 0 and int(f1, 10) >= 0 and int(f2, 10) >= 0):
if (flip):
print "f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+"\n")
else:
print "f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"+"\n")
flip = 1 - flip
elif (h == 'A0'): #triangle fan
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
index = index - 1
while (index > 1):
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
index = index - 1
if (index > 1):
seek = dat.seek(-6,1)
if (f0 != f1 and f1 != f2 and f2 != f0):
if (int(f0, 10) >= 0 and int(f1, 10) >= 0 and int(f2, 10) >= 0):
print "f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"+"\n")
elif (h == '80'): #quad
while (index > 3):
f0 = face(dat.read(2))
uv0 = UV(dat.read(2))
nor0 = dat.read(2)#normal(dat.read(2))
f1 = face(dat.read(2))
uv1 = UV(dat.read(2))
nor1 = dat.read(2)#normal(dat.read(2))
f2 = face(dat.read(2))
uv2 = UV(dat.read(2))
nor2 = dat.read(2)#normal(dat.read(2))
f3 = face(dat.read(2))
uv3 = UV(dat.read(2))
nor3 = dat.read(2)#normal(dat.read(2))
index = index - 4
if (int(f0, 10) >= 0 and int(f1, 10) >= 0 and int(f2, 10) >= 0 and int(f3, 10) >= 0):
print "f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"+' '+f3+"/"+uv3+"/"+"1"
obj.write("f "+f0+"/"+uv0+"/"+"1"+' '+f1+"/"+uv1+"/"+"1"+' '+f2+"/"+uv2+"/"+"1"+' '+f3+"/"+uv3+"/"+"1"+"\n")
else:
a = 1 # should no longer get here, but just in case...
else:
# backtrack over invalid primitive type bytes
a = 1
s = dat.seek(-1,1)
else:
#backtrack over trailing bytes so that
#the entire file is scanned a byte at a time
s = dat.seek(-3,1)
else:
#print v
obj.write(v+"\n")
yea... I'll work on that later...Still need add end of file detection so that the script will exit cleanly.