-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender_all.py
More file actions
68 lines (52 loc) · 2.16 KB
/
render_all.py
File metadata and controls
68 lines (52 loc) · 2.16 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
60
61
62
63
64
65
66
67
68
import os
import subprocess
SCENE_DIR = "scenes"
EXECUTABLE = "./miniRT"
def render_all():
if not os.path.exists(SCENE_DIR):
print(f"Directory {SCENE_DIR} not found.")
return
# Filter for .rt files
import os
import subprocess
SCENE_DIR = "scenes"
EXECUTABLE = "./miniRT"
def render_all():
if not os.path.exists(SCENE_DIR):
print(f"Directory {SCENE_DIR} not found.")
return
# Filter for .rt files
files = [f for f in os.listdir(SCENE_DIR) if f.endswith(".rt")]
if not files:
print("No .rt files found.")
return
RESULTS_DIR = "results"
if not os.path.exists(RESULTS_DIR):
os.makedirs(RESULTS_DIR)
print(f"Found {len(files)} scenes. Starting render...")
for i, file in enumerate(files):
scene_path = os.path.join(SCENE_DIR, file)
print(f"[{i+1}/{len(files)}] Rendering {file}...")
try:
# We assume the C program is compiled and --save works
# Since this is WSL, we assume X server is available or not passed to headless if handled
# But miniRT usually connects to X.
# If X is not available, mlx_init fails.
# Assuming the environment has X (since user screenshots worked).
# Render (saves as scenes/file.rt.bmp)
subprocess.run([EXECUTABLE, scene_path, "--save"], check=True)
# Move to results
generated_bmp = f"{scene_path}.bmp"
target_bmp = os.path.join(RESULTS_DIR, f"{file}.bmp")
if os.path.exists(generated_bmp):
if os.path.exists(target_bmp):
os.remove(target_bmp)
os.rename(generated_bmp, target_bmp)
print(f"Saved to {target_bmp}")
else:
print(f"Warning: {generated_bmp} was not created.")
except subprocess.CalledProcessError as e:
print(f"Error rendering {file}: {e}")
print(f"All renders complete. Check the '{RESULTS_DIR}' directory.")
if __name__ == "__main__":
render_all()