-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmc_obj.py
executable file
·27 lines (25 loc) · 993 Bytes
/
mc_obj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#! /usr/bin/python3
import sys
out = ''
with open(sys.argv[1], 'r') as input_file:
for line in input_file:
line = line.rstrip()
if line.startswith('v '):
coords = [float(c) for c in line[2:].split(' ')]
line = 'v '
line += "{:.5f} {:.5f} {:.5f}\n".format(coords[0] / 16 + 0.5, coords[1] / 16, coords[2] / 16 + 0.5)
elif line.startswith('f '):
face_vertices = line[2:].split(' ')
if len(face_vertices) % 2 == 1:
face_vertices.append(face_vertices[-1])
split_faces = []
for i in range(1, len(face_vertices) - 2, 2):
split_faces.append([face_vertices[0], face_vertices[i], face_vertices[i + 1], face_vertices[i + 2]])
line = ''
for face in split_faces:
line += 'f ' + ' '.join(face) + '\n'
else:
line += '\n'
out += line
with open(sys.argv[2], 'w') as output:
output.write(out)