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

chore: Swap webvr to webxr polyfill packages #273

Open
wants to merge 115 commits into
base: main
Choose a base branch
from

Conversation

kevleyski
Copy link
Contributor

@kevleyski kevleyski commented Dec 20, 2022

Description

Fixes #216 (WebXR support)

Specific Changes proposed

For devices that support WebXR use that
Add iOS device orientation permission check on entering 360 (note ESLint workaround as this is iOS Safari specfic)
Fall back to original WebVR polyfill if navigator.xr not available after initialising WebXR polyfill

Requirements Checklist

  • Feature implemented / Bug fixed
  • If necessary, more likely in a feature request than a bug fix
    • Unit Tests updated or fixed
    • Docs/guides updated
  • Reviewed by Two Core Contributors

Kevin Staunton-Lambert and others added 25 commits December 2, 2022 13:51
…w Device API is more likely the better thing to do though
[KJSL] Swap webvr ro webxr polyfill packages
[KJSL] Swap webvr ro webxr polyfill packages
[KJSL] Add WebXR immersive VR support
chore: Swap webvr ro webxr polyfill packages
…olyfill if webxr immersive is not available)
chore: Swap webvr ro webxr polyfill packages (continue to use webvr p…
… operation to play/pause and exit VR/AR session)
chore: Swap webvr for webxr polyfill packages (adding basic controller…
chore: Swap webvr ro webxr polyfill packages
chore: Swap webvr to webxr polyfill packages
@kevleyski
Copy link
Contributor Author

Had planned to add thinks like thumb stick controls scrubbing rate maybe and throw a TV not your AR wall - but then those can be a separate issue items

This is more a quick fix to get the player playing immersive VR

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG, thank you so much for this! Been highly requested for sure.

Had a couple of questions.

CONTRIBUTING.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/big-vr-play-button.js Outdated Show resolved Hide resolved
@@ -1,6 +1,8 @@
import 'babel-polyfill';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is babel-polyfill needed for here? Since this is a library, we generally prefer not including polyfills, requesting users include it on their page themselves.
Also, should this be using @babel/polyfill as it's newer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed to be a dependency of webxr polyfill - I'll recheck

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it isn't required https://github.com/immersive-web/webxr-polyfill#browser-support

I think we should make a note of it in the README, but otherwise leave it out of the bundle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so I tried pulling it out this results in the WebXR sessions not starting because there is some regenerator code not generated without babel-polyfill
I encourage other to help remove it if its a concern, I'm out of cycles today

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to "unresolve" this just so that it doesn't get lost, but I don't think it's a blocker.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, when I test this on oculus browser 36 / chromium 130, this works well. I would remove the polyfill here and leave it up to consumers if they want to support older browsers?

Comment on lines +724 to +725
// Detect WebXR is supported
if (window.navigator.xr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

src/plugin.js Outdated Show resolved Hide resolved
if (window.navigator.xr) {
this.log('WebXR is supported');
window.navigator.xr.isSessionSupported('immersive-vr').then((supportsImmersiveVR) => {
if (supportsImmersiveVR) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is false should we try and fall back to the WebVRPolyfill? Or does it happen automatically? A bit hard to understand since it's asynchronous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I went through a few permutations of that - after testing it seemed to not really matter
Then again could be getting lucky in timing each time

src/plugin.js Outdated
}

// No WebXR support fall back to using WebVR polyfill
if (!hasWebXR) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this always get set up regardless of whether webXR is available? Since hasWebXR will always be false here as it hasn't been set to true in the promise above.

kevleyski and others added 2 commits December 21, 2022 04:01
Co-authored-by: Gary Katsevman <[email protected]>
src/plugin.js Outdated Show resolved Hide resolved
Kevin Staunton-Lambert and others added 27 commits July 24, 2024 12:49
… out-of-date plugins so embedding base64/png images instead
Copy link

@bbsimong bbsimong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started looking at this and noticed this PR has been open for a little while, but has seen some recent activity. Is the MetaCDN team still planning on taking this forward? I've tried this out for a little bit and does seem to behave pretty well.

Comment on lines +13 to +14
* rollback THREE.js as this introduced a noticable gamma/brightness increase, adding gyro support, moved
* immersive controller images into base64

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, testing locally, an upgrade to 170 seems OK when setting the color spaces manually. This was an explicit change in r152: https://discourse.threejs.org/t/updates-to-color-management-in-three-js-r152/50791

I think these should be all:

// Line 742
this.videoTexture.colorSpace = THREE.SRGBColorSpace;

// Line 769
this.renderer.outputColorSpace = THREE.SRGBColorSpace;

That doesn't have to happen as part of this PR though.

MathUtils,
Quaternion,
Vector3
} from '../../node_modules/three/build/three.module.js';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just import from 'three'?

I'm looking at making threejs a peer dependency and that should help a good deal with three shaking?

window.navigator.xr.isSessionSupported('immersive-vr').then((supportsImmersiveVR) => {
if (supportsImmersiveVR) {
// We support WebXR show the enter VRButton
this.vrButton = VRButton.createButton(this.renderer);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: createButton takes in an optional sessionInit object that's spread into the requestSession parameters so that users can request additional features. That may be a neat thing to add in. Doesn't have to happen here though.

Comment on lines +19 to +20
import {XRControllerModelFactory} from '../node_modules/three/examples/jsm/webxr/XRControllerModelFactory';
import {BoxLineGeometry} from '../node_modules/three/examples/jsm/geometries/BoxLineGeometry';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be imported from three directly I think?

Suggested change
import {XRControllerModelFactory} from '../node_modules/three/examples/jsm/webxr/XRControllerModelFactory';
import {BoxLineGeometry} from '../node_modules/three/examples/jsm/geometries/BoxLineGeometry';
import {XRControllerModelFactory} from 'three/examples/jsm/webxr/XRControllerModelFactory';
import {BoxLineGeometry} from 'three/examples/jsm/geometries/BoxLineGeometry';

@@ -761,15 +899,350 @@ void main() {
window.addEventListener('resize', this.handleResize_, true);
window.addEventListener('vrdisplayactivate', this.handleVrDisplayActivate_, true);
window.addEventListener('vrdisplaydeactivate', this.handleVrDisplayDeactivate_, true);
window.addEventListener('pointerdown', this.handleUserActive_, true);

// For iOS we need permission for the device orientation data, this will pop up an 'Allow'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safari/iOS is only allowing DeviceMotionEvent.requestPermission during a user event and not on page load.

That said, onDeviceOrientationChange doesn't seem to do anything with the event data, is it needed?

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

Successfully merging this pull request may close these issues.

are you planning to move from webVR to WebXR ?
5 participants