facebookarchive / react-360

Create amazing 360 and VR content using React
https://facebook.github.io/react-360
Other
8.73k stars 1.23k forks source link

Raycasters incorrect if ReactVR canvas not 100% document height/width #395

Closed timoxley closed 6 years ago

timoxley commented 7 years ago

Currently the default raycaster calculations are performed relative to the document e.g.

https://github.com/facebook/react-vr/blob/24c2a4ca75c1cae81f2c4e01f3eed12fa0f2a99f/OVRUI/src/Inputs/MouseRayCaster.js#L29-L33

If you have a ReactVR scene that's embedded on a webpage and/or isn't 100% the document size, all raycasting will be incorrect, offset & scaled by the amount the ReactVR canvas is offset & scaled compared to the document.

Raycasters also trigger input handers whether the cursor is currently over the ReactVR canvas or not i.e. input events will be received even if there's some DOM content entirely covering the ReactVR canvas, and this seems to be unavoidable without hacks because AFAICT there's no pointer-events: none CSS that can event prevent this due to the event listeners being attached at the document level, rather than on the ReactVR element.

GuiSys should probably be optionally passed the DOM element the Player will render into (i.e. options.elementOrId), and then pass this into the default raycasters that GuiSys creates.

jgwinner commented 6 years ago

Interesting, I was planning on embedding some React VR views on my web pages - not necessarily for immersion (although that would be cool) but also for playing small games just as a Three.JS app. You're saying that these wouldn't work then, without your fix, right?

timoxley commented 6 years ago

@jgwinner It will work fine if you load the content in an iframe, which is currently the recommended way to do embedded reactvr.

jgwinner commented 6 years ago

Ah, that's what I had intended anyway, not that I'm against a fix :)

Good news though.

andrewimm commented 6 years ago

Resolved with new events layer in R360