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

WebXR Support #1834

Merged
merged 30 commits into from
Feb 8, 2020
Merged

WebXR Support #1834

merged 30 commits into from
Feb 8, 2020

Conversation

Maksims
Copy link
Contributor

@Maksims Maksims commented Jan 19, 2020

This PR removes VR APIs from engine, and adds XR support.
Currently it implements only starting/ending XR sessions (VR/AR). Input devices and reference space features will be added in another PR.

New APIs:

// pc.XrManager as 'xr' on pc.Application
app.xr // access to XrManager
// properties
app.xr.supported // true if WebXR is supported
app.xr.active // true if WebXR Session is active
app.xr.type // null or string (pc.XRTYPE_*) of current active session
// methods
app.xr.isAvailable(type) // check if session of pc.XRTYPE_* is available on current platform
app.xr.start(camera, type, [callback]) // attempt to start XR session for CameraComponent and of pc.XRTYPE_*. With optional callback that can return Error if failed to start.
app.xr.end([callback]) // attempt to end XR session. With optional callback with Error if failed to end.
// events
app.xr.on('available', function (type, available) { } ) // event fired when availability of specified type is changed. Where type is one of pc.XRTYPE_* and available is a boolean.
app.xr.on('available:[type]', function (available) { } ) // event fired when availability of specified type is changed. Where [type] is one of pc.XRTYPE_* and available is a boolean.
app.xr.on('start', function () { } ) // event fired when session is started
app.xr.on('end', function () { } ) // event fired when session is ended

// pc.CameraComponent
entity.camera.startXr(type, [callback]) // start session from specified camera component, where type is one of pc.XRTYPE_*. With optional callback that can return Error if failed to start.
entity.camera.endXr([callback]) // attempt to end XR session. With optional callback with Error if failed to end.

// pc
pc.XRTYPE_INLINE // 'inline' - type of session which is always available
pc.XRTYPE_VR // 'immersive-vr' - type of session, offers best VR experience with access to most hardware sensors
pc.XRTYPE_AR // 'immersive-ar' - type of session, available on platforms with camera.

Fixes #1748

I confirm I have signed the Contributor License Agreement.

@Maksims
Copy link
Contributor Author

Maksims commented Jan 25, 2020

Some progress here, added ability to choose session type.
Fixed issues with switching between rendering targets (backbuffer of framebuffer for XR).
Fixed issues with canvas resizing.

Tested AR on Android with chrome://flags/#webxr enabled. Surprised to see how well it works already.
For testing, can use this project: https://playcanvas.com/project/660566/overview/webxr

@Maksims Maksims marked this pull request as ready for review January 30, 2020 01:42
@Maksims
Copy link
Contributor Author

Maksims commented Jan 30, 2020

This PR already implements what WebVR was providing - starting/ending XR sessions.
It does not implements XR input devices, nor reference space features. This will be added in another PR.

So this can be merged, as it will provide ability to start experimenting with VR/AR.
It can be tested on this project: https://playcanvas.com/project/660566/overview/webxr

Basic example:

var XrBasic = pc.createScript('xrBasic');

// entity with button element
XrBasic.attributes.add('button', {
    type: 'entity'
});

// entity with camera component
XrBasic.attributes.add('cameraEntity', {
    type: 'entity'
});

XrBasic.prototype.initialize = function() {
    // click button
    this.button.element.on('click', function() {
        // check support
        if (this.app.xr.isAvailable(pc.XRTYPE_VR)) {
            // start session
            this.cameraEntity.camera.startXr(pc.XRTYPE_VR);
        }
    }, this);
};

@willeastcott
Copy link
Contributor

Great stuff!

The unit tests are failing. Can you fix please?

@Maksims
Copy link
Contributor Author

Maksims commented Jan 30, 2020

Added deprecation warnings, and fixed tests.

@willeastcott
Copy link
Contributor

Excellent. Can you also update this please:

https://github.com/playcanvas/engine/blob/master/examples/graphics/virtual-reality.html

Maybe even consider creating a new subfolder 'xr' and move it there (we'll probably add an AR and other related examples too!). 😄

@willeastcott
Copy link
Contributor

A few lint errors. You can auto-fix most/all:

npm run lint -- --fix

@Maksims
Copy link
Contributor Author

Maksims commented Jan 30, 2020

Fixed lint and added two examples for basic VR and basic AR.
Also updated Starter Kit: VR project in a webxr branch, so can be merged to master once engine is deployed with this PR.

@willeastcott willeastcott self-assigned this Jan 31, 2020
@Maksims
Copy link
Contributor Author

Maksims commented Feb 4, 2020

Hm, noticed one issue with Box Projected CubeMaps, they are not projected correctly in VR.

@willeastcott
Copy link
Contributor

Interesting. Screenshot?

@Maksims
Copy link
Contributor Author

Maksims commented Feb 4, 2020

Interesting. Screenshot?

box-project-wrong

@Maksims
Copy link
Contributor Author

Maksims commented Feb 4, 2020

Fixed normals issue.
Also updated https://playcanvas.com/project/434546/overview/webvr-orange-room project (not published yet), so WebXR can be tested on it as well.

I believe this is ready now.

@willeastcott
Copy link
Contributor

This is great - we're so close to merging. Last outstanding thing for me:

If I merged this and deployed as v1.25.0, what will VR developers face? Especially those with PlayCanvas projects based on the old WebVR integration?

  • Do we need a migration guide for existing PlayCanvas VR apps?
  • What about VR controllers? What has to be done to re-enable those?

@Maksims
Copy link
Contributor Author

Maksims commented Feb 5, 2020

If I merged this and deployed as v1.25.0, what will VR developers face? Especially those with PlayCanvas projects based on the old WebVR integration?

Currently this PR only enough for HMD (including mobile). WebVR is getting deprecated in most browsers, new Chrome wont even have its support behind the flag.

  • Do we need a migration guide for existing PlayCanvas VR apps?

We will need migration guide once we have all the functionality in place.

  • What about VR controllers? What has to be done to re-enable those?

Previously, WebVR had controllers implemented through GamePad API. WebXR implements own interfaces to interact with physical devices (even mouse and touch) and is done through XRInputSource.

We can deprecate WebVR later, and deploy this, allowing developers to play with WebXR straight away. Later deprecate WebVR, as browsers slowly deprecate its APIs as well.

@Maksims
Copy link
Contributor Author

Maksims commented Feb 5, 2020

Updated: WebVR is brought back. So we will deprecate it later.
And slightly simplified API.

@willeastcott
Copy link
Contributor

willeastcott commented Feb 5, 2020

I definitely like how you've simplified some of the API now - nice move.

@Maksims
Copy link
Contributor Author

Maksims commented Feb 8, 2020

Tested on Oculus Quest, works as intended.

@willeastcott willeastcott merged commit 64410ef into playcanvas:master Feb 8, 2020
@Maksims Maksims deleted the webxr branch February 9, 2020 03:36
TheJonRobinson added a commit to Mojiworks/playcanvas-engine that referenced this pull request Feb 23, 2020
* master: (31 commits)
  WebXR Input Sources (playcanvas#1873)
  Simplified constants definition in Math classes (playcanvas#1876)
  Improve batching to handle 8-bit and 32-bit index buffers (playcanvas#1872)
  Add particle start frame example to browser
  [FIX] Update WebXR examples to use latest enums (playcanvas#1870)
  [FIX] Add XRWebGLLayer to externs for Closure compiler (playcanvas#1869)
  update paths in the particle system start frame example (playcanvas#1868)
  add a animation start frame variable to the particle system which def… (playcanvas#1864)
  point cloud example using engine directly, and custom shader changing size and color of points (playcanvas#1867)
  WebXR Support (playcanvas#1834)
  Hardware Instancing fixes / sample (playcanvas#1846) (playcanvas#1856)
  [VERSION] v1.25.0-dev
  [RELEASE] v1.24.7
  Recompiled basis, now works on IE (playcanvas#1865)
  Small mesh cleanup (playcanvas#1866)
  [FIX] Revert memory-leak change (playcanvas#1862)
  [FIX] Flag model as immutable when it's added to a ModelComponent (playcanvas#1861)
  [FIX] Fix calculation of deprecated pc.MouseEvent#wheel (playcanvas#1859)
  [DOCS] Adjust Vec3.normalize docs to reflect behavior better (playcanvas#1849)
  pc.BatchManager.markGroupDirty is now public (playcanvas#1848)
  ...
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.

Add WebXR support
2 participants