Skip to content

Commit e5e6866

Browse files
committed
feat: add CaptureWorker to automate CS2 cubemap generation and screenshot stitching
1 parent 67b50db commit e5e6866

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

src/forms/cubemap_maker/worker.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ def load_local_faces(self, ss_dir, ev_suffix, session_id):
3030

3131
for name in face_names:
3232
pattern = os.path.join(ss_dir, f"{session_id}_cube_{ev_suffix}_{name}*.png")
33-
files = glob.glob(pattern)
33+
34+
# Retry mechanism for file appearance (Source 2 can be slow to flush to disk)
35+
files = []
36+
for _ in range(15): # Try for 3 seconds
37+
files = glob.glob(pattern)
38+
if files:
39+
break
40+
time.sleep(0.2)
41+
3442
if not files:
3543
raise FileNotFoundError(f"Missing face: {name} for session {session_id}")
3644

@@ -132,7 +140,7 @@ def run(self):
132140
time.sleep(0.5)
133141

134142
# Build command list to avoid semicolon issues in netcon
135-
t = 0.1 # Tick interval
143+
t = 0.2 # Increased tick interval for stability
136144
cmds = [
137145
"sv_cheats 1", "noclip 1", "r_drawviewmodel 0", "cl_drawhud 0", "r_drawpanorama 0", "cl_firstperson_legs 0",
138146
"fov_cs_debug 106.260205", "ent_fire cmd kill", "ent_create point_servercommand {targetname cmd}",
@@ -141,34 +149,34 @@ def run(self):
141149
# Forward
142150
f'ent_fire worldent addoutput "OnUser1>cmd>command>setpos_exact {x} {y} {z}>{1*t}>1"',
143151
f'ent_fire worldent addoutput "OnUser1>cmd>command>setang_exact 1 0 0>{1*t}>1"',
144-
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_forward>{1*t + 0.01}>1"',
145-
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{1*t + 0.02}>1"',
152+
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_forward>{1*t + 0.05}>1"',
153+
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{1*t + 0.1}>1"',
146154
# Right
147155
f'ent_fire worldent addoutput "OnUser1>cmd>command>setpos_exact {x} {y} {z}>{2*t}>1"',
148156
f'ent_fire worldent addoutput "OnUser1>cmd>command>setang_exact 0 270 -1>{2*t}>1"',
149-
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_right>{2*t + 0.01}>1"',
150-
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{2*t + 0.02}>1"',
157+
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_right>{2*t + 0.05}>1"',
158+
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{2*t + 0.1}>1"',
151159
# Back
152160
f'ent_fire worldent addoutput "OnUser1>cmd>command>setpos_exact {x} {y} {z}>{3*t}>1"',
153161
f'ent_fire worldent addoutput "OnUser1>cmd>command>setang_exact -1 180 0>{3*t}>1"',
154-
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_back>{3*t + 0.01}>1"',
155-
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{3*t + 0.02}>1"',
162+
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_back>{3*t + 0.05}>1"',
163+
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{3*t + 0.1}>1"',
156164
# Left
157165
f'ent_fire worldent addoutput "OnUser1>cmd>command>setpos_exact {x} {y} {z}>{4*t}>1"',
158166
f'ent_fire worldent addoutput "OnUser1>cmd>command>setang_exact 0 90 1>{4*t}>1"',
159-
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_left>{4*t + 0.01}>1"',
160-
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{4*t + 0.02}>1"',
167+
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_left>{4*t + 0.05}>1"',
168+
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{4*t + 0.1}>1"',
161169
# Up
162170
f'ent_fire worldent addoutput "OnUser1>cmd>command>fov_cs_debug 106.260205>{5*t}>1"',
163171
f'ent_fire worldent addoutput "OnUser1>cmd>command>setpos_exact {x} {y} {z}>{5*t}>1"',
164172
f'ent_fire worldent addoutput "OnUser1>cmd>command>setang_exact -89 0 0>{5*t}>1"',
165-
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_up>{5*t + 0.01}>1"',
166-
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{5*t + 0.02}>1"',
173+
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_up>{5*t + 0.05}>1"',
174+
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{5*t + 0.1}>1"',
167175
# Down
168176
f'ent_fire worldent addoutput "OnUser1>cmd>command>setpos_exact {x} {y} {z}>{6*t}>1"',
169-
f'ent_fire worldent addoutput "OnUser1>cmd>command>setang_exact 89 180 180>{6*t}>1"',
170-
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_down>{6*t + 0.01}>1"',
171-
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{6*t + 0.02}>1"',
177+
f'ent_fire worldent addoutput "OnUser1>cmd>command>setang_exact 89 180 0>{6*t}>1"',
178+
f'ent_fire worldent addoutput "OnUser1>cmd>command>screenshot_prefix {session_id}_cube_{ev_suffix}_down>{6*t + 0.05}>1"',
179+
f'ent_fire worldent addoutput "OnUser1>cmd>command>png_screenshot>{6*t + 0.1}>1"',
172180
# Cleanup
173181
f'ent_fire worldent addoutput "OnUser1>cmd>command>cl_drawhud 1;r_drawviewmodel 1;r_drawpanorama 1;cl_firstperson_legs 1;fov_cs_debug 0;noclip 1>{7*t}>1"',
174182
f'ent_fire worldent addoutput "OnUser1>cmd>command>r_always_render_all_windows {original_render_all}>{7*t + 0.1}>1"',
@@ -184,6 +192,8 @@ def run(self):
184192
sentinel="[Cubemap Done]",
185193
timeout=15.0
186194
)
195+
# Small delay after each EV to ensure engine stability
196+
time.sleep(1.0)
187197

188198
# 3. Stitching
189199
self.progress.emit("Stitching images...")

0 commit comments

Comments
 (0)