This repository was archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneParser.py
More file actions
60 lines (49 loc) · 2.14 KB
/
SceneParser.py
File metadata and controls
60 lines (49 loc) · 2.14 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import App
from Intersectable import *
from utility import clamp
import re
def load_scene_file(path):
scene = App.Scene(False)
data = []
try:
with open(path) as f:
data = f.readlines()
f.seek(0)
for line in data:
m = re.findall(r'(-?\d+\.\d|\d+)', line)
if m:
if "Sphere:" in line:
print("Sphere:", m)
if expected_match_size(m, 8):
scene.add_object(Sphere(
center=(float(m[0]), float(m[1]), float(m[2])),
radius=float(m[3]),
material=Material(
float(m[4]),
(clamp(int(m[5]), 0, 255), clamp(int(m[6]), 0, 255), clamp(int(m[7]), 0, 255)))))
elif "Plane:" in line:
print("Plane:", m)
if expected_match_size(m, 8):
scene.add_object(Plane(
origin=(float(m[0]), float(m[1]), float(m[2])),
normal=(float(m[3]), float(m[4]), float(m[5])),
material=Material(
float(m[6]), None)))
elif "Light:" in line:
print("Light:", m)
if expected_match_size(m, 8):
scene.add_light(Light(
position=(float(m[0]), float(m[1]), float(m[2])),
intensity=float(m[3]),
material=Material(
float(m[4]), (clamp(int(m[5]), 0, 255), clamp(int(m[6]), 0, 255), clamp(int(m[7]), 0, 255)))))
except Error:
print("Error loading scene file!")
return App.Scene(default=True) # default init
print("Loaded scene file!")
return scene
def expected_match_size(m, expected_size):
if len(m) == expected_size:
return True
print("Size of search result was not as expected!")
return False