Simple-WebXR-Unity icon indicating copy to clipboard operation
Simple-WebXR-Unity copied to clipboard

Add hit test support

Open Rufus31415 opened this issue 3 years ago • 9 comments

https://immersive-web.github.io/hit-test/

Rufus31415 avatar May 01 '21 20:05 Rufus31415

Hey! I was testing Hit Test on iOS with great success but it seems to not work properly on Android. Any idea?

EDIT: Remote debugging gave me the following error

"PROD-BUILD.framework.js:92 Uncaught (in promise) DOMException: Failed to execute 'requestHitTestSource' on 'XRSession': Hit test feature is not supported by the session. at someurl-PROD-BUILD.framework.js:92:53710"

gisornator avatar Jan 23 '22 19:01 gisornator

Hi! This means your browser doesn't support hit test. But I should test that XRSession contains requestHitTestSource to warn if this feature is not supported

Rufus31415 avatar Jan 24 '22 06:01 Rufus31415

Technically, the browser should support it. I tested it with Chrome 96.0.4664.92 (Android).

E.g. testing it through this works fine in the same browser: https://chromestatus.com/feature/4755348300759040

gisornator avatar Jan 24 '22 06:01 gisornator

One thing I found:

According to several resources, it seems that it is required to ask for hit-testing when starting the AR Session: https://developer.mozilla.org/en-US/docs/Web/API/XRSession/requestHitTestSource

So maybe (that's just a guess because I can try it earliest in the evening) that line 575 (SimpleWebXR.jslib) needs to be changed to require the hit-test module:

navigator.xr.requestSession(_isArSupported ? 'immersive-ar' : 'immersive-vr', { requiredFeatures: ["local", "hit-test"], optionalFeatures: ['local-floor', 'hand-tracking'] }).then(function (session)

gisornator avatar Jan 24 '22 07:01 gisornator

Okay, I was able to test it in the meantime and the solution from above worked now! I have a different issue now in regards of Unity's Input.Touch system. I'm not getting any errors in the console but I think this is related to the full screen.

gisornator avatar Jan 24 '22 09:01 gisornator

You are right, from now on, the hit-test feature shoul be declared, I'll add that here : https://github.com/Rufus31415/Simple-WebXR-Unity/blob/a9060413037d6b5dd985abba29ed17fcd51ff79d/com.rufus31415.simplewebxr/Runtime/Plugins/WebGL/SimpleWebXR.jslib#L575 Thanks

On Android, I know that for safety, in full screen mode, a new context is created and I'm not sure if Input.Touch which reacts on javascript events on the

still works. The only way to access the touch during a session is through the WebXR API with events InputSourceSelect, InputSourceSelectStart, ...

Rufus31415 avatar Jan 24 '22 10:01 Rufus31415

Thanks for the quick response! Yea, I will try that later tonight :) do you have something in the examples on how to interact with UI elements and InputSourceSelect, etc?

gisornator avatar Jan 24 '22 10:01 gisornator

If you use it with MRTK, WebXR events are propagated to MRTK core. So you just have nothing special to do except choosing your input source in MRTK settings

Rufus31415 avatar Jan 24 '22 11:01 Rufus31415

I cant touch my ui button and 3d collider when in AR mode fullscreen, so i cant have any interaction after AR start. any example to fix this?

DeveloperARKids avatar Mar 26 '22 20:03 DeveloperARKids