This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
/
three.ar.min.js
40 lines (40 loc) · 31.1 KB
/
three.ar.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @license
* three.ar.js
* Copyright (c) 2017 Google
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @license
* gl-preserve-state
* Copyright (c) 2016, Brandon Jones.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],t):t(e["three-ar"]={},e.THREE)}(this,function(e,t){"use strict";function i(e,t,i){var r=void 0;if("fragment"==i)r=e.createShader(e.FRAGMENT_SHADER);else{if("vertex"!=i)return null;r=e.createShader(e.VERTEX_SHADER)}e.shaderSource(r,t),e.compileShader(r);return e.getShaderParameter(r,e.COMPILE_STATUS)?r:(alert(e.getShaderInfoLog(r)),null)}function r(e,t){var i=0;switch(t){case 90:i=1;break;case 180:i=2;break;case 270:i=3;break;default:i=0}var r=0;switch(e){case 90:r=1;break;case 180:r=2;break;case 270:r=3;break;default:r=0}var n=r-i;return n<0&&(n+=4),n%4}var n="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},o=function(){},a=["#F44336","#E91E63","#9C27B0","#673AB7","#3F51B5","#2196F3","#03A9F4","#00BCD4","#009688","#4CAF50","#8BC34A","#CDDC39","#FFEB3B","#FFC107","#FF9800"].map(function(e){return new t.Color(e)}),s=Object.create(null);s.isTango=function(e){return e&&e.displayName.toLowerCase().includes("tango")};var l=s.isTango;s.isARKit=function(e){return e&&e.displayName.toLowerCase().includes("arkit")};var u=s.isARKit;s.isARDisplay=function(e){return u(e)||l(e)};var h=s.isARDisplay;s.getARDisplay=function(){return new Promise(function(e,t){navigator.getVRDisplays?navigator.getVRDisplays().then(function(t){if(t||0!==t.length){var i=!0,r=!1,n=void 0;try{for(var o,a=t[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var s=o.value;if(h(s))return void e(s)}}catch(e){r=!0,n=e}finally{try{!i&&a.return&&a.return()}finally{if(r)throw n}}e(null)}else e(null)}):e(null)})},s.loadModel=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new Promise(function(t,i){var r=e.mtlPath,a=e.objPath,s=e.OBJLoader||(n.THREE?n.THREE.OBJLoader:null),l=e.MTLLoader||(n.THREE?n.THREE.MTLLoader:null);if(e.objPath)if(s)if(!e.mtlPath||l){var u=Promise.resolve();r&&(u=function(e,t){return new Promise(function(i,r){var n=new t;n.setTexturePath(e.substr(0,e.lastIndexOf("/")+1)),n.setMaterialOptions({ignoreZeroRGBs:!0}),n.load(e,i,o,r)})}(r,l)),u.then(function(e){return e&&e.preload(),function(e,t,i){return new Promise(function(r,n){var a=new i;t&&(Object.keys(t.materials).forEach(function(e){return function(e){0===e.opacity&&(e.opacity=1)}(t.materials[e])}),a.setMaterials(t)),a.load(e,r,o,n)})}(a,e,s)}).then(t,i)}else i(new Error("Missing MTLLoader as fourth argument, or window.THREE.MTLLoader existence"));else i(new Error("Missing OBJLoader as third argument, or window.THREE.OBJLoader existence"));else i(new Error("`objPath` must be specified."))})};var c=new t.Matrix4,d=new t.Vector3,f=new t.Quaternion,v=new t.Vector3;s.placeObjectAtHit=function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(!t||!t.modelMatrix)throw new Error("placeObjectAtHit requires a VRHit object");c.fromArray(t.modelMatrix),c.decompose(d,f,v),1===i?(e.position.copy(d),r&&e.quaternion.copy(f)):(e.position.lerp(d,i),r&&e.quaternion.slerp(f,i))};var p=s.placeObjectAtHit;s.getRandomPaletteColor=function(){return a[Math.floor(Math.random()*a.length)]};var m=s.getRandomPaletteColor;s.displayUnsupportedMessage=function(e){var t=document.createElement("div");t.id="webgl-error-message",t.style.fontFamily="monospace",t.style.fontSize="13px",t.style.fontWeight="normal",t.style.textAlign="center",t.style.background="#fff",t.style.border="1px solid black",t.style.color="#000",t.style.padding="1.5em",t.style.width="400px",t.style.margin="5em auto 0",t.innerHTML="string"==typeof e?e:'This augmented reality experience requires\n WebARonARCore or WebARonARKit, experimental browsers from Google\n for Android and iOS. Learn more at the <a href="https://developers.google.com/ar/develop/web/getting-started">Google Developers site</a>.',document.body.appendChild(t)};var y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_=(function(){function e(e){this.value=e}function t(t){function i(n,o){try{var a=t[n](o),s=a.value;s instanceof e?Promise.resolve(s.value).then(function(e){i("next",e)},function(e){i("throw",e)}):r(a.done?"return":"normal",a.value)}catch(e){r("throw",e)}}function r(e,t){switch(e){case"return":n.resolve({value:t,done:!0});break;case"throw":n.reject(t);break;default:n.resolve({value:t,done:!1})}(n=n.next)?i(n.key,n.arg):o=null}var n,o;this._invoke=function(e,t){return new Promise(function(r,a){var s={key:e,arg:t,resolve:r,reject:a,next:null};o?o=o.next=s:(n=o=s,i(e,t))})},"function"!=typeof t.return&&(this.return=void 0)}"function"==typeof Symbol&&Symbol.asyncIterator&&(t.prototype[Symbol.asyncIterator]=function(){return this}),t.prototype.next=function(e){return this._invoke("next",e)},t.prototype.throw=function(e){return this._invoke("throw",e)},t.prototype.return=function(e){return this._invoke("return",e)}}(),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}),E=function(){function e(e,t){for(var i=0;i<t.length;i++){var r=t[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,i,r){return i&&e(t.prototype,i),r&&e(t,r),t}}(),g=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},b=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},w=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var i=[],r=!0,n=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done)&&(i.push(a.value),!t||i.length!==t);r=!0);}catch(e){n=!0,o=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw o}}return i}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),R=new t.RawShaderMaterial({side:t.DoubleSide,transparent:!0,uniforms:{dotColor:{value:new t.Color(16777215)},lineColor:{value:new t.Color(7368816)},backgroundColor:{value:new t.Color(4210752)},dotRadius:{value:.006666666667},alpha:{value:.4}},vertexShader:"precision mediump float;precision mediump int;uniform mat4 modelViewMatrix;uniform mat4 modelMatrix;uniform mat4 projectionMatrix;attribute vec3 position;varying vec3 vPosition;void main(){vPosition=(modelMatrix*vec4(position,1.0)).xyz;gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0);}",fragmentShader:"precision highp float;varying vec3 vPosition;\n#define countX 7.0\n#define countY 4.0\n#define gridAlpha 0.75\nuniform float dotRadius;uniform vec3 dotColor;uniform vec3 lineColor;uniform vec3 backgroundColor;uniform float alpha;float Circle(in vec2 p,float r){return length(p)-r;}float Line(in vec2 p,in vec2 a,in vec2 b){vec2 pa=p-a;vec2 ba=b-a;float t=clamp(dot(pa,ba)/dot(ba,ba),0.0,1.0);vec2 pt=a+t*ba;return length(pt-p);}float Union(float a,float b){return min(a,b);}void main(){vec2 count=vec2(countX,countY);vec2 size=vec2(1.0)/count;vec2 halfSize=size*0.5;vec2 uv=mod(vPosition.xz*1.5,size)-halfSize;float dots=Circle(uv-vec2(halfSize.x,0.0),dotRadius);dots=Union(dots,Circle(uv+vec2(halfSize.x,0.0),dotRadius));dots=Union(dots,Circle(uv+vec2(0.0,halfSize.y),dotRadius));dots=Union(dots,Circle(uv-vec2(0.0,halfSize.y),dotRadius));float lines=Line(uv,vec2(0.0,halfSize.y),-vec2(halfSize.x,0.0));lines=Union(lines,Line(uv,vec2(0.0,-halfSize.y),-vec2(halfSize.x,0.0)));lines=Union(lines,Line(uv,vec2(0.0,-halfSize.y),vec2(halfSize.x,0.0)));lines=Union(lines,Line(uv,vec2(0.0,halfSize.y),vec2(halfSize.x,0.0)));lines=Union(lines,Line(uv,vec2(-halfSize.x,halfSize.y),vec2(halfSize.x,halfSize.y)));lines=Union(lines,Line(uv,vec2(-halfSize.x,-halfSize.y),vec2(halfSize.x,-halfSize.y)));lines=Union(lines,Line(uv,vec2(-halfSize.x,0.0),vec2(halfSize.x,0.0)));lines=clamp(smoothstep(0.0,0.0035,lines),0.0,1.0);dots=clamp(smoothstep(0.0,0.001,dots),0.0,1.0);float result=Union(dots,lines);gl_FragColor=vec4(mix(backgroundColor+mix(dotColor,lineColor,dots),backgroundColor,result),mix(gridAlpha,alpha,result));}"}),T=function(e){function i(e){_(this,i);var t=b(this,(i.__proto__||Object.getPrototypeOf(i)).call(this));return t.addPlane_=function(e){var i=t.createPlane(e);i&&(t.add(i),t.planes.set(e.identifier,i))},t.removePlane_=function(e){var i=t.planes.get(e);i&&t.remove(i),t.planes.delete(e)},t.onPlaneAdded_=function(e){e.planes.forEach(function(e){return t.addPlane_(e)})},t.onPlaneUpdated_=function(e){var i=!0,r=!1,n=void 0;try{for(var o,a=e.planes[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var s=o.value;t.removePlane_(s.identifier),t.addPlane_(s)}}catch(e){r=!0,n=e}finally{try{!i&&a.return&&a.return()}finally{if(r)throw n}}},t.onPlaneRemoved_=function(e){var i=!0,r=!1,n=void 0;try{for(var o,a=e.planes[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var s=o.value;t.removePlane_(s.identifier)}}catch(e){r=!0,n=e}finally{try{!i&&a.return&&a.return()}finally{if(r)throw n}}},t.vrDisplay=e,t.planes=new Map,t.materials=new Map,t}return g(i,e),E(i,[{key:"enable",value:function(){this.vrDisplay.getPlanes().forEach(this.addPlane_),this.vrDisplay.addEventListener("planesadded",this.onPlaneAdded_),this.vrDisplay.addEventListener("planesupdated",this.onPlaneUpdated_),this.vrDisplay.addEventListener("planesremoved",this.onPlaneRemoved_)}},{key:"disable",value:function(){this.vrDisplay.removeEventListener("planesadded",this.onPlaneAdded_),this.vrDisplay.removeEventListener("planesupdated",this.onPlaneUpdated_),this.vrDisplay.removeEventListener("planesremoved",this.onPlaneRemoved_);var e=!0,t=!1,i=void 0;try{for(var r,n=this.planes.keys()[Symbol.iterator]();!(e=(r=n.next()).done);e=!0){var o=r.value;this.removePlane_(o)}}catch(e){t=!0,i=e}finally{try{!e&&n.return&&n.return()}finally{if(t)throw i}}this.materials.clear()}},{key:"createPlane",value:function(e){if(0==e.vertices.length)return null;for(var i=new t.Geometry,r=0;r<e.vertices.length/3;r++)i.vertices.push(new t.Vector3(e.vertices[3*r],e.vertices[3*r+1],e.vertices[3*r+2]));for(var n=0;n<i.vertices.length-2;n++)i.faces.push(new t.Face3(0,n+1,n+2));var o=void 0;if(this.materials.has(e.identifier))o=this.materials.get(e.identifier);else{var a=m();(o=R.clone()).uniforms.backgroundColor.value=a,this.materials.set(e.identifier,o)}var s=new t.Mesh(i,o),l=e.modelMatrix;return s.matrixAutoUpdate=!1,s.matrix.set(l[0],l[4],l[8],l[12],l[1],l[5],l[9],l[13],l[2],l[6],l[10],l[14],l[3],l[7],l[11],l[15]),this.add(s),s}},{key:"size",value:function(){return this.planes.size}}]),i}(t.Object3D),x={open:!0,showLastHit:!0,showPoseStatus:!0,showPlanes:!1},A=500,D=new Map,P=function(){function e(t,i,r){_(this,e),void 0===r&&i&&"Scene"!==i.type&&(r=i,i=null),this.config=Object.assign({},x,r),this.vrDisplay=t,this._view=new C({open:this.config.open}),this.config.showLastHit&&this.vrDisplay.hitTest&&this._view.addRow("hit-test",new F(t)),this.config.showPoseStatus&&this.vrDisplay.getFrameData&&this._view.addRow("pose-status",new U(t)),this.config.showPlanes&&this.vrDisplay.getPlanes&&(i?this._view.addRow("show-planes",new B(t,i)):console.warn("ARDebug `{ showPlanes: true }` option requires passing in a THREE.Scene as the second parameter in the constructor."))}return E(e,[{key:"open",value:function(){this._view.open()}},{key:"close",value:function(){this._view.close()}},{key:"getElement",value:function(){return this._view.getElement()}}]),e}(),C=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_(this,e),this.rows=new Map,this.el=document.createElement("div"),this.el.style.backgroundColor="#333",this.el.style.padding="5px",this.el.style.fontFamily="Roboto, Ubuntu, Arial, sans-serif",this.el.style.color="rgb(165, 165, 165)",this.el.style.position="absolute",this.el.style.right="20px",this.el.style.top="0px",this.el.style.width="200px",this.el.style.fontSize="12px",this.el.style.zIndex=9999,this._rowsEl=document.createElement("div"),this._rowsEl.style.transitionProperty="max-height",this._rowsEl.style.transitionDuration="0.5s",this._rowsEl.style.transitionDelay="0s",this._rowsEl.style.transitionTimingFunction="ease-out",this._rowsEl.style.overflow="hidden",this._controls=document.createElement("div"),this._controls.style.fontSize="13px",this._controls.style.fontWeight="bold",this._controls.style.paddingTop="5px",this._controls.style.textAlign="center",this._controls.style.cursor="pointer",this._controls.addEventListener("click",this.toggleControls.bind(this)),t.open?this.open():this.close(),this.el.appendChild(this._rowsEl),this.el.appendChild(this._controls)}return E(e,[{key:"toggleControls",value:function(){this._isOpen?this.close():this.open()}},{key:"open",value:function(){this._rowsEl.style.maxHeight="100px",this._isOpen=!0,this._controls.textContent="Close ARDebug";var e=!0,t=!1,i=void 0;try{for(var r,n=this.rows[Symbol.iterator]();!(e=(r=n.next()).done);e=!0){var o=r.value;w(o,2)[1].enable()}}catch(e){t=!0,i=e}finally{try{!e&&n.return&&n.return()}finally{if(t)throw i}}}},{key:"close",value:function(){this._rowsEl.style.maxHeight="0px",this._isOpen=!1,this._controls.textContent="Open ARDebug";var e=!0,t=!1,i=void 0;try{for(var r,n=this.rows[Symbol.iterator]();!(e=(r=n.next()).done);e=!0){var o=r.value;w(o,2)[1].disable()}}catch(e){t=!0,i=e}finally{try{!e&&n.return&&n.return()}finally{if(t)throw i}}}},{key:"getElement",value:function(){return this.el}},{key:"addRow",value:function(e,t){this.rows.set(e,t),this._isOpen&&t.enable(),this._rowsEl.appendChild(t.getElement())}}]),e}(),S=function(){function e(t){_(this,e),this.el=document.createElement("div"),this.el.style.width="100%",this.el.style.borderTop="1px solid rgb(54, 54, 54)",this.el.style.borderBottom="1px solid #14171A",this.el.style.position="relative",this.el.style.padding="3px 0px",this.el.style.overflow="hidden",this._titleEl=document.createElement("span"),this._titleEl.style.fontWeight="bold",this._titleEl.textContent=t,this._dataEl=document.createElement("span"),this._dataEl.style.position="absolute",this._dataEl.style.left="40px",this._dataElText=document.createTextNode(""),this._dataEl.appendChild(this._dataElText),this.el.appendChild(this._titleEl),this.el.appendChild(this._dataEl),this._throttledWriteToDOM=function(e,t,i){var r=void 0,n=void 0;return function(){for(var o=arguments.length,a=Array(o),s=0;s<o;s++)a[s]=arguments[s];var l=+new Date,u=void 0;r&&(u=r+t-l),void 0==u||u<0?(r=l,e.apply(i,a)):u>=0&&(clearTimeout(n),n=setTimeout(function(){r=l,e.apply(i,a)},u))}}(this._writeToDOM,A,this)}return E(e,[{key:"enable",value:function(){throw new Error("Implement in child class")}},{key:"disable",value:function(){throw new Error("Implement in child class")}},{key:"getElement",value:function(){return this.el}},{key:"update",value:function(e,t,i){i?this._writeToDOM(e,t):this._throttledWriteToDOM(e,t)}},{key:"_writeToDOM",value:function(e,t){this._dataElText.nodeValue=e,this._dataEl.style.color=t?"#00ff00":"#ff0077"}}]),e}(),F=function(e){function t(e){_(this,t);var i=b(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Hit"));return i.vrDisplay=e,i._onHitTest=i._onHitTest.bind(i),i._nativeHitTest=D.get("hitTest")||i.vrDisplay.hitTest,D.set("hitTest",i._nativeHitTest),i._didPreviouslyHit=null,i}return g(t,S),E(t,[{key:"enable",value:function(){this.vrDisplay.hitTest=this._onHitTest}},{key:"disable",value:function(){this.vrDisplay.hitTest=this._nativeHitTest}},{key:"_hitToString",value:function(e){var t=e.modelMatrix;return t[12].toFixed(2)+", "+t[13].toFixed(2)+", "+t[14].toFixed(2)}},{key:"_onHitTest",value:function(e,t){var i=this._nativeHitTest.call(this.vrDisplay,e,t),r=(parseInt(performance.now(),10)/1e3).toFixed(1),n=i&&i.length,o=(n?this._hitToString(i[0]):"MISS")+" @ "+r+"s";return this.update(o,n,n!==this._didPreviouslyHit),this._didPreviouslyHit=n,i}}]),t}(),U=function(e){function t(e){_(this,t);var i=b(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Pose"));return i.vrDisplay=e,i._onGetFrameData=i._onGetFrameData.bind(i),i._nativeGetFrameData=D.get("getFrameData")||i.vrDisplay.getFrameData,D.set("getFrameData",i._nativeGetFrameData),i.update("Looking for position...",!1,!0),i._initialPose=!1,i}return g(t,S),E(t,[{key:"enable",value:function(){this.vrDisplay.getFrameData=this._onGetFrameData}},{key:"disable",value:function(){this.vrDisplay.getFrameData=this._nativeGetFrameData}},{key:"_poseToString",value:function(e){return e[0].toFixed(2)+", "+e[1].toFixed(2)+", "+e[2].toFixed(2)}},{key:"_onGetFrameData",value:function(e){var t=this._nativeGetFrameData.call(this.vrDisplay,e),i=e&&e.pose&&e.pose.position,r=i&&"number"==typeof i[0]&&"number"==typeof i[1]&&"number"==typeof i[2]&&!(0===i[0]&&0===i[1]&&0===i[2]);if(!this._initialPose&&!r)return t;var n=r!==this._lastPoseValid;return r?this.update(this._poseToString(i),!0,n):r||!1===this._lastPoseValid||this.update("Position lost",!1,n),this._lastPoseValid=r,this._initialPose=!0,t}}]),t}(),B=function(e){function t(e,i){_(this,t);var r=b(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Planes"));return r.vrDisplay=e,r.planes=new T(r.vrDisplay),r._onPoll=r._onPoll.bind(r),r.update("Looking for planes...",!1,!0),i&&i.add(r.planes),r}return g(t,S),E(t,[{key:"enable",value:function(){this._timer&&this.disable(),this._timer=setInterval(this._onPoll,500),this.planes.enable()}},{key:"disable",value:function(){clearInterval(this._timer),this._timer=null,this.planes.disable()}},{key:"_planesToString",value:function(e){return e+" plane"+(1===e?"":"s")+" found"}},{key:"_onPoll",value:function(){var e=this.planes.size();this._lastPlaneCount!==e&&this.update(this._planesToString(e),e>0,!0),this._lastPlaneCount=e}}]),t}(),k=void 0,O=function(e){function t(e,i,r,n,o){_(this,t);var a=b(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,i,r,n,o));return a.isARPerpsectiveCamera=!0,a.vrDisplay=e,a.updateProjectionMatrix(),e&&e.capabilities.hasPassThroughCamera||console.warn("ARPerspectiveCamera does not a VRDisplay with\n a pass through camera. Using supplied values and defaults\n instead of device camera intrinsics"),a}return g(t,e),E(t,[{key:"updateProjectionMatrix",value:function(){var e=this.getProjectionMatrix();e?this.projectionMatrix.fromArray(e):function e(t,i,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,i);if(void 0===n){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,i,r)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(r)}(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"updateProjectionMatrix",this).call(this)}},{key:"getProjectionMatrix",value:function(){return this.vrDisplay&&this.vrDisplay.getFrameData?(k||(k=new VRFrameData),this.vrDisplay.getFrameData(k),k.leftProjectionMatrix):null}}]),t}(t.PerspectiveCamera),M=function(e){function i(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.02,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:.05,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:16711799,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:.25;_(this,i);var s=new t.RingGeometry(r,n,36,64),l=new t.MeshBasicMaterial({color:o});s.applyMatrix((new t.Matrix4).makeRotationX(t.Math.degToRad(-90)));var u=b(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,s,l));return u.visible=!1,u.easing=a,u.applyOrientation=!0,u.vrDisplay=e,u._planeDir=new t.Vector3,u}return g(i,e),E(i,[{key:"update",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:.5,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5;if(this.vrDisplay&&this.vrDisplay.hitTest){var i=this.vrDisplay.hitTest(e,t);i&&i.length>0&&(this.visible=!0,p(this,i[0],this.applyOrientation,this.easing))}}}]),i}(t.Mesh),L="attribute vec3 aVertexPosition;attribute vec2 aTextureCoord;varying vec2 vTextureCoord;void main(void){gl_Position=vec4(aVertexPosition,1.0);vTextureCoord=aTextureCoord;}",I="precision mediump float;varying vec2 vTextureCoord;uniform sampler2D uSampler;void main(void){gl_FragColor=texture2D(uSampler,vTextureCoord);}",N="\n#extension GL_OES_EGL_image_external : require\nprecision mediump float;varying vec2 vTextureCoord;uniform samplerExternalOES uSampler;void main(void){gl_FragColor=texture2D(uSampler,vTextureCoord);}",j=function(e,t,i){if(t){for(var r=[],n=null,o=0;o<t.length;++o)switch(a=t[o]){case e.TEXTURE_BINDING_2D:case e.TEXTURE_BINDING_CUBE_MAP:if((l=t[++o])<e.TEXTURE0||l>e.TEXTURE31){console.error("TEXTURE_BINDING_2D or TEXTURE_BINDING_CUBE_MAP must be followed by a valid texture unit"),r.push(null,null);break}n||(n=e.getParameter(e.ACTIVE_TEXTURE)),e.activeTexture(l),r.push(e.getParameter(a),null);break;case e.ACTIVE_TEXTURE:n=e.getParameter(e.ACTIVE_TEXTURE),r.push(null);break;default:r.push(e.getParameter(a))}for(i(e),o=0;o<t.length;++o){var a=t[o],s=r[o];switch(a){case e.ACTIVE_TEXTURE:break;case e.ARRAY_BUFFER_BINDING:e.bindBuffer(e.ARRAY_BUFFER,s);break;case e.COLOR_CLEAR_VALUE:e.clearColor(s[0],s[1],s[2],s[3]);break;case e.COLOR_WRITEMASK:e.colorMask(s[0],s[1],s[2],s[3]);break;case e.CURRENT_PROGRAM:e.useProgram(s);break;case e.ELEMENT_ARRAY_BUFFER_BINDING:e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,s);break;case e.FRAMEBUFFER_BINDING:e.bindFramebuffer(e.FRAMEBUFFER,s);break;case e.RENDERBUFFER_BINDING:e.bindRenderbuffer(e.RENDERBUFFER,s);break;case e.TEXTURE_BINDING_2D:if((l=t[++o])<e.TEXTURE0||l>e.TEXTURE31)break;e.activeTexture(l),e.bindTexture(e.TEXTURE_2D,s);break;case e.TEXTURE_BINDING_CUBE_MAP:var l=t[++o];if(l<e.TEXTURE0||l>e.TEXTURE31)break;e.activeTexture(l),e.bindTexture(e.TEXTURE_CUBE_MAP,s);break;case e.VIEWPORT:e.viewport(s[0],s[1],s[2],s[3]);break;case e.BLEND:case e.CULL_FACE:case e.DEPTH_TEST:case e.SCISSOR_TEST:case e.STENCIL_TEST:s?e.enable(a):e.disable(a);break;default:console.log("No GL restore behavior for 0x"+a.toString(16))}n&&e.activeTexture(n)}}else i(e)},H=function(){function e(t,n){_(this,e),this.vrDisplay=t,this.gl=n,this.vrDisplay&&(this.passThroughCamera=t.getPassThroughCamera(),this.passThroughCamera instanceof Image?(this.textureTarget=n.TEXTURE_2D,this.fragmentSource=I):(this.textureTarget=n.TEXTURE_EXTERNAL_OES,this.fragmentSource=N),this.program=function(e,t,r){var n=i(e,t,"vertex"),o=i(e,r,"fragment");if(!o)return null;var a=e.createProgram();return e.attachShader(a,n),e.attachShader(a,o),e.linkProgram(a),e.getProgramParameter(a,e.LINK_STATUS)||alert("Could not initialise arview shaders"),a}(n,L,this.fragmentSource)),n.useProgram(this.program),this.vertexPositionAttribute=n.getAttribLocation(this.program,"aVertexPosition"),this.textureCoordAttribute=n.getAttribLocation(this.program,"aTextureCoord"),this.samplerUniform=n.getUniformLocation(this.program,"uSampler"),this.vertexPositionBuffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.vertexPositionBuffer);var o=new Float32Array([-1,1,0,-1,-1,0,1,1,0,1,-1,0]);n.bufferData(n.ARRAY_BUFFER,o,n.STATIC_DRAW),this.vertexPositionBuffer.itemSize=3,this.vertexPositionBuffer.numItems=12,this.textureCoordBuffer=n.createBuffer(),n.bindBuffer(n.ARRAY_BUFFER,this.textureCoordBuffer);var a=null;if(this.vrDisplay){var s=window.WebARonARKitSendsCameraFrames?1:this.passThroughCamera.width/this.passThroughCamera.textureWidth,l=window.WebARonARKitSendsCameraFrames?1:this.passThroughCamera.height/this.passThroughCamera.textureHeight;a=[[0,0,0,l,s,0,s,l],[s,0,0,0,s,l,0,l],[s,l,s,0,0,l,0,0],[0,l,s,l,0,0,s,0]]}else a=[[0,0,0,1,1,0,1,1],[1,0,0,0,1,1,0,1],[1,1,1,0,0,1,0,0],[0,1,1,1,0,0,1,0]];this.f32TextureCoords=[];for(var u=0;u<a.length;u++)this.f32TextureCoords.push(new Float32Array(a[u]));this.combinedOrientation=r(screen.orientation?screen.orientation.angle:window.orientation,this.passThroughCamera.orientation),n.bufferData(n.ARRAY_BUFFER,this.f32TextureCoords[this.combinedOrientation],n.STATIC_DRAW),this.textureCoordBuffer.itemSize=2,this.textureCoordBuffer.numItems=8,n.bindBuffer(n.ARRAY_BUFFER,null),this.indexBuffer=n.createBuffer(),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this.indexBuffer);var h=new Uint16Array([0,1,2,2,1,3]);return n.bufferData(n.ELEMENT_ARRAY_BUFFER,h,n.STATIC_DRAW),this.indexBuffer.itemSize=1,this.indexBuffer.numItems=6,n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,null),this.texture=n.createTexture(),n.useProgram(null),this.projectionMatrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],this.mvMatrix=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],this}return E(e,[{key:"render",value:function(){var e=this,t=this.gl,i=[t.ARRAY_BUFFER_BINDING,t.ELEMENT_ARRAY_BUFFER_BINDING,t.CURRENT_PROGRAM,t.TEXTURE_BINDING_2D];j(t,i,function(){if(0!==e.passThroughCamera.textureWidth&&0!==e.passThroughCamera.textureHeight){var i=t.getParameter(t.UNPACK_FLIP_Y_WEBGL),n=t.getParameter(t.FRONT_FACE);t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!1),t.frontFace(t.CCW),t.useProgram(e.program),t.bindBuffer(t.ARRAY_BUFFER,e.vertexPositionBuffer),t.enableVertexAttribArray(e.vertexPositionAttribute),t.vertexAttribPointer(e.vertexPositionAttribute,e.vertexPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,e.textureCoordBuffer);var o=r(screen.orientation?screen.orientation.angle:window.orientation,e.passThroughCamera.orientation);o!==e.combinedOrientation&&(e.combinedOrientation=o,t.bufferData(t.ARRAY_BUFFER,e.f32TextureCoords[e.combinedOrientation],t.STATIC_DRAW)),t.enableVertexAttribArray(e.textureCoordAttribute),t.vertexAttribPointer(e.textureCoordAttribute,e.textureCoordBuffer.itemSize,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE0),t.bindTexture(e.textureTarget,e.texture),t.texImage2D(e.textureTarget,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e.passThroughCamera),t.uniform1i(e.samplerUniform,0),window.WebARonARKitSendsCameraFrames&&(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR)),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,e.indexBuffer),t.drawElements(t.TRIANGLES,e.indexBuffer.numItems,t.UNSIGNED_SHORT,0),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,i),t.frontFace(n)}})}}]),e}(),z=function(){function e(t,i){_(this,e),this.vrDisplay=t,u(this.vrDisplay)&&!window.WebARonARKitSendsCameraFrames||(this.renderer=i,this.gl=i.context,this.videoRenderer=new H(t,this.gl),this.width=window.innerWidth,this.height=window.innerHeight,window.addEventListener("resize",this.onWindowResize.bind(this),!1))}return E(e,[{key:"onWindowResize",value:function(){this.width=window.innerWidth,this.height=window.innerHeight}},{key:"render",value:function(){if(!u(this.vrDisplay)||window.WebARonARKitSendsCameraFrames){var e=this.gl,t=window.devicePixelRatio,i=this.width*t,r=this.height*t;e.viewportWidth!==i&&(e.viewportWidth=i),e.viewportHeight!==r&&(e.viewportHeight=r),this.gl.viewport(0,0,e.viewportWidth,e.viewportHeight),this.videoRenderer.render()}}}]),e}(),G=function(e){function i(e){_(this,i);var r=b(this,(i.__proto__||Object.getPrototypeOf(i)).call(this));if(!(e instanceof window.VRDisplay))throw new Error("A correct VRDisplay instance is required to initialize an ARAnchorManager.");if("function"!=typeof e.getAnchors)throw new Error("VRDisplay does not support anchors. Upgrade to latest AR browser to get anchor support.");return r.vrDisplay_=e,r.anchorsToObject3Ds_=new Map,r.object3DsToAnchors_=new Map,r.vrDisplay_.addEventListener("anchorsupdated",function(e){return r.onAnchorsUpdated_(e)}),r.scale_=new t.Vector3,r.matrix_=new t.Matrix4,r}return g(i,e),E(i,[{key:"add",value:function(e){if(!(e instanceof t.Object3D))throw new Error("Invalid Object3D trying to add an anchor");if(this.object3DsToAnchors_.has(e))return this;this.scale_.set(1,1,1),this.matrix_.compose(e.position,e.quaternion,this.scale_);var i=this.vrDisplay_.addAnchor(this.matrix_.elements);return this.anchorsToObject3Ds_.set(i,e),this.object3DsToAnchors_.set(e,i),this}},{key:"remove",value:function(e){if(!(e instanceof t.Object3D))throw new Error("Invalid Object3D trying to remove anchor");var i=this.object3DsToAnchors_.get(e);return!!i&&(this.anchorsToObject3Ds_.delete(i),this.object3DsToAnchors_.delete(e),this.vrDisplay_.removeAnchor(i),!0)}},{key:"onAnchorsUpdated_",value:function(e){var t=[],i=!0,r=!1,n=void 0;try{for(var o,a=e.anchors[Symbol.iterator]();!(i=(o=a.next()).done);i=!0){var s=o.value,l=this.anchorsToObject3Ds_.get(s);l&&(l.matrix.fromArray(s.modelMatrix),l.matrix.decompose(l.position,l.quaternion,this.scale_),t.push(l))}}catch(e){r=!0,n=e}finally{try{!i&&a.return&&a.return()}finally{if(r)throw n}}this.dispatchEvent({type:"anchorsupdated",anchors:t})}}]),i}(t.EventDispatcher);!function(){if(window.webarSpeechRecognitionInstance){!function(e){e.listeners={},e.addEventListener=function(e,t){if(!t)return this;var i=this.listeners[e];return i||(this.listeners[e]=i=[]),i.indexOf(t)<0&&i.push(t),this},e.removeEventListener=function(e,t){if(!t)return this;var i=this.listeners[e];if(i){var r=i.indexOf(t);r>=0&&(this.listeners[e]=i.splice(r,1))}return this},e.callEventListeners=function(e,t){t||(t={target:this}),t.target||(t.target=this),t.type=e;var i="on"+e;"function"==typeof this[i]&&this[i](t);var r=this.listeners[e];if(r)for(var n=0;n<r.length;n++){var o=y(r[n]);"object"===o?r[n].handleEvent(t):"function"===o&&r[n](t)}return this}}(window.webarSpeechRecognitionInstance),window.webkitSpeechRecognition=function(){return window.webarSpeechRecognitionInstance}}}(),"undefined"!=typeof window&&"object"===y(window.THREE)&&(window.THREE.ARDebug=P,window.THREE.ARPerspectiveCamera=O,window.THREE.ARReticle=M,window.THREE.ARUtils=s,window.THREE.ARView=z,window.THREE.ARAnchorManager=G),e.ARDebug=P,e.ARPerspectiveCamera=O,e.ARReticle=M,e.ARUtils=s,e.ARView=z,e.ARAnchorManager=G,Object.defineProperty(e,"__esModule",{value:!0})});