XRFrame: getViewerPose() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
ThegetViewerPose() method, a member of theXRFrame interface, returns aXRViewerPose object which describes the viewer's pose (position and orientation) relative to the specified reference space.
See thegetPose() method for a way to calculate a pose that represents the difference between two spaces.
In this article
Syntax
getViewerPose(referenceSpace)Parameters
referenceSpaceAn
XRReferenceSpaceobject specifying the space to use as thereference point or base for the computation of the viewer's current pose.
Return value
AXRViewerPose describing the viewer's position and orientation relativeto the specified reference space.
Exceptions
InvalidStateErrorDOMExceptionThrown if
getViewerPose()was notcalled within the context of a callback to asession'sXRSession.requestAnimationFrame().
Examples
In this callback function forrequestAnimationFrame(), theXRViewerPose describing the viewer's viewpoint on the world is obtained by callinggetViewerPose() on theXRFrame passed into the callback.
viewerPose = xrFrame.getViewerPose(xrReferenceSpace);if (viewerPose) { /* render the pose's views */}To see a complete example, take a look atMovement, orientation, and motion.
Specifications
| Specification |
|---|
| WebXR Device API> # dom-xrframe-getviewerpose> |