Skip to content

Instantly share code, notes, and snippets.

@pawlos
Last active December 5, 2019 20:21
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 pawlos/c28912755d43f3cb8ebb9b9238e72cee to your computer and use it in GitHub Desktop.
Save pawlos/c28912755d43f3cb8ebb9b9238e72cee to your computer and use it in GitHub Desktop.
Converts binary D3DX data into text form
import struct
cv = 0
ci = 0
with open('output3.txt','w') as o:
with open('mesh2_vertices.bin','rb') as f:
data = f.read()
#print(len(data))
i = 0
o.write("Vertex\n")
while i < len(data)/24:
p = i*24
x = struct.unpack("f", data[p:p+4])[0]
y = struct.unpack("f", data[p+4:p+2*4])[0]
z = struct.unpack("f", data[p+2*4:p+3*4])[0]
#print(x,y,z)
o.write('{},{},{}\n'.format(x,y,z))
i += 1
cv += 1
with open('mesh2_indices.bin', 'rb') as f:
data = f.read()
i = 0
o.write("Indices\n")
while i < len(data)/12:
p = i*12
idx1 = struct.unpack("I", data[p:p+1*4])[0]
idx2 = struct.unpack("I", data[p+1*4:p+2*4])[0]
idx3 = struct.unpack("I", data[p+2*4:p+3*4])[0]
#print(idx1, idx2, idx3)
o.write("{},{},{}\n".format(idx1, idx2, idx3))
i +=1
ci +=1
print ("Vertex: {}, Indices: {}".format(cv, ci))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment