Skip to content

Better Depth Options and Camera - #766

Open
whuang37 wants to merge 3 commits into
google:mainfrom
whuang37:agent-error-depth
Open

whuang37 wants to merge 3 commits into
google:mainfrom
whuang37:agent-error-depth

Conversation

@whuang37

Copy link
Copy Markdown
Collaborator

Description

  • A huge issue with depth is that texture enabling was super awkward where agents expected textures by default when calling enableDepth. Made that the default option
  • Added camera projection matrices for SimulatorCamera. Since it center crops the points need to be reprojected to accurately represent world coordinates
const parameters =
  xb.core.deviceCamera?.simulatorCamera?.getCameraParameters();

if (parameters) {
  const projected = xb.projectWorldToCameraUv(worldPoint, parameters);

  if (projected?.inFrame) {
    const pixelX = projected.uv.x * parameters.width;
    const pixelY = projected.uv.y * parameters.height;
  }
}

Type of Change

  • Bug fix
  • New feature / enhancement
  • New demo or sample
  • Documentation update

Media / Screen Recordings & Screenshots (If Applicable)

xrblocks-camera-projection-before-after

Checklist

  • Tested in simulator & device: Verified functionality in desktop simulator and/or physical hardware (where applicable).
  • Large Assets ($\ge$ 1MB): Submitted separately to xrblocks/proprietary-assets via jsdelivr CDN.
  • SDK Dynamic Dependencies: All new SDK dependencies are dynamically loaded at runtime.
  • Security: Confirmed no hardcoded API keys or secrets are committed.

@whuang37
whuang37 requested a review from dli7319 October 29, 2026 02:18
@dli7319

dli7319 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Please check the ai reviewer comments:
🟡 enableDepth({texture: false}) / enableDepth({mesh: false}) Disables Both Outputs (src/core/Options.ts:443–448): Because useDefaults is computed as mesh === undefined && texture === undefined, passing {texture: false} (to opt out of the new default texture while keeping the mesh) or {mesh: false} sets useDefaults = false and resolves mesh ?? useDefaults / texture ?? useDefaults to false, turning both outputs off. Compute const useDefaults = mesh !== true && texture !== true; so {mesh: true} and {texture: true} still select a single output as documented in Depth.md, while {texture: false} and {mesh: false} preserve the other default output.
🟡 SimulatorCamera Custom Camera Mode (matchRenderingCamera = false, src/simulator/SimulatorCamera.ts:63–67): onBeforeSimulatorSceneRender updates this.camera.position and this.camera.quaternion via getWorldPosition/getWorldQuaternion without calling this.camera.updateMatrixWorld() (leaving this.camera.matrixWorld stale if renderScene is mocked or skips world-matrix updates, as in SimulatorCamera.test.ts:94) or syncing this.camera.aspect to sWidth / sHeight before renderScene(this.camera) (causing cropFromClip to double-scale X when sWidth !== sHeight). Call this.camera.updateMatrixWorld() and sync this.camera.aspect + this.camera.updateProjectionMatrix() before rendering.
🟡 getDeviceCameraClipFromView Signature & Shared Matrix Mutation (src/camera/CameraUtils.ts:58–70): Removing the first parameter renderCamera from exported getDeviceCameraClipFromView(deviceCamera, targetDevice) breaks external positional callers (unlike getDeviceCameraWorldFromView and getDeviceCameraWorldFromClip, which keep renderCamera first), and line 68 returns DEVICE_CAMERA_PARAMETERS[targetDevice].projectionMatrix without .clone() (risking mutation of the shared MOOHAN_PROJECTION_MATRIX / QUEST_3_PROJECTION_MATRIX singletons). Also note in Simulator.mdx:91 that xb.getCameraParametersSnapshot(...) works across both the simulator and physical headsets whereas simulatorCamera?.getCameraParameters() is simulator-only.
🟡 Unit Test Coverage (src/camera/CameraUtils.test.ts, src/simulator/SimulatorCamera.test.ts, src/core/Options.ts): Add unit tests covering projectWorldToCameraUv (center/corner UVs, inFrame: true/false, viewPoint.z >= 0 returning null, and round-trip consistency with transformRgbUvToWorld), SimulatorCamera.getCameraParameters() (undefined before first capture and after dispose(), plus non-square 1024x512 / 512x1024 center-crop clipFromView), and options.enableDepth() option combinations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants