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

Updating VR polyfill to 0.10.4 #209

Merged
merged 1 commit into from
Mar 23, 2018
Merged

Updating VR polyfill to 0.10.4 #209

merged 1 commit into from
Mar 23, 2018

Conversation

delapuente
Copy link
Contributor

Fix #113

Orbital controls are missing since they were dropped in 0.10.0. Will fix them in a different bug.

@delapuente delapuente requested a review from cvan March 21, 2018 09:42
@delapuente delapuente added this to the v1.1.0 milestone Mar 21, 2018
Copy link
Contributor

@cvan cvan left a comment

Choose a reason for hiding this comment

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

thanks for updating the Polyfill! we'll get through it this time! :)

@@ -77,7 +77,8 @@ <h3>You&rsquo;ll need a <a href="https://webvr.rocks/">WebVR-enabled browser</a>
</div>

<script src="gl-matrix-min.js"></script>
<script src="webvr-polyfill.min.js"></script>
<script src="webvr-polyfill.min.new.js"></script>
<script>var vrPolyfill = new WebVRPolyfill();</script>
Copy link
Contributor

Choose a reason for hiding this comment

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

can we handle this in webvr.js or are there issues with doing that?

@@ -77,7 +77,8 @@ <h3>You&rsquo;ll need a <a href="https://webvr.rocks/">WebVR-enabled browser</a>
</div>

<script src="gl-matrix-min.js"></script>
<script src="webvr-polyfill.min.js"></script>
<script src="webvr-polyfill.min.new.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove the old one? assuming we get in FPS controls (#125) by the next release/tag, it should be fine to remove the old version? is that fine?

(display.displayName || '').indexOf('polyfill') > 0 ||
(display.deviceName || '').indexOf('polyfill') > 0 ||
display.hardwareUnitId;
return display.isPolyfilled;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 glad you caught that; it was on my mental todo list

Orbital controls are missing since they were dropped in 0.10.0
@delapuente delapuente requested a review from cvan March 21, 2018 13:41
cvan
cvan previously requested changes Mar 22, 2018
Copy link
Contributor

@cvan cvan left a comment

Choose a reason for hiding this comment

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

thanks for hopping on this issue; I know it's a big change.

I unfortunately can't get the Polyfill to work correctly to enter/exit VR on my iPhone 7, Samsung S8, Google Pixel 2. which devices do you have on hand that this works with?

also, exiting VR mode doesn't return to mono mode. (do you know if that's a filed issue?) I'm focusing on just high-end mobile (i.e., Google Pixel 2).

iOS has a slew of issues (memory, UI-overlay, Toggle VR button issues), which I'll file for later.


let me know if you want screenshots and error logs; I can capture and upload them. I figured I'd first determine which phones it works with you first, and we go from there.

@@ -87,8 +87,8 @@ <h3>You&rsquo;ll need a <a href="https://webvr.rocks/">WebVR-enabled browser</a>
<button id="entervr" value="Enter VR"></button>
</div>

<script src="gl-matrix-min.js"></script>
<script src="webvr-polyfill.min.js"></script>
<script src="vendor/gl-matrix-min.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for creating the vendor/ dir. I like 👍

* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
e.exports=function(){function e(e,M,i,t){this.gl=e,this.cardboardUI=M,this.bufferScale=i,this.dirtySubmitFrameBindings=t,this.ctxAttribs=e.getContextAttributes(),this.meshWidth=20,this.meshHeight=20,this.bufferWidth=e.drawingBufferWidth,this.bufferHeight=e.drawingBufferHeight,this.realBindFramebuffer=e.bindFramebuffer,this.realEnable=e.enable,this.realDisable=e.disable,this.realColorMask=e.colorMask,this.realClearColor=e.clearColor,this.realViewport=e.viewport,y()||(this.realCanvasWidth=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"width"),this.realCanvasHeight=Object.getOwnPropertyDescriptor(e.canvas.__proto__,"height")),this.isPatched=!1,this.lastBoundFramebuffer=null,this.cullFace=!1,this.depthTest=!1,this.blend=!1,this.scissorTest=!1,this.stencilTest=!1,this.viewport=[0,0,0,0],this.colorMask=[!0,!0,!0,!0],this.clearColor=[0,0,0,0],this.attribs={position:0,texCoord:1},this.program=p(e,R,G,this.attribs),this.uniforms=f(e,this.program),this.viewportOffsetScale=new Float32Array(8),this.setTextureBounds(),this.vertexBuffer=e.createBuffer(),this.indexBuffer=e.createBuffer(),this.indexCount=0,this.renderTarget=e.createTexture(),this.framebuffer=e.createFramebuffer(),this.depthStencilBuffer=null,this.depthBuffer=null,this.stencilBuffer=null,this.ctxAttribs.depth&&this.ctxAttribs.stencil?this.depthStencilBuffer=e.createRenderbuffer():this.ctxAttribs.depth?this.depthBuffer=e.createRenderbuffer():this.ctxAttribs.stencil&&(this.stencilBuffer=e.createRenderbuffer()),this.patch(),this.onResize()}function i(e){this.gl=e,this.attribs={position:0},this.program=p(e,F,P,this.attribs),this.uniforms=f(e,this.program),this.vertexBuffer=e.createBuffer(),this.gearOffset=0,this.gearVertexCount=0,this.arrowOffset=0,this.arrowVertexCount=0,this.projMat=new Float32Array(16),this.listener=null,this.onResize()}function t(e){this.coefficients=e}function A(e){this.width=e.width||d(),this.height=e.height||S(),this.widthMeters=e.widthMeters,this.heightMeters=e.heightMeters,this.bevelMeters=e.bevelMeters}function s(e){this.viewer=$.CardboardV2,this.updateDeviceParams(e),this.distortion=new t(this.viewer.distortionCoefficients)}function r(e){this.id=e.id,this.label=e.label,this.fov=e.fov,this.interLensDistance=e.interLensDistance,this.baselineLensDistance=e.baselineLensDistance,this.screenLensDistance=e.screenLensDistance,this.distortionCoefficients=e.distortionCoefficients,this.inverseCoefficients=e.inverseCoefficients}function N(e,M){if(this.dpdb=ee,this.recalculateDeviceParams_(),e){this.onDeviceParamsUpdated=M;var i=new XMLHttpRequest,t=this;i.open("GET",e,!0),i.addEventListener("load",function(){t.loading=!1,i.status>=200&&i.status<=299?(t.dpdb=JSON.parse(i.response),t.recalculateDeviceParams_()):console.error("Error loading online DPDB!")}),i.send()}}function D(e,M){this.set(e,M)}function n(e,M){this.kFilter=e,this.isDebug=M,this.currentAccelMeasurement=new D,this.currentGyroMeasurement=new D,this.previousGyroMeasurement=new D,y()?this.filterQ=new J(-1,0,0,1):this.filterQ=new J(1,0,0,1),this.previousFilterQ=new J,this.previousFilterQ.copy(this.filterQ),this.accelQ=new J,this.isOrientationInitialized=!1,this.estimatedGravity=new X,this.measuredGravity=new X,this.gyroIntegralQ=new J}function u(e,M){this.predictionTimeS=e,this.isDebug=M,this.previousQ=new J,this.previousTimestampS=null,this.deltaQ=new J,this.outQ=new J}function a(e,M,i,t){this.yawOnly=i,this.accelerometer=new X,this.gyroscope=new X,this.filter=new n(e,t),this.posePredictor=new u(M,t),this.isFirefoxAndroid=z(),this.isIOS=y();var A=h();this.isDeviceMotionInRadians=!this.isIOS&&A&&A<66,this.isWithoutDeviceMotion=O(),this.filterToWorldQ=new J,y()?this.filterToWorldQ.setFromAxisAngle(new X(1,0,0),Math.PI/2):this.filterToWorldQ.setFromAxisAngle(new X(1,0,0),-Math.PI/2),this.inverseWorldToScreenQ=new J,this.worldToScreenQ=new J,this.originalPoseAdjustQ=new J,this.originalPoseAdjustQ.setFromAxisAngle(new X(0,0,1),-window.orientation*Math.PI/180),this.setScreenTransform_(),C()&&this.filterToWorldQ.multiply(this.inverseWorldToScreenQ),this.resetQ=new J,this.orientationOut_=new Float32Array(4),this.start()}function g(){this.loadIcon_();var e=document.createElement("div"),M=e.style;M.position="fixed",M.top=0,M.right=0,M.bottom=0,M.left=0,M.backgroundColor="gray",M.fontFamily="sans-serif",M.zIndex=1e6;var i=document.createElement("img");i.src=this.icon;var M=i.style;M.marginLeft="25%",M.marginTop="25%",M.width="50%",e.appendChild(i);var t=document.createElement("div"),M=t.style;M.textAlign="center",M.fontSize="16px",M.lineHeight="24px",M.margin="24px 25%",M.width="50%",t.innerHTML="Place your phone into your Cardboard viewer.",e.appendChild(t);var A=document.createElement("div"),M=A.style;M.backgroundColor="#CFD8DC",M.position="fixed",M.bottom=0,M.width="100%",M.height="48px",M.padding="14px 24px",M.boxSizing="border-box",M.color="#656A6B",e.appendChild(A);var s=document.createElement("div");s.style.float="left",s.innerHTML="No Cardboard viewer?";var r=document.createElement("a");r.href="https://www.google.com/get/cardboard/get-cardboard/",r.innerHTML="get one",r.target="_blank";var M=r.style;M.float="right",M.fontWeight=600,M.textTransform="uppercase",M.borderLeft="1px solid gray",M.paddingLeft="24px",M.textDecoration="none",M.color="#656A6B",A.appendChild(s),A.appendChild(r),this.overlay=e,this.text=t,this.hide()}function o(){try{this.selectedKey=localStorage.getItem(Ne)}catch(e){console.error("Failed to load viewer profile: %s",e)}this.selectedKey||(this.selectedKey=re),this.dialog=this.createDialog_(s.Viewers),this.root=null,this.onChangeCallbacks_=[]}function L(e){Object.defineProperties(this,{hasPosition:{writable:!1,enumerable:!0,value:e.hasPosition},hasExternalDisplay:{writable:!1,enumerable:!0,value:e.hasExternalDisplay},canPresent:{writable:!1,enumerable:!0,value:e.canPresent},maxLayers:{writable:!1,enumerable:!0,value:e.maxLayers},hasOrientation:{enumerable:!0,get:function(){return b("VRDisplayCapabilities.prototype.hasOrientation","VRDisplay.prototype.getFrameData"),e.hasOrientation}}})}function I(e){var M=!("wakelock"in(e=e||{}))||e.wakelock;this.isPolyfilled=!0,this.displayId=ne++,this.displayName="",this.depthNear=.01,this.depthFar=1e4,this.isPresenting=!1,Object.defineProperty(this,"isConnected",{get:function(){return b("VRDisplay.prototype.isConnected","VRDisplayCapabilities.prototype.hasExternalDisplay"),!1}}),this.capabilities=new L({hasPosition:!1,hasOrientation:!1,hasExternalDisplay:!1,canPresent:!1,maxLayers:1}),this.stageParameters=null,this.waitingForPresent_=!1,this.layer_=null,this.originalParent_=null,this.fullscreenElement_=null,this.fullscreenWrapper_=null,this.fullscreenElementCachedStyle_=null,this.fullscreenEventTarget_=null,this.fullscreenChangeHandler_=null,this.fullscreenErrorHandler_=null,M&&m()&&(this.wakelock_=new De)}function j(e){var M=k({},Le);e=k(M,e||{}),I.call(this,{wakelock:e.MOBILE_WAKE_LOCK}),this.config=e,this.displayName="Cardboard VRDisplay",this.capabilities=new L({hasPosition:!1,hasOrientation:!0,hasExternalDisplay:!1,canPresent:!0,maxLayers:1}),this.stageParameters=null,this.bufferScale_=this.config.BUFFER_SCALE,this.poseSensor_=new se(this.config),this.distorter_=null,this.cardboardUI_=null,this.dpdb_=new N(this.config.DPDB_URL,this.onDeviceParamsUpdated_.bind(this)),this.deviceInfo_=new s(this.dpdb_.getDeviceParams()),this.viewerSelector_=new o,this.viewerSelector_.onChange(this.onViewerChanged_.bind(this)),this.deviceInfo_.setViewer(this.viewerSelector_.getCurrentViewer()),this.config.ROTATE_INSTRUCTIONS_DISABLED||(this.rotateInstructions_=new g),y()&&window.addEventListener("resize",this.onResize_.bind(this))}var T=function(e,M){if(!(e instanceof M))throw new TypeError("Cannot call a class as a function")},c=function(){function e(e,M){for(var i=0;i<M.length;i++){var t=M[i];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(M,i,t){return i&&e(M.prototype,i),t&&e(M,t),M}}(),E=function(){return function(e,M){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,M){var i=[],t=!0,A=!1,s=void 0;try{for(var r,N=e[Symbol.iterator]();!(t=(r=N.next()).done)&&(i.push(r.value),!M||i.length!==M);t=!0);}catch(e){A=!0,s=e}finally{try{!t&&N.return&&N.return()}finally{if(A)throw s}}return i}(e,M);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),w=function(e,M,i){return e+(M-e)*i},y=function(){var e=/iPad|iPhone|iPod/.test(navigator.platform);return function(){return e}}(),l=function(){var e=-1!==navigator.userAgent.indexOf("Version")&&-1!==navigator.userAgent.indexOf("Android")&&-1!==navigator.userAgent.indexOf("Chrome");return function(){return e}}(),z=(function(){var e=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}(),function(){var e=-1!==navigator.userAgent.indexOf("Firefox")&&-1!==navigator.userAgent.indexOf("Android");return function(){return e}}()),h=function(){var e=navigator.userAgent.match(/.*Chrome\/([0-9]+)/),M=e?parseInt(e[1],10):null;return function(){return M}}(),O=function(){var e=!1;if(65===h()){var M=navigator.userAgent.match(/.*Chrome\/([0-9\.]*)/);if(M){var i=M[1].split("."),t=E(i,4),A=(t[0],t[1],t[2]),s=t[3];e=3325===parseInt(A,10)&&parseInt(s,10)<148}}return function(){return e}}(),x=function(){var e=-1!==navigator.userAgent.indexOf("R7 Build");return function(){return e}}(),C=function(){var e=90==window.orientation||-90==window.orientation;return x()?!e:e},d=function(){return Math.max(window.screen.width,window.screen.height)*window.devicePixelRatio},S=function(){return Math.min(window.screen.width,window.screen.height)*window.devicePixelRatio},Q=function(){if(document.exitFullscreen)document.exitFullscreen();else if(document.webkitExitFullscreen)document.webkitExitFullscreen();else if(document.mozCancelFullScreen)document.mozCancelFullScreen();else{if(!document.msExitFullscreen)return!1;document.msExitFullscreen()}return!0},p=function(e,M,i,t){var A=e.createShader(e.VERTEX_SHADER);e.shaderSource(A,M),e.compileShader(A);var s=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(s,i),e.compileShader(s);var r=e.createProgram();e.attachShader(r,A),e.attachShader(r,s);for(var N in t)e.bindAttribLocation(r,t[N],N);return e.linkProgram(r),e.deleteShader(A),e.deleteShader(s),r},f=function(e,M){for(var i={},t=e.getProgramParameter(M,e.ACTIVE_UNIFORMS),A="",s=0;s<t;s++){var r=e.getActiveUniform(M,s);A=r.name.replace("[0]",""),i[A]=e.getUniformLocation(M,A)}return i},m=function(){var e=!1;return function(M){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(M)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(M.substr(0,4)))&&(e=!0)}(navigator.userAgent||navigator.vendor||window.opera),e},k=function(e,M){for(var i in M)M.hasOwnProperty(i)&&(e[i]=M[i]);return e},U=function(e){if(y()){var M=e.style.width,i=e.style.height;e.style.width=parseInt(M)+1+"px",e.style.height=parseInt(i)+"px",setTimeout(function(){e.style.width=M,e.style.height=i},100)}window.canvas=e},B=function(){function e(e,s,r,N,D,n){!function(e,t,A,s){var r=Math.tan(t?t.upDegrees*M:i),N=Math.tan(t?t.downDegrees*M:i),D=Math.tan(t?t.leftDegrees*M:i),n=Math.tan(t?t.rightDegrees*M:i),u=2/(D+n),a=2/(r+N);e[0]=u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=a,e[6]=0,e[7]=0,e[8]=-(D-n)*u*.5,e[9]=(r-N)*a*.5,e[10]=s/(A-s),e[11]=-1,e[12]=0,e[13]=0,e[14]=s*A/(A-s),e[15]=0}(e,N||null,n.depthNear,n.depthFar);var u=r.orientation||t,a=r.position||A;!function(e,M,i){var t=M[0],A=M[1],s=M[2],r=M[3],N=t+t,D=A+A,n=s+s,u=t*N,a=t*D,g=t*n,o=A*D,L=A*n,I=s*n,j=r*N,T=r*D,c=r*n;e[0]=1-(o+I),e[1]=a+c,e[2]=g-T,e[3]=0,e[4]=a-c,e[5]=1-(u+I),e[6]=L+j,e[7]=0,e[8]=g+T,e[9]=L-j,e[10]=1-(u+o),e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1}(s,u,a),D&&function(e,M,i){var t,A,s,r,N,D,n,u,a,g,o,L,I=i[0],j=i[1],T=i[2];M===e?(e[12]=M[0]*I+M[4]*j+M[8]*T+M[12],e[13]=M[1]*I+M[5]*j+M[9]*T+M[13],e[14]=M[2]*I+M[6]*j+M[10]*T+M[14],e[15]=M[3]*I+M[7]*j+M[11]*T+M[15]):(t=M[0],A=M[1],s=M[2],r=M[3],N=M[4],D=M[5],n=M[6],u=M[7],a=M[8],g=M[9],o=M[10],L=M[11],e[0]=t,e[1]=A,e[2]=s,e[3]=r,e[4]=N,e[5]=D,e[6]=n,e[7]=u,e[8]=a,e[9]=g,e[10]=o,e[11]=L,e[12]=t*I+N*j+a*T+M[12],e[13]=A*I+D*j+g*T+M[13],e[14]=s*I+n*j+o*T+M[14],e[15]=r*I+u*j+L*T+M[15])}(s,s,D),function(e,M){var i=M[0],t=M[1],A=M[2],s=M[3],r=M[4],N=M[5],D=M[6],n=M[7],u=M[8],a=M[9],g=M[10],o=M[11],L=M[12],I=M[13],j=M[14],T=M[15],c=i*N-t*r,E=i*D-A*r,w=i*n-s*r,y=t*D-A*N,l=t*n-s*N,z=A*n-s*D,h=u*I-a*L,O=u*j-g*L,x=u*T-o*L,C=a*j-g*I,d=a*T-o*I,S=g*T-o*j,Q=c*S-E*d+w*C+y*x-l*O+z*h;if(!Q)return null;Q=1/Q,e[0]=(N*S-D*d+n*C)*Q,e[1]=(A*d-t*S-s*C)*Q,e[2]=(I*z-j*l+T*y)*Q,e[3]=(g*l-a*z-o*y)*Q,e[4]=(D*x-r*S-n*O)*Q,e[5]=(i*S-A*x+s*O)*Q,e[6]=(j*w-L*z-T*E)*Q,e[7]=(u*z-g*w+o*E)*Q,e[8]=(r*d-N*x+n*h)*Q,e[9]=(t*x-i*d-s*h)*Q,e[10]=(L*l-I*w+T*c)*Q,e[11]=(a*w-u*l-o*c)*Q,e[12]=(N*O-r*C-D*h)*Q,e[13]=(i*C-t*O+A*h)*Q,e[14]=(I*E-L*y-j*c)*Q,e[15]=(u*y-a*E+g*c)*Q}(s,s)}var M=Math.PI/180,i=.25*Math.PI,t=new Float32Array([0,0,0,1]),A=new Float32Array([0,0,0]);return function(M,i,t){return!(!M||!i)&&(M.pose=i,M.timestamp=i.timestamp,e(M.leftProjectionMatrix,M.leftViewMatrix,i,t._getFieldOfView("left"),t._getEyeOffset("left"),t),e(M.rightProjectionMatrix,M.rightViewMatrix,i,t._getFieldOfView("right"),t._getEyeOffset("right"),t),!0)}}(),Y=function(e){var M,i=e.indexOf("://");M=-1!==i?i+3:0;var t=e.indexOf("/",M);return-1===t&&(t=e.length),e.substring(0,t)},v=function(){var e={};return function(M,i){void 0===e[M]&&(console.warn("webvr-polyfill: "+i),e[M]=!0)}}(),b=function(e,M){var i=M?"Please use "+M+" instead.":"";v(e,e+" has been deprecated. This may not work on native WebVR displays. "+i)};var _=function(e,M,i){if(!M)return void i(e);for(var t=[],A=null,s=0;s<M.length;++s){var r=M[s];switch(r){case e.TEXTURE_BINDING_2D:case e.TEXTURE_BINDING_CUBE_MAP:var N=M[++s];if(N<e.TEXTURE0||N>e.TEXTURE31){console.error("TEXTURE_BINDING_2D or TEXTURE_BINDING_CUBE_MAP must be followed by a valid texture unit"),t.push(null,null);break}A||(A=e.getParameter(e.ACTIVE_TEXTURE)),e.activeTexture(N),t.push(e.getParameter(r),null);break;case e.ACTIVE_TEXTURE:A=e.getParameter(e.ACTIVE_TEXTURE),t.push(null);break;default:t.push(e.getParameter(r))}}i(e);for(var s=0;s<M.length;++s){var r=M[s],D=t[s];switch(r){case e.ACTIVE_TEXTURE:break;case e.ARRAY_BUFFER_BINDING:e.bindBuffer(e.ARRAY_BUFFER,D);break;case e.COLOR_CLEAR_VALUE:e.clearColor(D[0],D[1],D[2],D[3]);break;case e.COLOR_WRITEMASK:e.colorMask(D[0],D[1],D[2],D[3]);break;case e.CURRENT_PROGRAM:e.useProgram(D);break;case e.ELEMENT_ARRAY_BUFFER_BINDING:e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,D);break;case e.FRAMEBUFFER_BINDING:e.bindFramebuffer(e.FRAMEBUFFER,D);break;case e.RENDERBUFFER_BINDING:e.bindRenderbuffer(e.RENDERBUFFER,D);break;case e.TEXTURE_BINDING_2D:var N=M[++s];if(N<e.TEXTURE0||N>e.TEXTURE31)break;e.activeTexture(N),e.bindTexture(e.TEXTURE_2D,D);break;case e.TEXTURE_BINDING_CUBE_MAP:var N=M[++s];if(N<e.TEXTURE0||N>e.TEXTURE31)break;e.activeTexture(N),e.bindTexture(e.TEXTURE_CUBE_MAP,D);break;case e.VIEWPORT:e.viewport(D[0],D[1],D[2],D[3]);break;case e.BLEND:case e.CULL_FACE:case e.DEPTH_TEST:case e.SCISSOR_TEST:case e.STENCIL_TEST:D?e.enable(r):e.disable(r);break;default:console.log("No GL restore behavior for 0x"+r.toString(16))}A&&e.activeTexture(A)}},R=["attribute vec2 position;","attribute vec3 texCoord;","varying vec2 vTexCoord;","uniform vec4 viewportOffsetScale[2];","void main() {"," vec4 viewport = viewportOffsetScale[int(texCoord.z)];"," vTexCoord = (texCoord.xy * viewport.zw) + viewport.xy;"," gl_Position = vec4( position, 1.0, 1.0 );","}"].join("\n"),G=["precision mediump float;","uniform sampler2D diffuse;","varying vec2 vTexCoord;","void main() {"," gl_FragColor = texture2D(diffuse, vTexCoord);","}"].join("\n");e.prototype.destroy=function(){var e=this.gl;this.unpatch(),e.deleteProgram(this.program),e.deleteBuffer(this.vertexBuffer),e.deleteBuffer(this.indexBuffer),e.deleteTexture(this.renderTarget),e.deleteFramebuffer(this.framebuffer),this.depthStencilBuffer&&e.deleteRenderbuffer(this.depthStencilBuffer),this.depthBuffer&&e.deleteRenderbuffer(this.depthBuffer),this.stencilBuffer&&e.deleteRenderbuffer(this.stencilBuffer),this.cardboardUI&&this.cardboardUI.destroy()},e.prototype.onResize=function(){var e=this.gl,M=this,i=[e.RENDERBUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0];_(e,i,function(e){M.realBindFramebuffer.call(e,e.FRAMEBUFFER,null),M.scissorTest&&M.realDisable.call(e,e.SCISSOR_TEST),M.realColorMask.call(e,!0,!0,!0,!0),M.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),M.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT),M.realBindFramebuffer.call(e,e.FRAMEBUFFER,M.framebuffer),e.bindTexture(e.TEXTURE_2D,M.renderTarget),e.texImage2D(e.TEXTURE_2D,0,M.ctxAttribs.alpha?e.RGBA:e.RGB,M.bufferWidth,M.bufferHeight,0,M.ctxAttribs.alpha?e.RGBA:e.RGB,e.UNSIGNED_BYTE,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,M.renderTarget,0),M.ctxAttribs.depth&&M.ctxAttribs.stencil?(e.bindRenderbuffer(e.RENDERBUFFER,M.depthStencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,M.bufferWidth,M.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,M.depthStencilBuffer)):M.ctxAttribs.depth?(e.bindRenderbuffer(e.RENDERBUFFER,M.depthBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_COMPONENT16,M.bufferWidth,M.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,M.depthBuffer)):M.ctxAttribs.stencil&&(e.bindRenderbuffer(e.RENDERBUFFER,M.stencilBuffer),e.renderbufferStorage(e.RENDERBUFFER,e.STENCIL_INDEX8,M.bufferWidth,M.bufferHeight),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.STENCIL_ATTACHMENT,e.RENDERBUFFER,M.stencilBuffer)),!e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE&&console.error("Framebuffer incomplete!"),M.realBindFramebuffer.call(e,e.FRAMEBUFFER,M.lastBoundFramebuffer),M.scissorTest&&M.realEnable.call(e,e.SCISSOR_TEST),M.realColorMask.apply(e,M.colorMask),M.realViewport.apply(e,M.viewport),M.realClearColor.apply(e,M.clearColor)}),this.cardboardUI&&this.cardboardUI.onResize()},e.prototype.patch=function(){if(!this.isPatched){var e=this,M=this.gl.canvas,i=this.gl;y()||(M.width=d()*this.bufferScale,M.height=S()*this.bufferScale,Object.defineProperty(M,"width",{configurable:!0,enumerable:!0,get:function(){return e.bufferWidth},set:function(i){e.bufferWidth=i,e.realCanvasWidth.set.call(M,i),e.onResize()}}),Object.defineProperty(M,"height",{configurable:!0,enumerable:!0,get:function(){return e.bufferHeight},set:function(i){e.bufferHeight=i,e.realCanvasHeight.set.call(M,i),e.onResize()}})),this.lastBoundFramebuffer=i.getParameter(i.FRAMEBUFFER_BINDING),null==this.lastBoundFramebuffer&&(this.lastBoundFramebuffer=this.framebuffer,this.gl.bindFramebuffer(i.FRAMEBUFFER,this.framebuffer)),this.gl.bindFramebuffer=function(M,t){e.lastBoundFramebuffer=t||e.framebuffer,e.realBindFramebuffer.call(i,M,e.lastBoundFramebuffer)},this.cullFace=i.getParameter(i.CULL_FACE),this.depthTest=i.getParameter(i.DEPTH_TEST),this.blend=i.getParameter(i.BLEND),this.scissorTest=i.getParameter(i.SCISSOR_TEST),this.stencilTest=i.getParameter(i.STENCIL_TEST),i.enable=function(M){switch(M){case i.CULL_FACE:e.cullFace=!0;break;case i.DEPTH_TEST:e.depthTest=!0;break;case i.BLEND:e.blend=!0;break;case i.SCISSOR_TEST:e.scissorTest=!0;break;case i.STENCIL_TEST:e.stencilTest=!0}e.realEnable.call(i,M)},i.disable=function(M){switch(M){case i.CULL_FACE:e.cullFace=!1;break;case i.DEPTH_TEST:e.depthTest=!1;break;case i.BLEND:e.blend=!1;break;case i.SCISSOR_TEST:e.scissorTest=!1;break;case i.STENCIL_TEST:e.stencilTest=!1}e.realDisable.call(i,M)},this.colorMask=i.getParameter(i.COLOR_WRITEMASK),i.colorMask=function(M,t,A,s){e.colorMask[0]=M,e.colorMask[1]=t,e.colorMask[2]=A,e.colorMask[3]=s,e.realColorMask.call(i,M,t,A,s)},this.clearColor=i.getParameter(i.COLOR_CLEAR_VALUE),i.clearColor=function(M,t,A,s){e.clearColor[0]=M,e.clearColor[1]=t,e.clearColor[2]=A,e.clearColor[3]=s,e.realClearColor.call(i,M,t,A,s)},this.viewport=i.getParameter(i.VIEWPORT),i.viewport=function(M,t,A,s){e.viewport[0]=M,e.viewport[1]=t,e.viewport[2]=A,e.viewport[3]=s,e.realViewport.call(i,M,t,A,s)},this.isPatched=!0,U(M)}},e.prototype.unpatch=function(){if(this.isPatched){var e=this.gl,M=this.gl.canvas;y()||(Object.defineProperty(M,"width",this.realCanvasWidth),Object.defineProperty(M,"height",this.realCanvasHeight)),M.width=this.bufferWidth,M.height=this.bufferHeight,e.bindFramebuffer=this.realBindFramebuffer,e.enable=this.realEnable,e.disable=this.realDisable,e.colorMask=this.realColorMask,e.clearColor=this.realClearColor,e.viewport=this.realViewport,this.lastBoundFramebuffer==this.framebuffer&&e.bindFramebuffer(e.FRAMEBUFFER,null),this.isPatched=!1,setTimeout(function(){U(M)},1)}},e.prototype.setTextureBounds=function(e,M){e||(e=[0,0,.5,1]),M||(M=[.5,0,.5,1]),this.viewportOffsetScale[0]=e[0],this.viewportOffsetScale[1]=e[1],this.viewportOffsetScale[2]=e[2],this.viewportOffsetScale[3]=e[3],this.viewportOffsetScale[4]=M[0],this.viewportOffsetScale[5]=M[1],this.viewportOffsetScale[6]=M[2],this.viewportOffsetScale[7]=M[3]},e.prototype.submitFrame=function(){var e=this.gl,M=this,i=[];if(this.dirtySubmitFrameBindings||i.push(e.CURRENT_PROGRAM,e.ARRAY_BUFFER_BINDING,e.ELEMENT_ARRAY_BUFFER_BINDING,e.TEXTURE_BINDING_2D,e.TEXTURE0),_(e,i,function(e){M.realBindFramebuffer.call(e,e.FRAMEBUFFER,null),M.cullFace&&M.realDisable.call(e,e.CULL_FACE),M.depthTest&&M.realDisable.call(e,e.DEPTH_TEST),M.blend&&M.realDisable.call(e,e.BLEND),M.scissorTest&&M.realDisable.call(e,e.SCISSOR_TEST),M.stencilTest&&M.realDisable.call(e,e.STENCIL_TEST),M.realColorMask.call(e,!0,!0,!0,!0),M.realViewport.call(e,0,0,e.drawingBufferWidth,e.drawingBufferHeight),(M.ctxAttribs.alpha||y())&&(M.realClearColor.call(e,0,0,0,1),e.clear(e.COLOR_BUFFER_BIT)),e.useProgram(M.program),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,M.indexBuffer),e.bindBuffer(e.ARRAY_BUFFER,M.vertexBuffer),e.enableVertexAttribArray(M.attribs.position),e.enableVertexAttribArray(M.attribs.texCoord),e.vertexAttribPointer(M.attribs.position,2,e.FLOAT,!1,20,0),e.vertexAttribPointer(M.attribs.texCoord,3,e.FLOAT,!1,20,8),e.activeTexture(e.TEXTURE0),e.uniform1i(M.uniforms.diffuse,0),e.bindTexture(e.TEXTURE_2D,M.renderTarget),e.uniform4fv(M.uniforms.viewportOffsetScale,M.viewportOffsetScale),e.drawElements(e.TRIANGLES,M.indexCount,e.UNSIGNED_SHORT,0),M.cardboardUI&&M.cardboardUI.renderNoState(),M.realBindFramebuffer.call(M.gl,e.FRAMEBUFFER,M.framebuffer),M.ctxAttribs.preserveDrawingBuffer||(M.realClearColor.call(e,0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)),M.dirtySubmitFrameBindings||M.realBindFramebuffer.call(e,e.FRAMEBUFFER,M.lastBoundFramebuffer),M.cullFace&&M.realEnable.call(e,e.CULL_FACE),M.depthTest&&M.realEnable.call(e,e.DEPTH_TEST),M.blend&&M.realEnable.call(e,e.BLEND),M.scissorTest&&M.realEnable.call(e,e.SCISSOR_TEST),M.stencilTest&&M.realEnable.call(e,e.STENCIL_TEST),M.realColorMask.apply(e,M.colorMask),M.realViewport.apply(e,M.viewport),!M.ctxAttribs.alpha&&M.ctxAttribs.preserveDrawingBuffer||M.realClearColor.apply(e,M.clearColor)}),y()){var t=e.canvas;t.width==M.bufferWidth&&t.height==M.bufferHeight||(M.bufferWidth=t.width,M.bufferHeight=t.height,M.onResize())}},e.prototype.updateDeviceInfo=function(e){var M=this.gl,i=this,t=[M.ARRAY_BUFFER_BINDING,M.ELEMENT_ARRAY_BUFFER_BINDING];_(M,t,function(M){var t=i.computeMeshVertices_(i.meshWidth,i.meshHeight,e);if(M.bindBuffer(M.ARRAY_BUFFER,i.vertexBuffer),M.bufferData(M.ARRAY_BUFFER,t,M.STATIC_DRAW),!i.indexCount){var A=i.computeMeshIndices_(i.meshWidth,i.meshHeight);M.bindBuffer(M.ELEMENT_ARRAY_BUFFER,i.indexBuffer),M.bufferData(M.ELEMENT_ARRAY_BUFFER,A,M.STATIC_DRAW),i.indexCount=A.length}})},e.prototype.computeMeshVertices_=function(e,M,i){for(var t=new Float32Array(2*e*M*5),A=i.getLeftEyeVisibleTanAngles(),s=i.getLeftEyeNoLensTanAngles(),r=i.getLeftEyeVisibleScreenRect(s),N=0,D=0;D<2;D++){for(var n=0;n<M;n++)for(var u=0;u<e;u++,N++){var a=u/(e-1),g=n/(M-1),o=a,L=g,I=w(A[0],A[2],a),j=w(A[3],A[1],g),T=Math.sqrt(I*I+j*j),c=i.distortion.distortInverse(T),E=I*c/T,y=j*c/T;a=(E-s[0])/(s[2]-s[0]),g=(y-s[3])/(s[1]-s[3]),a=2*(r.x+a*r.width-.5),g=2*(r.y+g*r.height-.5),t[5*N+0]=a,t[5*N+1]=g,t[5*N+2]=o,t[5*N+3]=L,t[5*N+4]=D}var l=A[2]-A[0];A[0]=-(l+A[0]),A[2]=l-A[2],l=s[2]-s[0],s[0]=-(l+s[0]),s[2]=l-s[2],r.x=1-(r.x+r.width)}return t},e.prototype.computeMeshIndices_=function(e,M){for(var i=new Uint16Array(2*(e-1)*(M-1)*6),t=e/2,A=M/2,s=0,r=0,N=0;N<2;N++)for(var D=0;D<M;D++)for(var n=0;n<e;n++,s++)0!=n&&0!=D&&(n<=t==D<=A?(i[r++]=s,i[r++]=s-e-1,i[r++]=s-e,i[r++]=s-e-1,i[r++]=s,i[r++]=s-1):(i[r++]=s-1,i[r++]=s-e,i[r++]=s,i[r++]=s-e,i[r++]=s-1,i[r++]=s-e-1));return i},e.prototype.getOwnPropertyDescriptor_=function(e,M){var i=Object.getOwnPropertyDescriptor(e,M);return void 0!==i.get&&void 0!==i.set||(i.configurable=!0,i.enumerable=!0,i.get=function(){return this.getAttribute(M)},i.set=function(e){this.setAttribute(M,e)}),i};var F=["attribute vec2 position;","uniform mat4 projectionMat;","void main() {"," gl_Position = projectionMat * vec4( position, -1.0, 1.0 );","}"].join("\n"),P=["precision mediump float;","uniform vec4 color;","void main() {"," gl_FragColor = color;","}"].join("\n"),W=Math.PI/180,Z=.3125;i.prototype.destroy=function(){var e=this.gl;this.listener&&e.canvas.removeEventListener("click",this.listener,!1),e.deleteProgram(this.program),e.deleteBuffer(this.vertexBuffer)},i.prototype.listen=function(e,M){var i=this.gl.canvas;this.listener=function(t){var A=i.clientWidth/2;t.clientX>A-42&&t.clientX<A+42&&t.clientY>i.clientHeight-42?e(t):t.clientX<42&&t.clientY<42&&M(t)},i.addEventListener("click",this.listener,!1)},i.prototype.onResize=function(){var e=this.gl,M=this,i=[e.ARRAY_BUFFER_BINDING];_(e,i,function(e){function i(e,M){var i=(90-e)*W,t=Math.cos(i),r=Math.sin(i);A.push(Z*t*a+s,Z*r*a+a),A.push(M*t*a+s,M*r*a+a)}function t(M,i){A.push(g+M,e.drawingBufferHeight-g-i)}var A=[],s=e.drawingBufferWidth/2,r=Math.max(screen.width,screen.height)*window.devicePixelRatio,N=e.drawingBufferWidth/r,D=N*window.devicePixelRatio,n=4*D/2,u=42*D,a=28*D/2,g=14*D;A.push(s-n,u),A.push(s-n,e.drawingBufferHeight),A.push(s+n,u),A.push(s+n,e.drawingBufferHeight),M.gearOffset=A.length/2;for(var o=0;o<=6;o++){var L=60*o;i(L,1),i(L+12,1),i(L+20,.75),i(L+40,.75),i(L+48,1)}M.gearVertexCount=A.length/2-M.gearOffset,M.arrowOffset=A.length/2;var I=n/Math.sin(45*W);t(0,a),t(a,0),t(a+I,I),t(I,a+I),t(I,a-I),t(0,a),t(a,2*a),t(a+I,2*a-I),t(I,a-I),t(0,a),t(I,a-n),t(28*D,a-n),t(I,a+n),t(28*D,a+n),M.arrowVertexCount=A.length/2-M.arrowOffset,e.bindBuffer(e.ARRAY_BUFFER,M.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,new Float32Array(A),e.STATIC_DRAW)})},i.prototype.render=function(){var e=this.gl,M=this,i=[e.CULL_FACE,e.DEPTH_TEST,e.BLEND,e.SCISSOR_TEST,e.STENCIL_TEST,e.COLOR_WRITEMASK,e.VIEWPORT,e.CURRENT_PROGRAM,e.ARRAY_BUFFER_BINDING];_(e,i,function(e){e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.BLEND),e.disable(e.SCISSOR_TEST),e.disable(e.STENCIL_TEST),e.colorMask(!0,!0,!0,!0),e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),M.renderNoState()})},i.prototype.renderNoState=function(){var e=this.gl;e.useProgram(this.program),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.enableVertexAttribArray(this.attribs.position),e.vertexAttribPointer(this.attribs.position,2,e.FLOAT,!1,8,0),e.uniform4f(this.uniforms.color,1,1,1,1),function(e,M,i,t,A,s,r){var N=1/(M-i),D=1/(t-A),n=1/(s-r);e[0]=-2*N,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*D,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*n,e[11]=0,e[12]=(M+i)*N,e[13]=(A+t)*D,e[14]=(r+s)*n,e[15]=1}(this.projMat,0,e.drawingBufferWidth,0,e.drawingBufferHeight,.1,1024),e.uniformMatrix4fv(this.uniforms.projectionMat,!1,this.projMat),e.drawArrays(e.TRIANGLE_STRIP,0,4),e.drawArrays(e.TRIANGLE_STRIP,this.gearOffset,this.gearVertexCount),e.drawArrays(e.TRIANGLE_STRIP,this.arrowOffset,this.arrowVertexCount)};t.prototype.distortInverse=function(e){for(var M=0,i=1,t=e-this.distort(M);Math.abs(i-M)>1e-4;){var A=e-this.distort(i),s=i-A*((i-M)/(A-t));M=i,i=s,t=A}return i},t.prototype.distort=function(e){for(var M=e*e,i=0,t=0;t<this.coefficients.length;t++)i=M*(i+this.coefficients[t]);return(i+1)*e};var H=Math.PI/180,V=180/Math.PI,X=function(e,M,i){this.x=e||0,this.y=M||0,this.z=i||0};X.prototype={constructor:X,set:function(e,M,i){return this.x=e,this.y=M,this.z=i,this},copy:function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},normalize:function(){var e=this.length();if(0!==e){var M=1/e;this.multiplyScalar(M)}else this.x=0,this.y=0,this.z=0;return this},multiplyScalar:function(e){this.x*=e,this.y*=e,this.z*=e},applyQuaternion:function(e){var M=this.x,i=this.y,t=this.z,A=e.x,s=e.y,r=e.z,N=e.w,D=N*M+s*t-r*i,n=N*i+r*M-A*t,u=N*t+A*i-s*M,a=-A*M-s*i-r*t;return this.x=D*N+a*-A+n*-r-u*-s,this.y=n*N+a*-s+u*-A-D*-r,this.z=u*N+a*-r+D*-s-n*-A,this},dot:function(e){return this.x*e.x+this.y*e.y+this.z*e.z},crossVectors:function(e,M){var i=e.x,t=e.y,A=e.z,s=M.x,r=M.y,N=M.z;return this.x=t*N-A*r,this.y=A*s-i*N,this.z=i*r-t*s,this}};var J=function(e,M,i,t){this.x=e||0,this.y=M||0,this.z=i||0,this.w=void 0!==t?t:1};J.prototype={constructor:J,set:function(e,M,i,t){return this.x=e,this.y=M,this.z=i,this.w=t,this},copy:function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this},setFromEulerXYZ:function(e,M,i){var t=Math.cos(e/2),A=Math.cos(M/2),s=Math.cos(i/2),r=Math.sin(e/2),N=Math.sin(M/2),D=Math.sin(i/2);return this.x=r*A*s+t*N*D,this.y=t*N*s-r*A*D,this.z=t*A*D+r*N*s,this.w=t*A*s-r*N*D,this},setFromEulerYXZ:function(e,M,i){var t=Math.cos(e/2),A=Math.cos(M/2),s=Math.cos(i/2),r=Math.sin(e/2),N=Math.sin(M/2),D=Math.sin(i/2);return this.x=r*A*s+t*N*D,this.y=t*N*s-r*A*D,this.z=t*A*D-r*N*s,this.w=t*A*s+r*N*D,this},setFromAxisAngle:function(e,M){var i=M/2,t=Math.sin(i);return this.x=e.x*t,this.y=e.y*t,this.z=e.z*t,this.w=Math.cos(i),this},multiply:function(e){return this.multiplyQuaternions(this,e)},multiplyQuaternions:function(e,M){var i=e.x,t=e.y,A=e.z,s=e.w,r=M.x,N=M.y,D=M.z,n=M.w;return this.x=i*n+s*r+t*D-A*N,this.y=t*n+s*N+A*r-i*D,this.z=A*n+s*D+i*N-t*r,this.w=s*n-i*r-t*N-A*D,this},inverse:function(){return this.x*=-1,this.y*=-1,this.z*=-1,this.normalize(),this},normalize:function(){var e=Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);return 0===e?(this.x=0,this.y=0,this.z=0,this.w=1):(e=1/e,this.x=this.x*e,this.y=this.y*e,this.z=this.z*e,this.w=this.w*e),this},slerp:function(e,M){if(0===M)return this;if(1===M)return this.copy(e);var i=this.x,t=this.y,A=this.z,s=this.w,r=s*e.w+i*e.x+t*e.y+A*e.z;if(r<0?(this.w=-e.w,this.x=-e.x,this.y=-e.y,this.z=-e.z,r=-r):this.copy(e),r>=1)return this.w=s,this.x=i,this.y=t,this.z=A,this;var N=Math.acos(r),D=Math.sqrt(1-r*r);if(Math.abs(D)<.001)return this.w=.5*(s+this.w),this.x=.5*(i+this.x),this.y=.5*(t+this.y),this.z=.5*(A+this.z),this;var n=Math.sin((1-M)*N)/D,u=Math.sin(M*N)/D;return this.w=s*n+this.w*u,this.x=i*n+this.x*u,this.y=t*n+this.y*u,this.z=A*n+this.z*u,this},setFromUnitVectors:function(){var e,M;return function(i,t){return void 0===e&&(e=new X),(M=i.dot(t)+1)<1e-6?(M=0,Math.abs(i.x)>Math.abs(i.z)?e.set(-i.y,i.x,0):e.set(0,-i.z,i.y)):e.crossVectors(i,t),this.x=e.x,this.y=e.y,this.z=e.z,this.w=M,this.normalize(),this}}()};var K=new A({widthMeters:.11,heightMeters:.062,bevelMeters:.004}),q=new A({widthMeters:.1038,heightMeters:.0584,bevelMeters:.004}),$={CardboardV1:new r({id:"CardboardV1",label:"Cardboard I/O 2014",fov:40,interLensDistance:.06,baselineLensDistance:.035,screenLensDistance:.042,distortionCoefficients:[.441,.156],inverseCoefficients:[-.4410035,.42756155,-.4804439,.5460139,-.58821183,.5733938,-.48303202,.33299083,-.17573841,.0651772,-.01488963,.001559834]}),CardboardV2:new r({id:"CardboardV2",label:"Cardboard I/O 2015",fov:60,interLensDistance:.064,baselineLensDistance:.035,screenLensDistance:.039,distortionCoefficients:[.34,.55],inverseCoefficients:[-.33836704,-.18162185,.862655,-1.2462051,1.0560602,-.58208317,.21609078,-.05444823,.009177956,-.0009904169,6183535e-11,-16981803e-13]})};s.prototype.updateDeviceParams=function(e){this.device=this.determineDevice_(e)||this.device},s.prototype.getDevice=function(){return this.device},s.prototype.setViewer=function(e){this.viewer=e,this.distortion=new t(this.viewer.distortionCoefficients)},s.prototype.determineDevice_=function(e){if(!e)return y()?(console.warn("Using fallback iOS device measurements."),q):(console.warn("Using fallback Android device measurements."),K);var M=.0254/e.xdpi,i=.0254/e.ydpi,t=d(),s=S();return new A({widthMeters:M*t,heightMeters:i*s,bevelMeters:.001*e.bevelMm})},s.prototype.getDistortedFieldOfViewLeftEye=function(){var e=this.viewer,M=this.device,i=this.distortion,t=e.screenLensDistance,A=(M.widthMeters-e.interLensDistance)/2,s=e.interLensDistance/2,r=e.baselineLensDistance-M.bevelMeters,N=M.heightMeters-r,D=V*Math.atan(i.distort(A/t)),n=V*Math.atan(i.distort(s/t)),u=V*Math.atan(i.distort(r/t)),a=V*Math.atan(i.distort(N/t));return{leftDegrees:Math.min(D,e.fov),rightDegrees:Math.min(n,e.fov),downDegrees:Math.min(u,e.fov),upDegrees:Math.min(a,e.fov)}},s.prototype.getLeftEyeVisibleTanAngles=function(){var e=this.viewer,M=this.device,i=this.distortion,t=Math.tan(-H*e.fov),A=Math.tan(H*e.fov),s=Math.tan(H*e.fov),r=Math.tan(-H*e.fov),N=M.widthMeters/4,D=M.heightMeters/2,n=e.baselineLensDistance-M.bevelMeters-D,u=e.interLensDistance/2-N,a=-n,g=e.screenLensDistance,o=i.distort((u-N)/g),L=i.distort((a+D)/g),I=i.distort((u+N)/g),j=i.distort((a-D)/g),T=new Float32Array(4);return T[0]=Math.max(t,o),T[1]=Math.min(A,L),T[2]=Math.min(s,I),T[3]=Math.max(r,j),T},s.prototype.getLeftEyeNoLensTanAngles=function(){var e=this.viewer,M=this.device,i=this.distortion,t=new Float32Array(4),A=i.distortInverse(Math.tan(-H*e.fov)),s=i.distortInverse(Math.tan(H*e.fov)),r=i.distortInverse(Math.tan(H*e.fov)),N=i.distortInverse(Math.tan(-H*e.fov)),D=M.widthMeters/4,n=M.heightMeters/2,u=e.baselineLensDistance-M.bevelMeters-n,a=e.interLensDistance/2-D,g=-u,o=e.screenLensDistance,L=(a-D)/o,I=(g+n)/o,j=(a+D)/o,T=(g-n)/o;return t[0]=Math.max(A,L),t[1]=Math.min(s,I),t[2]=Math.min(r,j),t[3]=Math.max(N,T),t},s.prototype.getLeftEyeVisibleScreenRect=function(e){var M=this.viewer,i=this.device,t=M.screenLensDistance,A=(i.widthMeters-M.interLensDistance)/2,s=M.baselineLensDistance-i.bevelMeters,r=(e[0]*t+A)/i.widthMeters,N=(e[1]*t+s)/i.heightMeters,D=(e[2]*t+A)/i.widthMeters,n=(e[3]*t+s)/i.heightMeters;return{x:r,y:n,width:D-r,height:N-n}},s.prototype.getFieldOfViewLeftEye=function(e){return e?this.getUndistortedFieldOfViewLeftEye():this.getDistortedFieldOfViewLeftEye()},s.prototype.getFieldOfViewRightEye=function(e){var M=this.getFieldOfViewLeftEye(e);return{leftDegrees:M.rightDegrees,rightDegrees:M.leftDegrees,upDegrees:M.upDegrees,downDegrees:M.downDegrees}},s.prototype.getUndistortedFieldOfViewLeftEye=function(){var e=this.getUndistortedParams_();return{leftDegrees:V*Math.atan(e.outerDist),rightDegrees:V*Math.atan(e.innerDist),downDegrees:V*Math.atan(e.bottomDist),upDegrees:V*Math.atan(e.topDist)}},s.prototype.getUndistortedViewportLeftEye=function(){var e=this.getUndistortedParams_(),M=this.viewer,i=this.device,t=M.screenLensDistance,A=i.widthMeters/t,s=i.heightMeters/t,r=i.width/A,N=i.height/s,D=Math.round((e.eyePosX-e.outerDist)*r),n=Math.round((e.eyePosY-e.bottomDist)*N);return{x:D,y:n,width:Math.round((e.eyePosX+e.innerDist)*r)-D,height:Math.round((e.eyePosY+e.topDist)*N)-n}},s.prototype.getUndistortedParams_=function(){var e=this.viewer,M=this.device,i=this.distortion,t=e.screenLensDistance,A=e.interLensDistance/2/t,s=M.widthMeters/t,r=M.heightMeters/t,N=s/2-A,D=(e.baselineLensDistance-M.bevelMeters)/t,n=e.fov,u=i.distortInverse(Math.tan(H*n)),a=Math.min(N,u),g=Math.min(A,u),o=Math.min(D,u),L=Math.min(r-D,u);return{outerDist:a,innerDist:g,topDist:L,bottomDist:o,eyePosX:N,eyePosY:D}};s.Viewers=$;var ee={format:1,last_updated:"2017-09-12T18:54:02Z",devices:[{type:"android",rules:[{mdmh:"asus/*/Nexus 7/*"},{ua:"Nexus 7"}],dpi:[320.8,323],bw:3,ac:500},{type:"android",rules:[{mdmh:"asus/*/ASUS_Z00AD/*"},{ua:"ASUS_Z00AD"}],dpi:[403,404.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Google/*/Pixel XL/*"},{ua:"Pixel XL"}],dpi:[537.9,533],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Google/*/Pixel/*"},{ua:"Pixel"}],dpi:[432.6,436.7],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"HTC/*/HTC6435LVW/*"},{ua:"HTC6435LVW"}],dpi:[449.7,443.3],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"HTC/*/HTC One XL/*"},{ua:"HTC One XL"}],dpi:[315.3,314.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"htc/*/Nexus 9/*"},{ua:"Nexus 9"}],dpi:289,bw:3,ac:500},{type:"android",rules:[{mdmh:"HTC/*/HTC One M9/*"},{ua:"HTC One M9"}],dpi:[442.5,443.3],bw:3,ac:500},{type:"android",rules:[{mdmh:"HTC/*/HTC One_M8/*"},{ua:"HTC One_M8"}],dpi:[449.7,447.4],bw:3,ac:500},{type:"android",rules:[{mdmh:"HTC/*/HTC One/*"},{ua:"HTC One"}],dpi:472.8,bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Huawei/*/Nexus 6P/*"},{ua:"Nexus 6P"}],dpi:[515.1,518],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"LENOVO/*/Lenovo PB2-690Y/*"},{ua:"Lenovo PB2-690Y"}],dpi:[457.2,454.713],bw:3,ac:500},{type:"android",rules:[{mdmh:"LGE/*/Nexus 5X/*"},{ua:"Nexus 5X"}],dpi:[422,419.9],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"LGE/*/LGMS345/*"},{ua:"LGMS345"}],dpi:[221.7,219.1],bw:3,ac:500},{type:"android",rules:[{mdmh:"LGE/*/LG-D800/*"},{ua:"LG-D800"}],dpi:[422,424.1],bw:3,ac:500},{type:"android",rules:[{mdmh:"LGE/*/LG-D850/*"},{ua:"LG-D850"}],dpi:[537.9,541.9],bw:3,ac:500},{type:"android",rules:[{mdmh:"LGE/*/VS985 4G/*"},{ua:"VS985 4G"}],dpi:[537.9,535.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"LGE/*/Nexus 5/*"},{ua:"Nexus 5 B"}],dpi:[442.4,444.8],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"LGE/*/Nexus 4/*"},{ua:"Nexus 4"}],dpi:[319.8,318.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"LGE/*/LG-P769/*"},{ua:"LG-P769"}],dpi:[240.6,247.5],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"LGE/*/LGMS323/*"},{ua:"LGMS323"}],dpi:[206.6,204.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"LGE/*/LGLS996/*"},{ua:"LGLS996"}],dpi:[403.4,401.5],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Micromax/*/4560MMX/*"},{ua:"4560MMX"}],dpi:[240,219.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Micromax/*/A250/*"},{ua:"Micromax A250"}],dpi:[480,446.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Micromax/*/Micromax AQ4501/*"},{ua:"Micromax AQ4501"}],dpi:240,bw:3,ac:500},{type:"android",rules:[{mdmh:"motorola/*/G5/*"},{ua:"Moto G (5) Plus"}],dpi:[403.4,403],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/DROID RAZR/*"},{ua:"DROID RAZR"}],dpi:[368.1,256.7],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/XT830C/*"},{ua:"XT830C"}],dpi:[254,255.9],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/XT1021/*"},{ua:"XT1021"}],dpi:[254,256.7],bw:3,ac:500},{type:"android",rules:[{mdmh:"motorola/*/XT1023/*"},{ua:"XT1023"}],dpi:[254,256.7],bw:3,ac:500},{type:"android",rules:[{mdmh:"motorola/*/XT1028/*"},{ua:"XT1028"}],dpi:[326.6,327.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/XT1034/*"},{ua:"XT1034"}],dpi:[326.6,328.4],bw:3,ac:500},{type:"android",rules:[{mdmh:"motorola/*/XT1053/*"},{ua:"XT1053"}],dpi:[315.3,316.1],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/XT1562/*"},{ua:"XT1562"}],dpi:[403.4,402.7],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/Nexus 6/*"},{ua:"Nexus 6 B"}],dpi:[494.3,489.7],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/XT1063/*"},{ua:"XT1063"}],dpi:[295,296.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/XT1064/*"},{ua:"XT1064"}],dpi:[295,295.6],bw:3,ac:500},{type:"android",rules:[{mdmh:"motorola/*/XT1092/*"},{ua:"XT1092"}],dpi:[422,424.1],bw:3,ac:500},{type:"android",rules:[{mdmh:"motorola/*/XT1095/*"},{ua:"XT1095"}],dpi:[422,423.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"motorola/*/G4/*"},{ua:"Moto G (4)"}],dpi:401,bw:4,ac:1e3},{type:"android",rules:[{mdmh:"OnePlus/*/A0001/*"},{ua:"A0001"}],dpi:[403.4,401],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"OnePlus/*/ONE E1005/*"},{ua:"ONE E1005"}],dpi:[442.4,441.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"OnePlus/*/ONE A2005/*"},{ua:"ONE A2005"}],dpi:[391.9,405.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"OPPO/*/X909/*"},{ua:"X909"}],dpi:[442.4,444.1],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/GT-I9082/*"},{ua:"GT-I9082"}],dpi:[184.7,185.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G360P/*"},{ua:"SM-G360P"}],dpi:[196.7,205.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/Nexus S/*"},{ua:"Nexus S"}],dpi:[234.5,229.8],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/GT-I9300/*"},{ua:"GT-I9300"}],dpi:[304.8,303.9],bw:5,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-T230NU/*"},{ua:"SM-T230NU"}],dpi:216,bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SGH-T399/*"},{ua:"SGH-T399"}],dpi:[217.7,231.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SGH-M919/*"},{ua:"SGH-M919"}],dpi:[440.8,437.7],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-N9005/*"},{ua:"SM-N9005"}],dpi:[386.4,387],bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SAMSUNG-SM-N900A/*"},{ua:"SAMSUNG-SM-N900A"}],dpi:[386.4,387.7],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/GT-I9500/*"},{ua:"GT-I9500"}],dpi:[442.5,443.3],bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/GT-I9505/*"},{ua:"GT-I9505"}],dpi:439.4,bw:4,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G900F/*"},{ua:"SM-G900F"}],dpi:[415.6,431.6],bw:5,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G900M/*"},{ua:"SM-G900M"}],dpi:[415.6,431.6],bw:5,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G800F/*"},{ua:"SM-G800F"}],dpi:326.8,bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G906S/*"},{ua:"SM-G906S"}],dpi:[562.7,572.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/GT-I9300/*"},{ua:"GT-I9300"}],dpi:[306.7,304.8],bw:5,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-T535/*"},{ua:"SM-T535"}],dpi:[142.6,136.4],bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-N920C/*"},{ua:"SM-N920C"}],dpi:[515.1,518.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-N920P/*"},{ua:"SM-N920P"}],dpi:[386.3655,390.144],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-N920W8/*"},{ua:"SM-N920W8"}],dpi:[515.1,518.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/GT-I9300I/*"},{ua:"GT-I9300I"}],dpi:[304.8,305.8],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/GT-I9195/*"},{ua:"GT-I9195"}],dpi:[249.4,256.7],bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SPH-L520/*"},{ua:"SPH-L520"}],dpi:[249.4,255.9],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SAMSUNG-SGH-I717/*"},{ua:"SAMSUNG-SGH-I717"}],dpi:285.8,bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SPH-D710/*"},{ua:"SPH-D710"}],dpi:[217.7,204.2],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/GT-N7100/*"},{ua:"GT-N7100"}],dpi:265.1,bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SCH-I605/*"},{ua:"SCH-I605"}],dpi:265.1,bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/Galaxy Nexus/*"},{ua:"Galaxy Nexus"}],dpi:[315.3,314.2],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-N910H/*"},{ua:"SM-N910H"}],dpi:[515.1,518],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-N910C/*"},{ua:"SM-N910C"}],dpi:[515.2,520.2],bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-G130M/*"},{ua:"SM-G130M"}],dpi:[165.9,164.8],bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-G928I/*"},{ua:"SM-G928I"}],dpi:[515.1,518.4],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G920F/*"},{ua:"SM-G920F"}],dpi:580.6,bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-G920P/*"},{ua:"SM-G920P"}],dpi:[522.5,577],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G925F/*"},{ua:"SM-G925F"}],dpi:580.6,bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-G925V/*"},{ua:"SM-G925V"}],dpi:[522.5,576.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G930F/*"},{ua:"SM-G930F"}],dpi:576.6,bw:3,ac:1e3},{type:"android",rules:[{mdmh:"samsung/*/SM-G935F/*"},{ua:"SM-G935F"}],dpi:533,bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-G950F/*"},{ua:"SM-G950F"}],dpi:[562.707,565.293],bw:3,ac:500},{type:"android",rules:[{mdmh:"samsung/*/SM-G955U/*"},{ua:"SM-G955U"}],dpi:[522.514,525.762],bw:3,ac:500},{type:"android",rules:[{mdmh:"Sony/*/C6903/*"},{ua:"C6903"}],dpi:[442.5,443.3],bw:3,ac:500},{type:"android",rules:[{mdmh:"Sony/*/D6653/*"},{ua:"D6653"}],dpi:[428.6,427.6],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Sony/*/E6653/*"},{ua:"E6653"}],dpi:[428.6,425.7],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Sony/*/E6853/*"},{ua:"E6853"}],dpi:[403.4,401.9],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"Sony/*/SGP321/*"},{ua:"SGP321"}],dpi:[224.7,224.1],bw:3,ac:500},{type:"android",rules:[{mdmh:"TCT/*/ALCATEL ONE TOUCH Fierce/*"},{ua:"ALCATEL ONE TOUCH Fierce"}],dpi:[240,247.5],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"THL/*/thl 5000/*"},{ua:"thl 5000"}],dpi:[480,443.3],bw:3,ac:1e3},{type:"android",rules:[{mdmh:"ZTE/*/ZTE Blade L2/*"},{ua:"ZTE Blade L2"}],dpi:240,bw:3,ac:500},{type:"ios",rules:[{res:[640,960]}],dpi:[325.1,328.4],bw:4,ac:1e3},{type:"ios",rules:[{res:[640,1136]}],dpi:[317.1,320.2],bw:3,ac:1e3},{type:"ios",rules:[{res:[750,1334]}],dpi:326.4,bw:4,ac:1e3},{type:"ios",rules:[{res:[1242,2208]}],dpi:[453.6,458.4],bw:4,ac:1e3},{type:"ios",rules:[{res:[1125,2001]}],dpi:[410.9,415.4],bw:4,ac:1e3}]};N.prototype.getDeviceParams=function(){return this.deviceParams},N.prototype.recalculateDeviceParams_=function(){var e=this.calcDeviceParams_();e?(this.deviceParams=e,this.onDeviceParamsUpdated&&this.onDeviceParamsUpdated(this.deviceParams)):console.error("Failed to recalculate device parameters.")},N.prototype.calcDeviceParams_=function(){var e=this.dpdb;if(!e)return console.error("DPDB not available."),null;if(1!=e.format)return console.error("DPDB has unexpected format version."),null;if(!e.devices||!e.devices.length)return console.error("DPDB does not have a devices section."),null;var M=navigator.userAgent||navigator.vendor||window.opera,i=d(),t=S();if(!e.devices)return console.error("DPDB has no devices section."),null;for(var A=0;A<e.devices.length;A++){var s=e.devices[A];if(s.rules)if("ios"==s.type||"android"==s.type){if(y()==("ios"==s.type)){for(var r=!1,N=0;N<s.rules.length;N++){var D=s.rules[N];if(this.matchRule_(D,M,i,t)){r=!0;break}}if(r){var n=s.dpi[0]||s.dpi,u=s.dpi[1]||s.dpi;return new function(e){this.xdpi=e.xdpi,this.ydpi=e.ydpi,this.bevelMm=e.bevelMm}({xdpi:n,ydpi:u,bevelMm:s.bw})}}}else console.warn("Device["+A+"] has invalid type.");else console.warn("Device["+A+"] has no rules section.")}return console.warn("No DPDB device match."),null},N.prototype.matchRule_=function(e,M,i,t){if(!e.ua&&!e.res)return!1;if(e.ua&&M.indexOf(e.ua)<0)return!1;if(e.res){if(!e.res[0]||!e.res[1])return!1;var A=e.res[0],s=e.res[1];if(Math.min(i,t)!=Math.min(A,s)||Math.max(i,t)!=Math.max(A,s))return!1}return!0};D.prototype.set=function(e,M){this.sample=e,this.timestampS=M},D.prototype.copy=function(e){this.set(e.sample,e.timestampS)};n.prototype.addAccelMeasurement=function(e,M){this.currentAccelMeasurement.set(e,M)},n.prototype.addGyroMeasurement=function(e,M){this.currentGyroMeasurement.set(e,M);var i=M-this.previousGyroMeasurement.timestampS;(function(e){if(isNaN(e))return!1;if(e<=.001)return!1;if(e>1)return!1;return!0})(i)&&this.run_(),this.previousGyroMeasurement.copy(this.currentGyroMeasurement)},n.prototype.run_=function(){if(!this.isOrientationInitialized)return this.accelQ=this.accelToQuaternion_(this.currentAccelMeasurement.sample),this.previousFilterQ.copy(this.accelQ),void(this.isOrientationInitialized=!0);var e=this.currentGyroMeasurement.timestampS-this.previousGyroMeasurement.timestampS,M=this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample,e);this.gyroIntegralQ.multiply(M),this.filterQ.copy(this.previousFilterQ),this.filterQ.multiply(M);var i=new J;i.copy(this.filterQ),i.inverse(),this.estimatedGravity.set(0,0,-1),this.estimatedGravity.applyQuaternion(i),this.estimatedGravity.normalize(),this.measuredGravity.copy(this.currentAccelMeasurement.sample),this.measuredGravity.normalize();var t=new J;t.setFromUnitVectors(this.estimatedGravity,this.measuredGravity),t.inverse(),this.isDebug&&console.log("Delta: %d deg, G_est: (%s, %s, %s), G_meas: (%s, %s, %s)",V*function(e){if(e.w>1)return console.warn("getQuaternionAngle: w > 1"),0;return 2*Math.acos(e.w)}(t),this.estimatedGravity.x.toFixed(1),this.estimatedGravity.y.toFixed(1),this.estimatedGravity.z.toFixed(1),this.measuredGravity.x.toFixed(1),this.measuredGravity.y.toFixed(1),this.measuredGravity.z.toFixed(1));var A=new J;A.copy(this.filterQ),A.multiply(t),this.filterQ.slerp(A,1-this.kFilter),this.previousFilterQ.copy(this.filterQ)},n.prototype.getOrientation=function(){return this.filterQ},n.prototype.accelToQuaternion_=function(e){var M=new X;M.copy(e),M.normalize();var i=new J;return i.setFromUnitVectors(new X(0,0,-1),M),i.inverse(),i},n.prototype.gyroToQuaternionDelta_=function(e,M){var i=new J,t=new X;return t.copy(e),t.normalize(),i.setFromAxisAngle(t,e.length()*M),i};u.prototype.getPrediction=function(e,M,i){if(!this.previousTimestampS)return this.previousQ.copy(e),this.previousTimestampS=i,e;var t=new X;t.copy(M),t.normalize();var A=M.length();if(A<20*H)return this.isDebug&&console.log("Moving slowly, at %s deg/s: no prediction",(V*A).toFixed(1)),this.outQ.copy(e),this.previousQ.copy(e),this.outQ;var s=A*this.predictionTimeS;return this.deltaQ.setFromAxisAngle(t,s),this.outQ.copy(this.previousQ),this.outQ.multiply(this.deltaQ),this.previousQ.copy(e),this.previousTimestampS=i,this.outQ};a.prototype.getPosition=function(){return null},a.prototype.getOrientation=function(){var e=void 0;if(this.isWithoutDeviceMotion&&this._deviceOrientationQ){this.deviceOrientationFixQ=this.deviceOrientationFixQ||function(){var e=(new J).setFromAxisAngle(new X(0,0,-1),0),M=new J;return-90===window.orientation?M.setFromAxisAngle(new X(0,1,0),Math.PI/-2):M.setFromAxisAngle(new X(0,1,0),Math.PI/2),e.multiply(M)}(),this.deviceOrientationFilterToWorldQ=this.deviceOrientationFilterToWorldQ||function(){var e=new J;return e.setFromAxisAngle(new X(1,0,0),-Math.PI/2),e}(),e=this._deviceOrientationQ;var M=new J;return M.copy(e),M.multiply(this.deviceOrientationFilterToWorldQ),M.multiply(this.resetQ),M.multiply(this.worldToScreenQ),M.multiplyQuaternions(this.deviceOrientationFixQ,M),this.yawOnly&&(M.x=0,M.z=0,M.normalize()),this.orientationOut_[0]=M.x,this.orientationOut_[1]=M.y,this.orientationOut_[2]=M.z,this.orientationOut_[3]=M.w,this.orientationOut_}var i=this.filter.getOrientation();e=this.posePredictor.getPrediction(i,this.gyroscope,this.previousTimestampS);var M=new J;return M.copy(this.filterToWorldQ),M.multiply(this.resetQ),M.multiply(e),M.multiply(this.worldToScreenQ),this.yawOnly&&(M.x=0,M.z=0,M.normalize()),this.orientationOut_[0]=M.x,this.orientationOut_[1]=M.y,this.orientationOut_[2]=M.z,this.orientationOut_[3]=M.w,this.orientationOut_},a.prototype.resetPose=function(){this.resetQ.copy(this.filter.getOrientation()),this.resetQ.x=0,this.resetQ.y=0,this.resetQ.z*=-1,this.resetQ.normalize(),C()&&this.resetQ.multiply(this.inverseWorldToScreenQ),this.resetQ.multiply(this.originalPoseAdjustQ)},a.prototype.onDeviceOrientation_=function(e){this._deviceOrientationQ=this._deviceOrientationQ||new J;var M=e.alpha,i=e.beta,t=e.gamma;M=(M||0)*Math.PI/180,i=(i||0)*Math.PI/180,t=(t||0)*Math.PI/180,this._deviceOrientationQ.setFromEulerYXZ(i,M,-t)},a.prototype.onDeviceMotion_=function(e){this.updateDeviceMotion_(e)},a.prototype.updateDeviceMotion_=function(e){var M=e.accelerationIncludingGravity,i=e.rotationRate,t=e.timeStamp/1e3,A=t-this.previousTimestampS;return A<0?(v("fusion-pose-sensor:invalid:non-monotonic","Invalid timestamps detected: non-monotonic timestamp from devicemotion"),void(this.previousTimestampS=t)):A<=.001||A>1?(v("fusion-pose-sensor:invalid:outside-threshold","Invalid timestamps detected: Timestamp from devicemotion outside expected range."),void(this.previousTimestampS=t)):(this.accelerometer.set(-M.x,-M.y,-M.z),x()?this.gyroscope.set(-i.beta,i.alpha,i.gamma):this.gyroscope.set(i.alpha,i.beta,i.gamma),this.isDeviceMotionInRadians||this.gyroscope.multiplyScalar(Math.PI/180),this.filter.addAccelMeasurement(this.accelerometer,t),this.filter.addGyroMeasurement(this.gyroscope,t),void(this.previousTimestampS=t))},a.prototype.onOrientationChange_=function(e){this.setScreenTransform_()},a.prototype.onMessage_=function(e){var M=e.data;if(M&&M.type){var i=M.type.toLowerCase();"devicemotion"===i&&this.updateDeviceMotion_(M.deviceMotionEvent)}},a.prototype.setScreenTransform_=function(){switch(this.worldToScreenQ.set(0,0,0,1),window.orientation){case 0:break;case 90:this.worldToScreenQ.setFromAxisAngle(new X(0,0,1),-Math.PI/2);break;case-90:this.worldToScreenQ.setFromAxisAngle(new X(0,0,1),Math.PI/2)}this.inverseWorldToScreenQ.copy(this.worldToScreenQ),this.inverseWorldToScreenQ.inverse()},a.prototype.start=function(){this.onDeviceMotionCallback_=this.onDeviceMotion_.bind(this),this.onOrientationChangeCallback_=this.onOrientationChange_.bind(this),this.onMessageCallback_=this.onMessage_.bind(this),this.onDeviceOrientationCallback_=this.onDeviceOrientation_.bind(this),y()&&function(){var e=window.self!==window.top,M=Y(document.referrer),i=Y(window.location.href);return e&&M!==i}()&&window.addEventListener("message",this.onMessageCallback_),window.addEventListener("orientationchange",this.onOrientationChangeCallback_),this.isWithoutDeviceMotion?window.addEventListener("deviceorientation",this.onDeviceOrientationCallback_):window.addEventListener("devicemotion",this.onDeviceMotionCallback_)},a.prototype.stop=function(){window.removeEventListener("devicemotion",this.onDeviceMotionCallback_),window.removeEventListener("deviceorientation",this.onDeviceOrientationCallback_),window.removeEventListener("orientationchange",this.onOrientationChangeCallback_),window.removeEventListener("message",this.onMessageCallback_)};var Me=new X(1,0,0),ie=new X(0,0,1),te={};screen.orientation?te=screen.orientation:screen.msOrientation?te=screen.msOrientation:Object.defineProperty(te,"angle",{get:function(){return window.orientation||0}});var Ae=new J;Ae.setFromAxisAngle(Me,-Math.PI/2),Ae.multiply((new J).setFromAxisAngle(ie,Math.PI/2));var se=function(){function e(M){T(this,e),this.config=M,this.sensor=null,t
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a filed issue, but just FYI: the source maps are removed now

<script src="gl-matrix-min.js"></script>
<script src="webvr-polyfill.min.js"></script>
<script src="vendor/gl-matrix-min.js"></script>
<script src="vendor/webvr-polyfill.min.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

this is definitely far beyond the scope of this issue/PR, and I'm not suggesting address it now, but ideally we don't include the <script> (and call it from webvr.js) unless we need it (#126). I say this more as a reminder to myself so we can remove this as a blocking <script> someday 😄

@delapuente
Copy link
Contributor Author

delapuente commented Mar 22, 2018

To be honest, I never got it working on my OnePlus 3T. I'm debugging with the device emulator of Chrome but even now, with the current version, I can not get it working.

@delapuente delapuente dismissed cvan’s stale review March 23, 2018 07:45

Agreed on merging in Slack. No regressions found compared with the previous version.

@delapuente delapuente merged commit fbc8dbb into MozillaReality:master Mar 23, 2018
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.

upgrade version of webvr-polyfill dependency
2 participants