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 all 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
59 changes: 59 additions & 0 deletions webxrlayers-1.bs
Expand Up @@ -36,6 +36,7 @@ spec: webxr-1;
type: dfn; text: active immersive session
type: dfn; text: type; for: XRReferenceSpace
type: dfn; text: session; for: XRSpace
type: dfn; text: native origin; for: XRSpace
type: dfn; text: XRLayer
type: dfn; text: XRReferenceSpace
type: dfn; text: type; for: XRReferenceSpace
Expand Down Expand Up @@ -1386,6 +1387,64 @@ 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 {
readonly attribute XRCompositionLayer layer;
readonly attribute unsigned long x;
readonly attribute unsigned long y;
readonly attribute XRSpace hitSpace;
};
</pre>

The <dfn attribute for="XRLayerHitResult">layer</dfn> member returns what layer was hit.

The <dfn attribute for="XRLayerHitResult">x</dfn> and <dfn attribute for="XRLayerHitResult">y</dfn> member return the x and y position
where the layer was hit. This position is <code>0</code for the top/left position and <code>1</code> for the bottom/right position.

The <dfn attribute for="XRLayerHitResult">position</dfn> member returns the position in 3D space where the hit occured.

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

<pre class="idl">
[SecureContext, Exposed=Window] partial interface XRFrame {
sequence&lt;XRLayerHitResult&gt; findHitTest(XRSpace space, XRRigidTransform ray);
};
</pre>

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

The <dfn method for="XRFrame">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=] {{XRFrame/session}} was not created with "[=feature descriptor/layers=]" enabled, throw an {{NotSupportedError}} and abort these steps.
1. If [=this=]'s [=XRFrame/active=] boolean is <code>false</code>, throw an {{InvalidStateError}} and abort these steps.
1. Let |hitresults| be a new sequence created in the [=relevant realm=] of [=this=].
1. For each |layer| in [=this=] {{XRFrame/session}}'s {{XRRenderState/layers}}:
1. If |ray| using the orign |space| doesn't intersect |layer|, continue to the next entry.
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. Initialize |result|'s {{XRLayerHitResult/hitSpace}} as follows:
<dl class="switch">
<dt> If a previous hit was found with the same |layer| and [=this=], the user agent MAY:
<dd> Let |result|'s {{XRLayerHitResult/hitSpace}} be the same {{XRSpace}} object as returned by an earlier call with the same |layer| and [=this=].
<dt> Otherwise
<dd> Let |result|'s {{XRLayerHitResult/hitSpace}} be a [=new=] {{XRSpace}} in the [=relevant realm=] of [=this=].
</dl>
1. Set |result|'s {{XRLayerHitResult/hitSpace}} to an {{XRSpace}} that has a [=XRSpace/native origin=] to the pose that should be used to render the 3D position that was hit.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be defined above, and it should be mentioned that the space is only valid during frames where the hit has happened.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be defined above

What do you mean by "defined above"?

it should be mentioned that the space is only valid during frames where the hit has happened.

I looked how gripSpace is defined in the WebXR spec but I don't see where it mentions that it's only valid during the XRFrame.

1. Append |result| to |hitresults|.
1. Return |hitresults|.

</div>

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

Expand Down