-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.py
35 lines (28 loc) · 1.19 KB
/
render.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
28
29
30
31
32
33
34
35
import rlviewer
import cv2
import numpy as np
import os
import json
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('file', help='path to the .obj file')
args = parser.parse_args()
output_dir = "out"
if not os.path.exists(output_dir):
os.makedirs(output_dir)
rlviewer.load(args.file)
rlviewer.set_light(0, 120, 0, 0, 5000)
rlviewer.set_light(1, -120, 0, 0, 5000)
rlviewer.set_light(2, 0, 0, 120, 5000)
rlviewer.set_light(3, 0, 0, -120, 5000)
for lat in range(0, 90, 5):
for lon in range(0, 360, 3):
# Take a picture of the object positioned in the origin with
# the camera moving on a sphere with a radius of 20 and
# positioned at the given latitude and longitude.
m = rlviewer.get_matrix(20.0, np.radians(lat), np.radians(lon))
with open(f"{output_dir}/image-{lat:03d}-{lon:03d}.json", 'w') as f:
json.dump(m.tolist(), f, indent=4)
img = rlviewer.grab(20.0, np.radians(lat), np.radians(lon))
cv2.imwrite(f"{output_dir}/image-{lat:03d}-{lon:03d}.png", img)