immersive-web / proposals

Initial proposals for future Immersive Web work (see README)
95 stars 11 forks source link

Expose hit-testing (raycasting) capability for WebXR #9

Closed lincolnfrog closed 6 years ago

lincolnfrog commented 6 years ago

Title: Expose hit-testing (raycasting) capability for WebXR

Background: In order for web applications to make use of Augmented Reality (AR) capabilities, they must be able to identify real-world geometry. For example, a web application may wish to detect a horizontal plane (e.g, the floor) in the camera feed, and render an object (e.g, a chair) on that plane.

There are many ways that real-world geometry could be exposed through a web API. We propose starting by adding a hit-test API. This API would allow the developer to cast a ray into the real world and return a list of intersection points for that ray against whatever world understanding the underlying system gathers.

This approach abstracts the understanding of the world with a high level primitive that will work across many underlying technologies. A hit-test API would unlock a significant number of use cases for AR while allowing the work to expose other types of world understanding in a web-friendly way to proceed in parallel.

Use Cases: Use-cases enabled by such an API include:

Proposed Approach: Technologies for identifying real-world geometry from the camera input are becoming available on mobile devices, and the user agent could use these to implement a hit-test API. The simplicity of this API also enables a wide range of implementation choices and input types. The intent is to explore an extension to the WebXR Device API - one abstracted from world understanding and closely connected to device pose and frame production - because the ability to render data over the real world (whether in passthrough or see-through mode) requires a strong connection between pose and world understanding.

For illustration purposes, such an API might look like the following: XRPresentationFrame::hitTest(XRPose rayPose) -> Promise<sequence<XRHitResult>> Input is a pose (position/orientation or matrix) whose position represents the origin of the raycast and whose orientation represents the direction of the raycast The return value is a sequence of XRHitResult that contain an XRPose which represents all the hit locations the ray intersected with. In the future, it also may contain other fields (such as the object that was hit)

blairmacintyre commented 6 years ago

As we've talked about offline, I'm still very enthusiastic about having a hitTest method in WebXR, on any session that knows about the world. @speigg and I have been talking a lot about this recently as he works on moving Argon4 to use WebXR instead of it's argon.js framework.

Two comments.

kearwood commented 6 years ago

This is looking good, IMHO.

A couple of refinements could be made to further describe the results:

lincolnfrog commented 6 years ago

@blairmacintyre hitTest() on session seems good to me, it's less opinionated and more tolerant of timing / frames.

To your second point, I agree hitTest could be implemented across any type of XR session. I am not sure what use-case there would be for the user-agent to provide hit-testing in VR, but I could imagine that happening.

lincolnfrog commented 6 years ago

@kearwood You make a bunch of great points! I will try to add / address your points in the readme and i'll let you know when I am done so you can review. Thanks!!!

toji commented 6 years ago

Based on the conversation here and on the CG calls, this proposal meets the criteria for an individual repo. One has been created here: https://github.com/immersive-web/hit-test

Further discussion or issues regarding this proposal should take place on the new repository.