Created
January 31, 2025 06:02
-
-
Save jeandrek/56b04c480aa2ca29d36a2434f23f9a3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
f = open('dog.obj','r') | |
verts = [] | |
uvs = [] | |
faces = [] | |
for line in f: | |
if line[:2] == 'v ': | |
verts.append(tuple(map(lambda s:float(s),line.split()[1:]))) | |
elif line[:3] == 'vt ': | |
uvs.append(tuple(map(lambda s:float(s),line.split()[1:]))) | |
elif line[:2] == 'f ': | |
faces.append(list(map(lambda s:tuple(map(lambda t:int(t),s.split('/'))),line.split()[1:]))) | |
f.close() | |
print(f"{len(verts)} vertices\n{len(uvs)} tex coords\n{len(faces)} faces") | |
with open('vertices.txt','w') as verts_file: | |
with open('texcoords.txt', 'w') as uvs_file: | |
for face in faces: | |
for (i, j, k) in face: | |
vert = verts[i - 1] | |
uv = uvs[j - 1] | |
for coord in vert: | |
verts_file.write(f"{coord}\n") | |
for coord in uv: | |
uvs_file.write(f"{coord}\n") | |
print("Written to vertices.txt & texcoords.txt") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment