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

Casting a ray downwards from a virtual object to place it on the floor: possible? #107

Open
nickw1 opened this issue Nov 28, 2021 · 0 comments

Comments

@nickw1
Copy link

nickw1 commented Nov 28, 2021

Hi,

Apologies if this is an inappropriate place to raise this question, but I have seen similar types of question on here.

I am investigating whether it is possible in WebXR to place a virtual object (sourced, for example, from a geodata API) on the floor by casting a ray downwards from its position, and detecting hits made from this ray. My use-case is a geographic AR application which downloads points of interest from a server, which might otherwise (if the Hit Test API was not used) be "floating" above the ground. The aim is to use the Hit Test API to place them on the closest detected plane below them. I create an XRHitTestSource for each object (three boxes, in the example), using a ray which starts from the object and points downwards, using local-floor space.(I realise that setting y to 0 in local-floor space would probably work in many cases, but might not work if the plane below the point is raised above the lowest detected plane).

When I test this, it does detect planes using these XRHitTestSources but seemingly in the wrong location. Frequently the planes are above the cube (larger y) even though the ray has a y component of -1.

My code is here:
https://github.com/nickw1/webxr-expts/blob/master/3/index.js

Note it uses WebXR with A-Frame but usage of the WebXR API should be pretty clear, and there are extensive comments.

I may of course be mis-understanding something, apologies if so.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant