Last active
December 5, 2019 20:21
-
-
Save pawlos/c28912755d43f3cb8ebb9b9238e72cee to your computer and use it in GitHub Desktop.
Converts binary D3DX data into text form
This file contains 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
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