UNPKG

holoplay

Version:

A library for the Looking Glass 3D display that relies on three.js to show content in true 3D from the browser.

19 lines 24.6 kB
(function(e,t){typeof exports==="object"&&typeof module!=="undefined"?t(exports):typeof define==="function"&&define.amd?define(["exports"],t):(e=e||self,t(e.HoloPlay={}))})(this,(function(e){"use strict";var t=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};function n(e,t){return t={exports:{}},e(t,t.exports),t.exports}var i=n((function(e){(function(t,n){var i=Math.pow(2,-24),r=Math.pow(2,32),s=Math.pow(2,53);function o(e){var t=new ArrayBuffer(256);var i=new DataView(t);var o;var l=0;function a(e){var n=t.byteLength;var r=l+e;while(n<r)n*=2;if(n!==t.byteLength){var s=i;t=new ArrayBuffer(n);i=new DataView(t);var a=l+3>>2;for(var u=0;u<a;++u)i.setUint32(u*4,s.getUint32(u*4))}o=e;return i}function u(){l+=o}function c(e){u(a(8).setFloat64(l,e))}function d(e){u(a(1).setUint8(l,e))}function h(e){var t=a(e.length);for(var n=0;n<e.length;++n)t.setUint8(l+n,e[n]);u()}function f(e){u(a(2).setUint16(l,e))}function v(e){u(a(4).setUint32(l,e))}function p(e){var t=e%r;var n=(e-t)/r;var i=a(8);i.setUint32(l,n);i.setUint32(l+4,t);u()}function m(e,t){if(t<24){d(e<<5|t)}else if(t<256){d(e<<5|24);d(t)}else if(t<65536){d(e<<5|25);f(t)}else if(t<4294967296){d(e<<5|26);v(t)}else{d(e<<5|27);p(t)}}function g(e){var t;if(e===false)return d(244);if(e===true)return d(245);if(e===null)return d(246);if(e===n)return d(247);switch(typeof e){case"number":if(Math.floor(e)===e){if(0<=e&&e<=s)return m(0,e);if(-s<=e&&e<0)return m(1,-(e+1))}d(251);return c(e);case"string":var i=[];for(t=0;t<e.length;++t){var r=e.charCodeAt(t);if(r<128){i.push(r)}else if(r<2048){i.push(192|r>>6);i.push(128|r&63)}else if(r<55296){i.push(224|r>>12);i.push(128|r>>6&63);i.push(128|r&63)}else{r=(r&1023)<<10;r|=e.charCodeAt(++t)&1023;r+=65536;i.push(240|r>>18);i.push(128|r>>12&63);i.push(128|r>>6&63);i.push(128|r&63)}}m(3,i.length);return h(i);default:var o;if(Array.isArray(e)){o=e.length;m(4,o);for(t=0;t<o;++t)g(e[t])}else if(e instanceof Uint8Array){m(2,e.length);h(e)}else{var l=Object.keys(e);o=l.length;m(5,o);for(t=0;t<o;++t){var a=l[t];g(a);g(e[a])}}}}g(e);if("slice"in t)return t.slice(0,l);var w=new ArrayBuffer(l);var b=new DataView(w);for(var y=0;y<l;++y)b.setUint8(y,i.getUint8(y));return w}function l(e,t,s){var o=new DataView(e);var l=0;if(typeof t!=="function")t=function(e){return e};if(typeof s!=="function")s=function(){return n};function a(e,t){l+=t;return e}function u(t){return a(new Uint8Array(e,l,t),t)}function c(){var e=new ArrayBuffer(4);var t=new DataView(e);var n=v();var r=n&32768;var s=n&31744;var o=n&1023;if(s===31744)s=255<<10;else if(s!==0)s+=127-15<<10;else if(o!==0)return o*i;t.setUint32(0,r<<16|s<<13|o<<13);return t.getFloat32(0)}function d(){return a(o.getFloat32(l),4)}function h(){return a(o.getFloat64(l),8)}function f(){return a(o.getUint8(l),1)}function v(){return a(o.getUint16(l),2)}function p(){return a(o.getUint32(l),4)}function m(){return p()*r+p()}function g(){if(o.getUint8(l)!==255)return false;l+=1;return true}function w(e){if(e<24)return e;if(e===24)return f();if(e===25)return v();if(e===26)return p();if(e===27)return m();if(e===31)return-1;throw"Invalid length encoding"}function b(e){var t=f();if(t===255)return-1;var n=w(t&31);if(n<0||t>>5!==e)throw"Invalid indefinite length element";return n}function y(e,t){for(var n=0;n<t;++n){var i=f();if(i&128){if(i<224){i=(i&31)<<6|f()&63;t-=1}else if(i<240){i=(i&15)<<12|(f()&63)<<6|f()&63;t-=2}else{i=(i&15)<<18|(f()&63)<<12|(f()&63)<<6|f()&63;t-=3}}if(i<65536){e.push(i)}else{i-=65536;e.push(55296|i>>10);e.push(56320|i&1023)}}}function E(){var e=f();var i=e>>5;var r=e&31;var o;var l;if(i===7){switch(r){case 25:return c();case 26:return d();case 27:return h()}}l=w(r);if(l<0&&(i<2||6<i))throw"Invalid length";switch(i){case 0:return l;case 1:return-1-l;case 2:if(l<0){var a=[];var v=0;while((l=b(i))>=0){v+=l;a.push(u(l))}var p=new Uint8Array(v);var m=0;for(o=0;o<a.length;++o){p.set(a[o],m);m+=a[o].length}return p}return u(l);case 3:var R=[];if(l<0){while((l=b(i))>=0)y(R,l)}else y(R,l);return String.fromCharCode.apply(null,R);case 4:var x;if(l<0){x=[];while(!g())x.push(E())}else{x=new Array(l);for(o=0;o<l;++o)x[o]=E()}return x;case 5:var C={};for(o=0;o<l||l<0&&!g();++o){var T=E();C[T]=E()}return C;case 6:return t(E(),l);case 7:switch(l){case 20:return false;case 21:return true;case 22:return null;case 23:return n;default:return s(l)}}}var R=E();if(l!==e.byteLength)throw"Remaining bytes";return R}var a={encode:o,decode:l};if(typeof n==="function"&&n.amd)n("cbor/cbor",a);else if(e.exports)e.exports=a;else if(!t.CBOR)t.CBOR=a})(t)})); /** * This files defines the HoloPlayClient class and Message class. * * Copyright (c) [2019] [Looking Glass Factory] * * @link https://lookingglassfactory.com/ * @file This files defines the HoloPlayClient class and Message class. * @author Looking Glass Factory. * @version 0.0.8 * @license SEE LICENSE IN LICENSE.md */const r=typeof window==="undefined"?require("ws"):window.WebSocket;class s{constructor(e,t,n,i=false,r,s,o){this.reqs=[];this.reps=[];this.requestId=this.getRequestId();this.debug=i;this.isGreedy=s;this.errCallback=t;this.closeCallback=n;this.alwaysdebug=false;this.isConnected=false;let u=null;if(r||s||o){u=new l(r,s,o,this.debug)}else{if(i)this.alwaysdebug=true;if(typeof e=="function")u=new a}this.openWebsocket(u,e)}sendMessage(e,t=60){if(this.alwaysdebug)e.cmd.debug=true;let n=e.toCbor();return this.sendRequestObj(n,t)}disconnect(){this.ws.close()}openWebsocket(e=null,t=null){this.ws=new r("ws://localhost:11222/driver",["rep.sp.nanomsg.org"]);this.ws.parent=this;this.ws.binaryType="arraybuffer";this.ws.onmessage=this.messageHandler;this.ws.onopen=()=>{this.isConnected=true;if(this.debug){console.log("socket open")}if(e!=null){this.sendMessage(e).then(t)}};this.ws.onerror=this.onSocketError;this.ws.onclose=this.onClose}sendRequestObj(e,t){return new Promise((n,i)=>{let r={id:this.requestId++,parent:this,payload:e,success:n,error:i,send:function(){if(this.debug)console.log("attemtping to send request with ID "+this.id);this.timeout=setTimeout(r.send.bind(this),t*1e3);let n=new Uint8Array(e.byteLength+4);let i=new DataView(n.buffer);i.setUint32(0,this.id);n.set(new Uint8Array(this.payload),4);this.parent.ws.send(n.buffer)}};this.reqs.push(r);r.send()})}messageHandler(e){console.log("message");let t=e.data;if(t.byteLength<4)return;let n=new DataView(t);let r=n.getUint32(0);if(r<2147483648){this.parent.err("bad nng header");return}let s=this.parent.findReqIndex(r);if(s==-1){this.parent.err("got reply that doesn't match known request!");return}let o={id:r,payload:i.decode(t.slice(4))};if(o.payload.error==0){this.parent.reqs[s].success(o.payload)}else{this.parent.reqs[s].error(o.payload)}clearTimeout(this.parent.reqs[s].timeout);this.parent.reqs.splice(s,1);this.parent.reps.push(o);if(this.debug){console.log(o.payload)}}getRequestId(){return Math.floor(this.prng()*2147483647)+2147483648}onClose(e){this.parent.isConnected=false;if(this.parent.debug){console.log("socket closed")}if(typeof this.parent.closeCallback=="function")this.parent.closeCallback(e)}onSocketError(e){if(this.parent.debug){console.log(e)}if(typeof this.parent.errCallback=="function"){this.parent.errCallback(e)}}err(e){if(this.debug){console.log("[DRIVER ERROR]"+e)}}findReqIndex(e){let t=0;for(;t<this.reqs.length;t++){if(this.reqs[t].id==e){return t}}return-1}prng(){if(this.rng==undefined){this.rng=u()}return this.rng()}}class o{constructor(e,t){this.cmd=e;this.bin=t}toCbor(){return i.encode(this)}}class l extends o{constructor(e="",t=false,n="",i=false){let r={init:{}};if(e!="")r["init"].appid=e;if(n!="")r["init"].onclose=n;if(t)r["init"].greedy=true;if(i)r["init"].debug=true;super(r,null)}}class a extends o{constructor(){let e={info:{}};super(e,null)}}function u(){function e(e){for(var t=0,n=1779033703^e.length;t<e.length;t++)n=Math.imul(n^e.charCodeAt(t),3432918353),n=n<<13|n>>>19;return function(){n=Math.imul(n^n>>>16,2246822507);n=Math.imul(n^n>>>13,3266489909);return(n^=n>>>16)>>>0}}function t(e,t,n,i){return()=>{var r=t<<9,s=e*5;s=(s<<7|s>>>25)*9;n^=e;i^=t;t^=n;e^=i;n^=r;i=i<<11|i>>>21;return(s>>>0)/4294967296}}var n=Date.now();var i=e(n.toString());return t(i(),i(),i(),i())}const c={configVersion:"1.0",serial:"00000",pitch:{value:47.556365966796875},slope:{value:-5.488804340362549},center:{value:.15815216302871704},viewCone:{value:40},invView:{value:1},verticalAngle:{value:0},DPI:{value:338},screenW:{value:2560},screenH:{value:1600},flipImageX:{value:0},flipImageY:{value:0},flipSubp:{value:0}};function d(){if(confirm("HoloPlayService not detected! Click OK to download. If you have it already installed, please make sure it is running.")){window.location.href="http://look.glass/holoplayservice"}}let h=null;function f(){if(!h){h=new Promise((e,t)=>{new s(t=>{if(t.devices.length==0){alert("No Looking Glass detected. Please make sure your Looking Glass is plugged in.")}e(t.devices)},e=>{console.error("error loading calibration",e);d();t(e)},console.log)})}return h}function v(){return f().then(e=>{if(e.length==0){throw new Error("no devices")}return e[0]})}function p(){return v().then(e=>e.calibration).catch(e=>{console.error("no devices connected. using default calibration.");return c})}const m={standard:{quiltResolution:4096,tileCount:new THREE.Vector2(5,9),viewCone:35,fov:12.5},large:{quiltResolution:4096,tileCount:new THREE.Vector2(5,9),viewCone:35,fov:12.5},pro:{quiltResolution:4096,tileCount:new THREE.Vector2(5,9),viewCone:35,fov:12.5},"8k":{quiltResolution:8192,tileCount:new THREE.Vector2(5,9),viewCone:35,fov:12.5},default:{quiltResolution:2048,tileCount:new THREE.Vector2(4,8),viewCone:35,fov:12.5}};function g(e){return v().then(t=>m[t.hardwareVersion][e]).catch(t=>m["default"][e])}function w(){return g("quiltResolution")}function b(){return g("tileCount")}function y(){return g("viewCone")}function E(){return g("fov")}var R=Object.freeze({__proto__:null,DEFAULT_CALIBRATION:c,getFirstDevice:v,getCalibration:p,getIdealQuiltResolution:w,getIdealQuiltTileCount:b,getIdealViewCone:y,getIdealFov:E});const x=`\n varying vec2 iUv;\n\n void main() {\n iUv = uv;\n vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);\n gl_Position = projectionMatrix * modelViewPosition;\n }\n`;const C=`\n uniform sampler2D quiltTexture;\n uniform float pitch;\n uniform float tilt;\n uniform float center;\n uniform float invView; \n uniform float flipX; \n uniform float flipY; \n uniform float subp; \n uniform float tilesX;\n uniform float tilesY;\n uniform vec2 quiltViewPortion;\n varying vec2 iUv;\n\n vec2 texArr(vec3 uvz) {\n float z = floor(uvz.z * tilesX * tilesY);\n float x = (mod(z, tilesX) + uvz.x) / tilesX;\n float y = (floor(z / tilesX) + uvz.y) / tilesY;\n return vec2(x, y) * quiltViewPortion;\n }\n\n float remap(float value, float from1, float to1, float from2, float to2) {\n return (value - from1) / (to1 - from1) * (to2 - from2) + from2;\n }\n\n void main() {\n vec4 rgb[3];\n vec3 nuv = vec3(iUv.xy, 0.0);\n\n // Flip UVs if necessary\n nuv.x = (1.0 - flipX) * nuv.x + flipX * (1.0 - nuv.x);\n nuv.y = (1.0 - flipY) * nuv.y + flipY * (1.0 - nuv.y);\n\n for (int i = 0; i < 3; i++) {\n nuv.z = (iUv.x + float(i) * subp + iUv.y * tilt) * pitch - center;\n nuv.z = mod(nuv.z + ceil(abs(nuv.z)), 1.0);\n nuv.z = (1.0 - invView) * nuv.z + invView * (1.0 - nuv.z); \n rgb[i] = texture2D(quiltTexture, texArr(vec3(iUv.x, iUv.y, nuv.z)));\n }\n\n gl_FragColor = vec4(rgb[0].r, rgb[1].g, rgb[2].b, 1);\n }\n`;const T={uniforms:{quiltTexture:{value:null},pitch:{value:0},tilt:{value:0},center:{value:0},invView:{value:0},flipX:{value:0},flipY:{value:0},subp:{value:0},tilesX:{value:0},tilesY:{value:0},screenW:{value:0},screenH:{value:0},quiltViewPortion:{value:new THREE.Vector2(1,1)}},vertexShader:x,fragmentShader:C};class q{constructor(e,t){p().then(e=>{this.calibrationData=e;this.updateCalibration()});this.tileCount=e;this.scene=new THREE.Scene;const n=new THREE.PlaneGeometry(1,1);const i=new THREE.ShaderMaterial(T);this.quiltPlane=new THREE.Mesh(n,i);this.scene.add(this.quiltPlane);this.camera=new THREE.OrthographicCamera(-.5,.5,.5,-.5,0);this.renderer=t||new THREE.WebGLRenderer;this.renderSize=new THREE.Vector2(window.innerWidth,window.innerHeight);this.domElement=this.renderer.domElement;this.domElement.style.position="absolute"}render(){this.renderer.setSize(this.renderSize.x,this.renderSize.y);this.negateWindowZoomAndOffset();this.renderer.render(this.scene,this.camera)}update(e,t){this.tileCount.copy(t);this.quiltPlane.material.uniforms.tilesX.value=this.tileCount.x;this.quiltPlane.material.uniforms.tilesY.value=this.tileCount.y;this.quiltPlane.material.uniforms.quiltViewPortion.value.set(Math.floor(e/this.tileCount.x)*this.tileCount.x/e,Math.floor(e/this.tileCount.y)*this.tileCount.y/e)}negateWindowZoomAndOffset(){const e=window.outerWidth/document.body.getBoundingClientRect().width;const t=window.outerHeight-window.innerHeight;this.domElement.style.width=`${this.domElement.width/e}px`;this.domElement.style.height=`${this.domElement.height/e}px`;this.domElement.style.left=`${(window.screen.availLeft-window.screenLeft)/e}px`;this.domElement.style.top=`${-(window.screenTop+t)/e}px`}setQuiltImageURL(e){const t=new Image;t.src=e;this.setQuiltImage(t)}setQuiltImage(e){const t=new THREE.Texture;t.image=e;t.minFilter=THREE.NearestFilter;t.magFilter=THREE.NearestFilter;this.setQuiltTexture(t);e.addEventListener("load",()=>{t.needsUpdate=true;this.render()});if(e.complete){e.load()}}setQuiltTexture(e){this.quiltPlane.material.uniforms.quiltTexture.value=e}updateCalibration(){if(!this.calibrationData){return}this.renderSize.set(this.calibrationData.screenW.value,this.calibrationData.screenH.value);const e=this.quiltPlane.material;const t=this.calibrationData.screenW.value/this.calibrationData.DPI.value;let n=this.calibrationData.pitch.value*t;n*=Math.cos(Math.atan(1/this.calibrationData.slope.value));e.uniforms.pitch.value=n;let i=this.calibrationData.screenH.value/(this.calibrationData.screenW.value*this.calibrationData.slope.value);if(this.calibrationData.flipImageX.value==1){i*=-1}e.uniforms.tilt.value=i;e.uniforms.center.value=this.calibrationData.center.value;e.uniforms.invView.value=this.calibrationData.invView.value;e.uniforms.flipX.value=this.calibrationData.flipImageX.value;e.uniforms.flipY.value=this.calibrationData.flipImageY.value;e.uniforms.subp.value=1/(this.calibrationData.screenW.value*3);e.uniforms.tilesX.value=this.tileCount.x;e.uniforms.tilesY.value=this.tileCount.y}} /*! (c) Andrea Giammarchi - ISC */var k=undefined||{};try{k.EventTarget=(new EventTarget).constructor}catch(e){(function(e,t){var n=e.create;var i=e.defineProperty;var r=s.prototype;o(r,"addEventListener",(function(e,n,i){for(var r=t.get(this),s=r[e]||(r[e]=[]),o=0,l=s.length;o<l;o++){if(s[o].listener===n)return}s.push({target:this,listener:n,options:i})}));o(r,"dispatchEvent",(function(e){var n=t.get(this);var i=n[e.type];if(i){o(e,"target",this);o(e,"currentTarget",this);i.slice(0).forEach(l,e);delete e.currentTarget;delete e.target}return true}));o(r,"removeEventListener",(function(e,n){for(var i=t.get(this),r=i[e]||(i[e]=[]),s=0,o=r.length;s<o;s++){if(r[s].listener===n){r.splice(s,1);return}}}));k.EventTarget=s;function s(){t.set(this,n(null))}function o(e,t,n){i(e,t,{configurable:true,writable:true,value:n})}function l(e){var t=e.options;if(t&&t.once)e.target.removeEventListener(this.type,e.listener);if(typeof e.listener==="function")e.listener.call(e.target,this);else e.listener.handleEvent(this)}})(Object,new WeakMap)}var H=k.EventTarget;const F=["square","left","right","circle"];class M extends H{constructor(){super();this.lastButtonState=[];for(let e=0;e<F.length;e++){this.lastButtonState.push(false)}this.gamepadInfo=null;window.addEventListener("gamepadconnected",e=>{if(e.gamepad.id.indexOf("HoloPlay")>-1){this.gamepadInfo=navigator.getGamepads()[e.gamepad.index]}});window.addEventListener("gamepaddisconnected",e=>{if(e.gamepad.id.indexOf("HoloPlay")>-1){this.gamepadInfo=null}});requestAnimationFrame(this.update.bind(this))}update(){requestAnimationFrame(this.update.bind(this));if(this.gamepadInfo==null){return}let e;let t=navigator.getGamepads();for(let n=0;n<t.length;n++){if(t[n].index==this.gamepadInfo.index){e=t[n];break}}if(!e){return}for(let t=0;t<e.buttons.length;t++){if(!this.lastButtonState[t]&&e.buttons[t].pressed){this.dispatchButtonEvent("buttonDown",t);this.dispatchButtonEvent("buttonPressed",t)}else if(this.lastButtonState[t]&&e.buttons[t].pressed){this.dispatchButtonEvent("buttonPressed",t)}else if(this.lastButtonState[t]&&!e.buttons[t].pressed){this.dispatchButtonEvent("buttonUp",t)}this.lastButtonState[t]=e.buttons[t].pressed}}dispatchButtonEvent(e,t){this.dispatchEvent(new CustomEvent(e,{detail:{name:F[t],index:t}}))}}class D extends THREE.ArrayCamera{constructor(){super();this.tileCount=new THREE.Vector2;this.target=new THREE.Vector3(0,0,0);this.position.set(0,0,1);this.fov=12.5;this.aspect=2560/1600;this.viewCone=35;y().then(e=>{this.viewCone=e});E().then(e=>{this.fov=e;this.cameras.forEach(e=>{e.fov=this.fov;e.updateProjectionMatrix()})});p().then(e=>{this.aspect=e.screenW.value/e.screenH.value;this.cameras.forEach(e=>{e.aspect=this.aspect;e.updateProjectionMatrix()})})}update(e,t){if(this.tileCount.x!=t.x||this.tileCount.y!=t.y){this.cameras=[];for(let e=0;e<t.x*t.y;e++){const e=new THREE.PerspectiveCamera(this.fov,this.aspect);e.viewport=new THREE.Vector4;this.cameras.push(e)}this.tileCount.copy(t)}const n=new THREE.Vector2(Math.floor(e/t.x),Math.floor(e/t.y));for(let e=0;e<this.cameras.length;e++){const i=this.cameras[e];i.rotation.copy(this.rotation);const r=new THREE.Vector2(e%t.x,Math.floor(e/t.x));i.viewport.set(r.x*n.x,r.y*n.y,n.x,n.y);const s=this.position.distanceTo(this.target);const o=THREE.Math.degToRad(THREE.Math.lerp(-this.viewCone/2,this.viewCone/2,e/(this.cameras.length-1)));const l=s*Math.tan(o);i.position.copy(this.localToWorld(new THREE.Vector3(l,0,0)));i.updateMatrixWorld();i.projectionMatrix.elements[8]=-2*l/(2*s*Math.tan(.5*THREE.Math.degToRad(i.fov))*i.aspect)}}lookAt(e){super.lookAt(e);this.target.copy(e)}} /*! * fullscreen-polyfill * 1.0.2 - 5/23/2018 * https://github.com/nguyenj/fullscreen-polyfill#readme * (c) John Nguyen; MIT License */var V=function(){var e=["fullscreen","fullscreenEnabled","fullscreenElement","fullscreenchange","fullscreenerror","exitFullscreen","requestFullscreen"],t=["webkitIsFullScreen","webkitFullscreenEnabled","webkitFullscreenElement","webkitfullscreenchange","webkitfullscreenerror","webkitExitFullscreen","webkitRequestFullscreen"],n=["mozFullScreen","mozFullScreenEnabled","mozFullScreenElement","mozfullscreenchange","mozfullscreenerror","mozCancelFullScreen","mozRequestFullScreen"],i=["","msFullscreenEnabled","msFullscreenElement","MSFullscreenChange","MSFullscreenError","msExitFullscreen","msRequestFullscreen"];document||(document={});var r,s=(r=[e[1],t[1],n[1],i[1]].find((function(e){return document[e]})),[e,t,n,i].find((function(e){return e.find((function(e){return e===r}))}))||[]);function o(t,n){document[e[0]]=document[s[0]]||!!document[s[2]]||!1,document[e[1]]=document[s[1]]||!1,document[e[2]]=document[s[2]]||null,document.dispatchEvent(new Event(t),n.target)}return document[e[1]]?{}:(document[e[0]]=document[s[0]]||!!document[s[2]]||!1,document[e[1]]=document[s[1]]||!1,document[e[2]]=document[s[2]]||null,document.addEventListener(s[3],o.bind(document,e[3]),!1),document.addEventListener(s[4],o.bind(document,e[4]),!1),document[e[5]]=function(){return document[s[5]]()},void(Element.prototype[e[6]]=function(){return this[s[6]].apply(this,arguments)}))}();class S{constructor(e){this.renderer=e;this.lkgDevice=null;v().then(e=>{this.lkgDevice=e;const t=this.isOnLkg();if(t){this.renderer.render2d=false;this.moveWarning.style.display="none"}else{this.renderer.render2d=true;this.moveWarning.style.display=""}requestAnimationFrame(this.update.bind(this))});this.onLkg=null;this.moveWarning=this.makeMoveWarning();document.body.appendChild(this.moveWarning);this.fullscreenButton=this.makeFullscreenButton();document.body.appendChild(this.fullscreenButton)}isOnLkg(){const e=window.screen.width==this.lkgDevice.calibration.screenW.value&&window.screen.height==this.lkgDevice.calibration.screenH.value;const t=window.screen.availLeft==this.lkgDevice.windowCoords[0];return e&&t}update(){requestAnimationFrame(this.update.bind(this));const e=this.isOnLkg();if(e&&!this.onLkg){this.renderer.render2d=false;this.moveWarning.style.display="none"}else if(!e&&this.onLkg){this.renderer.render2d=true;this.moveWarning.style.display=""}this.onLkg=e;if(this.onLkg&&!document.fullscreen){if(document.hasFocus()){this.fullscreenButton.innerText="click to go fullscreen"}else{this.fullscreenButton.innerText="click to focus window"}this.fullscreenButton.style.display=""}else{this.fullscreenButton.style.display="none"}}makeMoveWarning(){const e=document.createElement("div");e.innerText="drag this window to the Looking Glass";e.style.cssText=`\n background: white;\n border-radius: 8px;\n bottom: 0px;\n display: none;\n font-family: sans-serif;\n font-size: 6em;\n left: 0px;\n margin: 16px;\n opacity: 0.5;\n padding: 8px;\n position: absolute;\n z-index: ${Number.MAX_SAFE_INTEGER};\n `;return e}makeFullscreenButton(){const e=document.createElement("div");e.innerText="go fullscreen";e.style.cssText=`\n background: white;\n border-radius: 8px;\n bottom: 0px;\n display: none;\n font-family: sans-serif;\n font-size: 6em;\n font-weight: bold;\n left: 0px;\n margin: 16px;\n opacity: 0.75;\n padding: 8px;\n pointer-events: none;\n position: absolute;\n z-index: ${Number.MAX_SAFE_INTEGER};\n `;window.addEventListener("click",()=>{this.renderer.domElement.requestFullscreen()});return e}}class z{constructor(e){this.enforceMandatoryDocumentStyle();let t=e||{};this.quiltResolution=t.quiltResolution||4096;this.tileCount=t.tileCount||new THREE.Vector2(5,9);this.render2d=t.render2d||false;this.renderQuilt=t.render2d||false;this.fullscreenHelper=null;if(!t.disableFullscreenUi){this.fullscreenHelper=new S(this)}this.webglRenderer=new THREE.WebGLRenderer;this.domElement=this.webglRenderer.domElement;this.quiltRenderTarget=new THREE.WebGLRenderTarget(this.quiltResolution,this.quiltResolution,{format:THREE.RGBFormat});this.quiltRenderer=new q(this.tileCount,this.webglRenderer);this.quiltRenderer.setQuiltTexture(this.quiltRenderTarget.texture);if(!t.quiltResolution){w().then(e=>{this.quiltResolution=e})}if(!t.tileCount){b().then(e=>{this.tileCount.copy(e)})}this.debug2dCamera=new THREE.PerspectiveCamera;E().then(e=>{this.debug2dCamera.fov=e;this.debug2dCamera.updateProjectionMatrix()})}enforceMandatoryDocumentStyle(){document.body.style.margin="0px";document.body.style.overflow="hidden"}render(e,t){this.enforceMandatoryDocumentStyle();if(this.render2d){this.debug2dCamera.position.copy(t.position);this.debug2dCamera.rotation.copy(t.rotation);const n=window.innerWidth/window.innerHeight;if(n!=this.debug2dCamera.aspect){this.debug2dCamera.aspect=n;this.debug2dCamera.updateProjectionMatrix()}this.webglRenderer.domElement.style.top=this.webglRenderer.domElement.style.left="0px";this.webglRenderer.setSize(window.innerWidth,window.innerHeight);this.webglRenderer.render(e,this.debug2dCamera)}else if(this.renderQuilt){t.update(this.quiltResolution,this.tileCount);const n=Math.min(window.innerWidth,window.innerHeight);this.webglRenderer.domElement.style.width=this.webglRenderer.domElement.style.height=`${n}px`;this.webglRenderer.domElement.style.top=this.webglRenderer.domElement.style.left="0px";this.webglRenderer.setRenderTarget(null);this.webglRenderer.setSize(this.quiltResolution,this.quiltResolution,false);this.webglRenderer.render(e,t)}else{this.quiltRenderTarget.setSize(this.quiltResolution,this.quiltResolution);t.update(this.quiltResolution,this.tileCount);this.webglRenderer.setRenderTarget(this.quiltRenderTarget);this.webglRenderer.setSize(this.quiltResolution,this.quiltResolution,false);this.webglRenderer.render(e,t);this.webglRenderer.setRenderTarget(null);this.quiltRenderer.update(this.quiltResolution,this.tileCount);this.quiltRenderer.render()}}}e.Buttons=M;e.Calibration=R;e.Camera=D;e.FullscreenHelper=S;e.QuiltRenderer=q;e.Renderer=z;Object.defineProperty(e,"__esModule",{value:true})}));