2113921139
2114021140 };
2114121141
21142+ this.isPresenting = isPresenting;
21143+
21144+ this.requestAnimationFrame = function ( callback ) {
21145+
21146+ device.requestAnimationFrame( callback );
21147+
21148+ };
21149+
2114221150 this.submitFrame = function () {
2114321151
2114421152 if ( isPresenting() ) device.submitFrame();
@@ -21157,6 +21165,141 @@
2115721165
2115821166 }
2115921167
21168+ /**
21169+ * @author mrdoob / http://mrdoob.com/
21170+ */
21171+
21172+ function WebXRManager( gl ) {
21173+
21174+ var device = null;
21175+ var session = null;
21176+
21177+ var frameOfRef = null;
21178+ var isExclusive = false;
21179+
21180+ var pose = null;
21181+
21182+ function isPresenting() {
21183+
21184+ return session !== null && frameOfRef !== null;
21185+
21186+ }
21187+
21188+ //
21189+
21190+ var cameraL = new PerspectiveCamera();
21191+ cameraL.layers.enable( 1 );
21192+ cameraL.viewport = new Vector4();
21193+
21194+ var cameraR = new PerspectiveCamera();
21195+ cameraR.layers.enable( 2 );
21196+ cameraR.viewport = new Vector4();
21197+
21198+ var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
21199+ cameraVR.layers.enable( 1 );
21200+ cameraVR.layers.enable( 2 );
21201+
21202+ //
21203+
21204+ this.enabled = false;
21205+
21206+ this.getDevice = function () {
21207+
21208+ return device;
21209+
21210+ };
21211+
21212+ this.setDevice = function ( value ) {
21213+
21214+ if ( value !== undefined ) device = value;
21215+
21216+ gl.setCompatibleXRDevice( value );
21217+
21218+ };
21219+
21220+ this.setSession = function ( value ) {
21221+
21222+ session = value;
21223+
21224+ if ( session !== null ) {
21225+
21226+ session.baseLayer = new XRWebGLLayer( session, gl );
21227+ session.requestFrameOfReference( 'stage' ).then( function ( value ) {
21228+
21229+ frameOfRef = value;
21230+ isExclusive = session.exclusive;
21231+
21232+ console.log( 0 );
21233+
21234+ } );
21235+
21236+ }
21237+
21238+ };
21239+
21240+ this.getCamera = function ( camera ) {
21241+
21242+ return isPresenting() ? cameraVR : camera;
21243+
21244+ };
21245+
21246+ this.isPresenting = isPresenting;
21247+
21248+ this.requestAnimationFrame = function ( callback ) {
21249+
21250+ console.log( 1 );
21251+
21252+ function onFrame( time, frame ) {
21253+
21254+ pose = frame.getDevicePose( frameOfRef );
21255+
21256+ var layer = session.baseLayer;
21257+ var views = frame.views;
21258+
21259+ for ( var i = 0; i < views.length; i ++ ) {
21260+
21261+ var view = views[ i ];
21262+ var viewport = layer.getViewport( view );
21263+ var viewMatrix = pose.getViewMatrix( view );
21264+
21265+ var camera = cameraVR.cameras[ i ];
21266+ camera.projectionMatrix.fromArray( view.projectionMatrix );
21267+ camera.matrixWorldInverse.fromArray( viewMatrix );
21268+ camera.matrixWorld.getInverse( camera.matrixWorldInverse );
21269+ camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
21270+
21271+ if ( i === 0 ) {
21272+
21273+ cameraVR.matrixWorld.copy( camera.matrixWorld );
21274+ cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );
21275+
21276+ // HACK (mrdoob)
21277+ // https://github.com/w3c/webvr/issues/203
21278+
21279+ cameraVR.projectionMatrix.copy( camera.projectionMatrix );
21280+
21281+ }
21282+
21283+ }
21284+
21285+ gl.bindFramebuffer( gl.FRAMEBUFFER, session.baseLayer.framebuffer );
21286+
21287+ callback();
21288+
21289+ }
21290+
21291+ session.requestAnimationFrame( onFrame );
21292+
21293+ };
21294+
21295+ this.submitFrame = function () {
21296+
21297+ // if ( device && device.isPresenting ) device.submitFrame();
21298+
21299+ };
21300+
21301+ }
21302+
2116021303 /**
2116121304 * @author supereggbert / http://www.paulbrunt.co.uk/
2116221305 * @author mrdoob / http://mrdoob.com/
2140221545
2140321546 // vr
2140421547
21405- var vr = new WebVRManager( _this );
21548+ var vr = ( 'xr' in navigator ) ? new WebXRManager( _gl ) : new WebVRManager( _this );
2140621549
2140721550 this.vr = vr;
2140821551
2146721610
2146821611 this.setSize = function ( width, height, updateStyle ) {
2146921612
21470- var device = vr.getDevice();
21471-
21472- if ( device && device.isPresenting ) {
21613+ if ( vr.isPresenting() ) {
2147321614
2147421615 console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
2147521616 return;
2215122292
2215222293 function requestAnimationLoopFrame() {
2215322294
22154- var device = vr.getDevice();
22295+ if ( vr.isPresenting() ) {
2215522296
22156- if ( device && device.isPresenting ) {
22157-
22158- device.requestAnimationFrame( animationLoop );
22297+ vr.requestAnimationFrame( animationLoop );
2215922298
2216022299 } else {
2216122300
@@ -22502,14 +22641,22 @@
2250222641
2250322642 if ( object.layers.test( camera2.layers ) ) {
2250422643
22505- var bounds = camera2.bounds;
22644+ if ( 'viewport' in camera2 ) { // XR
22645+
22646+ state.viewport( _currentViewport.copy( camera2.viewport ) );
22647+
22648+ } else {
22649+
22650+ var bounds = camera2.bounds;
2250622651
22507- var x = bounds.x * _width;
22508- var y = bounds.y * _height;
22509- var width = bounds.z * _width;
22510- var height = bounds.w * _height;
22652+ var x = bounds.x * _width;
22653+ var y = bounds.y * _height;
22654+ var width = bounds.z * _width;
22655+ var height = bounds.w * _height;
2251122656
22512- state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
22657+ state.viewport( _currentViewport.set( x, y, width, height ).multiplyScalar( _pixelRatio ) );
22658+
22659+ }
2251322660
2251422661 renderObject( object, scene, camera2, geometry, material, group );
2251522662
3522235369
3522335370 'name': clip.name,
3522435371 'duration': clip.duration,
35225- 'tracks': tracks
35372+ 'tracks': tracks,
35373+ 'uuid': clip.uuid
3522635374
3522735375 };
3522835376
3710537253
3710637254 for ( var i = 0; i < json.length; i ++ ) {
3710737255
37108- var clip = AnimationClip.parse( json[ i ] );
37256+ var data = json[ i ];
37257+
37258+ var clip = AnimationClip.parse( data );
37259+
37260+ if ( data.uuid !== undefined ) clip.uuid = data.uuid;
3710937261
3711037262 animations.push( clip );
3711137263
3855338705
3855438706 },
3855538707
38708+ setMediaElementSource: function ( mediaElement ) {
38709+
38710+ this.hasPlaybackControl = false;
38711+ this.sourceType = 'mediaNode';
38712+ this.source = this.context.createMediaElementSource( mediaElement );
38713+ this.connect();
38714+
38715+ return this;
38716+
38717+ },
38718+
3855638719 setBuffer: function ( audioBuffer ) {
3855738720
3855838721 this.buffer = audioBuffer;
0 commit comments