@@ -175,27 +175,32 @@ def _capture_usd_snapshot_job(app, job: _UsdSnapshotJob) -> dict[str, bytes]:
175175 # frame_viewport_prims preserves the incoming view direction.
176176 if job .viewer_cfg is not None :
177177 _apply_viewer_cfg (app , job .viewer_cfg )
178- _configure_collision_mesh_visualization ()
179-
180- for node_id , target , cache_path in job .ref_captures :
181- root_path = absolute_prim_path (stage , target .relative_prim_path )
182- collision_paths = _collect_collision_prim_paths (stage , root_path )
183- _select_collision_prims (app , collision_paths )
184- viewport = get_active_viewport ()
185- framed = frame_viewport_prims (viewport , prims = [root_path ])
186- if not framed :
187- print (
188- f"[thumbnail_capture] warning: frame_viewport_prims failed for { root_path } " ,
189- file = sys .stderr ,
190- )
191- png_bytes = capture_viewport_png (app , cache_path , pre_capture_updates = PRE_CAPTURE_UPDATES )
192- if png_bytes :
193- out [node_id ] = png_bytes
194- else :
195- print (
196- f"[thumbnail_capture] capture produced no file for { target .relative_prim_path } : { cache_path } " ,
197- file = sys .stderr ,
198- )
178+ _set_collision_mesh_visualization (enabled = True )
179+ try :
180+ for node_id , target , cache_path in job .ref_captures :
181+ root_path = absolute_prim_path (stage , target .relative_prim_path )
182+ collision_paths = _collect_collision_prim_paths (stage , root_path )
183+ _select_collision_prims (app , collision_paths )
184+ viewport = get_active_viewport ()
185+ framed = frame_viewport_prims (viewport , prims = [root_path ])
186+ if not framed :
187+ print (
188+ f"[thumbnail_capture] warning: frame_viewport_prims failed for { root_path } " ,
189+ file = sys .stderr ,
190+ )
191+ png_bytes = capture_viewport_png (app , cache_path , pre_capture_updates = PRE_CAPTURE_UPDATES )
192+ if png_bytes :
193+ out [node_id ] = png_bytes
194+ else :
195+ print (
196+ f"[thumbnail_capture] capture produced no file for { target .relative_prim_path } : { cache_path } " ,
197+ file = sys .stderr ,
198+ )
199+ finally :
200+ # The collider-viz carb settings are persistent, so disable them and clear the
201+ # selection to avoid leaking collider wireframes into later asset captures.
202+ omni .usd .get_context ().get_selection ().clear_selected_prim_paths ()
203+ _set_collision_mesh_visualization (enabled = False )
199204
200205 return out
201206
@@ -224,7 +229,7 @@ def _capture_stage_snapshot(
224229 )
225230
226231 if collision_paths :
227- _configure_collision_mesh_visualization ( )
232+ _set_collision_mesh_visualization ( enabled = True )
228233 _select_collision_prims (app , collision_paths )
229234
230235 png_bytes = capture_viewport_png (app , cache_path )
@@ -282,15 +287,15 @@ def _collect_collision_prim_paths(stage, root_path: str) -> list[str]:
282287 return paths
283288
284289
285- def _configure_collision_mesh_visualization ( ) -> None :
286- """Enable viewport Show By Type → Physics → Colliders → Selected."""
290+ def _set_collision_mesh_visualization ( * , enabled : bool ) -> None :
291+ """Toggle viewport Show By Type → Physics → Colliders → Selected."""
287292 import carb .settings
288293
289294 # VisualizerMode: 0=None, 1=Selected, 2=All. Use Selected so only the picked
290295 # object_reference subtree shows collider wireframes, not the whole scene.
291296 settings = carb .settings .get_settings ()
292- settings .set_bool ("/persistent/physics/visualizationCollisionMesh" , True )
293- settings .set_int ("/persistent/physics/visualizationDisplayColliders" , 1 )
297+ settings .set_bool ("/persistent/physics/visualizationCollisionMesh" , enabled )
298+ settings .set_int ("/persistent/physics/visualizationDisplayColliders" , 1 if enabled else 0 )
294299
295300
296301def _select_collision_prims (app , selected_prim_paths : list [str ]) -> None :
0 commit comments