immersive-web / hit-test

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

readonly properties in XRRay and GC churn?

AndrewJDR opened this issue · comments

XRRay instances may be used in calls like requestHitTest reasonably frequently (e.g. a few times every frame), and because its origin/direction properties on XRRay are readonly (DOMPointReadOnly), it doesn't seem possible to re-use an existing XRRay instance with a requestHitTest call -- You're forced to construct a new one for every call to requestHitTest. This can lead to GC churn. It's quite a common practice in webgl JS and matrix/vector libraries to be able reuse instances of vec3/matrix4/etc to save on GC churn... might it be possible to specify webxr hit test related data types to allow for this? e.g. use DOMPoint instead of DOMPointReadOnly on the XRRay (or similar)...

This repo hasn't been updated in quite a while; I don't think the requestHitTest API will be exactly as presented here. But this is a good concern to keep in mind.

In particular, if you look at https://github.com/immersive-web/webxr/blob/master/hit-testing-explainer.md you can see that the hit testing approach there is more asynchronous, and specifies the ray relative to a device coordinate system. So, hit testing with controllers (in immersive AR) will likely use the same ray each frame; hit testing on phones (via screen touch) will change the ray in response to user touch.

Closing - API shape changed (the app no longer needs to create XRRay instances every frame).