import omni
from pxr import UsdGeom

stage = omni.usd.get_context().get_stage()
camera_path = "/World/SplatCamSensor"
if not stage.GetPrimAtPath(camera_path):
    camera = UsdGeom.Camera.Define(stage, camera_path)
    camera.GetFocalLengthAttr().Set(24)
    camera.GetHorizontalApertureAttr().Set(20.955)
    camera.GetVerticalApertureAttr().Set(15.2908)
print("已创建摄像机 /World/SplatCamSensor")




import omni.kit.viewport.utility as vp_util

viewport = vp_util.get_active_viewport()
imgpath = "/workspace/scripts/3dgs_demo_capture/viewcap_util.png"
vp_util.capture_viewport_to_file(viewport, imgpath)
print("截图已保存到：", imgpath)





import omni.kit.viewport.utility as vp_util

# 先切视口到你想要的相机
viewport = vp_util.get_active_viewport()
viewport.camera_path = "/World/SplatCamSensor"    # <--- 这行是关键

# 再截图
imgpath = "/workspace/scripts/3dgs_demo_capture/viewcap_util.png"
vp_util.capture_viewport_to_file(viewport, imgpath)
print("截图已保存到：", imgpath)