Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first pass at hit testing #154

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions webxrlayers-1.bs
Expand Up @@ -1386,6 +1386,54 @@ when the [=XR Compositor=] can no longer reproject the layer.

The author SHOULD redraw the content of the layer at the next [=XR animation frame=]. The event must be of type {{XRLayerEvent}}.

Hit testing {#hittesting}
===========

XRLayerHitResult {#xrlayerhitresulttype}
----------------

<pre class="idl">
interface XRLayerHitResult {
XRCompositionLayer layer;
unsigned long x;
unsigned long y;
DOMPointInit position;
};
</pre>

The <dfn dict-member for="XRLayerHitResult">layer</dfn> member defines what layer was hit.

The <dfn dict-member for="XRLayerHitResult">x</dfn> and <dfn dict-member for="XRLayerHitResult">y</dfn> member define the x and y position
cabanier marked this conversation as resolved.
Show resolved Hide resolved
where the layer was hit.

The <dfn dict-member for="XRLayerHitResult">position</dfn> member defines the position in 3D space where the hit occured.
cabanier marked this conversation as resolved.
Show resolved Hide resolved

Finding hit tests {#finding-hit-tests}
-----------------

<pre class="idl">
[SecureContext, Exposed=Window] partial interface XRSession {
XRLayerHitResult? findHitTest(XRSpace space, XRRigidTransform ray);
};
</pre>

<div class="algorithm" data-algorithm="findHitTestAlgo">

The <dfn method for="XRSession">findHitTest(XRSpace |space|, XRRigidTransform |ray|)</dfn> method casts a ray into the
scene containing instances of {{XRCompositionLayer|XRCompositionLayers}}

When this method is invoked, the user agent MUST run the following steps:
1. If [=this=] was not created with "[=feature descriptor/layers=]" enabled, throw an {{NotSupportedError}} and abort these steps.
1. If |session|'s [=ended=] value is <code>true</code>, throw an {{InvalidStateError}} and abort these steps.
1. If the |ray| using the orign |space| doesn't intersect any layers of the {{XRRenderState/layers}} array, return <code>null</code> and abort these steps.
1. Let |result| be a new instance of {{XRLayerHitResult}} in the [=relevant realm=] of [=this=].
1. Set |result|'s {{XRLayerHitResult/layer}} to the hit {{XRCompositionLayer}}.
1. Set |result|'s {{XRLayerHitResult/x}} and {{XRLayerHitResult/y}} to the position where the |ray| hit {XRLayerHitResult/layer}}.
1. Set |result|'s {{XRLayerHitResult/position}} to the 3D position where the |ray| hit {XRLayerHitResult/layer}}.
1. Return |result|.

</div>

WebXR Device API Integration {#webxrintegration}
============================

Expand Down