Skip to content

Commit

Permalink
Updated builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Jun 15, 2017
1 parent 07b0896 commit e5d7a89
Show file tree
Hide file tree
Showing 3 changed files with 860 additions and 497 deletions.
180 changes: 180 additions & 0 deletions build/three.js
Original file line number Diff line number Diff line change
Expand Up @@ -19684,6 +19684,164 @@

}

/**
* @author mrdoob / http://mrdoob.com/
*/

function WebVRManager( renderer ) {

var scope = this;

var device = null;
var frameData = null;

if ( 'VRFrameData' in window ) {

frameData = new window.VRFrameData();

}

var cameraL = new THREE.PerspectiveCamera();
cameraL.bounds = new THREE.Vector4( 0.0, 0.0, 0.5, 1.0 );
cameraL.layers.enable( 1 );

var cameraR = new THREE.PerspectiveCamera();
cameraR.bounds = new THREE.Vector4( 0.5, 0.0, 0.5, 1.0 );
cameraR.layers.enable( 2 );

var cameraVR = new THREE.ArrayCamera( [ cameraL, cameraR ] );

//

var currentSize, currentPixelRatio;

function onVRDisplayPresentChange() {

if ( device.isPresenting ) {

var eyeParameters = device.getEyeParameters( 'left' );
var renderWidth = eyeParameters.renderWidth;
var renderHeight = eyeParameters.renderHeight;

currentPixelRatio = renderer.getPixelRatio();
currentSize = renderer.getSize();

renderer.setPixelRatio( 1 );
renderer.setSize( renderWidth * 2, renderHeight, false );

} else if ( scope.enabled ) {

renderer.setPixelRatio( currentPixelRatio );
renderer.setSize( currentSize.width, currentSize.height, true );

}

}

window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );

//

this.enabled = false;

this.getDevice = function () {

return device;

};

this.setDevice = function ( value ) {

if ( value !== undefined ) device = value;

};

this.getCamera = function ( camera ) {

if ( device === null ) return camera;

device.depthNear = camera.near;
device.depthFar = camera.far;

device.getFrameData( frameData );

//

var pose = frameData.pose;

if ( pose.position !== null ) {

camera.position.fromArray( pose.position );

} else {

camera.position.set( 0, 0, 0 );

}

if ( pose.orientation !== null ) {

camera.quaternion.fromArray( pose.orientation );

}

camera.updateMatrixWorld();

if ( device.isPresenting === false ) return camera;

//

cameraVR.matrixWorld.copy( camera.matrixWorld );
cameraVR.matrixWorldInverse.copy( camera.matrixWorldInverse );

cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );

var parent = camera.parent;

if ( parent !== null ) {

cameraL.matrixWorldInverse.multiply( parent.matrixWorldInverse );
cameraR.matrixWorldInverse.multiply( parent.matrixWorldInverse );

}

cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );

// HACK @mrdoob
// https://github.com/w3c/webvr/issues/203

cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );

//

var layers = device.getLayers();

if ( layers.length ) {

var layer = layers[ 0 ];

if ( layer.leftBounds !== null && layer.leftBounds.length === 4 ) {

cameraL.bounds.fromArray( layer.leftBounds );

}

if ( layer.rightBounds !== null && layer.rightBounds.length === 4 ) {

cameraR.bounds.fromArray( layer.rightBounds );

}

}

return cameraVR;

};

}

/**
* @author mrdoob / http://mrdoob.com/
*/
Expand Down Expand Up @@ -20166,6 +20324,7 @@
var programCache = new WebGLPrograms( this, capabilities );
var lightCache = new WebGLLights();
var renderLists = new WebGLRenderLists();
var vr = new WebVRManager( this );

this.info.programs = programCache.programs;

Expand Down Expand Up @@ -20216,6 +20375,7 @@
this.properties = properties;
this.renderLists = renderLists;
this.state = state;
this.vr = vr;

// shadow map

Expand Down Expand Up @@ -20953,6 +21113,20 @@

// Rendering

this.animate = function ( callback ) {

function onFrame() {

callback();

( vr.getDevice() || window ).requestAnimationFrame( onFrame );

}

( vr.getDevice() || window ).requestAnimationFrame( onFrame );

};

this.render = function ( scene, camera, renderTarget, forceClear ) {

if ( ! ( camera && camera.isCamera ) ) {
Expand All @@ -20978,6 +21152,12 @@

if ( camera.parent === null ) camera.updateMatrixWorld();

if ( vr.enabled ) {

camera = vr.getCamera( camera );

}

_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
_frustum.setFromMatrix( _projScreenMatrix );

Expand Down
Loading

0 comments on commit e5d7a89

Please sign in to comment.