Skip to main content
Methods for spatial queries — raycasting, screen-to-world projection, and canvas snapshots.

raycast(origin, direction, maxDist?)

Cast a ray and find the first intersection with a geom.
THREE.Vector3
required
Ray origin in world coordinates.
THREE.Vector3
required
Ray direction (will be normalized).
number
default:"100"
Maximum ray distance.
Returns: RayHit | null

project2DTo3D(x, y, cameraPos, lookAt)

Project a 2D screen point to a 3D world point via raycasting.
number
required
Normalized X coordinate (0 = left, 1 = right).
number
required
Normalized Y coordinate (0 = top, 1 = bottom).
THREE.Vector3
required
Camera world position.
THREE.Vector3
required
Camera look-at point.
Returns: { point: THREE.Vector3, bodyId: number, geomId: number } | null

projectImagePointTo3D(options)

Project detector/image coordinates back into the rendered MuJoCo scene. Prefer this method for perception models because it makes the coordinate convention and camera source explicit.
number
required
X coordinate in the selected coordinate space.
number
required
Y coordinate in the selected coordinate space.
'normalized' | 'normalized-1000' | 'pixel' | 'ndc'
default:"normalized"
Coordinate convention for the detector result.
CameraFrameCaptureOptions
Camera source. Uses the same fields as captureCameraFrame.
Returns: ImagePointProjectionResult | null See Perception Projection for examples.

getCanvasSnapshot(width?, height?, mimeType?)

Capture the current canvas as a base64-encoded image.
number
Output width. Defaults to canvas width.
number
Output height. Defaults to canvas height.
string
default:"image/png"
Image format: 'image/png', 'image/jpeg', 'image/webp'.
Returns: string — base64 data URL.

Camera Animation

Camera state and animation are available via the standalone useCameraAnimation() hook:
See useCameraAnimation for full documentation.

Example: Vision Pipeline