-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (33 loc) · 1.06 KB
/
main.py
File metadata and controls
40 lines (33 loc) · 1.06 KB
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
36
37
38
39
40
#!/usr/bin/env python
"""Puray - a Pure Python Raytracer by Arun Ravindran, 2019"""
import argparse
import importlib
import os
from multiprocessing import cpu_count
from engine import RenderEngine
from scene import Scene
def main():
parser = argparse.ArgumentParser()
parser.add_argument("scene", help="Path to scene file (without .py extension)")
parser.add_argument(
"-p",
"--processes",
action="store",
type=int,
dest="processes",
default=0,
help="Number of processes (0=auto)",
)
args = parser.parse_args()
if args.processes == 0:
process_count = cpu_count()
else:
process_count = args.processes
mod = importlib.import_module(args.scene)
scene = Scene(mod.CAMERA, mod.OBJECTS, mod.LIGHTS, mod.WIDTH, mod.HEIGHT)
engine = RenderEngine()
os.chdir(os.path.dirname(os.path.abspath(mod.__file__)))
with open(mod.RENDERED_IMG, "w") as img_fileobj:
engine.render_multiprocess(scene, process_count, img_fileobj)
if __name__ == "__main__":
main()