XRHitTestResult: createAnchor() 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.
ThecreateAnchor() method of theXRHitTestResult interface creates anXRAnchor from a hit test result that is attached to a real-world object.
In this article
Syntax
js
createAnchor()Parameters
None.
Return value
Examples
>Creating an anchor from a hit test result
The following example starts with anXRHitTestResult retrieved by callingXRFrame.getHitTestResults(). After callingcreateAnchor(), the Promise resolves with anXRAnchor to attach a virtual object to that location.
js
hitTestResult.createAnchor().then( (anchor) => { // add anchored objects to the scene }, (error) => { console.error(`Could not create anchor: ${error}`); },);Specifications
| Specification |
|---|
| WebXR Anchors Module> # dom-xrhittestresult-createanchor> |