Created
July 22, 2022 16:47
-
-
Save csauve/a3c6e76a066a8992d554cacb5b7b75b4 to your computer and use it in GitHub Desktop.
The Thing (2002) msh to obj converter
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 | |
import sys | |
verts_start = 0xA4 | |
vert_count = 0x2B | |
vert_format = "<I 3f 3f 2f" | |
vert_size = struct.calcsize(vert_format) | |
indices_start = 0x6B8 | |
indices_count = 0x84 | |
face_format = "<3H" | |
face_size = struct.calcsize(face_format) | |
# obj outputs | |
vert_coord = [] | |
vert_tex = [] | |
vert_norm = [] | |
faces = [] | |
with open("flamerfuel-flame-thrower.msh", "rb") as msh: | |
for o_v in range(verts_start, verts_start + vert_count * vert_size, vert_size): | |
msh.seek(o_v) | |
v = struct.unpack(vert_format, msh.read(vert_size)) | |
# print(f"{hex(o_v)}: {v}") | |
vert_coord.append((v[1], v[2], v[3])) | |
vert_norm.append((v[4], v[5], v[6])) | |
vert_tex.append((v[7], v[8])) | |
for o_f in range(indices_start, indices_start + indices_count * 2, face_size): | |
msh.seek(o_f) | |
f = struct.unpack(face_format, msh.read(face_size)) | |
faces.append(f) | |
for x, y, z in vert_coord: | |
print(f"v {x} {y} {z}") | |
for u, v in vert_tex: | |
print(f"vt {u} {v}") | |
for i, j, k in vert_norm: | |
print(f"vn {i} {j} {k}") | |
for v0, v1, v2 in faces: | |
print(f"f {v0 + 1}/{v0 + 1}/{v0 + 1} {v1 + 1}/{v1 + 1}/{v1 + 1} {v2 + 1}/{v2 + 1}/{v2 + 1}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment