Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. XRHitTestSource

XRHitTestSource

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

TheXRHitTestSource interface of theWebXR Device API handles hit test subscriptions. You can get anXRHitTestSource object by using theXRSession.requestHitTestSource() method.

This object doesn't itself contain hit test results, but it is used to compute hit tests for eachXRFrame by callingXRFrame.getHitTestResults(), which returnsXRHitTestResult objects.

Instance properties

None.

Instance methods

XRHitTestSource.cancel()Experimental

Unsubscribes from the hit test.

Examples

Getting anXRHitTestSource object for a session

CallXRSession.requestHitTestSource() to get a hit test source.

js
const xrSession = navigator.xr.requestSession("immersive-ar", {  requiredFeatures: ["local", "hit-test"],});let hitTestSource = null;xrSession  .requestHitTestSource({    space: viewerSpace, // obtained from xrSession.requestReferenceSpace("viewer");    offsetRay: new XRRay({ y: 0.5 }),  })  .then((viewerHitTestSource) => {    hitTestSource = viewerHitTestSource;  });// frame loopfunction onXRFrame(time, xrFrame) {  let hitTestResults = xrFrame.getHitTestResults(hitTestSource);  // do things with the hit test results}

Unsubscribe from hit test

To unsubscribe from a hit test source, callXRHitTestSource.cancel(). Since the object will no longer be usable, you can clean up and set theXRHitTestSource object tonull.

js
hitTestSource.cancel();hitTestSource = null;

Specifications

Specification
WebXR Hit Test Module
# hit-test-source-interface

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp