-
Notifications
You must be signed in to change notification settings - Fork 1.7k
WebXR Support #1834
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
Merged
Merged
WebXR Support #1834
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
d6abbea
origin/webxr
Maksims e14f9b9
lint fixes
Maksims 5b8d0d9
respect parent transform, fix start/end session rendering
Maksims 31054d6
resize graphics device to respect XR session framebuffer
Maksims 5f8ff76
provide multiple XR session types; AR
Maksims f9d8568
better API, tidy up, lint clean
Maksims 70d339a
merge
Maksims 45903ba
jsdocs fixes
Maksims 95c3fff
fix tests
Maksims d8b9599
add backwards compatibility warnings for VR
Maksims 5d0c342
remove deprecated VR camera logic
Maksims 77ba3ae
Merge branch 'master' into webxr
Maksims 4f70715
Merge branch 'master' of github.com:playcanvas/engine into webxr
Maksims 92fb7e6
remove VR examples and add XR examples
Maksims d21a68c
Merge branch 'webxr' of github.com:Maksims/engine-1 into webxr
Maksims 2deb5f5
lint errors
Maksims 1d001fb
Merge branch 'master' into webxr
willeastcott 407c0e6
Merge branch 'master' of github.com:playcanvas/engine into webxr
Maksims 52304f9
Merge branch 'webxr' of github.com:Maksims/engine-1 into webxr
Maksims 1ebcd83
address PR comments
Maksims 9aedc74
calculate camera XR frustum based on XR view
Maksims 462d537
fix XR normals bug, and change position/rotation calculation
Maksims 2616d31
API renaming/simplification
Maksims 8b84b9d
undepricate WebVR
Maksims f500fb2
fixes
Maksims c6dd516
rename pc.XR_TYPE_* to simplified version
Maksims b0c78bf
remove CameraComponent.isXr property
Maksims be08fb2
Merge branch 'master' into webxr
Maksims 2639133
Merge branch 'master' of github.com:playcanvas/engine into webxr
Maksims 40272a7
Merge branch 'webxr' of github.com:Maksims/engine-1 into webxr
Maksims File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>PlayCanvas Virtual Reality</title> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> | ||
| <link rel="icon" type="image/png" href="../playcanvas-favicon.png" /> | ||
| <script src="../../build/output/playcanvas.js"></script> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| padding: 0; | ||
| overflow: hidden; | ||
| } | ||
| canvas { | ||
| width:100%; | ||
| height:100%; | ||
|
|
||
| } | ||
| .message { | ||
| position: absolute; | ||
| padding: 8px 16px; | ||
| left: 20px; | ||
| bottom: 0px; | ||
| color: #ccc; | ||
| background-color: rgba(0, 0, 0, .5); | ||
| font-family: "Proxima Nova", Arial, sans-serif; | ||
| } | ||
| </style> | ||
| </head> | ||
|
|
||
| <body> | ||
| <canvas id="application-canvas"></canvas> | ||
| <div> | ||
| <p class="message"></p> | ||
| </div> | ||
| <script> | ||
| // draw some axes | ||
| var drawAxes = function (pos, scale) { | ||
| var color = new pc.Color(1,0,0); | ||
|
|
||
| var axis = new pc.Vec3(); | ||
| var end = new pc.Vec3().copy(pos).add(axis.set(scale,0,0)); | ||
|
|
||
| app.renderLine(pos, end, color); | ||
|
|
||
| color.set(0, 1, 0); | ||
| end.sub(axis.set(scale,0,0)).add(axis.set(0,scale,0)); | ||
| app.renderLine(pos, end, color); | ||
|
|
||
| color.set(0, 0, 1); | ||
| end.sub(axis.set(0,scale,0)).add(axis.set(0,0,scale)); | ||
| app.renderLine(pos, end, color); | ||
| } | ||
| </script> | ||
|
|
||
|
|
||
| <script> | ||
| var message = function (msg) { | ||
| var el = document.querySelector('.message'); | ||
| el.textContent = msg; | ||
| } | ||
|
|
||
| var canvas = document.getElementById('application-canvas'); | ||
| var app = new pc.Application(canvas, { | ||
| mouse: new pc.Mouse(canvas), | ||
| touch: new pc.TouchDevice(canvas), | ||
| keyboard: new pc.Keyboard(window) | ||
| }); | ||
| app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW); | ||
| app.setCanvasResolution(pc.RESOLUTION_AUTO); | ||
|
|
||
| window.addEventListener("resize", function () { | ||
| app.resizeCanvas(canvas.width, canvas.height); | ||
| }); | ||
|
|
||
| // use device pixel ratio | ||
| app.graphicsDevice.maxPixelRatio = window.devicePixelRatio; | ||
|
|
||
| app.start(); | ||
|
|
||
| // create camera | ||
| var c = new pc.Entity(); | ||
| c.addComponent('camera', { | ||
| clearColor: new pc.Color(0, 0, 0, 0), | ||
| farClip: 10000 | ||
| }); | ||
| app.root.addChild(c); | ||
|
|
||
| var l = new pc.Entity(); | ||
| l.addComponent("light", { | ||
| type: "spot", | ||
| range: 30 | ||
| }); | ||
| l.translate(0,10,0); | ||
| app.root.addChild(l); | ||
|
|
||
|
|
||
| var createCube = function(x,y,z) { | ||
| var cube = new pc.Entity(); | ||
| cube.addComponent("model", { | ||
| type: "box", | ||
| }); | ||
| cube.setLocalScale(.5, .5, .5); | ||
| cube.translate(x * .5, y, z * .5); | ||
| app.root.addChild(cube); | ||
| }; | ||
|
|
||
| // create a grid of cubes | ||
| var SIZE = 4; | ||
| for (var x = 0; x < SIZE; x++) { | ||
| for (var y = 0; y < SIZE; y++) { | ||
| createCube(2*x - SIZE, -1, 2*y - SIZE); | ||
| } | ||
| } | ||
|
|
||
| if (app.xr.supported) { | ||
| var activate = function () { | ||
| if (app.xr.isAvailable(pc.XR_TYPE_IMMERSIVE_AR)) { | ||
| c.camera.startXr(pc.XR_TYPE_IMMERSIVE_AR, function (err) { | ||
| if (err) message("WebXR Immersive AR failed to start: " + err.message); | ||
| }); | ||
| } else { | ||
| message("WebXR Immersive AR is not available"); | ||
| } | ||
| }; | ||
|
|
||
| app.mouse.on("mousedown", function () { | ||
| if (! app.xr.active) | ||
| activate(); | ||
| }); | ||
|
|
||
| if (app.touch) { | ||
| app.touch.on("touchend", function () { | ||
| if (! app.xr.active) { | ||
| // if not in VR, activate | ||
| activate(); | ||
| } else { | ||
| // otherwise reset camera | ||
| c.camera.endXr(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // end session by keyboard ESC | ||
| app.keyboard.on('keydown', function (evt) { | ||
| if (evt.key === pc.KEY_ESCAPE && app.xr.active) { | ||
| app.xr.end(); | ||
| } | ||
| }); | ||
|
|
||
| app.xr.on('start', function () { | ||
| message("WebXR Immersive AR session has started"); | ||
| }); | ||
| app.xr.on('end', function () { | ||
| message("WebXR Immersive AR session has ended"); | ||
| }); | ||
| app.xr.on('available:' + pc.XR_TYPE_IMMERSIVE_AR, function (available) { | ||
| message("WebXR Immersive AR is now " + (available ? 'available' : 'unavailable')); | ||
| }); | ||
|
|
||
| if (! app.xr.isAvailable(pc.XR_TYPE_IMMERSIVE_AR)) { | ||
| message("WebXR Immersive AR is not available"); | ||
| } | ||
| } else { | ||
| message("WebXR is not supported"); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.