-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvertObjImgToPPM.py
More file actions
33 lines (27 loc) · 944 Bytes
/
convertObjImgToPPM.py
File metadata and controls
33 lines (27 loc) · 944 Bytes
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
28
29
30
31
32
33
import os
from PIL import Image
from pathlib import Path
Image.MAX_IMAGE_PIXELS = None
for path in Path('.').rglob('*.mtl'):
#print(path.parent)
print(path)
f_path = str(path)
lines = []
with open(f_path, 'r') as f:
lines = f.read().strip().split('\n')
for i in range(len(lines)):
if lines[i].startswith('map_'):
split_words = lines[i].split(' ')
initial = split_words[0]
joined = ' '.join(split_words[1:])
if not os.path.exists(joined):
print("bad path, skipping: ", joined)
#exit()
else:
print("good path: ", joined)
im = Image.open(joined)
new_file = Path(joined).stem + ".ppm"
im.save(str(path.parent) + "/" + new_file)
lines[i] = initial + " " + new_file
with open(f_path, 'w') as f:
f.write('\n'.join(lines))