refactor: simplify camera init, document aperture warning as cosmetic

Camera.__init__() internally calls UsdGeom.Camera.Define() which
resets aperture to defaults, making it impossible to pre-set values.
The aperture mismatch warnings are cosmetic — IS auto-corrects them
and our values are applied correctly after init.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tangger
2026-04-03 14:41:00 +08:00
parent 1105a49e8f
commit 6032b12c59

View File

@@ -32,7 +32,7 @@ class CustomCamera(Camera):
reference_path: Reference prim path for camera mounting
name: Camera name
"""
# ===== Pre-compute camera parameters =====
# ===== From cfg =====
pixel_size = cfg["params"].get("pixel_size")
f_number = cfg["params"].get("f_number")
focus_distance = cfg["params"].get("focus_distance")
@@ -47,18 +47,9 @@ class CustomCamera(Camera):
focal_length_y = fy * pixel_size * 1e-3
focal_length = (focal_length_x + focal_length_y) / 2 / 10.0
# Pre-set aperture on USD prim before Camera.__init__ to avoid mismatch warnings
from pxr import UsdGeom
import omni.usd
stage = omni.usd.get_context().get_stage()
cam_prim = stage.GetPrimAtPath(prim_path)
if cam_prim.IsValid():
cam = UsdGeom.Camera(cam_prim)
cam.GetHorizontalApertureAttr().Set(horizontal_aperture * 10.0) # USD uses mm
cam.GetVerticalApertureAttr().Set(vertical_aperture * 10.0)
cam.GetFocalLengthAttr().Set(focal_length * 10.0)
# ===== Initialize camera =====
# Note: Camera.__init__ triggers aperture consistency warnings with default USD values.
# These are cosmetic — IS auto-corrects, and we override with correct values below.
super().__init__(
prim_path=prim_path,
name=name,