diff --git a/dist/xeokit-sdk.cjs.js b/dist/xeokit-sdk.cjs.js index 5e6d5c9a0c..8bd460075a 100644 --- a/dist/xeokit-sdk.cjs.js +++ b/dist/xeokit-sdk.cjs.js @@ -18879,7 +18879,7 @@ class Perspective extends Component { const WIDTH_INDEX = 2; const HEIGHT_INDEX = 3; - const boundary = this.scene.viewport.boundary; + const boundary = this.scene.canvas.boundary; const aspect = boundary[WIDTH_INDEX] / boundary[HEIGHT_INDEX]; const fovAxis = this._fovAxis; @@ -19181,7 +19181,7 @@ class Ortho extends Component { const scale = this._scale; const halfSize = 0.5 * scale; - const boundary = scene.viewport.boundary; + const boundary = scene.canvas.boundary; const boundaryWidth = boundary[WIDTH_INDEX]; const boundaryHeight = boundary[HEIGHT_INDEX]; const aspect = boundaryWidth / boundaryHeight; diff --git a/dist/xeokit-sdk.es.js b/dist/xeokit-sdk.es.js index 2cf90ca161..316023d6b8 100644 --- a/dist/xeokit-sdk.es.js +++ b/dist/xeokit-sdk.es.js @@ -18875,7 +18875,7 @@ class Perspective extends Component { const WIDTH_INDEX = 2; const HEIGHT_INDEX = 3; - const boundary = this.scene.viewport.boundary; + const boundary = this.scene.canvas.boundary; const aspect = boundary[WIDTH_INDEX] / boundary[HEIGHT_INDEX]; const fovAxis = this._fovAxis; @@ -19177,7 +19177,7 @@ class Ortho extends Component { const scale = this._scale; const halfSize = 0.5 * scale; - const boundary = scene.viewport.boundary; + const boundary = scene.canvas.boundary; const boundaryWidth = boundary[WIDTH_INDEX]; const boundaryHeight = boundary[HEIGHT_INDEX]; const aspect = boundaryWidth / boundaryHeight; diff --git a/dist/xeokit-sdk.es5.js b/dist/xeokit-sdk.es5.js index 85d8e0b692..23376d44ef 100644 --- a/dist/xeokit-sdk.es5.js +++ b/dist/xeokit-sdk.es5.js @@ -4923,7 +4923,7 @@ var tolerance=2;this.on("mousedown",function(params){downX=params[0];downY=param */_this29.camera=camera;_this29._state=new RenderState({matrix:math.mat4(),inverseMatrix:math.mat4(),transposedMatrix:math.mat4(),near:0.1,far:2000.0});_this29._inverseMatrixDirty=true;_this29._transposedMatrixDirty=true;_this29._fov=60.0;// Recompute aspect from change in canvas size _this29._canvasResized=_this29.scene.canvas.on("boundary",_this29._needUpdate,_assertThisInitialized(_this29));_this29.fov=cfg.fov;_this29.fovAxis=cfg.fovAxis;_this29.near=cfg.near;_this29.far=cfg.far;return _this29;}_createClass(Perspective,[{key:"type",get:/** @private - */function get(){return"Perspective";}},{key:"_update",value:function _update(){var WIDTH_INDEX=2;var HEIGHT_INDEX=3;var boundary=this.scene.viewport.boundary;var aspect=boundary[WIDTH_INDEX]/boundary[HEIGHT_INDEX];var fovAxis=this._fovAxis;var fov=this._fov;if(fovAxis==="x"||fovAxis==="min"&&aspect<1||fovAxis==="max"&&aspect>1){fov=fov/aspect;}fov=Math.min(fov,120);math.perspectiveMat4(fov*(Math.PI/180.0),aspect,this._state.near,this._state.far,this._state.matrix);this._inverseMatrixDirty=true;this._transposedMatrixDirty=true;this.glRedraw();this.camera._updateScheduled=true;this.fire("matrix",this._state.matrix);}/** + */function get(){return"Perspective";}},{key:"_update",value:function _update(){var WIDTH_INDEX=2;var HEIGHT_INDEX=3;var boundary=this.scene.canvas.boundary;var aspect=boundary[WIDTH_INDEX]/boundary[HEIGHT_INDEX];var fovAxis=this._fovAxis;var fov=this._fov;if(fovAxis==="x"||fovAxis==="min"&&aspect<1||fovAxis==="max"&&aspect>1){fov=fov/aspect;}fov=Math.min(fov,120);math.perspectiveMat4(fov*(Math.PI/180.0),aspect,this._state.near,this._state.far,this._state.matrix);this._inverseMatrixDirty=true;this._transposedMatrixDirty=true;this.glRedraw();this.camera._updateScheduled=true;this.fire("matrix",this._state.matrix);}/** * Sets the Perspective's field-of-view angle (FOV). * * Fires an "fov" event on change. @@ -5032,7 +5032,7 @@ this.fire("far",this._state.far);}},{key:"matrix",get:function get(){if(this._up * @final */_this30.camera=camera;_this30._state=new RenderState({matrix:math.mat4(),inverseMatrix:math.mat4(),transposedMatrix:math.mat4(),near:0.1,far:2000.0});_this30._inverseMatrixDirty=true;_this30._transposedMatrixDirty=true;_this30.scale=cfg.scale;_this30.near=cfg.near;_this30.far=cfg.far;_this30._onCanvasBoundary=_this30.scene.canvas.on("boundary",_this30._needUpdate,_assertThisInitialized(_this30));return _this30;}_createClass(Ortho,[{key:"type",get:/** @private - */function get(){return"Ortho";}},{key:"_update",value:function _update(){var WIDTH_INDEX=2;var HEIGHT_INDEX=3;var scene=this.scene;var scale=this._scale;var halfSize=0.5*scale;var boundary=scene.viewport.boundary;var boundaryWidth=boundary[WIDTH_INDEX];var boundaryHeight=boundary[HEIGHT_INDEX];var aspect=boundaryWidth/boundaryHeight;var left;var right;var top;var bottom;if(boundaryWidth>boundaryHeight){left=-halfSize;right=halfSize;top=halfSize/aspect;bottom=-halfSize/aspect;}else{left=-halfSize*aspect;right=halfSize*aspect;top=halfSize;bottom=-halfSize;}math.orthoMat4c(left,right,bottom,top,this._state.near,this._state.far,this._state.matrix);this._inverseMatrixDirty=true;this._transposedMatrixDirty=true;this.glRedraw();this.fire("matrix",this._state.matrix);}/** + */function get(){return"Ortho";}},{key:"_update",value:function _update(){var WIDTH_INDEX=2;var HEIGHT_INDEX=3;var scene=this.scene;var scale=this._scale;var halfSize=0.5*scale;var boundary=scene.canvas.boundary;var boundaryWidth=boundary[WIDTH_INDEX];var boundaryHeight=boundary[HEIGHT_INDEX];var aspect=boundaryWidth/boundaryHeight;var left;var right;var top;var bottom;if(boundaryWidth>boundaryHeight){left=-halfSize;right=halfSize;top=halfSize/aspect;bottom=-halfSize/aspect;}else{left=-halfSize*aspect;right=halfSize*aspect;top=halfSize;bottom=-halfSize;}math.orthoMat4c(left,right,bottom,top,this._state.near,this._state.far,this._state.matrix);this._inverseMatrixDirty=true;this._transposedMatrixDirty=true;this.glRedraw();this.fire("matrix",this._state.matrix);}/** * Sets scale factor for this Ortho's extents on X and Y axis. * * Clamps to minimum value of ````0.01```. diff --git a/dist/xeokit-sdk.min.cjs.js b/dist/xeokit-sdk.min.cjs.js index 472d5e0d57..acf256caeb 100644 --- a/dist/xeokit-sdk.min.cjs.js +++ b/dist/xeokit-sdk.min.cjs.js @@ -1,4 +1,4 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let r=!0,l=r?Float64Array:Float32Array;const o=new l(16),c=new l(16),u=new l(4),h={setDoublePrecisionEnabled(e){r=e,l=r?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>r,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new l(e||2),vec3:e=>new l(e||3),vec4:e=>new l(e||4),mat3:e=>new l(e||9),mat3ToMat4:(e,t=new l(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new l(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new l(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new l(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new l(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new l(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new l(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||h.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new l([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>h.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new l(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new l(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>h.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new l(9));const n=e[0],i=e[3],a=e[6],r=e[1],o=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+o*I+c*v,s[4]=r*d+o*y+c*w,s[7]=r*f+o*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.translationMat4v(e,i))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=h.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,p,A,d,f,I;return u=l*o,p=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||h.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*p+d,s[7]=0,s[8]=r*A+f,s[9]=r*p-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>h.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,p=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=p+v,s[2]=A-m,s[3]=0,s[4]=p-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const n=h.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],p=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(p,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(p,-1,1)),Math.abs(p)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(p,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(p,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=h.mat4())=>(h.quaternionToRotationMat4(t,n),h.scaleMat4v(s,n),h.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new l(3),t=new l(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=h.lenVec3(e);h.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,p=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=p,t[9]*=p,t[10]*=p,h.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=h.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],p=t[1],A=t[2];if(i===u&&a===p&&r===A)return h.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-p,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>h.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=h.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];h.addVec4(i,n,o),h.subVec4(i,n,c);const a=2*n[2],r=c[0],l=c[1],u=c[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=o[0]/r,s[9]=o[1]/l,s[10]=-o[2]/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/u,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],h.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=h.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new l(16),t=new l(16),s=new l(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||h.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||h.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const n=e[0]*h.DEGTORAD/2,i=e[1]*h.DEGTORAD/2,a=e[2]*h.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),p=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"YXZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"ZXY"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"ZYX"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"YZX"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o-c*u*p):"XZY"===t&&(s[0]=c*l*o-r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o+c*u*p),s},mat4ToQuaternion(e,t=h.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let p;const A=s+r+u;return A>0?(p=.5/Math.sqrt(A+1),t[3]=.25/p,t[0]=(c-l)*p,t[1]=(i-o)*p,t[2]=(a-n)*p):s>r&&s>u?(p=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/p,t[0]=.25*p,t[1]=(n+a)/p,t[2]=(i+o)/p):r>u?(p=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/p,t[0]=(n+a)/p,t[1]=.25*p,t[2]=(l+c)/p):(p=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/p,t[0]=(i+o)/p,t[1]=(l+c)/p,t[2]=.25*p),t},vec3PairToQuaternion(e,t,s=h.vec4()){const n=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let i=n+h.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):h.cross3Vec3(e,t,s),s[3]=i,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new l(16);return(t,s,n)=>(n=n||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=h.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,p=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+p*-o-A*-l,s[1]=p*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-p*-r,s},quaternionToMat4(e,t){t=h.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,p=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+p,t[2]=f-u,t[4]=d-p,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=h.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,u))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new l(e||6),AABB2:e=>new l(e||4),OBB3:e=>new l(e||32),OBB2:e=>new l(e||16),Sphere3:(e,t,s,n)=>new l([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new l(3),t=new l(3),s=new l(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=h.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],p=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>p?u:p,Math.abs(h.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new l(3);return(t,s,n)=>{s=s||h.AABB3();let i,a,r,l=h.MAX_DOUBLE,o=h.MAX_DOUBLE,c=h.MAX_DOUBLE,u=h.MIN_DOUBLE,p=h.MIN_DOUBLE,A=h.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>p&&(p=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=p,s[5]=A,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new l(3);return(t,s)=>{s=s||h.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=p);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ip&&(p=u);return n[3]=p,n}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=h.AABB2()){let s,n,i,a,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=h.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,p=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+p*p+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=p/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3);return(a,r,l,o,c,u)=>{u=u||h.vec3();const p=h.subVec3(o,l,e),A=h.subVec3(c,l,t),d=h.cross3Vec3(r,A,s),f=h.dotVec3(p,d);if(f<1e-6)return null;const I=h.subVec3(a,l,n),y=h.dotVec3(I,d);if(y<0||y>f)return null;const m=h.cross3Vec3(I,p,i),v=h.dotVec3(r,m);if(v<0||y+v>f)return null;const w=h.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3);return(i,a,r,l,o,c)=>{c=c||h.vec3(),a=h.normalizeVec3(a,e);const u=h.subVec3(l,r,t),p=h.subVec3(o,r,s),A=h.cross3Vec3(u,p,n);h.normalizeVec3(A,A);const d=-h.dotVec3(r,A),f=-(h.dotVec3(i,A)+d)/h.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i,a,r,l)=>{const o=h.subVec3(r,i,e),c=h.subVec3(a,i,t),u=h.subVec3(n,i,s),p=h.dotVec3(o,o),A=h.dotVec3(o,c),d=h.dotVec3(o,u),f=h.dotVec3(c,c),I=h.dotVec3(c,u),y=p*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(p*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=h.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3);return(r,l,o)=>{let c,u;const p=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3),r=new l(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let p=0;p>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,p;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new l(4),t=new l(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,h.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],h.transformVec3(s,e,t),h.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new l(16),t=new l(16),s=new l(4),n=new l(4),i=new l(4),a=new l(4);return(r,l,o,c,u,p)=>{const A=h.mulMat4(o,l,e),d=h.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,h.transformVec4(d,s,n),h.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,h.transformVec4(d,i,a),h.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],h.subVec3(a,n,p),h.normalizeVec3(p)}})(),canvasPosToLocalRay:(()=>{const e=new l(3),t=new l(3);return(s,n,i,a,r,l,o)=>{h.canvasPosToWorldRay(s,n,i,r,e,t),h.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new l(16),t=new l(4),s=new l(4);return(n,i,a,r,l)=>{const o=h.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,h.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],h.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new l(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return o.triangles=s,o.leaf=!0,o;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),o.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};h.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class p{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const A={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var d=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{v.removeItem(e.id),delete P.scenes[e.id],delete m[e.id],A.components.scenes--}))},this.clear=function(){let e;for(const t in P.scenes)P.scenes.hasOwnProperty(t)&&(e=P.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete P.scenes[e.id]))},this.scheduleTask=function(e,t){w.push(e),w.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;w.length>0&&(e<0||n0&&E>0){var t=1e3/E;D+=t,T.push(t),T.length>=30&&(D-=T.shift()),A.frame.fps=Math.round(D/T.length)}!function(e){const t=P.runTasks(e+10),s=P.getNumTasks();A.frame.tasksRun=t,A.frame.tasksScheduled=s,A.frame.tasksBudget=10}(e),function(e){for(var t in g.time=e,P.scenes)if(P.scenes.hasOwnProperty(t)){var s=P.scenes[t];g.sceneId=t,g.startTime=s.startTime,g.deltaTime=null!=g.prevTime?g.time-g.prevTime:0,s.fire("tick",g,!0)}g.prevTime=e}(e),function(){const e=P.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=m[r],n||(n=m[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),b=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R);class C{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof C))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+y.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(y.isNumeric(s)||y.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+y.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+y.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+y.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():P.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(h.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){z.set(this._viewPos),z[3]=1,h.transformPoint4(this.scene.camera.projMatrix,z,K);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+K[0]/K[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-K[1]/K[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof W?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),O(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class X{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class q{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class J{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var Z=h.vec3(),$=h.vec3();class ee extends C{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new Y(s,t.origin),this._cornerMarker=new Y(s,t.corner),this._targetMarker=new Y(s,t.target),this._originWorld=h.vec3(),this._cornerWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new X(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new X(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new J(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,p=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&se(t[0],p)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(se(n[0],A),A[0]>p[0]+5||A[0]p[1]+5||A[1]{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const ie=h.vec3(),ae=h.vec3(),re=h.vec3();class le extends C{get type(){return"Spinner"}constructor(e,t={}){super(e,t),this._canvas=t.canvas,this._element=null,this._isCustom=!1,t.elementId&&(this._element=document.getElementById(t.elementId),this._element?this._adjustPosition():this.error("Can't find given Spinner HTML element: '"+t.elementId+"' - will automatically create default element")),this._element||this._createDefaultSpinner(),this.processes=0}_createDefaultSpinner(){this._injectDefaultCSS();const e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const oe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},ce=document.createElement("canvas");if(ce){const e=ce.getContext("webgl",{antialias:!0})||ce.getContext("experimental-webgl",{antialias:!0});oe.WEBGL=!!e,oe.WEBGL&&(oe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="mediump":oe.FS_MAX_FLOAT_PRECISION="lowp":oe.FS_MAX_FLOAT_PRECISION="mediump",oe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),oe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),oe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),oe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),oe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),oe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),oe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),oe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),oe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),oe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){oe.SUPPORTED_EXTENSIONS[e]=!0})))}const ue=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class he extends C{constructor(e,t={}){super(e,t),this._backgroundColor=h.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new le(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+h.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function ve(e){console.error(e.join("\n"))}class we{constructor(e,t){this.id=ye.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new de(e,e.VERTEX_SHADER,me(this.source.vertex)),this._fragmentShader=new de(e,e.FRAGMENT_SHADER,me(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ve(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ve(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ve(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Te{constructor(e,t){this.scene=e,this.aabb=h.AABB3(),this.origin=h.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Te(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Te(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new we(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,p=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Pe[0]=a,Pe[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,p),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Pe),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new we(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new ge(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new ge(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Ce=new Float32Array(xe(17,[0,1])),_e=new Float32Array(xe(17,[1,0])),Be=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Ne(n,t));return s}(17,4)),Oe=new Float32Array(2);class Se{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new we(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new ge(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new ge(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Oe[0]=r,Oe[1]=l,n.uniform2fv(this._uViewport,Oe),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,_e):n.uniform2fv(this._uSampleOffsets,Ce),n.uniform1fv(this._uSampleWeights,Be);const p=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,p,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Ne(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function xe(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Le{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=r.size[0];r.size[1];const n=t%s-Math.floor(s/2),i=Math.floor(t/s)-Math.floor(s/2),a=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));m.push({x:n,y:i,dist:a,result:[d[e+0],d[e+1],d[e+2],d[e+3]]})}let v=null;if(m.length>0){m.sort(((e,t)=>e.dist-t.dist)),m=m[0].result;const e=A[m[3]],t=e.origin,s=e.coordinateScale;v=[m[0]*s[0]+t[0],m[1]*s[1]+t[1],m[2]*s[2]+t[2]]}if(null===f&&null==v)return null;let w=null;return null!==v&&(w=t.camera.projectWorldPos(v)),{worldPos:f,snappedWorldPos:v,snappedCanvasPos:w}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new De(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}const Ge=new e({});class Ve{constructor(e){this.id=Ge.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Ge.removeItem(this.id)}}class je extends C{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new Ve({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class ke extends C{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.viewport.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),h.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Qe extends C{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.viewport.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),h.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class We extends C{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){h.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class ze extends C{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Ke=h.vec3(),Ye=h.vec3(),Xe=h.vec3(),qe=h.vec3(),Je=h.vec3(),Ze=h.vec3(),$e=h.vec4(),et=h.vec4(),tt=h.vec4(),st=h.mat4(),nt=h.mat4(),it=h.vec3(),at=h.vec3(),rt=h.vec3(),lt=h.vec3();class ot extends C{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new Ve({deviceMatrix:h.mat4(),hasDeviceMatrix:!1,matrix:h.mat4(),normalMatrix:h.mat4(),inverseMatrix:h.mat4()}),this._perspective=new ke(this),this._ortho=new Qe(this),this._frustum=new We(this),this._customProjection=new ze(this),this._project=this._perspective,this._eye=h.vec3([0,0,10]),this._look=h.vec3([0,0,0]),this._up=h.vec3([0,1,0]),this._worldUp=h.vec3([0,1,0]),this._worldRight=h.vec3([1,0,0]),this._worldForward=h.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(h.subVec3(this._eye,this._look,it),h.normalizeVec3(it,at),h.mulVec3Scalar(at,1e3,rt),h.addVec3(this._look,rt,lt),t=lt):t=this._eye,e.hasDeviceMatrix?(h.lookAtMat4v(t,this._look,this._up,nt),h.mulMat4(e.deviceMatrix,nt,e.matrix)):h.lookAtMat4v(t,this._look,this._up,e.matrix),h.inverseMat4(this._state.matrix,this._state.inverseMatrix),h.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=h.subVec3(this._eye,this._look,Ke);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,st),t=h.transformPoint3(st,t,Ye),this.eye=h.addVec3(this._look,t,Xe),this.up=h.transformPoint3(st,this._up,qe)}orbitPitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._eye,this._look,Ke);const s=h.cross3Vec3(h.normalizeVec3(t,Ye),h.normalizeVec3(this._up,Xe));h.rotationMat4v(.0174532925*e,s,st),t=h.transformPoint3(st,t,qe),this.up=h.transformPoint3(st,this._up,Je),this.eye=h.addVec3(t,this._look,Ze)}yaw(e){let t=h.subVec3(this._look,this._eye,Ke);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,st),t=h.transformPoint3(st,t,Ye),this.look=h.addVec3(t,this._eye,Xe),this._gimbalLock&&(this.up=h.transformPoint3(st,this._up,qe))}pitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._look,this._eye,Ke);const s=h.cross3Vec3(h.normalizeVec3(t,Ye),h.normalizeVec3(this._up,Xe));h.rotationMat4v(.0174532925*e,s,st),this.up=h.transformPoint3(st,this._up,Ze),t=h.transformPoint3(st,t,qe),this.look=h.addVec3(t,this._eye,Je)}pan(e){const t=h.subVec3(this._eye,this._look,Ke),s=[0,0,0];let n;if(0!==e[0]){const i=h.cross3Vec3(h.normalizeVec3(t,[]),h.normalizeVec3(this._up,Ye));n=h.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=h.mulVec3Scalar(h.normalizeVec3(this._up,Xe),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=h.mulVec3Scalar(h.normalizeVec3(t,qe),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=h.addVec3(this._eye,s,Je),this.look=h.addVec3(this._look,s,Ze)}zoom(e){const t=h.subVec3(this._eye,this._look,Ke),s=Math.abs(h.lenVec3(t,Ye)),n=Math.abs(s+e);if(n<.5)return;const i=h.normalizeVec3(t,Xe);this.eye=h.addVec3(this._look,h.mulVec3Scalar(i,n),qe)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=h.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return h.lenVec3(h.subVec3(this._look,this._eye,Ke))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=$e,s=et,n=tt;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,h.mulMat4v4(this.viewMatrix,t,s),h.mulMat4v4(this.projMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}class ct extends C{get type(){return"Light"}get isLight(){return!0}constructor(e,t={}){super(e,t)}}class ut extends ct{get type(){return"DirLight"}constructor(e,t={}){super(e,t),this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,n=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new Ve({type:"dir",dir:h.vec3([1,1,1]),color:h.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=h.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];h.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=h.identityMat4()),h.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Le(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}class ht extends ct{get type(){return"AmbientLight"}constructor(e,t={}){super(e,t),this._state={type:"ambient",color:h.vec3([.7,.7,.7]),intensity:1},this.color=t.color,this.intensity=t.intensity,this.scene._lightCreated(this)}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}get intensity(){return this._state.intensity}destroy(){super.destroy(),this.scene._lightDestroyed(this)}}class pt extends C{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),A.memory.meshes++}destroy(){super.destroy(),A.memory.meshes--}}var At=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const dt=function(){const e=h.mat4(),t=h.mat4();return function(s,n){n=n||h.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([l/u,o/u,c/u],t),h.mulMat4(e,t,n),n}}();var ft=function(){const e=h.mat4(),t=h.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function mt(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function vt(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const wt={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=yt(e,l,"floor","ceil"),n=mt(s),a=vt(e,l,n),a>r&&(i=s,r=a),s=yt(e,l,"ceil","ceil"),n=mt(s),a=vt(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},gt=A.memory,Tt=h.AABB3();class Et extends pt{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Ve({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=wt.getPositionsBounds(t.positions),n=wt.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=wt.getUVBounds(t.uv),n=wt.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=wt.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),gt.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),gt.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new ge(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),gt.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new ge(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),gt.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new ge(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),gt.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new ge(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),gt.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=At(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),gt.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=h.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new ge(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),gt.positions+=this._pickTrianglePositionsBuf.numItems,gt.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),wt.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=wt.getPositionsBounds(e),n=wt.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),wt.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),wt.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=h.AABB3()),h.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=h.OBB3()),h.positions3ToAABB3(this._state.positions,Tt,this._state.positionsDecodeMatrix),h.AABB3ToOBB3(Tt,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),gt.meshes--}}function bt(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return y.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}class Dt extends C{get type(){return"Material"}constructor(e,t={}){super(e,t),A.memory.materials++}destroy(){super.destroy(),A.memory.materials--}}const Pt={opaque:0,mask:1,blend:2},Rt=["opaque","mask","blend"];class Ct extends Dt{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new Ve({type:"PhongMaterial",ambient:h.vec3([1,1,1]),diffuse:h.vec3([1,1,1]),specular:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=Pt[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Rt[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}const _t={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Bt extends Dt{get type(){return"EmphasisMaterial"}get presets(){return _t}constructor(e,t={}){super(e,t),this._state=new Ve({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=_t[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(_t).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Ot={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class St extends Dt{get type(){return"EdgeMaterial"}get presets(){return Ot}constructor(e,t={}){super(e,t),this._state=new Ve({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ot[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ot).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Nt={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class xt extends C{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=h.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return Nt}set units(e){e||(e="meters");Nt[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=h.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=h.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class Lt extends C{constructor(e,t={}){super(e,t),this._supported=oe.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const Mt={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class Ft extends Dt{get type(){return"PointsMaterial"}get presets(){return Mt}constructor(e,t={}){super(e,t),this._state=new Ve({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=Mt[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Mt).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Ht={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class Ut extends Dt{get type(){return"LinesMaterial"}get presets(){return Ht}constructor(e,t={}){super(e,t),this._state=new Ve({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ht[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ht).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Gt=h.vec3(),Vt=h.vec3(),jt=h.mat4();class kt{constructor(){this.normal=h.vec3(),this.offset=0,this.testVertex=h.vec3()}set(e,t,s,n){const i=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=s*i,this.offset=n*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Qt{constructor(){this.planes=[new kt,new kt,new kt,new kt,new kt,new kt]}}function Wt(e,t,s){const n=h.mulMat4(s,t,jt),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],p=n[7],A=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,p-o,I-A,w-y),e.planes[1].set(l+i,p+o,I+A,w+y),e.planes[2].set(l-a,p-c,I-d,w-m),e.planes[3].set(l+a,p+c,I+d,w+m),e.planes[4].set(l-r,p-u,I-f,w-v),e.planes[5].set(l+r,p+u,I+f,w+v)}function zt(e,t){let s=Qt.INSIDE;const n=Gt,i=Vt;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Qt.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Qt.INTERSECT)}return s}Qt.INSIDE=0,Qt.INTERSECT=1,Qt.OUTSIDE=2;class Kt{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class Yt{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new Kt(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class Xt extends C{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var Zt=qt.exports.RBush3D,$t=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let r=!0,l=r?Float64Array:Float32Array;const o=new l(16),c=new l(16),u=new l(4),h={setDoublePrecisionEnabled(e){r=e,l=r?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>r,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new l(e||2),vec3:e=>new l(e||3),vec4:e=>new l(e||4),mat3:e=>new l(e||9),mat3ToMat4:(e,t=new l(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new l(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new l(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new l(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>h.dotVec4(e,e),lenVec4:e=>Math.sqrt(h.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>h.dotVec3(e,e),sqLenVec2:e=>h.dotVec2(e,e),lenVec3:e=>Math.sqrt(h.sqLenVec3(e)),distVec3:(()=>{const e=new l(3);return(t,s)=>h.lenVec3(h.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(h.sqLenVec2(e)),distVec2:(()=>{const e=new l(2);return(t,s)=>h.lenVec2(h.subVec2(t,s,e))})(),rcpVec3:(e,t)=>h.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/h.lenVec4(e);return h.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/h.lenVec3(e);return h.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/h.lenVec2(e);return h.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=h.dotVec3(e,t)/Math.sqrt(h.sqLenVec3(e)*h.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new l(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=h.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=h.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=h.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||h.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>h.m4s(0),setMat4ToOnes:()=>h.m4s(1),diagonalMat4v:e=>new l([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>h.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>h.diagonalMat4c(e,e,e,e),identityMat4:(e=new l(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new l(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>h.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new l(9));const n=e[0],i=e[3],a=e[6],r=e[1],o=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+o*I+c*v,s[4]=r*d+o*y+c*w,s[7]=r*f+o*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=h.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||h.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||h.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.translationMat4v(e,i))})(),translationMat4s:(e,t)=>h.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>h.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=h.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,p,A,d,f,I;return u=l*o,p=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||h.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*p+d,s[7]=0,s[8]=r*A+f,s[9]=r*p-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>h.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=h.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=h.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new l(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,h.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>h.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=h.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,p=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=p+v,s[2]=A-m,s[3]=0,s[4]=p-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=h.vec4()){const n=h.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],p=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(p,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(p,-1,1)),Math.abs(p)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(p,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(p,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=h.mat4())=>(h.quaternionToRotationMat4(t,n),h.scaleMat4v(s,n),h.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new l(3),t=new l(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=h.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=h.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=h.lenVec3(e);h.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,p=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=p,t[9]*=p,t[10]*=p,h.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=h.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],p=t[1],A=t[2];if(i===u&&a===p&&r===A)return h.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-p,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>h.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=h.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];h.addVec4(i,n,o),h.subVec4(i,n,c);const a=2*n[2],r=c[0],l=c[1],u=c[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=o[0]/r,s[9]=o[1]/l,s[10]=-o[2]/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/u,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=h.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],h.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=h.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new l(16),t=new l(16),s=new l(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||h.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||h.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=h.vec4()){const n=e[0]*h.DEGTORAD/2,i=e[1]*h.DEGTORAD/2,a=e[2]*h.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),p=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"YXZ"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"ZXY"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o-c*u*p):"ZYX"===t?(s[0]=c*l*o-r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o+c*u*p):"YZX"===t?(s[0]=c*l*o+r*u*p,s[1]=r*u*o+c*l*p,s[2]=r*l*p-c*u*o,s[3]=r*l*o-c*u*p):"XZY"===t&&(s[0]=c*l*o-r*u*p,s[1]=r*u*o-c*l*p,s[2]=r*l*p+c*u*o,s[3]=r*l*o+c*u*p),s},mat4ToQuaternion(e,t=h.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let p;const A=s+r+u;return A>0?(p=.5/Math.sqrt(A+1),t[3]=.25/p,t[0]=(c-l)*p,t[1]=(i-o)*p,t[2]=(a-n)*p):s>r&&s>u?(p=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/p,t[0]=.25*p,t[1]=(n+a)/p,t[2]=(i+o)/p):r>u?(p=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/p,t[0]=(n+a)/p,t[1]=.25*p,t[2]=(l+c)/p):(p=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/p,t[0]=(i+o)/p,t[1]=(l+c)/p,t[2]=.25*p),t},vec3PairToQuaternion(e,t,s=h.vec4()){const n=Math.sqrt(h.dotVec3(e,e)*h.dotVec3(t,t));let i=n+h.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):h.cross3Vec3(e,t,s),s[3]=i,h.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=h.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new l(16);return(t,s,n)=>(n=n||h.vec3(),h.quaternionToRotationMat4(t,e),h.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=h.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=h.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,p=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+p*-o-A*-l,s[1]=p*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-p*-r,s},quaternionToMat4(e,t){t=h.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,p=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+p,t[2]=f-u,t[4]=d-p,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=h.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>h.normalizeQuaternion(h.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=h.vec4()){const s=(e=h.normalizeQuaternion(e,u))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new l(e||6),AABB2:e=>new l(e||4),OBB3:e=>new l(e||32),OBB2:e=>new l(e||16),Sphere3:(e,t,s,n)=>new l([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new l(3),t=new l(3),s=new l(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],h.subVec3(t,e,s),Math.abs(h.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=h.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],p=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>p?u:p,Math.abs(h.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||h.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||h.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=h.AABB3())=>(e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MAX_DOUBLE,e[3]=h.MIN_DOUBLE,e[4]=h.MIN_DOUBLE,e[5]=h.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=h.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new l(3);return(t,s,n)=>{s=s||h.AABB3();let i,a,r,l=h.MAX_DOUBLE,o=h.MAX_DOUBLE,c=h.MAX_DOUBLE,u=h.MIN_DOUBLE,p=h.MIN_DOUBLE,A=h.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>p&&(p=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=p,s[5]=A,s}})(),OBB3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=h.AABB3()){let s,n,i,a=h.MAX_DOUBLE,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE,u=h.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new l(3);return(t,s)=>{s=s||h.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=p);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new l(3),t=new l(3);return(s,n)=>{n=n||h.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ip&&(p=u);return n[3]=p,n}})(),getSphere3Center:(e,t=h.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=h.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=h.MAX_DOUBLE,e[1]=h.MAX_DOUBLE,e[2]=h.MIN_DOUBLE,e[3]=h.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=h.AABB2()){let s,n,i,a,r=h.MAX_DOUBLE,l=h.MAX_DOUBLE,o=h.MIN_DOUBLE,c=h.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=h.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,p=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+p*p+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=p/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3);return(a,r,l,o,c,u)=>{u=u||h.vec3();const p=h.subVec3(o,l,e),A=h.subVec3(c,l,t),d=h.cross3Vec3(r,A,s),f=h.dotVec3(p,d);if(f<1e-6)return null;const I=h.subVec3(a,l,n),y=h.dotVec3(I,d);if(y<0||y>f)return null;const m=h.cross3Vec3(I,p,i),v=h.dotVec3(r,m);if(v<0||y+v>f)return null;const w=h.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new l(3),t=new l(3),s=new l(3),n=new l(3);return(i,a,r,l,o,c)=>{c=c||h.vec3(),a=h.normalizeVec3(a,e);const u=h.subVec3(l,r,t),p=h.subVec3(o,r,s),A=h.cross3Vec3(u,p,n);h.normalizeVec3(A,A);const d=-h.dotVec3(r,A),f=-(h.dotVec3(i,A)+d)/h.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new l(3),t=new l(3),s=new l(3);return(n,i,a,r,l)=>{const o=h.subVec3(r,i,e),c=h.subVec3(a,i,t),u=h.subVec3(n,i,s),p=h.dotVec3(o,o),A=h.dotVec3(o,c),d=h.dotVec3(o,u),f=h.dotVec3(c,c),I=h.dotVec3(c,u),y=p*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(p*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=h.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3);return(r,l,o)=>{let c,u;const p=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new l(3),t=new l(3),s=new l(3),n=new l(3),i=new l(3),a=new l(3),r=new l(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let p=0;p>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,p;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new l(4),t=new l(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,h.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],h.transformVec3(s,e,t),h.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new l(16),t=new l(16),s=new l(4),n=new l(4),i=new l(4),a=new l(4);return(r,l,o,c,u,p)=>{const A=h.mulMat4(o,l,e),d=h.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,h.transformVec4(d,s,n),h.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,h.transformVec4(d,i,a),h.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],h.subVec3(a,n,p),h.normalizeVec3(p)}})(),canvasPosToLocalRay:(()=>{const e=new l(3),t=new l(3);return(s,n,i,a,r,l,o)=>{h.canvasPosToWorldRay(s,n,i,r,e,t),h.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new l(16),t=new l(4),s=new l(4);return(n,i,a,r,l)=>{const o=h.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,h.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],h.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new l(6),o={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return o.triangles=s,o.leaf=!0,o;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),o.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};h.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class p{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const A={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var d=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{v.removeItem(e.id),delete P.scenes[e.id],delete m[e.id],A.components.scenes--}))},this.clear=function(){let e;for(const t in P.scenes)P.scenes.hasOwnProperty(t)&&(e=P.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete P.scenes[e.id]))},this.scheduleTask=function(e,t){w.push(e),w.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;w.length>0&&(e<0||n0&&E>0){var t=1e3/E;D+=t,T.push(t),T.length>=30&&(D-=T.shift()),A.frame.fps=Math.round(D/T.length)}!function(e){const t=P.runTasks(e+10),s=P.getNumTasks();A.frame.tasksRun=t,A.frame.tasksScheduled=s,A.frame.tasksBudget=10}(e),function(e){for(var t in g.time=e,P.scenes)if(P.scenes.hasOwnProperty(t)){var s=P.scenes[t];g.sceneId=t,g.startTime=s.startTime,g.deltaTime=null!=g.prevTime?g.time-g.prevTime:0,s.fire("tick",g,!0)}g.prevTime=e}(e),function(){const e=P.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=m[r],n||(n=m[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),b=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(R):requestAnimationFrame(R);class C{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof C))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+y.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(y.isNumeric(s)||y.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+y.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+y.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+y.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():P.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(h.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){z.set(this._viewPos),z[3]=1,h.transformPoint4(this.scene.camera.projMatrix,z,K);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+K[0]/K[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-K[1]/K[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof W?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),O(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class X{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class q{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class J{constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var Z=h.vec3(),$=h.vec3();class ee extends C{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new Y(s,t.origin),this._cornerMarker=new Y(s,t.corner),this._targetMarker=new Y(s,t.target),this._originWorld=h.vec3(),this._cornerWorld=h.vec3(),this._targetWorld=h.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new q(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new X(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new X(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new J(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(h.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);h.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,p=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&se(t[0],p)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(se(n[0],A),A[0]>p[0]+5||A[0]p[1]+5||A[1]{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";y.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const ie=h.vec3(),ae=h.vec3(),re=h.vec3();class le extends C{get type(){return"Spinner"}constructor(e,t={}){super(e,t),this._canvas=t.canvas,this._element=null,this._isCustom=!1,t.elementId&&(this._element=document.getElementById(t.elementId),this._element?this._adjustPosition():this.error("Can't find given Spinner HTML element: '"+t.elementId+"' - will automatically create default element")),this._element||this._createDefaultSpinner(),this.processes=0}_createDefaultSpinner(){this._injectDefaultCSS();const e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const oe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},ce=document.createElement("canvas");if(ce){const e=ce.getContext("webgl",{antialias:!0})||ce.getContext("experimental-webgl",{antialias:!0});oe.WEBGL=!!e,oe.WEBGL&&(oe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?oe.FS_MAX_FLOAT_PRECISION="mediump":oe.FS_MAX_FLOAT_PRECISION="lowp":oe.FS_MAX_FLOAT_PRECISION="mediump",oe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),oe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),oe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),oe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),oe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),oe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),oe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),oe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),oe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),oe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){oe.SUPPORTED_EXTENSIONS[e]=!0})))}const ue=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class he extends C{constructor(e,t={}){super(e,t),this._backgroundColor=h.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new le(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+h.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function ve(e){console.error(e.join("\n"))}class we{constructor(e,t){this.id=ye.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new de(e,e.VERTEX_SHADER,me(this.source.vertex)),this._fragmentShader=new de(e,e.FRAGMENT_SHADER,me(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ve(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ve(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ve(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ve(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Te{constructor(e,t){this.scene=e,this.aabb=h.AABB3(),this.origin=h.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Te(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Te(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new we(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,p=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Pe[0]=a,Pe[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,p),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Pe),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new we(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new ge(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new ge(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Ce=new Float32Array(xe(17,[0,1])),_e=new Float32Array(xe(17,[1,0])),Be=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Ne(n,t));return s}(17,4)),Oe=new Float32Array(2);class Se{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new we(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new ge(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new ge(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new ge(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=h.mat4();return()=>(e&&h.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Oe[0]=r,Oe[1]=l,n.uniform2fv(this._uViewport,Oe),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,_e):n.uniform2fv(this._uSampleOffsets,Ce),n.uniform1fv(this._uSampleWeights,Be);const p=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,p,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Ne(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function xe(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Le{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=r.size[0];r.size[1];const n=t%s-Math.floor(s/2),i=Math.floor(t/s)-Math.floor(s/2),a=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));m.push({x:n,y:i,dist:a,result:[d[e+0],d[e+1],d[e+2],d[e+3]]})}let v=null;if(m.length>0){m.sort(((e,t)=>e.dist-t.dist)),m=m[0].result;const e=A[m[3]],t=e.origin,s=e.coordinateScale;v=[m[0]*s[0]+t[0],m[1]*s[1]+t[1],m[2]*s[2]+t[2]]}if(null===f&&null==v)return null;let w=null;return null!==v&&(w=t.camera.projectWorldPos(v)),{worldPos:f,snappedWorldPos:v,snappedCanvasPos:w}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new De(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}const Ge=new e({});class Ve{constructor(e){this.id=Ge.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Ge.removeItem(this.id)}}class je extends C{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new Ve({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class ke extends C{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),h.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Qe extends C{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),h.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class We extends C{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){h.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class ze extends C{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new Ve({matrix:h.mat4(),inverseMatrix:h.mat4(),transposedMatrix:h.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(h.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(h.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,h.mulMat4v4(this.inverseMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,h.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Ke=h.vec3(),Ye=h.vec3(),Xe=h.vec3(),qe=h.vec3(),Je=h.vec3(),Ze=h.vec3(),$e=h.vec4(),et=h.vec4(),tt=h.vec4(),st=h.mat4(),nt=h.mat4(),it=h.vec3(),at=h.vec3(),rt=h.vec3(),lt=h.vec3();class ot extends C{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new Ve({deviceMatrix:h.mat4(),hasDeviceMatrix:!1,matrix:h.mat4(),normalMatrix:h.mat4(),inverseMatrix:h.mat4()}),this._perspective=new ke(this),this._ortho=new Qe(this),this._frustum=new We(this),this._customProjection=new ze(this),this._project=this._perspective,this._eye=h.vec3([0,0,10]),this._look=h.vec3([0,0,0]),this._up=h.vec3([0,1,0]),this._worldUp=h.vec3([0,1,0]),this._worldRight=h.vec3([1,0,0]),this._worldForward=h.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(h.subVec3(this._eye,this._look,it),h.normalizeVec3(it,at),h.mulVec3Scalar(at,1e3,rt),h.addVec3(this._look,rt,lt),t=lt):t=this._eye,e.hasDeviceMatrix?(h.lookAtMat4v(t,this._look,this._up,nt),h.mulMat4(e.deviceMatrix,nt,e.matrix)):h.lookAtMat4v(t,this._look,this._up,e.matrix),h.inverseMat4(this._state.matrix,this._state.inverseMatrix),h.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=h.subVec3(this._eye,this._look,Ke);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,st),t=h.transformPoint3(st,t,Ye),this.eye=h.addVec3(this._look,t,Xe),this.up=h.transformPoint3(st,this._up,qe)}orbitPitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._eye,this._look,Ke);const s=h.cross3Vec3(h.normalizeVec3(t,Ye),h.normalizeVec3(this._up,Xe));h.rotationMat4v(.0174532925*e,s,st),t=h.transformPoint3(st,t,qe),this.up=h.transformPoint3(st,this._up,Je),this.eye=h.addVec3(t,this._look,Ze)}yaw(e){let t=h.subVec3(this._look,this._eye,Ke);h.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,st),t=h.transformPoint3(st,t,Ye),this.look=h.addVec3(t,this._eye,Xe),this._gimbalLock&&(this.up=h.transformPoint3(st,this._up,qe))}pitch(e){if(this._constrainPitch&&(e=h.dotVec3(this._up,this._worldUp)/h.DEGTORAD)<1)return;let t=h.subVec3(this._look,this._eye,Ke);const s=h.cross3Vec3(h.normalizeVec3(t,Ye),h.normalizeVec3(this._up,Xe));h.rotationMat4v(.0174532925*e,s,st),this.up=h.transformPoint3(st,this._up,Ze),t=h.transformPoint3(st,t,qe),this.look=h.addVec3(t,this._eye,Je)}pan(e){const t=h.subVec3(this._eye,this._look,Ke),s=[0,0,0];let n;if(0!==e[0]){const i=h.cross3Vec3(h.normalizeVec3(t,[]),h.normalizeVec3(this._up,Ye));n=h.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=h.mulVec3Scalar(h.normalizeVec3(this._up,Xe),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=h.mulVec3Scalar(h.normalizeVec3(t,qe),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=h.addVec3(this._eye,s,Je),this.look=h.addVec3(this._look,s,Ze)}zoom(e){const t=h.subVec3(this._eye,this._look,Ke),s=Math.abs(h.lenVec3(t,Ye)),n=Math.abs(s+e);if(n<.5)return;const i=h.normalizeVec3(t,Xe);this.eye=h.addVec3(this._look,h.mulVec3Scalar(i,n),qe)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=h.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return h.lenVec3(h.subVec3(this._look,this._eye,Ke))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=$e,s=et,n=tt;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,h.mulMat4v4(this.viewMatrix,t,s),h.mulMat4v4(this.projMatrix,s,n),h.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}class ct extends C{get type(){return"Light"}get isLight(){return!0}constructor(e,t={}){super(e,t)}}class ut extends ct{get type(){return"DirLight"}constructor(e,t={}){super(e,t),this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,n=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new Ve({type:"dir",dir:h.vec3([1,1,1]),color:h.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=h.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];h.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=h.identityMat4()),h.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Le(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}class ht extends ct{get type(){return"AmbientLight"}constructor(e,t={}){super(e,t),this._state={type:"ambient",color:h.vec3([.7,.7,.7]),intensity:1},this.color=t.color,this.intensity=t.intensity,this.scene._lightCreated(this)}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}get intensity(){return this._state.intensity}destroy(){super.destroy(),this.scene._lightDestroyed(this)}}class pt extends C{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),A.memory.meshes++}destroy(){super.destroy(),A.memory.meshes--}}var At=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=h.vec3(),u=h.vec3(),p=h.vec3(),A=h.vec3(),d=h.vec3(),f=h.vec3(),I=h.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const dt=function(){const e=h.mat4(),t=h.mat4();return function(s,n){n=n||h.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return h.identityMat4(e),h.translationMat4v(s,e),h.identityMat4(t),h.scalingMat4v([l/u,o/u,c/u],t),h.mulMat4(e,t,n),n}}();var ft=function(){const e=h.mat4(),t=h.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function mt(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function vt(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const wt={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=yt(e,l,"floor","ceil"),n=mt(s),a=vt(e,l,n),a>r&&(i=s,r=a),s=yt(e,l,"ceil","ceil"),n=mt(s),a=vt(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},gt=A.memory,Tt=h.AABB3();class Et extends pt{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new Ve({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=wt.getPositionsBounds(t.positions),n=wt.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=wt.getUVBounds(t.uv),n=wt.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=wt.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),gt.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),gt.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new ge(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),gt.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new ge(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),gt.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new ge(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),gt.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new ge(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),gt.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=At(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new ge(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),gt.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=h.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new ge(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new ge(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),gt.positions+=this._pickTrianglePositionsBuf.numItems,gt.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),wt.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=wt.getPositionsBounds(e),n=wt.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),wt.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),wt.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=h.AABB3()),h.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=h.OBB3()),h.positions3ToAABB3(this._state.positions,Tt,this._state.positionsDecodeMatrix),h.AABB3ToOBB3(Tt,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),gt.meshes--}}function bt(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return y.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}class Dt extends C{get type(){return"Material"}constructor(e,t={}){super(e,t),A.memory.materials++}destroy(){super.destroy(),A.memory.materials--}}const Pt={opaque:0,mask:1,blend:2},Rt=["opaque","mask","blend"];class Ct extends Dt{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new Ve({type:"PhongMaterial",ambient:h.vec3([1,1,1]),diffuse:h.vec3([1,1,1]),specular:h.vec3([1,1,1]),emissive:h.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=Pt[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Rt[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}const _t={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class Bt extends Dt{get type(){return"EmphasisMaterial"}get presets(){return _t}constructor(e,t={}){super(e,t),this._state=new Ve({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=_t[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(_t).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Ot={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class St extends Dt{get type(){return"EdgeMaterial"}get presets(){return Ot}constructor(e,t={}){super(e,t),this._state=new Ve({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ot[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ot).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Nt={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class xt extends C{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=h.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return Nt}set units(e){e||(e="meters");Nt[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=h.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=h.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class Lt extends C{constructor(e,t={}){super(e,t),this._supported=oe.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const Mt={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class Ft extends Dt{get type(){return"PointsMaterial"}get presets(){return Mt}constructor(e,t={}){super(e,t),this._state=new Ve({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=Mt[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Mt).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Ht={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class Ut extends Dt{get type(){return"LinesMaterial"}get presets(){return Ht}constructor(e,t={}){super(e,t),this._state=new Ve({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Ht[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Ht).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Gt=h.vec3(),Vt=h.vec3(),jt=h.mat4();class kt{constructor(){this.normal=h.vec3(),this.offset=0,this.testVertex=h.vec3()}set(e,t,s,n){const i=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=s*i,this.offset=n*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Qt{constructor(){this.planes=[new kt,new kt,new kt,new kt,new kt,new kt]}}function Wt(e,t,s){const n=h.mulMat4(s,t,jt),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],p=n[7],A=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,p-o,I-A,w-y),e.planes[1].set(l+i,p+o,I+A,w+y),e.planes[2].set(l-a,p-c,I-d,w-m),e.planes[3].set(l+a,p+c,I+d,w+m),e.planes[4].set(l-r,p-u,I-f,w-v),e.planes[5].set(l+r,p+u,I+f,w+v)}function zt(e,t){let s=Qt.INSIDE;const n=Gt,i=Vt;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Qt.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Qt.INTERSECT)}return s}Qt.INSIDE=0,Qt.INTERSECT=1,Qt.OUTSIDE=2;class Kt{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class Yt{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new Kt(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class Xt extends C{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var Zt=qt.exports.RBush3D,$t=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT diff --git a/dist/xeokit-sdk.min.es.js b/dist/xeokit-sdk.min.es.js index af9b1282c3..bcd0e10dbf 100644 --- a/dist/xeokit-sdk.min.es.js +++ b/dist/xeokit-sdk.min.es.js @@ -1,4 +1,4 @@ -class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e={}){this._id=t.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==e.hideOnMouseDown&&(document.addEventListener("mousedown",(e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),e.items&&(this.items=e.items),this._hideOnAction=!1!==e.hideOnAction,this.context=e.context,this.enabled=!1!==e.enabled,this.hide()}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e{const a=this._getNextId(),r=new s(a);for(let s=0,a=e.length;s0,c=this._getNextId(),u=s.getTitle||(()=>s.title||""),h=s.doAction||s.callback||(()=>{}),p=s.getEnabled||(()=>!0),A=s.getShown||(()=>!0),d=new i(c,u,h,p,A);if(d.parentMenu=r,l.items.push(d),o){const e=t(n);d.subMenu=e,e.parentItem=d}this._itemList.push(d),this._itemMap[d.id]=d}}return this._menuList.push(r),this._menuMap[r.id]=r,r};this._rootMenu=t(e)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const e=t=>{this._createMenuUI(t);const s=t.groups;for(let t=0,n=s.length;t'),s.push("
    "),t)for(let e=0,n=t.length;e'+o+" [MORE]"):s.push('
  • '+o+"
  • ")}}s.push("
"),s.push("");const n=s.join("");document.body.insertAdjacentHTML("beforeend",n);const i=document.querySelector("."+e.id);e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=e=>{e.preventDefault()};const a=this;let r=null;if(t)for(let e=0,s=t.length;e{e.preventDefault();const s=t.subMenu;if(!s)return void(r&&(a._hideMenu(r.id),r=null));if(r&&r.id!==s.id&&(a._hideMenu(r.id),r=null),!1===t.enabled)return;const n=t.itemElement,i=s.menuElement,l=n.getBoundingClientRect();i.getBoundingClientRect();l.right+200>window.innerWidth?a._showMenu(s.id,l.left-200,l.top-1):a._showMenu(s.id,l.right-5,l.top-1),r=s})),n||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),a._context&&!1!==t.enabled&&(t.doAction&&t.doAction(a._context),this._hideOnAction?a.hide():(a._updateItemsTitles(),a._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(a._context)})))):console.error("ContextMenu item element not found: "+t.id)}}}_updateItemsTitles(){if(this._context)for(let e=0,t=this._itemList.length;ewindow.innerHeight&&(s=window.innerHeight-n),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=s+"px"}_hideMenuElement(e){e.style.display="none"}}class r{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let l=!0,o=l?Float64Array:Float32Array;const c=new o(16),u=new o(16),h=new o(4),p={setDoublePrecisionEnabled(e){l=e,o=l?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>l,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new o(e||2),vec3:e=>new o(e||3),vec4:e=>new o(e||4),mat3:e=>new o(e||9),mat3ToMat4:(e,t=new o(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new o(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new o(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new o(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>p.dotVec4(e,e),lenVec4:e=>Math.sqrt(p.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>p.dotVec3(e,e),sqLenVec2:e=>p.dotVec2(e,e),lenVec3:e=>Math.sqrt(p.sqLenVec3(e)),distVec3:(()=>{const e=new o(3);return(t,s)=>p.lenVec3(p.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(p.sqLenVec2(e)),distVec2:(()=>{const e=new o(2);return(t,s)=>p.lenVec2(p.subVec2(t,s,e))})(),rcpVec3:(e,t)=>p.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/p.lenVec4(e);return p.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/p.lenVec3(e);return p.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/p.lenVec2(e);return p.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=p.dotVec3(e,t)/Math.sqrt(p.sqLenVec3(e)*p.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new o(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=p.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=p.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=p.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||p.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>p.m4s(0),setMat4ToOnes:()=>p.m4s(1),diagonalMat4v:e=>new o([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>p.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>p.diagonalMat4c(e,e,e,e),identityMat4:(e=new o(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new o(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>p.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new o(9));const n=e[0],i=e[3],a=e[6],r=e[1],l=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+l*I+c*v,s[4]=r*d+l*y+c*w,s[7]=r*f+l*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=p.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||p.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||p.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.translationMat4v(e,i))})(),translationMat4s:(e,t)=>p.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>p.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=p.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,h,A,d,f,I;return u=l*o,h=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||p.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*h+d,s[7]=0,s[8]=r*A+f,s[9]=r*h-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>p.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=p.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=p.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>p.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=p.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,h=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=h+v,s[2]=A-m,s[3]=0,s[4]=h-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=p.vec4()){const n=p.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],h=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(h,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(h,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(h,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=p.mat4())=>(p.quaternionToRotationMat4(t,n),p.scaleMat4v(s,n),p.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new o(3),t=new o(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=p.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=p.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=p.lenVec3(e);p.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,h=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=h,t[9]*=h,t[10]*=h,p.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=p.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],h=t[1],A=t[2];if(i===u&&a===h&&r===A)return p.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-h,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>p.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=p.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];p.addVec4(i,n,c),p.subVec4(i,n,u);const a=2*n[2],r=u[0],l=u[1],o=u[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=c[0]/r,s[9]=c[1]/l,s[10]=-c[2]/o,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/o,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],p.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=p.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new o(16),t=new o(16),s=new o(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||p.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||p.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=p.vec4()){const n=e[0]*p.DEGTORAD/2,i=e[1]*p.DEGTORAD/2,a=e[2]*p.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),h=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"YXZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"ZXY"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"ZYX"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"YZX"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o-c*u*h):"XZY"===t&&(s[0]=c*l*o-r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o+c*u*h),s},mat4ToQuaternion(e,t=p.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let h;const A=s+r+u;return A>0?(h=.5/Math.sqrt(A+1),t[3]=.25/h,t[0]=(c-l)*h,t[1]=(i-o)*h,t[2]=(a-n)*h):s>r&&s>u?(h=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/h,t[0]=.25*h,t[1]=(n+a)/h,t[2]=(i+o)/h):r>u?(h=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/h,t[0]=(n+a)/h,t[1]=.25*h,t[2]=(l+c)/h):(h=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/h,t[0]=(i+o)/h,t[1]=(l+c)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=p.vec4()){const n=Math.sqrt(p.dotVec3(e,e)*p.dotVec3(t,t));let i=n+p.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):p.cross3Vec3(e,t,s),s[3]=i,p.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=p.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new o(16);return(t,s,n)=>(n=n||p.vec3(),p.quaternionToRotationMat4(t,e),p.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=p.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,h=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+h*-o-A*-l,s[1]=h*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-h*-r,s},quaternionToMat4(e,t){t=p.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,h=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+h,t[2]=f-u,t[4]=d-h,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=p.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>p.normalizeQuaternion(p.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=p.vec4()){const s=(e=p.normalizeQuaternion(e,h))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new o(e||6),AABB2:e=>new o(e||4),OBB3:e=>new o(e||32),OBB2:e=>new o(e||16),Sphere3:(e,t,s,n)=>new o([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new o(3),t=new o(3),s=new o(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],p.subVec3(t,e,s),Math.abs(p.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=p.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],h=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>h?u:h,Math.abs(p.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||p.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||p.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=p.AABB3())=>(e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MAX_DOUBLE,e[3]=p.MIN_DOUBLE,e[4]=p.MIN_DOUBLE,e[5]=p.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=p.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new o(3);return(t,s,n)=>{s=s||p.AABB3();let i,a,r,l=p.MAX_DOUBLE,o=p.MAX_DOUBLE,c=p.MAX_DOUBLE,u=p.MIN_DOUBLE,h=p.MIN_DOUBLE,A=p.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>h&&(h=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=h,s[5]=A,s}})(),OBB3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new o(3);return(t,s)=>{s=s||p.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=h);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ih&&(h=u);return n[3]=h,n}})(),getSphere3Center:(e,t=p.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=p.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MIN_DOUBLE,e[3]=p.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=p.AABB2()){let s,n,i,a,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=p.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,h=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+h*h+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=h/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3);return(a,r,l,o,c,u)=>{u=u||p.vec3();const h=p.subVec3(o,l,e),A=p.subVec3(c,l,t),d=p.cross3Vec3(r,A,s),f=p.dotVec3(h,d);if(f<1e-6)return null;const I=p.subVec3(a,l,n),y=p.dotVec3(I,d);if(y<0||y>f)return null;const m=p.cross3Vec3(I,h,i),v=p.dotVec3(r,m);if(v<0||y+v>f)return null;const w=p.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3);return(i,a,r,l,o,c)=>{c=c||p.vec3(),a=p.normalizeVec3(a,e);const u=p.subVec3(l,r,t),h=p.subVec3(o,r,s),A=p.cross3Vec3(u,h,n);p.normalizeVec3(A,A);const d=-p.dotVec3(r,A),f=-(p.dotVec3(i,A)+d)/p.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i,a,r,l)=>{const o=p.subVec3(r,i,e),c=p.subVec3(a,i,t),u=p.subVec3(n,i,s),h=p.dotVec3(o,o),A=p.dotVec3(o,c),d=p.dotVec3(o,u),f=p.dotVec3(c,c),I=p.dotVec3(c,u),y=h*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(h*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=p.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3);return(r,l,o)=>{let c,u;const h=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3),r=new o(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let h=0;h>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,h;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new o(4),t=new o(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,p.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],p.transformVec3(s,e,t),p.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new o(16),t=new o(16),s=new o(4),n=new o(4),i=new o(4),a=new o(4);return(r,l,o,c,u,h)=>{const A=p.mulMat4(o,l,e),d=p.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,p.transformVec4(d,s,n),p.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,p.transformVec4(d,i,a),p.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],p.subVec3(a,n,h),p.normalizeVec3(h)}})(),canvasPosToLocalRay:(()=>{const e=new o(3),t=new o(3);return(s,n,i,a,r,l,o)=>{p.canvasPosToWorldRay(s,n,i,r,e,t),p.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new o(16),t=new o(4),s=new o(4);return(n,i,a,r,l)=>{const o=p.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,p.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],p.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new o(6),l={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return l.triangles=s,l.leaf=!0,l;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),l.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};p.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class A{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const d={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var f=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{w.removeItem(e.id),delete R.scenes[e.id],delete v[e.id],d.components.scenes--}))},this.clear=function(){let e;for(const t in R.scenes)R.scenes.hasOwnProperty(t)&&(e=R.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete R.scenes[e.id]))},this.scheduleTask=function(e,t){g.push(e),g.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;g.length>0&&(e<0||n0&&b>0){var t=1e3/b;P+=t,E.push(t),E.length>=30&&(P-=E.shift()),d.frame.fps=Math.round(P/E.length)}!function(e){const t=R.runTasks(e+10),s=R.getNumTasks();d.frame.tasksRun=t,d.frame.tasksScheduled=s,d.frame.tasksBudget=10}(e),function(e){for(var t in T.time=e,R.scenes)if(R.scenes.hasOwnProperty(t)){var s=R.scenes[t];T.sceneId=t,T.startTime=s.startTime,T.deltaTime=null!=T.prevTime?T.time-T.prevTime:0,s.fire("tick",T,!0)}T.prevTime=e}(e),function(){const e=R.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=v[r],n||(n=v[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),D=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C);class _{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof _))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+m.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(m.isNumeric(s)||m.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+m.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+m.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+m.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():R.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(p.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){Y.set(this._viewPos),Y[3]=1,p.transformPoint4(this.scene.camera.projMatrix,Y,X);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+X[0]/X[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-X[1]/X[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof K?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),S(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class J{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class Z{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class ${constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var ee=p.vec3(),te=p.vec3();class se extends _{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new q(s,t.origin),this._cornerMarker=new q(s,t.corner),this._targetMarker=new q(s,t.target),this._originWorld=p.vec3(),this._cornerWorld=p.vec3(),this._targetWorld=p.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new J(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new J(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new $(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(p.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);p.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,h=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&ie(t[0],h)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(ie(n[0],A),A[0]>h[0]+5||A[0]h[1]+5||A[1]{this.fire("mouseOver",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,angleMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get control(){return this._control}get measurements(){return this._measurements}createMeasurement(e={}){this.viewer.scene.components[e.id]&&(this.error("Viewer scene component with this ID already exists: "+e.id),delete e.id);const t=e.origin,s=e.corner,n=e.target,i=new se(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},corner:{entity:s.entity,worldPos:s.worldPos},target:{entity:n.entity,worldPos:n.worldPos},visible:e.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[i.id]=i,i.on("destroyed",(()=>{delete this._measurements[i.id]})),this.fire("measurementCreated",i),i}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}setLabelsShown(e){for(const[t,s]of Object.entries(this.measurements))s.labelShown=e}clear(){const e=Object.keys(this._measurements);for(var t=0,s=e.length;t{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const le=p.vec3(),oe=p.vec3(),ce=p.vec3();class ue extends r{constructor(e,t){super("Annotations",e),this._labelHTML=t.labelHTML||"
",this._markerHTML=t.markerHTML||"
",this._container=t.container||document.body,this._values=t.values||{},this.annotations={},this.surfaceOffset=t.surfaceOffset}getContainerElement(){return this._container}send(e,t){if("clearAnnotations"===e)this.clear()}set surfaceOffset(e){null==e&&(e=.3),this._surfaceOffset=e}get surfaceOffset(){return this._surfaceOffset}createAnnotation(e){var t,s;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){const n=e.pickResult;if(n.worldPos&&n.worldNormal){const e=p.normalizeVec3(n.worldNormal,le),i=p.mulVec3Scalar(e,this._surfaceOffset,oe);t=p.addVec3(n.worldPos,i,ce),s=n.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,s=e.entity;var n=null;e.markerElementId&&((n=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var i=null;e.labelElementId&&((i=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));const a=new re(this.viewer.scene,{id:e.id,plugin:this,entity:s,worldPos:t,container:this._container,markerElement:n,labelElement:i,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:m.apply(e.values,m.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[a.id]=a,a.on("destroyed",(()=>{delete this.annotations[a.id],this.fire("annotationDestroyed",a.id)})),this.fire("annotationCreated",a.id),a}destroyAnnotation(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}clear(){const e=Object.keys(this.annotations);for(var t=0,s=e.length;t
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const pe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},Ae=document.createElement("canvas");if(Ae){const e=Ae.getContext("webgl",{antialias:!0})||Ae.getContext("experimental-webgl",{antialias:!0});pe.WEBGL=!!e,pe.WEBGL&&(pe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="mediump":pe.FS_MAX_FLOAT_PRECISION="lowp":pe.FS_MAX_FLOAT_PRECISION="mediump",pe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),pe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),pe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),pe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),pe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),pe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),pe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),pe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),pe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),pe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){pe.SUPPORTED_EXTENSIONS[e]=!0})))}const de=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class fe extends _{constructor(e,t={}){super(e,t),this._backgroundColor=p.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new he(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+p.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function Ee(e){console.error(e.join("\n"))}class be{constructor(e,t){this.id=ge.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new me(e,e.VERTEX_SHADER,Te(this.source.vertex)),this._fragmentShader=new me(e,e.FRAGMENT_SHADER,Te(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Ee(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Ee(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void Ee(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Pe{constructor(e,t){this.scene=e,this.aabb=p.AABB3(),this.origin=p.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Pe(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Pe(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new be(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,h=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Be[0]=a,Be[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,h),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Be),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new be(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new De(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Se=new Float32Array(He(17,[0,1])),Ne=new Float32Array(He(17,[1,0])),xe=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Fe(n,t));return s}(17,4)),Le=new Float32Array(2);class Me{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new be(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new De(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new De(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Le[0]=r,Le[1]=l,n.uniform2fv(this._uViewport,Le),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,Ne):n.uniform2fv(this._uSampleOffsets,Se),n.uniform1fv(this._uSampleWeights,xe);const h=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,h,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Fe(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function He(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Ue{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=r.size[0];r.size[1];const n=t%s-Math.floor(s/2),i=Math.floor(t/s)-Math.floor(s/2),a=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));m.push({x:n,y:i,dist:a,result:[d[e+0],d[e+1],d[e+2],d[e+3]]})}let v=null;if(m.length>0){m.sort(((e,t)=>e.dist-t.dist)),m=m[0].result;const e=A[m[3]],t=e.origin,s=e.coordinateScale;v=[m[0]*s[0]+t[0],m[1]*s[1]+t[1],m[2]*s[2]+t[2]]}if(null===f&&null==v)return null;let w=null;return null!==v&&(w=t.camera.projectWorldPos(v)),{worldPos:f,snappedWorldPos:v,snappedCanvasPos:w}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new _e(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}const Qe=new e({});class We{constructor(e){this.id=Qe.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Qe.removeItem(this.id)}}class ze extends _{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new We({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Ke extends _{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.viewport.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),p.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Ye extends _{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.viewport.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),p.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class Xe extends _{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){p.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class qe extends _{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Je=p.vec3(),Ze=p.vec3(),$e=p.vec3(),et=p.vec3(),tt=p.vec3(),st=p.vec3(),nt=p.vec4(),it=p.vec4(),at=p.vec4(),rt=p.mat4(),lt=p.mat4(),ot=p.vec3(),ct=p.vec3(),ut=p.vec3(),ht=p.vec3();class pt extends _{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new We({deviceMatrix:p.mat4(),hasDeviceMatrix:!1,matrix:p.mat4(),normalMatrix:p.mat4(),inverseMatrix:p.mat4()}),this._perspective=new Ke(this),this._ortho=new Ye(this),this._frustum=new Xe(this),this._customProjection=new qe(this),this._project=this._perspective,this._eye=p.vec3([0,0,10]),this._look=p.vec3([0,0,0]),this._up=p.vec3([0,1,0]),this._worldUp=p.vec3([0,1,0]),this._worldRight=p.vec3([1,0,0]),this._worldForward=p.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(p.subVec3(this._eye,this._look,ot),p.normalizeVec3(ot,ct),p.mulVec3Scalar(ct,1e3,ut),p.addVec3(this._look,ut,ht),t=ht):t=this._eye,e.hasDeviceMatrix?(p.lookAtMat4v(t,this._look,this._up,lt),p.mulMat4(e.deviceMatrix,lt,e.matrix)):p.lookAtMat4v(t,this._look,this._up,e.matrix),p.inverseMat4(this._state.matrix,this._state.inverseMatrix),p.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=p.subVec3(this._eye,this._look,Je);p.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,rt),t=p.transformPoint3(rt,t,Ze),this.eye=p.addVec3(this._look,t,$e),this.up=p.transformPoint3(rt,this._up,et)}orbitPitch(e){if(this._constrainPitch&&(e=p.dotVec3(this._up,this._worldUp)/p.DEGTORAD)<1)return;let t=p.subVec3(this._eye,this._look,Je);const s=p.cross3Vec3(p.normalizeVec3(t,Ze),p.normalizeVec3(this._up,$e));p.rotationMat4v(.0174532925*e,s,rt),t=p.transformPoint3(rt,t,et),this.up=p.transformPoint3(rt,this._up,tt),this.eye=p.addVec3(t,this._look,st)}yaw(e){let t=p.subVec3(this._look,this._eye,Je);p.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,rt),t=p.transformPoint3(rt,t,Ze),this.look=p.addVec3(t,this._eye,$e),this._gimbalLock&&(this.up=p.transformPoint3(rt,this._up,et))}pitch(e){if(this._constrainPitch&&(e=p.dotVec3(this._up,this._worldUp)/p.DEGTORAD)<1)return;let t=p.subVec3(this._look,this._eye,Je);const s=p.cross3Vec3(p.normalizeVec3(t,Ze),p.normalizeVec3(this._up,$e));p.rotationMat4v(.0174532925*e,s,rt),this.up=p.transformPoint3(rt,this._up,st),t=p.transformPoint3(rt,t,et),this.look=p.addVec3(t,this._eye,tt)}pan(e){const t=p.subVec3(this._eye,this._look,Je),s=[0,0,0];let n;if(0!==e[0]){const i=p.cross3Vec3(p.normalizeVec3(t,[]),p.normalizeVec3(this._up,Ze));n=p.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=p.mulVec3Scalar(p.normalizeVec3(this._up,$e),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=p.mulVec3Scalar(p.normalizeVec3(t,et),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=p.addVec3(this._eye,s,tt),this.look=p.addVec3(this._look,s,st)}zoom(e){const t=p.subVec3(this._eye,this._look,Je),s=Math.abs(p.lenVec3(t,Ze)),n=Math.abs(s+e);if(n<.5)return;const i=p.normalizeVec3(t,$e);this.eye=p.addVec3(this._look,p.mulVec3Scalar(i,n),et)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=p.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return p.lenVec3(p.subVec3(this._look,this._eye,Je))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=nt,s=it,n=at;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,p.mulMat4v4(this.viewMatrix,t,s),p.mulMat4v4(this.projMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}class At extends _{get type(){return"Light"}get isLight(){return!0}constructor(e,t={}){super(e,t)}}class dt extends At{get type(){return"DirLight"}constructor(e,t={}){super(e,t),this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,n=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new We({type:"dir",dir:p.vec3([1,1,1]),color:p.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=p.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];p.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=p.identityMat4()),p.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Ue(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}class ft extends At{get type(){return"AmbientLight"}constructor(e,t={}){super(e,t),this._state={type:"ambient",color:p.vec3([.7,.7,.7]),intensity:1},this.color=t.color,this.intensity=t.intensity,this.scene._lightCreated(this)}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}get intensity(){return this._state.intensity}destroy(){super.destroy(),this.scene._lightDestroyed(this)}}class It extends _{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),d.memory.meshes++}destroy(){super.destroy(),d.memory.meshes--}}var yt=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const mt=function(){const e=p.mat4(),t=p.mat4();return function(s,n){n=n||p.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return p.identityMat4(e),p.translationMat4v(s,e),p.identityMat4(t),p.scalingMat4v([l/u,o/u,c/u],t),p.mulMat4(e,t,n),n}}();var vt=function(){const e=p.mat4(),t=p.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function Tt(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function Et(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const bt={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=gt(e,l,"floor","ceil"),n=Tt(s),a=Et(e,l,n),a>r&&(i=s,r=a),s=gt(e,l,"ceil","ceil"),n=Tt(s),a=Et(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Dt=d.memory,Pt=p.AABB3();class Rt extends It{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new We({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=bt.getPositionsBounds(t.positions),n=bt.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=bt.getUVBounds(t.uv),n=bt.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=bt.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Dt.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Dt.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new De(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Dt.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new De(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),Dt.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new De(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Dt.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new De(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Dt.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=yt(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Dt.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=p.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new De(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),Dt.positions+=this._pickTrianglePositionsBuf.numItems,Dt.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),bt.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=bt.getPositionsBounds(e),n=bt.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),bt.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),bt.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=p.AABB3()),p.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=p.OBB3()),p.positions3ToAABB3(this._state.positions,Pt,this._state.positionsDecodeMatrix),p.AABB3ToOBB3(Pt,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Dt.meshes--}}function Ct(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return m.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}class _t extends _{get type(){return"Material"}constructor(e,t={}){super(e,t),d.memory.materials++}destroy(){super.destroy(),d.memory.materials--}}const Bt={opaque:0,mask:1,blend:2},Ot=["opaque","mask","blend"];class St extends _t{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new We({type:"PhongMaterial",ambient:p.vec3([1,1,1]),diffuse:p.vec3([1,1,1]),specular:p.vec3([1,1,1]),emissive:p.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=Bt[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Ot[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}const Nt={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class xt extends _t{get type(){return"EmphasisMaterial"}get presets(){return Nt}constructor(e,t={}){super(e,t),this._state=new We({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=Nt[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Nt).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Lt={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class Mt extends _t{get type(){return"EdgeMaterial"}get presets(){return Lt}constructor(e,t={}){super(e,t),this._state=new We({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Lt[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Lt).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Ft={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class Ht extends _{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=p.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return Ft}set units(e){e||(e="meters");Ft[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=p.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=p.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class Ut extends _{constructor(e,t={}){super(e,t),this._supported=pe.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const Gt={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class Vt extends _t{get type(){return"PointsMaterial"}get presets(){return Gt}constructor(e,t={}){super(e,t),this._state=new We({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=Gt[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Gt).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const jt={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class kt extends _t{get type(){return"LinesMaterial"}get presets(){return jt}constructor(e,t={}){super(e,t),this._state=new We({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=jt[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(jt).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Qt=p.vec3(),Wt=p.vec3(),zt=p.mat4();class Kt{constructor(){this.normal=p.vec3(),this.offset=0,this.testVertex=p.vec3()}set(e,t,s,n){const i=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=s*i,this.offset=n*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Yt{constructor(){this.planes=[new Kt,new Kt,new Kt,new Kt,new Kt,new Kt]}}function Xt(e,t,s){const n=p.mulMat4(s,t,zt),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],h=n[7],A=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,h-o,I-A,w-y),e.planes[1].set(l+i,h+o,I+A,w+y),e.planes[2].set(l-a,h-c,I-d,w-m),e.planes[3].set(l+a,h+c,I+d,w+m),e.planes[4].set(l-r,h-u,I-f,w-v),e.planes[5].set(l+r,h+u,I+f,w+v)}function qt(e,t){let s=Yt.INSIDE;const n=Qt,i=Wt;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Yt.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Yt.INTERSECT)}return s}Yt.INSIDE=0,Yt.INTERSECT=1,Yt.OUTSIDE=2;class Jt{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class Zt{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new Jt(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class $t extends _{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var ss=es.exports.RBush3D,ns=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; +class e{constructor(e,t){this.items=e||[],this._lastUniqueId=(t||0)+1}addItem(){let e;if(2===arguments.length){const t=arguments[0];if(e=arguments[1],this.items[t])throw"ID clash: '"+t+"'";return this.items[t]=e,t}for(e=arguments[0]||{};;){const t=this._lastUniqueId++;if(!this.items[t])return this.items[t]=e,t}}removeItem(e){const t=this.items[e];return delete this.items[e],t}}const t=new e;class s{constructor(e){this.id=e,this.parentItem=null,this.groups=[],this.menuElement=null,this.shown=!1,this.mouseOver=0}}class n{constructor(){this.items=[]}}class i{constructor(e,t,s,n,i){this.id=e,this.getTitle=t,this.doAction=s,this.getEnabled=n,this.getShown=i,this.itemElement=null,this.subMenu=null,this.enabled=!0}}class a{constructor(e={}){this._id=t.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==e.hideOnMouseDown&&(document.addEventListener("mousedown",(e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=e=>{e.target.classList.contains("xeokit-context-menu-item")||this.hide()})),e.items&&(this.items=e.items),this._hideOnAction=!1!==e.hideOnAction,this.context=e.context,this.enabled=!1!==e.enabled,this.hide()}on(e,t){let s=this._eventSubs[e];s||(s=[],this._eventSubs[e]=s),s.push(t)}fire(e,t){const s=this._eventSubs[e];if(s)for(let e=0,n=s.length;e{const a=this._getNextId(),r=new s(a);for(let s=0,a=e.length;s0,c=this._getNextId(),u=s.getTitle||(()=>s.title||""),h=s.doAction||s.callback||(()=>{}),p=s.getEnabled||(()=>!0),A=s.getShown||(()=>!0),d=new i(c,u,h,p,A);if(d.parentMenu=r,l.items.push(d),o){const e=t(n);d.subMenu=e,e.parentItem=d}this._itemList.push(d),this._itemMap[d.id]=d}}return this._menuList.push(r),this._menuMap[r.id]=r,r};this._rootMenu=t(e)}_getNextId(){return"ContextMenu_"+this._id+"_"+this._nextId++}_createUI(){const e=t=>{this._createMenuUI(t);const s=t.groups;for(let t=0,n=s.length;t'),s.push("
    "),t)for(let e=0,n=t.length;e'+o+" [MORE]"):s.push('
  • '+o+"
  • ")}}s.push("
"),s.push("");const n=s.join("");document.body.insertAdjacentHTML("beforeend",n);const i=document.querySelector("."+e.id);e.menuElement=i,i.style["border-radius"]="4px",i.style.display="none",i.style["z-index"]=3e5,i.style.background="white",i.style.border="1px solid black",i.style["box-shadow"]="0 4px 5px 0 gray",i.oncontextmenu=e=>{e.preventDefault()};const a=this;let r=null;if(t)for(let e=0,s=t.length;e{e.preventDefault();const s=t.subMenu;if(!s)return void(r&&(a._hideMenu(r.id),r=null));if(r&&r.id!==s.id&&(a._hideMenu(r.id),r=null),!1===t.enabled)return;const n=t.itemElement,i=s.menuElement,l=n.getBoundingClientRect();i.getBoundingClientRect();l.right+200>window.innerWidth?a._showMenu(s.id,l.left-200,l.top-1):a._showMenu(s.id,l.right-5,l.top-1),r=s})),n||(t.itemElement.addEventListener("click",(e=>{e.preventDefault(),a._context&&!1!==t.enabled&&(t.doAction&&t.doAction(a._context),this._hideOnAction?a.hide():(a._updateItemsTitles(),a._updateItemsEnabledStatus()))})),t.itemElement.addEventListener("mouseenter",(e=>{e.preventDefault(),!1!==t.enabled&&t.doHover&&t.doHover(a._context)})))):console.error("ContextMenu item element not found: "+t.id)}}}_updateItemsTitles(){if(this._context)for(let e=0,t=this._itemList.length;ewindow.innerHeight&&(s=window.innerHeight-n),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=s+"px"}_hideMenuElement(e){e.style.display="none"}}class r{constructor(e,t,s){this.id=s&&s.id?s.id:e,this.viewer=t,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,t.addPlugin(this)}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){console.log(`[xeokit plugin ${this.id}]: ${e}`)}warn(e){console.warn(`[xeokit plugin ${this.id}]: ${e}`)}error(e){console.error(`[xeokit plugin ${this.id}]: ${e}`)}send(e,t){}destroy(){this.viewer.removePlugin(this)}}let l=!0,o=l?Float64Array:Float32Array;const c=new o(16),u=new o(16),h=new o(4),p={setDoublePrecisionEnabled(e){l=e,o=l?Float64Array:Float32Array},getDoublePrecisionEnabled:()=>l,MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId(e,t){const s=t.indexOf("#");return s===e.length&&t.startsWith(e)?t.substring(s+1):t},globalizeObjectId:(e,t)=>e+"#"+t,safeInv(e){const t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:e=>new o(e||2),vec3:e=>new o(e||3),vec4:e=>new o(e||4),mat3:e=>new o(e||9),mat3ToMat4:(e,t=new o(16))=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t),mat4:e=>new o(e||16),mat4ToMat3(e,t){},doublesToFloats(e,t,s){const n=new o(2);for(let i=0,a=e.length;i{const e=[];for(let t=0;t<256;t++)e[t]=(t<16?"0":"")+t.toString(16);return()=>{const t=4294967295*Math.random()|0,s=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return`${e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]}-${e[255&s]}${e[s>>8&255]}-${e[s>>16&15|64]}${e[s>>24&255]}-${e[63&n|128]}${e[n>>8&255]}-${e[n>>16&255]}${e[n>>24&255]}${e[255&i]}${e[i>>8&255]}${e[i>>16&255]}${e[i>>24&255]}`}})(),clamp:(e,t,s)=>Math.max(t,Math.min(s,e)),fmod(e,t){if(ee[0]===t[0]&&e[1]===t[1]&&e[2]===t[2],negateVec3:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t),negateVec4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t),addVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s),addVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s),addVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s),addVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s),subVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s),subVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s),subVec2:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s),geometricMeanVec2(...e){const t=new o(e[0]);for(let s=1;s(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s),subScalarVec4:(e,t,s)=>(s||(s=e),s[0]=t-e[0],s[1]=t-e[1],s[2]=t-e[2],s[3]=t-e[3],s),mulVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]*t[0],s[1]=e[1]*t[1],s[2]=e[2]*t[2],s[3]=e[3]*t[3],s),mulVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s),mulVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s),mulVec2Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s),divVec3:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s),divVec4:(e,t,s)=>(s||(s=e),s[0]=e[0]/t[0],s[1]=e[1]/t[1],s[2]=e[2]/t[2],s[3]=e[3]/t[3],s),divScalarVec3:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s),divVec3Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s),divVec4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]/t,s[1]=e[1]/t,s[2]=e[2]/t,s[3]=e[3]/t,s),divScalarVec4:(e,t,s)=>(s||(s=t),s[0]=e/t[0],s[1]=e/t[1],s[2]=e/t[2],s[3]=e/t[3],s),dotVec4:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3],cross3Vec4(e,t){const s=e[0],n=e[1],i=e[2],a=t[0],r=t[1],l=t[2];return[n*l-i*r,i*a-s*l,s*r-n*a,0]},cross3Vec3(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=t[0],l=t[1],o=t[2];return s[0]=i*o-a*l,s[1]=a*r-n*o,s[2]=n*l-i*r,s},sqLenVec4:e=>p.dotVec4(e,e),lenVec4:e=>Math.sqrt(p.sqLenVec4(e)),dotVec3:(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],dotVec2:(e,t)=>e[0]*t[0]+e[1]*t[1],sqLenVec3:e=>p.dotVec3(e,e),sqLenVec2:e=>p.dotVec2(e,e),lenVec3:e=>Math.sqrt(p.sqLenVec3(e)),distVec3:(()=>{const e=new o(3);return(t,s)=>p.lenVec3(p.subVec3(t,s,e))})(),lenVec2:e=>Math.sqrt(p.sqLenVec2(e)),distVec2:(()=>{const e=new o(2);return(t,s)=>p.lenVec2(p.subVec2(t,s,e))})(),rcpVec3:(e,t)=>p.divScalarVec3(1,e,t),normalizeVec4(e,t){const s=1/p.lenVec4(e);return p.mulVec4Scalar(e,s,t)},normalizeVec3(e,t){const s=1/p.lenVec3(e);return p.mulVec3Scalar(e,s,t)},normalizeVec2(e,t){const s=1/p.lenVec2(e);return p.mulVec2Scalar(e,s,t)},angleVec3(e,t){let s=p.dotVec3(e,t)/Math.sqrt(p.sqLenVec3(e)*p.sqLenVec3(t));return s=s<-1?-1:s>1?1:s,Math.acos(s)},vec3FromMat4Scale:(()=>{const e=new o(3);return(t,s)=>(e[0]=t[0],e[1]=t[1],e[2]=t[2],s[0]=p.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],s[1]=p.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],s[2]=p.lenVec3(e),s)})(),vecToArray:(()=>{function e(e){return Math.round(1e5*e)/1e5}return t=>{for(let s=0,n=(t=Array.prototype.slice.call(t)).length;s({x:e[0],y:e[1],z:e[2]}),xyzObjectToArray:(e,t)=>((t=t||p.vec3())[0]=e.x,t[1]=e.y,t[2]=e.z,t),dupMat4:e=>e.slice(0,16),mat4To3:e=>[e[0],e[1],e[2],e[4],e[5],e[6],e[8],e[9],e[10]],m4s:e=>[e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e],setMat4ToZeroes:()=>p.m4s(0),setMat4ToOnes:()=>p.m4s(1),diagonalMat4v:e=>new o([e[0],0,0,0,0,e[1],0,0,0,0,e[2],0,0,0,0,e[3]]),diagonalMat4c:(e,t,s,n)=>p.diagonalMat4v([e,t,s,n]),diagonalMat4s:e=>p.diagonalMat4c(e,e,e,e),identityMat4:(e=new o(16))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e),identityMat3:(e=new o(9))=>(e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e),isIdentityMat4:e=>1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15],negateMat4:(e,t)=>(t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t),addMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]+t[0],s[1]=e[1]+t[1],s[2]=e[2]+t[2],s[3]=e[3]+t[3],s[4]=e[4]+t[4],s[5]=e[5]+t[5],s[6]=e[6]+t[6],s[7]=e[7]+t[7],s[8]=e[8]+t[8],s[9]=e[9]+t[9],s[10]=e[10]+t[10],s[11]=e[11]+t[11],s[12]=e[12]+t[12],s[13]=e[13]+t[13],s[14]=e[14]+t[14],s[15]=e[15]+t[15],s),addMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]+t,s[1]=e[1]+t,s[2]=e[2]+t,s[3]=e[3]+t,s[4]=e[4]+t,s[5]=e[5]+t,s[6]=e[6]+t,s[7]=e[7]+t,s[8]=e[8]+t,s[9]=e[9]+t,s[10]=e[10]+t,s[11]=e[11]+t,s[12]=e[12]+t,s[13]=e[13]+t,s[14]=e[14]+t,s[15]=e[15]+t,s),addScalarMat4:(e,t,s)=>p.addMat4Scalar(t,e,s),subMat4:(e,t,s)=>(s||(s=e),s[0]=e[0]-t[0],s[1]=e[1]-t[1],s[2]=e[2]-t[2],s[3]=e[3]-t[3],s[4]=e[4]-t[4],s[5]=e[5]-t[5],s[6]=e[6]-t[6],s[7]=e[7]-t[7],s[8]=e[8]-t[8],s[9]=e[9]-t[9],s[10]=e[10]-t[10],s[11]=e[11]-t[11],s[12]=e[12]-t[12],s[13]=e[13]-t[13],s[14]=e[14]-t[14],s[15]=e[15]-t[15],s),subMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]-t,s[1]=e[1]-t,s[2]=e[2]-t,s[3]=e[3]-t,s[4]=e[4]-t,s[5]=e[5]-t,s[6]=e[6]-t,s[7]=e[7]-t,s[8]=e[8]-t,s[9]=e[9]-t,s[10]=e[10]-t,s[11]=e[11]-t,s[12]=e[12]-t,s[13]=e[13]-t,s[14]=e[14]-t,s[15]=e[15]-t,s),subScalarMat4:(e,t,s)=>(s||(s=t),s[0]=e-t[0],s[1]=e-t[1],s[2]=e-t[2],s[3]=e-t[3],s[4]=e-t[4],s[5]=e-t[5],s[6]=e-t[6],s[7]=e-t[7],s[8]=e-t[8],s[9]=e-t[9],s[10]=e-t[10],s[11]=e-t[11],s[12]=e-t[12],s[13]=e-t[13],s[14]=e-t[14],s[15]=e-t[15],s),mulMat4(e,t,s){s||(s=e);const n=e[0],i=e[1],a=e[2],r=e[3],l=e[4],o=e[5],c=e[6],u=e[7],h=e[8],p=e[9],A=e[10],d=e[11],f=e[12],I=e[13],y=e[14],m=e[15],v=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],x=t[15];return s[0]=v*n+w*l+g*h+T*f,s[1]=v*i+w*o+g*p+T*I,s[2]=v*a+w*c+g*A+T*y,s[3]=v*r+w*u+g*d+T*m,s[4]=E*n+b*l+D*h+P*f,s[5]=E*i+b*o+D*p+P*I,s[6]=E*a+b*c+D*A+P*y,s[7]=E*r+b*u+D*d+P*m,s[8]=R*n+C*l+_*h+B*f,s[9]=R*i+C*o+_*p+B*I,s[10]=R*a+C*c+_*A+B*y,s[11]=R*r+C*u+_*d+B*m,s[12]=O*n+S*l+N*h+x*f,s[13]=O*i+S*o+N*p+x*I,s[14]=O*a+S*c+N*A+x*y,s[15]=O*r+S*u+N*d+x*m,s},mulMat3(e,t,s){s||(s=new o(9));const n=e[0],i=e[3],a=e[6],r=e[1],l=e[4],c=e[7],u=e[2],h=e[5],p=e[8],A=t[0],d=t[3],f=t[6],I=t[1],y=t[4],m=t[7],v=t[2],w=t[5],g=t[8];return s[0]=n*A+i*I+a*v,s[3]=n*d+i*y+a*w,s[6]=n*f+i*m+a*g,s[1]=r*A+l*I+c*v,s[4]=r*d+l*y+c*w,s[7]=r*f+l*m+c*g,s[2]=u*A+h*I+p*v,s[5]=u*d+h*y+p*w,s[8]=u*f+h*m+p*g,s},mulMat4Scalar:(e,t,s)=>(s||(s=e),s[0]=e[0]*t,s[1]=e[1]*t,s[2]=e[2]*t,s[3]=e[3]*t,s[4]=e[4]*t,s[5]=e[5]*t,s[6]=e[6]*t,s[7]=e[7]*t,s[8]=e[8]*t,s[9]=e[9]*t,s[10]=e[10]*t,s[11]=e[11]*t,s[12]=e[12]*t,s[13]=e[13]*t,s[14]=e[14]*t,s[15]=e[15]*t,s),mulMat4v4(e,t,s=p.vec4()){const n=t[0],i=t[1],a=t[2],r=t[3];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12]*r,s[1]=e[1]*n+e[5]*i+e[9]*a+e[13]*r,s[2]=e[2]*n+e[6]*i+e[10]*a+e[14]*r,s[3]=e[3]*n+e[7]*i+e[11]*a+e[15]*r,s},transposeMat4(e,t){const s=e[4],n=e[14],i=e[8],a=e[13],r=e[12],l=e[9];if(!t||e===t){const t=e[1],o=e[2],c=e[3],u=e[6],h=e[7],p=e[11];return e[1]=s,e[2]=i,e[3]=r,e[4]=t,e[6]=l,e[7]=a,e[8]=o,e[9]=u,e[11]=n,e[12]=c,e[13]=h,e[14]=p,e}return t[0]=e[0],t[1]=s,t[2]=i,t[3]=r,t[4]=e[1],t[5]=e[5],t[6]=l,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=n,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3(e,t){if(t===e){const s=e[1],n=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=s,t[5]=e[7],t[6]=n,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4(e){const t=e[0],s=e[1],n=e[2],i=e[3],a=e[4],r=e[5],l=e[6],o=e[7],c=e[8],u=e[9],h=e[10],p=e[11],A=e[12],d=e[13],f=e[14],I=e[15];return A*u*l*i-c*d*l*i-A*r*h*i+a*d*h*i+c*r*f*i-a*u*f*i-A*u*n*o+c*d*n*o+A*s*h*o-t*d*h*o-c*s*f*o+t*u*f*o+A*r*n*p-a*d*n*p-A*s*l*p+t*d*l*p+a*s*f*p-t*r*f*p-c*r*n*I+a*u*n*I+c*s*l*I-t*u*l*I-a*s*h*I+t*r*h*I},inverseMat4(e,t){t||(t=e);const s=e[0],n=e[1],i=e[2],a=e[3],r=e[4],l=e[5],o=e[6],c=e[7],u=e[8],h=e[9],p=e[10],A=e[11],d=e[12],f=e[13],I=e[14],y=e[15],m=s*l-n*r,v=s*o-i*r,w=s*c-a*r,g=n*o-i*l,T=n*c-a*l,E=i*c-a*o,b=u*f-h*d,D=u*I-p*d,P=u*y-A*d,R=h*I-p*f,C=h*y-A*f,_=p*y-A*I,B=1/(m*_-v*C+w*R+g*P-T*D+E*b);return t[0]=(l*_-o*C+c*R)*B,t[1]=(-n*_+i*C-a*R)*B,t[2]=(f*E-I*T+y*g)*B,t[3]=(-h*E+p*T-A*g)*B,t[4]=(-r*_+o*P-c*D)*B,t[5]=(s*_-i*P+a*D)*B,t[6]=(-d*E+I*w-y*v)*B,t[7]=(u*E-p*w+A*v)*B,t[8]=(r*C-l*P+c*b)*B,t[9]=(-s*C+n*P-a*b)*B,t[10]=(d*T-f*w+y*m)*B,t[11]=(-u*T+h*w-A*m)*B,t[12]=(-r*R+l*D-o*b)*B,t[13]=(s*R-n*D+i*b)*B,t[14]=(-d*g+f*v-I*m)*B,t[15]=(u*g-h*v+p*m)*B,t},traceMat4:e=>e[0]+e[5]+e[10]+e[15],translationMat4v(e,t){const s=t||p.identityMat4();return s[12]=e[0],s[13]=e[1],s[14]=e[2],s},translationMat3v(e,t){const s=t||p.identityMat3();return s[6]=e[0],s[7]=e[1],s},translationMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.translationMat4v(e,i))})(),translationMat4s:(e,t)=>p.translationMat4c(e,e,e,t),translateMat4v:(e,t)=>p.translateMat4c(e[0],e[1],e[2],t),translateMat4c(e,t,s,n){const i=n[3];n[0]+=i*e,n[1]+=i*t,n[2]+=i*s;const a=n[7];n[4]+=a*e,n[5]+=a*t,n[6]+=a*s;const r=n[11];n[8]+=r*e,n[9]+=r*t,n[10]+=r*s;const l=n[15];return n[12]+=l*e,n[13]+=l*t,n[14]+=l*s,n},setMat4Translation:(e,t,s)=>(s[0]=e[0],s[1]=e[1],s[2]=e[2],s[3]=e[3],s[4]=e[4],s[5]=e[5],s[6]=e[6],s[7]=e[7],s[8]=e[8],s[9]=e[9],s[10]=e[10],s[11]=e[11],s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=e[15],s),rotationMat4v(e,t,s){const n=p.normalizeVec4([t[0],t[1],t[2],0],[]),i=Math.sin(e),a=Math.cos(e),r=1-a,l=n[0],o=n[1],c=n[2];let u,h,A,d,f,I;return u=l*o,h=o*c,A=c*l,d=l*i,f=o*i,I=c*i,(s=s||p.mat4())[0]=r*l*l+a,s[1]=r*u+I,s[2]=r*A-f,s[3]=0,s[4]=r*u-I,s[5]=r*o*o+a,s[6]=r*h+d,s[7]=0,s[8]=r*A+f,s[9]=r*h-d,s[10]=r*c*c+a,s[11]=0,s[12]=0,s[13]=0,s[14]=0,s[15]=1,s},rotationMat4c:(e,t,s,n,i)=>p.rotationMat4v(e,[t,s,n],i),scalingMat4v:(e,t=p.identityMat4())=>(t[0]=e[0],t[5]=e[1],t[10]=e[2],t),scalingMat3v:(e,t=p.identityMat3())=>(t[0]=e[0],t[4]=e[1],t),scalingMat4c:(()=>{const e=new o(3);return(t,s,n,i)=>(e[0]=t,e[1]=s,e[2]=n,p.scalingMat4v(e,i))})(),scaleMat4c:(e,t,s,n)=>(n[0]*=e,n[4]*=t,n[8]*=s,n[1]*=e,n[5]*=t,n[9]*=s,n[2]*=e,n[6]*=t,n[10]*=s,n[3]*=e,n[7]*=t,n[11]*=s,n),scaleMat4v(e,t){const s=e[0],n=e[1],i=e[2];return t[0]*=s,t[4]*=n,t[8]*=i,t[1]*=s,t[5]*=n,t[9]*=i,t[2]*=s,t[6]*=n,t[10]*=i,t[3]*=s,t[7]*=n,t[11]*=i,t},scalingMat4s:e=>p.scalingMat4c(e,e,e),rotationTranslationMat4(e,t,s=p.mat4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=n+n,o=i+i,c=a+a,u=n*l,h=n*o,A=n*c,d=i*o,f=i*c,I=a*c,y=r*l,m=r*o,v=r*c;return s[0]=1-(d+I),s[1]=h+v,s[2]=A-m,s[3]=0,s[4]=h-v,s[5]=1-(u+I),s[6]=f+y,s[7]=0,s[8]=A+m,s[9]=f-y,s[10]=1-(u+d),s[11]=0,s[12]=t[0],s[13]=t[1],s[14]=t[2],s[15]=1,s},mat4ToEuler(e,t,s=p.vec4()){const n=p.clamp,i=e[0],a=e[4],r=e[8],l=e[1],o=e[5],c=e[9],u=e[2],h=e[6],A=e[10];return"XYZ"===t?(s[1]=Math.asin(n(r,-1,1)),Math.abs(r)<.99999?(s[0]=Math.atan2(-c,A),s[2]=Math.atan2(-a,i)):(s[0]=Math.atan2(h,o),s[2]=0)):"YXZ"===t?(s[0]=Math.asin(-n(c,-1,1)),Math.abs(c)<.99999?(s[1]=Math.atan2(r,A),s[2]=Math.atan2(l,o)):(s[1]=Math.atan2(-u,i),s[2]=0)):"ZXY"===t?(s[0]=Math.asin(n(h,-1,1)),Math.abs(h)<.99999?(s[1]=Math.atan2(-u,A),s[2]=Math.atan2(-a,o)):(s[1]=0,s[2]=Math.atan2(l,i))):"ZYX"===t?(s[1]=Math.asin(-n(u,-1,1)),Math.abs(u)<.99999?(s[0]=Math.atan2(h,A),s[2]=Math.atan2(l,i)):(s[0]=0,s[2]=Math.atan2(-a,o))):"YZX"===t?(s[2]=Math.asin(n(l,-1,1)),Math.abs(l)<.99999?(s[0]=Math.atan2(-c,o),s[1]=Math.atan2(-u,i)):(s[0]=0,s[1]=Math.atan2(r,A))):"XZY"===t&&(s[2]=Math.asin(-n(a,-1,1)),Math.abs(a)<.99999?(s[0]=Math.atan2(h,o),s[1]=Math.atan2(r,i)):(s[0]=Math.atan2(-c,A),s[1]=0)),s},composeMat4:(e,t,s,n=p.mat4())=>(p.quaternionToRotationMat4(t,n),p.scaleMat4v(s,n),p.translateMat4v(e,n),n),decomposeMat4:(()=>{const e=new o(3),t=new o(16);return function(s,n,i,a){e[0]=s[0],e[1]=s[1],e[2]=s[2];let r=p.lenVec3(e);e[0]=s[4],e[1]=s[5],e[2]=s[6];const l=p.lenVec3(e);e[8]=s[8],e[9]=s[9],e[10]=s[10];const o=p.lenVec3(e);p.determinantMat4(s)<0&&(r=-r),n[0]=s[12],n[1]=s[13],n[2]=s[14],t.set(s);const c=1/r,u=1/l,h=1/o;return t[0]*=c,t[1]*=c,t[2]*=c,t[4]*=u,t[5]*=u,t[6]*=u,t[8]*=h,t[9]*=h,t[10]*=h,p.mat4ToQuaternion(t,i),a[0]=r,a[1]=l,a[2]=o,this}})(),getColMat4(e,t){const s=4*t;return[e[s],e[s+1],e[s+2],e[s+3]]},setRowMat4(e,t,s){e[t]=s[0],e[t+4]=s[1],e[t+8]=s[2],e[t+12]=s[3]},lookAtMat4v(e,t,s,n){n||(n=p.mat4());const i=e[0],a=e[1],r=e[2],l=s[0],o=s[1],c=s[2],u=t[0],h=t[1],A=t[2];if(i===u&&a===h&&r===A)return p.identityMat4();let d,f,I,y,m,v,w,g,T,E;return d=i-u,f=a-h,I=r-A,E=1/Math.sqrt(d*d+f*f+I*I),d*=E,f*=E,I*=E,y=o*I-c*f,m=c*d-l*I,v=l*f-o*d,E=Math.sqrt(y*y+m*m+v*v),E?(E=1/E,y*=E,m*=E,v*=E):(y=0,m=0,v=0),w=f*v-I*m,g=I*y-d*v,T=d*m-f*y,E=Math.sqrt(w*w+g*g+T*T),E?(E=1/E,w*=E,g*=E,T*=E):(w=0,g=0,T=0),n[0]=y,n[1]=w,n[2]=d,n[3]=0,n[4]=m,n[5]=g,n[6]=f,n[7]=0,n[8]=v,n[9]=T,n[10]=I,n[11]=0,n[12]=-(y*i+m*a+v*r),n[13]=-(w*i+g*a+T*r),n[14]=-(d*i+f*a+I*r),n[15]=1,n},lookAtMat4c:(e,t,s,n,i,a,r,l,o)=>p.lookAtMat4v([e,t,s],[n,i,a],[r,l,o],[]),orthoMat4c(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2/o,r[6]=0,r[7]=0,r[8]=0,r[9]=0,r[10]=-2/c,r[11]=0,r[12]=-(e+t)/l,r[13]=-(n+s)/o,r[14]=-(a+i)/c,r[15]=1,r},frustumMat4v(e,t,s){s||(s=p.mat4());const n=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];p.addVec4(i,n,c),p.subVec4(i,n,u);const a=2*n[2],r=u[0],l=u[1],o=u[2];return s[0]=a/r,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=a/l,s[6]=0,s[7]=0,s[8]=c[0]/r,s[9]=c[1]/l,s[10]=-c[2]/o,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i[2]/o,s[15]=0,s},frustumMat4(e,t,s,n,i,a,r){r||(r=p.mat4());const l=t-e,o=n-s,c=a-i;return r[0]=2*i/l,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=2*i/o,r[6]=0,r[7]=0,r[8]=(t+e)/l,r[9]=(n+s)/o,r[10]=-(a+i)/c,r[11]=-1,r[12]=0,r[13]=0,r[14]=-a*i*2/c,r[15]=0,r},perspectiveMat4(e,t,s,n,i){const a=[],r=[];return a[2]=s,r[2]=n,r[1]=a[2]*Math.tan(e/2),a[1]=-r[1],r[0]=r[1]*t,a[0]=-r[0],p.frustumMat4v(a,r,i)},compareMat4:(e,t)=>e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15],transformPoint3(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2];return s[0]=e[0]*n+e[4]*i+e[8]*a+e[12],s[1]=e[1]*n+e[5]*i+e[9]*a+e[13],s[2]=e[2]*n+e[6]*i+e[10]*a+e[14],s},transformPoint4:(e,t,s=p.vec4())=>(s[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],s[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],s[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],s[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],s),transformPoints3(e,t,s){const n=s||[],i=t.length;let a,r,l,o;const c=e[0],u=e[1],h=e[2],p=e[3],A=e[4],d=e[5],f=e[6],I=e[7],y=e[8],m=e[9],v=e[10],w=e[11],g=e[12],T=e[13],E=e[14],b=e[15];let D;for(let e=0;e{const e=new o(16),t=new o(16),s=new o(16);return function(n,i,a,r){return this.transformVec3(this.mulMat4(this.inverseMat4(i,e),this.inverseMat4(a,t),s),n,r)}})(),lerpVec3(e,t,s,n,i,a){const r=a||p.vec3(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r},lerpMat4(e,t,s,n,i,a){const r=a||p.mat4(),l=(e-t)/(s-t);return r[0]=n[0]+l*(i[0]-n[0]),r[1]=n[1]+l*(i[1]-n[1]),r[2]=n[2]+l*(i[2]-n[2]),r[3]=n[3]+l*(i[3]-n[3]),r[4]=n[4]+l*(i[4]-n[4]),r[5]=n[5]+l*(i[5]-n[5]),r[6]=n[6]+l*(i[6]-n[6]),r[7]=n[7]+l*(i[7]-n[7]),r[8]=n[8]+l*(i[8]-n[8]),r[9]=n[9]+l*(i[9]-n[9]),r[10]=n[10]+l*(i[10]-n[10]),r[11]=n[11]+l*(i[11]-n[11]),r[12]=n[12]+l*(i[12]-n[12]),r[13]=n[13]+l*(i[13]-n[13]),r[14]=n[14]+l*(i[14]-n[14]),r[15]=n[15]+l*(i[15]-n[15]),r},flatten(e){const t=[];let s,n,i,a,r;for(s=0,n=e.length;s(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e),eulerToQuaternion(e,t,s=p.vec4()){const n=e[0]*p.DEGTORAD/2,i=e[1]*p.DEGTORAD/2,a=e[2]*p.DEGTORAD/2,r=Math.cos(n),l=Math.cos(i),o=Math.cos(a),c=Math.sin(n),u=Math.sin(i),h=Math.sin(a);return"XYZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"YXZ"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"ZXY"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o-c*u*h):"ZYX"===t?(s[0]=c*l*o-r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o+c*u*h):"YZX"===t?(s[0]=c*l*o+r*u*h,s[1]=r*u*o+c*l*h,s[2]=r*l*h-c*u*o,s[3]=r*l*o-c*u*h):"XZY"===t&&(s[0]=c*l*o-r*u*h,s[1]=r*u*o-c*l*h,s[2]=r*l*h+c*u*o,s[3]=r*l*o+c*u*h),s},mat4ToQuaternion(e,t=p.vec4()){const s=e[0],n=e[4],i=e[8],a=e[1],r=e[5],l=e[9],o=e[2],c=e[6],u=e[10];let h;const A=s+r+u;return A>0?(h=.5/Math.sqrt(A+1),t[3]=.25/h,t[0]=(c-l)*h,t[1]=(i-o)*h,t[2]=(a-n)*h):s>r&&s>u?(h=2*Math.sqrt(1+s-r-u),t[3]=(c-l)/h,t[0]=.25*h,t[1]=(n+a)/h,t[2]=(i+o)/h):r>u?(h=2*Math.sqrt(1+r-s-u),t[3]=(i-o)/h,t[0]=(n+a)/h,t[1]=.25*h,t[2]=(l+c)/h):(h=2*Math.sqrt(1+u-s-r),t[3]=(a-n)/h,t[0]=(i+o)/h,t[1]=(l+c)/h,t[2]=.25*h),t},vec3PairToQuaternion(e,t,s=p.vec4()){const n=Math.sqrt(p.dotVec3(e,e)*p.dotVec3(t,t));let i=n+p.dotVec3(e,t);return i<1e-8*n?(i=0,Math.abs(e[0])>Math.abs(e[2])?(s[0]=-e[1],s[1]=e[0],s[2]=0):(s[0]=0,s[1]=-e[2],s[2]=e[1])):p.cross3Vec3(e,t,s),s[3]=i,p.normalizeQuaternion(s)},angleAxisToQuaternion(e,t=p.vec4()){const s=e[3]/2,n=Math.sin(s);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(s),t},quaternionToEuler:(()=>{const e=new o(16);return(t,s,n)=>(n=n||p.vec3(),p.quaternionToRotationMat4(t,e),p.mat4ToEuler(e,s,n),n)})(),mulQuaternions(e,t,s=p.vec4()){const n=e[0],i=e[1],a=e[2],r=e[3],l=t[0],o=t[1],c=t[2],u=t[3];return s[0]=r*l+n*u+i*c-a*o,s[1]=r*o+i*u+a*l-n*c,s[2]=r*c+a*u+n*o-i*l,s[3]=r*u-n*l-i*o-a*c,s},vec3ApplyQuaternion(e,t,s=p.vec3()){const n=t[0],i=t[1],a=t[2],r=e[0],l=e[1],o=e[2],c=e[3],u=c*n+l*a-o*i,h=c*i+o*n-r*a,A=c*a+r*i-l*n,d=-r*n-l*i-o*a;return s[0]=u*c+d*-r+h*-o-A*-l,s[1]=h*c+d*-l+A*-r-u*-o,s[2]=A*c+d*-o+u*-l-h*-r,s},quaternionToMat4(e,t){t=p.identityMat4(t);const s=e[0],n=e[1],i=e[2],a=e[3],r=2*s,l=2*n,o=2*i,c=r*a,u=l*a,h=o*a,A=r*s,d=l*s,f=o*s,I=l*n,y=o*n,m=o*i;return t[0]=1-(I+m),t[1]=d+h,t[2]=f-u,t[4]=d-h,t[5]=1-(A+m),t[6]=y+c,t[8]=f+u,t[9]=y-c,t[10]=1-(A+I),t},quaternionToRotationMat4(e,t){const s=e[0],n=e[1],i=e[2],a=e[3],r=s+s,l=n+n,o=i+i,c=s*r,u=s*l,h=s*o,p=n*l,A=n*o,d=i*o,f=a*r,I=a*l,y=a*o;return t[0]=1-(p+d),t[4]=u-y,t[8]=h+I,t[1]=u+y,t[5]=1-(c+d),t[9]=A-f,t[2]=h-I,t[6]=A+f,t[10]=1-(c+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion(e,t=e){const s=p.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s,t[3]=e[3]/s,t},conjugateQuaternion:(e,t=e)=>(t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t),inverseQuaternion:(e,t)=>p.normalizeQuaternion(p.conjugateQuaternion(e,t)),quaternionToAngleAxis(e,t=p.vec4()){const s=(e=p.normalizeQuaternion(e,h))[3],n=2*Math.acos(s),i=Math.sqrt(1-s*s);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=n,t},AABB3:e=>new o(e||6),AABB2:e=>new o(e||4),OBB3:e=>new o(e||32),OBB2:e=>new o(e||16),Sphere3:(e,t,s,n)=>new o([e,t,s,n]),transformOBB3(e,t,s=t){let n;const i=t.length;let a,r,l;const o=e[0],c=e[1],u=e[2],h=e[3],p=e[4],A=e[5],d=e[6],f=e[7],I=e[8],y=e[9],m=e[10],v=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n{const e=new o(3),t=new o(3),s=new o(3);return n=>(e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5],p.subVec3(t,e,s),Math.abs(p.lenVec3(s)))})(),getAABB3DiagPoint:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],t[0]=n[3],t[1]=n[4],t[2]=n[5];const a=p.subVec3(t,e,s),r=i[0]-n[0],l=n[3]-i[0],o=i[1]-n[1],c=n[4]-i[1],u=i[2]-n[2],h=n[5]-i[2];return a[0]+=r>l?r:l,a[1]+=o>c?o:c,a[2]+=u>h?u:h,Math.abs(p.lenVec3(a))}})(),getAABB3Area:e=>(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2]),getAABB3Center(e,t){const s=t||p.vec3();return s[0]=(e[0]+e[3])/2,s[1]=(e[1]+e[4])/2,s[2]=(e[2]+e[5])/2,s},getAABB2Center(e,t){const s=t||p.vec2();return s[0]=(e[2]+e[0])/2,s[1]=(e[3]+e[1])/2,s},collapseAABB3:(e=p.AABB3())=>(e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MAX_DOUBLE,e[3]=p.MIN_DOUBLE,e[4]=p.MIN_DOUBLE,e[5]=p.MIN_DOUBLE,e),AABB3ToOBB3:(e,t=p.OBB3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t),positions3ToAABB3:(()=>{const e=new o(3);return(t,s,n)=>{s=s||p.AABB3();let i,a,r,l=p.MAX_DOUBLE,o=p.MAX_DOUBLE,c=p.MAX_DOUBLE,u=p.MIN_DOUBLE,h=p.MIN_DOUBLE,A=p.MIN_DOUBLE;for(let s=0,d=t.length;su&&(u=i),a>h&&(h=a),r>A&&(A=r);return s[0]=l,s[1]=o,s[2]=c,s[3]=u,s[4]=h,s[5]=A,s}})(),OBB3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToAABB3(e,t=p.AABB3()){let s,n,i,a=p.MAX_DOUBLE,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE,u=p.MIN_DOUBLE;for(let t=0,h=e.length;to&&(o=s),n>c&&(c=n),i>u&&(u=i);return t[0]=a,t[1]=r,t[2]=l,t[3]=o,t[4]=c,t[5]=u,t},points3ToSphere3:(()=>{const e=new o(3);return(t,s)=>{s=s||p.vec4();let n,i=0,a=0,r=0;const l=t.length;for(n=0;nc&&(c=o);return s[3]=c,s}})(),positions3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length;let c=0;for(i=0;ic&&(c=h);return n[3]=c,n}})(),OBB3ToSphere3:(()=>{const e=new o(3),t=new o(3);return(s,n)=>{n=n||p.vec4();let i,a=0,r=0,l=0;const o=s.length,c=o/4;for(i=0;ih&&(h=u);return n[3]=h,n}})(),getSphere3Center:(e,t=p.vec3())=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),getPositionsCenter(e,t=p.vec3()){let s=0,n=0,i=0;for(var a=0,r=e.length;a(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]s&&(e[0]=s),e[1]>n&&(e[1]=n),e[2]>i&&(e[2]=i),e[3](e[0]=p.MAX_DOUBLE,e[1]=p.MAX_DOUBLE,e[2]=p.MIN_DOUBLE,e[3]=p.MIN_DOUBLE,e),point3AABB3Intersect:(e,t)=>e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(n=e[0]*s[0],i=e[0]*s[3]):(n=e[0]*s[3],i=e[0]*s[0]),e[1]>0?(n+=e[1]*s[1],i+=e[1]*s[4]):(n+=e[1]*s[4],i+=e[1]*s[1]),e[2]>0?(n+=e[2]*s[2],i+=e[2]*s[5]):(n+=e[2]*s[5],i+=e[2]*s[2]);if(n<=-t&&i<=-t)return-1;return n>=-t&&i>=-t?1:0},OBB3ToAABB2(e,t=p.AABB2()){let s,n,i,a,r=p.MAX_DOUBLE,l=p.MAX_DOUBLE,o=p.MIN_DOUBLE,c=p.MIN_DOUBLE;for(let t=0,u=e.length;to&&(o=s),n>c&&(c=n);return t[0]=r,t[1]=l,t[2]=o,t[3]=c,t},expandAABB2:(e,t)=>(e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2](e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]2*(1-e)*(s-t)+2*e*(n-s),tangentQuadraticBezier3:(e,t,s,n,i)=>-3*t*(1-e)*(1-e)+3*s*(1-e)*(1-e)-6*e*s*(1-e)+6*e*n*(1-e)-3*e*e*n+3*e*e*i,tangentSpline:e=>6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e),catmullRomInterpolate(e,t,s,n,i){const a=.5*(s-e),r=.5*(n-t),l=i*i;return(2*t-2*s+a+r)*(i*l)+(-3*t+3*s-2*a-r)*l+a*i+t},b2p0(e,t){const s=1-e;return s*s*t},b2p1:(e,t)=>2*(1-e)*e*t,b2p2:(e,t)=>e*e*t,b2(e,t,s,n){return this.b2p0(e,t)+this.b2p1(e,s)+this.b2p2(e,n)},b3p0(e,t){const s=1-e;return s*s*s*t},b3p1(e,t){const s=1-e;return 3*s*s*e*t},b3p2:(e,t)=>3*(1-e)*e*e*t,b3p3:(e,t)=>e*e*e*t,b3(e,t,s,n,i){return this.b3p0(e,t)+this.b3p1(e,s)+this.b3p2(e,n)+this.b3p3(e,i)},triangleNormal(e,t,s,n=p.vec3()){const i=t[0]-e[0],a=t[1]-e[1],r=t[2]-e[2],l=s[0]-e[0],o=s[1]-e[1],c=s[2]-e[2],u=a*c-r*o,h=r*l-i*c,A=i*o-a*l,d=Math.sqrt(u*u+h*h+A*A);return 0===d?(n[0]=0,n[1]=0,n[2]=0):(n[0]=u/d,n[1]=h/d,n[2]=A/d),n},rayTriangleIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3);return(a,r,l,o,c,u)=>{u=u||p.vec3();const h=p.subVec3(o,l,e),A=p.subVec3(c,l,t),d=p.cross3Vec3(r,A,s),f=p.dotVec3(h,d);if(f<1e-6)return null;const I=p.subVec3(a,l,n),y=p.dotVec3(I,d);if(y<0||y>f)return null;const m=p.cross3Vec3(I,h,i),v=p.dotVec3(r,m);if(v<0||y+v>f)return null;const w=p.dotVec3(A,m)/f;return u[0]=a[0]+w*r[0],u[1]=a[1]+w*r[1],u[2]=a[2]+w*r[2],u}})(),rayPlaneIntersect:(()=>{const e=new o(3),t=new o(3),s=new o(3),n=new o(3);return(i,a,r,l,o,c)=>{c=c||p.vec3(),a=p.normalizeVec3(a,e);const u=p.subVec3(l,r,t),h=p.subVec3(o,r,s),A=p.cross3Vec3(u,h,n);p.normalizeVec3(A,A);const d=-p.dotVec3(r,A),f=-(p.dotVec3(i,A)+d)/p.dotVec3(a,A);return c[0]=i[0]+f*a[0],c[1]=i[1]+f*a[1],c[2]=i[2]+f*a[2],c}})(),cartesianToBarycentric:(()=>{const e=new o(3),t=new o(3),s=new o(3);return(n,i,a,r,l)=>{const o=p.subVec3(r,i,e),c=p.subVec3(a,i,t),u=p.subVec3(n,i,s),h=p.dotVec3(o,o),A=p.dotVec3(o,c),d=p.dotVec3(o,u),f=p.dotVec3(c,c),I=p.dotVec3(c,u),y=h*f-A*A;if(0===y)return null;const m=1/y,v=(f*d-A*I)*m,w=(h*I-A*d)*m;return l[0]=1-v-w,l[1]=w,l[2]=v,l}})(),barycentricInsideTriangle(e){const t=e[1],s=e[2];return s>=0&&t>=0&&s+t<1},barycentricToCartesian(e,t,s,n,i=p.vec3()){const a=e[0],r=e[1],l=e[2];return i[0]=t[0]*a+s[0]*r+n[0]*l,i[1]=t[1]*a+s[1]*r+n[1]*l,i[2]=t[2]*a+s[2]*r+n[2]*l,i},mergeVertices(e,t,s,n){const i={},a=[],r=[],l=t?[]:null,o=s?[]:null,c=[];let u,h,p,A;const d=1e4;let f,I,y=0;for(f=0,I=e.length;f{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3);return(r,l,o)=>{let c,u;const h=new Array(r.length/3);let A,d,f,I,y,m,v;for(c=0,u=l.length;c{const e=new o(3),t=new o(3),s=new o(3),n=new o(3),i=new o(3),a=new o(3),r=new o(3);return(l,o,c)=>{const u=new Float32Array(l.length);for(let h=0;h>24&255,u=p>>16&255,c=p>>8&255,o=255&p,l=t[s],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+1],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,l=t[s+2],r=3*l,i[A++]=e[r],i[A++]=e[r+1],i[A++]=e[r+2],a[d++]=o,a[d++]=c,a[d++]=u,a[d++]=h,p++;return{positions:i,colors:a}},faceToVertexNormals(e,t,s={}){const n=s.smoothNormalsAngleThreshold||20,i={},a=[],r={};let l,o,c,u,h;const A=1e4;let d,f,I,y,m,v;for(f=0,y=e.length;f{const e=new o(4),t=new o(4);return(s,n,i,a,r)=>{e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=1,p.transformVec4(s,e,t),a[0]=t[0],a[1]=t[1],a[2]=t[2],e[0]=i[0],e[1]=i[1],e[2]=i[2],p.transformVec3(s,e,t),p.normalizeVec3(t),r[0]=t[0],r[1]=t[1],r[2]=t[2]}})(),canvasPosToWorldRay:(()=>{const e=new o(16),t=new o(16),s=new o(4),n=new o(4),i=new o(4),a=new o(4);return(r,l,o,c,u,h)=>{const A=p.mulMat4(o,l,e),d=p.inverseMat4(A,t),f=r.width,I=r.height,y=(c[0]-f/2)/(f/2),m=-(c[1]-I/2)/(I/2);s[0]=y,s[1]=m,s[2]=-1,s[3]=1,p.transformVec4(d,s,n),p.mulVec4Scalar(n,1/n[3]),i[0]=y,i[1]=m,i[2]=1,i[3]=1,p.transformVec4(d,i,a),p.mulVec4Scalar(a,1/a[3]),u[0]=a[0],u[1]=a[1],u[2]=a[2],p.subVec3(a,n,h),p.normalizeVec3(h)}})(),canvasPosToLocalRay:(()=>{const e=new o(3),t=new o(3);return(s,n,i,a,r,l,o)=>{p.canvasPosToWorldRay(s,n,i,r,e,t),p.worldRayToLocalRay(a,e,t,l,o)}})(),worldRayToLocalRay:(()=>{const e=new o(16),t=new o(4),s=new o(4);return(n,i,a,r,l)=>{const o=p.inverseMat4(n,e);t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=1,p.transformVec4(o,t,s),r[0]=s[0],r[1]=s[1],r[2]=s[2],p.transformVec3(o,a,l)}})(),buildKDTree:(()=>{const e=new Float32Array;function t(s,n,i,a){const r=new o(6),l={triangles:null,left:null,right:null,leaf:!1,splitDim:0,aabb:r};let c,u;for(r[0]=r[1]=r[2]=Number.POSITIVE_INFINITY,r[3]=r[4]=r[5]=Number.NEGATIVE_INFINITY,c=0,u=s.length;cr[3]&&(r[3]=i[t]),i[t+1]r[4]&&(r[4]=i[t+1]),i[t+2]r[5]&&(r[5]=i[t+2])}}if(s.length<20||a>10)return l.triangles=s,l.leaf=!0,l;e[0]=r[3]-r[0],e[1]=r[4]-r[1],e[2]=r[5]-r[2];let p=0;e[1]>e[p]&&(p=1),e[2]>e[p]&&(p=2),l.splitDim=p;const A=(r[p]+r[p+3])/2,d=new Array(s.length);let f=0;const I=new Array(s.length);let y=0;for(c=0,u=s.length;c{const n=e.length/3,i=new Array(n);for(let e=0;e=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t},octDecodeVec2s(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t}};p.buildEdgeIndices=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();class A{constructor(){this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}get length(){return this._length}shift(){if(this._index>=this._headLength){const e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}const e=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,e}push(e){return this._length++,this._tail.push(e),this}unshift(e){return this._head[--this._index]=e,this._length++,this}}const d={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var f=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],s=e[0].charCodeAt(0),n=s+e[1],i=s;i{};t=t||n,s=s||n;var i=new XMLHttpRequest;i.overrideMimeType("application/json"),i.open("GET",e,!0),i.addEventListener("load",(function(e){var n=e.target.response;if(200===this.status){var i;try{i=JSON.parse(n)}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}t(i)}else if(0===this.status){console.warn("loadFile: HTTP Status 0 received.");try{t(JSON.parse(n))}catch(e){s(`utils.loadJSON(): Failed to parse JSON response - ${e}`)}}else s(e)}),!1),i.addEventListener("error",(function(e){s(e)}),!1),i.send(null)},loadArraybuffer:function(e,t,s){var n=e=>{};t=t||n,s=s||n;const i=e.match(/^data:(.*?)(;base64)?,(.*)$/);if(i){const e=!!i[2];var a=i[3];a=window.decodeURIComponent(a),e&&(a=window.atob(a));try{const e=new ArrayBuffer(a.length),s=new Uint8Array(e);for(var r=0;r{w.removeItem(e.id),delete R.scenes[e.id],delete v[e.id],d.components.scenes--}))},this.clear=function(){let e;for(const t in R.scenes)R.scenes.hasOwnProperty(t)&&(e=R.scenes[t],"default.scene"===t?e.clear():(e.destroy(),delete R.scenes[e.id]))},this.scheduleTask=function(e,t){g.push(e),g.push(t)},this.runTasks=function(e=-1){let t,s,n=(new Date).getTime(),i=0;for(;g.length>0&&(e<0||n0&&b>0){var t=1e3/b;P+=t,E.push(t),E.length>=30&&(P-=E.shift()),d.frame.fps=Math.round(P/E.length)}!function(e){const t=R.runTasks(e+10),s=R.getNumTasks();d.frame.tasksRun=t,d.frame.tasksScheduled=s,d.frame.tasksBudget=10}(e),function(e){for(var t in T.time=e,R.scenes)if(R.scenes.hasOwnProperty(t)){var s=R.scenes[t];T.sceneId=t,T.startTime=s.startTime,T.deltaTime=null!=T.prevTime?T.time-T.prevTime:0,s.fire("tick",T,!0)}T.prevTime=e}(e),function(){const e=R.scenes,t=!1;let s,n,i,a,r;for(r in e)e.hasOwnProperty(r)&&(s=e[r],n=v[r],n||(n=v[r]={}),i=s.ticksPerOcclusionTest,n.ticksPerOcclusionTest!==i&&(n.ticksPerOcclusionTest=i,n.renderCountdown=i),--s.occlusionTestCountdown<=0&&(s.doOcclusionTest(),s.occlusionTestCountdown=i),a=s.ticksPerRender,n.ticksPerRender!==a&&(n.ticksPerRender=a,n.renderCountdown=a),0==--n.renderCountdown&&(s.render(t),n.renderCountdown=a))}(),D=e,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(C):requestAnimationFrame(C);class _{get type(){return"Component"}get isComponent(){return!0}constructor(e=null,t={}){if(this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=t.viewer;else{if("Scene"===e.type)this.scene=e;else{if(!(e instanceof _))throw"Invalid param: owner must be a Component";this.scene=e.scene}this._owner=e}this._dontClear=!!t.dontClear,this._renderer=this.scene._renderer,this.meta=t.meta||{},this.id=t.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,e&&e._own(this)}glRedraw(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}glResort(){this._renderer&&this._renderer.needStateSort()}get owner(){return this._owner}isType(e){return this.type===e}fire(e,t,s){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==s&&(this._events[e]=t||!0);const n=this._eventSubs[e];let i;if(n)for(const s in n)n.hasOwnProperty(s)&&(i=n[s],this._eventCallDepth++,this._eventCallDepth<300?i.callback.call(i.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}on(t,s,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new e),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});let i=this._eventSubs[t];i?this._eventSubsNum[t]++:(i={},this._eventSubs[t]=i,this._eventSubsNum[t]=1);const a=this._subIdMap.addItem();i[a]={callback:s,scope:n||this},this._subIdEvents[a]=t;const r=this._events[t];return void 0!==r&&s.call(n||this,r),a}off(e){if(null==e)return;if(!this._subIdEvents)return;const t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];const s=this._eventSubs[t];s&&(delete s[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}once(e,t,s){const n=this,i=this.on(e,(function(e){n.off(i),t.call(s||this,e)}),s)}hasSubs(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}log(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}_message(e){return" ["+this.type+" "+m.inQuotes(this.id)+"]: "+e}warn(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}error(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}_attach(e){const t=e.name;if(!t)return void this.error("Component 'name' expected");let s=e.component;const n=e.sceneDefault,i=e.sceneSingleton,a=e.type,r=e.on,l=!1!==e.recompiles;if(s&&(m.isNumeric(s)||m.isString(s))){const e=s;if(s=this.scene.components[e],!s)return void this.error("Component not found: "+m.inQuotes(e))}if(!s)if(!0===i){const e=this.scene.types[a];for(const t in e)if(e.hasOwnProperty){s=e[t];break}if(!s)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===n&&(s=this.scene[t],!s))return this.error("Scene has no default component for '"+t+"'"),null;if(s){if(s.scene.id!==this.scene.id)return void this.error("Not in same scene: "+s.type+" "+m.inQuotes(s.id));if(a&&!s.isType(a))return void this.error("Expected a "+a+" type or subtype: "+s.type+" "+m.inQuotes(s.id))}this._attachments||(this._attachments={});const o=this._attached[t];let c,u,h;if(o){if(s&&o.id===s.id)return;const e=this._attachments[o.id];for(c=e.subs,u=0,h=c.length;u{delete this._ownedComponents[e.id]}),this)}_needUpdate(e){this._updateScheduled||(this._updateScheduled=!0,0===e?this._doUpdate():R.scheduleTask(this._doUpdate,this))}_doUpdate(){this._updateScheduled&&(this._updateScheduled=!1,this._update&&this._update())}_update(){}clear(){if(this._ownedComponents)for(var e in this._ownedComponents)if(this._ownedComponents.hasOwnProperty(e)){this._ownedComponents[e].destroy(),delete this._ownedComponents[e]}}destroy(){if(this.destroyed)return;let e,t,s,n,i,a;if(this.fire("destroyed",this.destroyed=!0),this._attachments)for(e in this._attachments)if(this._attachments.hasOwnProperty(e)){for(t=this._attachments[e],s=t.component,n=t.subs,i=0,a=n.length;i0?this.meshes[0]._colorize[3]/255:1}set opacity(e){if(0===this.meshes.length)return;const t=null!=e,s=this.meshes[0]._colorize[3];let n=255;if(t){if(e<0?e=0:e>1&&(e=1),n=Math.floor(255*e),s===n)return}else if(n=255,s===n)return;for(let e=0,t=this.meshes.length;e{this._viewPosDirty=!0,this._needUpdate()})),this._onCameraProjMatrix=this.scene.camera.on("projMatrix",(()=>{this._canvasPosDirty=!0,this._needUpdate()})),this._onEntityDestroyed=null,this._onEntityModelDestroyed=null,this._renderer.addMarker(this),this.entity=t.entity,this.worldPos=t.worldPos,this.occludable=t.occludable}_update(){if(this._viewPosDirty&&(p.transformPoint3(this.scene.camera.viewMatrix,this._worldPos,this._viewPos),this._viewPosDirty=!1,this._canvasPosDirty=!0,this.fire("viewPos",this._viewPos)),this._canvasPosDirty){Y.set(this._viewPos),Y[3]=1,p.transformPoint4(this.scene.camera.projMatrix,Y,X);const e=this.scene.canvas.boundary;this._canvasPos[0]=Math.floor((1+X[0]/X[3])*e[2]/2),this._canvasPos[1]=Math.floor((1-X[1]/X[3])*e[3]/2),this._canvasPosDirty=!1,this.fire("canvasPos",this._canvasPos)}}_setVisible(e){this._visible,this._visible=e,this.fire("visible",this._visible)}set entity(e){if(this._entity){if(this._entity===e)return;null!==this._onEntityDestroyed&&(this._entity.off(this._onEntityDestroyed),this._onEntityDestroyed=null),null!==this._onEntityModelDestroyed&&(this._entity.model.off(this._onEntityModelDestroyed),this._onEntityModelDestroyed=null)}this._entity=e,this._entity&&(this._entity instanceof K?this._onEntityModelDestroyed=this._entity.model.on("destroyed",(()=>{this._entity=null,this._onEntityModelDestroyed=null})):this._onEntityDestroyed=this._entity.on("destroyed",(()=>{this._entity=null,this._onEntityDestroyed=null}))),this.fire("entity",this._entity,!0)}get entity(){return this._entity}set occludable(e){(e=!!e)!==this._occludable&&(this._occludable=e)}get occludable(){return this._occludable}set worldPos(e){this._worldPos.set(e||[0,0,0]),S(this._worldPos,this._origin,this._rtcPos),this._occludable&&this._renderer.markerWorldPosUpdated(this),this._viewPosDirty=!0,this.fire("worldPos",this._worldPos),this._needUpdate()}get worldPos(){return this._worldPos}get origin(){return this._origin}get rtcPos(){return this._rtcPos}get viewPos(){return this._update(),this._viewPos}get canvasPos(){return this._update(),this._canvasPos}get visible(){return!!this._visible}destroy(){this.fire("destroyed",!0),this.scene.camera.off(this._onCameraViewMatrix),this.scene.camera.off(this._onCameraProjMatrix),this._entity&&(null!==this._onEntityDestroyed&&this._entity.off(this._onEntityDestroyed),null!==this._onEntityModelDestroyed&&this._entity.model.off(this._onEntityModelDestroyed)),this._renderer.removeMarker(this),super.destroy()}}class J{constructor(e,t={}){this._color=t.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=t.thickness||1,this._thicknessClickable=t.thicknessClickable||6;var s=this._wire,n=s.style;n.border="solid "+this._thickness+"px "+this._color,n.position="absolute",n["z-index"]=void 0===t.zIndex?"2000001":t.zIndex,n.width="0px",n.height="0px",n.visibility="visible",n.top="0px",n.left="0px",n["-webkit-transform-origin"]="0 0",n["-moz-transform-origin"]="0 0",n["-ms-transform-origin"]="0 0",n["-o-transform-origin"]="0 0",n["transform-origin"]="0 0",n["-webkit-transform"]="rotate(0deg)",n["-moz-transform"]="rotate(0deg)",n["-ms-transform"]="rotate(0deg)",n["-o-transform"]="rotate(0deg)",n.transform="rotate(0deg)",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._wireClickable,a=i.style;a.border="solid "+this._thicknessClickable+"px "+this._color,a.position="absolute",a["z-index"]=void 0===t.zIndex?"2000002":t.zIndex+1,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}get _visible(){return"visible"===this._wire.style.visibility}_update(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,s=this._wire.style;s.width=Math.round(e)+"px",s.left=Math.round(this._x1)+"px",s.top=Math.round(this._y1)+"px",s["-webkit-transform"]="rotate("+t+"deg)",s["-moz-transform"]="rotate("+t+"deg)",s["-ms-transform"]="rotate("+t+"deg)",s["-o-transform"]="rotate("+t+"deg)",s.transform="rotate("+t+"deg)";var n=this._wireClickable.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)"}setStartAndEnd(e,t,s,n){this._x1=e,this._y1=t,this._x2=s,this._y2=n,this._update()}setColor(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}setOpacity(e){this._wire.style.opacity=e}setVisible(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}setClickable(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}destroy(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}class Z{constructor(e,t={}){this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var s=this._dot,n=s.style;n["border-radius"]="25px",n.border="solid 2px white",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"40000005":t.zIndex,n.width="8px",n.height="8px",n.visibility=!1!==t.visible?"visible":"hidden",n.top="0px",n.left="0px",n["box-shadow"]="0 2px 5px 0 #182A3D;",n.opacity=1,n["pointer-events"]="none",t.onContextMenu,e.appendChild(s);var i=this._dotClickable,a=i.style;a["border-radius"]="35px",a.border="solid 10px white",a.position="absolute",a["z-index"]=void 0===t.zIndex?"40000007":t.zIndex+1,a.width="8px",a.height="8px",a.visibility="visible",a.top="0px",a.left="0px",a.opacity=0,a["pointer-events"]="none",t.onContextMenu,e.appendChild(i),t.onMouseOver&&i.addEventListener("mouseover",(e=>{t.onMouseOver(e,this)})),t.onMouseLeave&&i.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this)})),t.onMouseWheel&&i.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&i.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()})),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.borderColor)}setPos(e,t){this._x=e,this._y=t;var s=this._dot.style;s.left=Math.round(e)-4+"px",s.top=Math.round(t)-4+"px";var n=this._dotClickable.style;n.left=Math.round(e)-9+"px",n.top=Math.round(t)-9+"px"}setFillColor(e){this._dot.style.background=e||"lightgreen"}setBorderColor(e){this._dot.style.border="solid 2px"+(e||"black")}setOpacity(e){this._dot.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}setClickable(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}destroy(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}class ${constructor(e,t={}){this._highlightClass="viewer-ruler-label-highlighted",this._prefix=t.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var s=this._label,n=s.style;n["border-radius"]="5px",n.color="white",n.padding="4px",n.border="solid 1px",n.background="lightgreen",n.position="absolute",n["z-index"]=void 0===t.zIndex?"5000005":t.zIndex,n.width="auto",n.height="auto",n.visibility="visible",n.top="0px",n.left="0px",n["pointer-events"]="all",n.opacity=1,t.onContextMenu,s.innerText="",e.appendChild(s),this.setPos(t.x||0,t.y||0),this.setFillColor(t.fillColor),this.setBorderColor(t.fillColor),this.setText(t.text),t.onMouseOver&&s.addEventListener("mouseover",(e=>{t.onMouseOver(e,this),e.preventDefault()})),t.onMouseLeave&&s.addEventListener("mouseleave",(e=>{t.onMouseLeave(e,this),e.preventDefault()})),t.onMouseWheel&&s.addEventListener("wheel",(e=>{t.onMouseWheel(e,this)})),t.onContextMenu&&s.addEventListener("contextmenu",(e=>{t.onContextMenu(e,this),e.preventDefault()}))}setPos(e,t){this._x=e,this._y=t;var s=this._label.style;s.left=Math.round(e)-20+"px",s.top=Math.round(t)-12+"px"}setPosOnWire(e,t,s,n){var i=e+.5*(s-e),a=t+.5*(n-t),r=this._label.style;r.left=Math.round(i)-20+"px",r.top=Math.round(a)-12+"px"}setPosBetweenWires(e,t,s,n,i,a){var r=(e+s+i)/3,l=(t+n+a)/3,o=this._label.style;o.left=Math.round(r)-20+"px",o.top=Math.round(l)-12+"px"}setText(e){this._label.innerHTML=this._prefix+(e||"")}setFillColor(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}setBorderColor(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}setOpacity(e){this._label.style.opacity=e}setVisible(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setCulled(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}setHighlighted(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}setClickable(e){this._label.style["pointer-events"]=e?"all":"none"}destroy(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}var ee=p.vec3(),te=p.vec3();class se extends _{constructor(e,t={}){if(super(e.viewer.scene,t),this.plugin=e,this._container=t.container,!this._container)throw"config missing: container";this._color=t.color||e.defaultColor;var s=this.plugin.viewer.scene;this._originMarker=new q(s,t.origin),this._cornerMarker=new q(s,t.corner),this._targetMarker=new q(s,t.target),this._originWorld=p.vec3(),this._cornerWorld=p.vec3(),this._targetWorld=p.vec3(),this._wp=new Float64Array(12),this._vp=new Float64Array(12),this._pp=new Float64Array(12),this._cp=new Int16Array(6);const n=t.onMouseOver?e=>{t.onMouseOver(e,this)}:null,i=t.onMouseLeave?e=>{t.onMouseLeave(e,this)}:null,a=t.onContextMenu?e=>{t.onContextMenu(e,this)}:null,r=e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};this._originDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._cornerDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetDot=new Z(this._container,{fillColor:this._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._originWire=new J(this._container,{color:this._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._targetWire=new J(this._container,{color:this._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._angleLabel=new $(this._container,{fillColor:this._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:n,onMouseLeave:i,onMouseWheel:r,onContextMenu:a}),this._wpDirty=!1,this._vpDirty=!1,this._cpDirty=!1,this._visible=!1,this._originVisible=!1,this._cornerVisible=!1,this._targetVisible=!1,this._originWireVisible=!1,this._targetWireVisible=!1,this._angleVisible=!1,this._labelsVisible=!1,this._clickable=!1,this._originMarker.on("worldPos",(e=>{this._originWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._cornerMarker.on("worldPos",(e=>{this._cornerWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._targetMarker.on("worldPos",(e=>{this._targetWorld.set(e||[0,0,0]),this._wpDirty=!0,this._needUpdate(0)})),this._onViewMatrix=s.camera.on("viewMatrix",(()=>{this._vpDirty=!0,this._needUpdate(0)})),this._onProjMatrix=s.camera.on("projMatrix",(()=>{this._cpDirty=!0,this._needUpdate()})),this._onCanvasBoundary=s.canvas.on("boundary",(()=>{this._cpDirty=!0,this._needUpdate(0)})),this.approximate=t.approximate,this.visible=t.visible,this.originVisible=t.originVisible,this.cornerVisible=t.cornerVisible,this.targetVisible=t.targetVisible,this.originWireVisible=t.originWireVisible,this.targetWireVisible=t.targetWireVisible,this.angleVisible=t.angleVisible,this.labelsVisible=t.labelsVisible}_update(){if(!this._visible)return;const e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(p.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){const A=-.3,d=this._originMarker.viewPos[2],f=this._cornerMarker.viewPos[2],I=this._targetMarker.viewPos[2];if(d>A||f>A||I>A)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);p.transformPositions4(e.camera.project.matrix,this._vp,this._pp);var t=this._pp,s=this._cp,n=e.canvas.canvas.getBoundingClientRect();const y=this._container.getBoundingClientRect();for(var i=n.top-y.top,a=n.left-y.left,r=e.canvas.boundary,l=r[2],o=r[3],c=0,u=0,h=t.length;u{switch(a=!0,r=e.entity,l.set(e.worldPos),o.set(e.canvasPos),this._state){case 0:this.markerDiv.style.marginLeft=e.canvasPos[0]-5+"px",this.markerDiv.style.marginTop=e.canvasPos[1]-5+"px",this.markerDiv.style.background="pink",this.markerDiv.style.border="2px solid red";break;case 1:this._currentAngleMeasurement&&(this._currentAngleMeasurement.originWireVisible=!0,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.cornerVisible=!0,this._currentAngleMeasurement.angleVisible=!1,this._currentAngleMeasurement.corner.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer";break;case 2:this._currentAngleMeasurement&&(this._currentAngleMeasurement.targetWireVisible=!0,this._currentAngleMeasurement.targetVisible=!0,this._currentAngleMeasurement.angleVisible=!0,this._currentAngleMeasurement.target.worldPos=e.worldPos),this.markerDiv.style.marginLeft="-10000px",this.markerDiv.style.marginTop="-10000px",n.style.cursor="pointer"}})),this._onInputMouseDown=i.on("mousedown",(e=>{c=e[0],u=e[1]})),this._onInputMouseUp=i.on("mouseup",(e=>{if(!(e[0]>c+5||e[0]u+5||e[1]{if(a=!1,this.markerDiv.style.marginLeft="-100px",this.markerDiv.style.marginTop="-100px",this._currentAngleMeasurement){switch(this._state){case 0:this._currentAngleMeasurement.originVisible=!1;break;case 1:this._currentAngleMeasurement.cornerVisible=!1,this._currentAngleMeasurement.originWireVisible=!1,this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1;break;case 2:this._currentAngleMeasurement.targetVisible=!1,this._currentAngleMeasurement.targetWireVisible=!1,this._currentAngleMeasurement.angleVisible=!1}n.style.cursor="default"}})),n.addEventListener("touchstart",this._onCanvasTouchStart=e=>{const t=e.touches,s=e.changedTouches;1===t.length&&1===s.length&&ie(t[0],h)},{passive:!0}),n.addEventListener("touchend",this._onCanvasTouchEnd=e=>{const s=e.touches,n=e.changedTouches;if(0===s.length&&1===n.length){if(ie(n[0],A),A[0]>h[0]+5||A[0]h[1]+5||A[1]{this.fire("mouseOver",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onMouseLeave=(e,t)=>{this.fire("mouseLeave",{plugin:this,angleMeasurement:t,measurement:t,event:e})},this._onContextMenu=(e,t)=>{this.fire("contextMenu",{plugin:this,angleMeasurement:t,measurement:t,event:e})}}getContainerElement(){return this._container}send(e,t){}get control(){return this._control}get measurements(){return this._measurements}createMeasurement(e={}){this.viewer.scene.components[e.id]&&(this.error("Viewer scene component with this ID already exists: "+e.id),delete e.id);const t=e.origin,s=e.corner,n=e.target,i=new se(this,{id:e.id,plugin:this,container:this._container,origin:{entity:t.entity,worldPos:t.worldPos},corner:{entity:s.entity,worldPos:s.worldPos},target:{entity:n.entity,worldPos:n.worldPos},visible:e.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[i.id]=i,i.on("destroyed",(()=>{delete this._measurements[i.id]})),this.fire("measurementCreated",i),i}destroyMeasurement(e){const t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}setLabelsShown(e){for(const[t,s]of Object.entries(this.measurements))s.labelShown=e}clear(){const e=Object.keys(this._measurements);for(var t=0,s=e.length;t{this.plugin.fire("markerClicked",this)}),this._marker.addEventListener("mouseenter",this._onMouseEnterExternalMarker=()=>{this.plugin.fire("markerMouseEnter",this)}),this._marker.addEventListener("mouseleave",this._onMouseLeaveExternalMarker=()=>{this.plugin.fire("markerMouseLeave",this)}),this._markerExternal=!0):(this._markerHTML=t.markerHTML,this._htmlDirty=!0,this._markerExternal=!1),t.labelElement?(this._label=t.labelElement,this._labelExternal=!0):(this._labelHTML=t.labelHTML,this._htmlDirty=!0,this._labelExternal=!1),this._markerShown=!!t.markerShown,this._labelShown=!!t.labelShown,this._values=t.values||{},this._layoutDirty=!0,this._visibilityDirty=!0,this._buildHTML(),this._onTick=this.scene.on("tick",(()=>{this._htmlDirty&&(this._buildHTML(),this._htmlDirty=!1,this._layoutDirty=!0,this._visibilityDirty=!0),(this._layoutDirty||this._visibilityDirty)&&(this._markerShown||this._labelShown)&&(this._updatePosition(),this._layoutDirty=!1),this._visibilityDirty&&(this._marker.style.visibility=this.visible&&this._markerShown?"visible":"hidden",this._label.style.visibility=this.visible&&this._markerShown&&this._labelShown?"visible":"hidden",this._visibilityDirty=!1)})),this.on("canvasPos",(()=>{this._layoutDirty=!0})),this.on("visible",(()=>{this._visibilityDirty=!0})),this.setMarkerShown(!1!==t.markerShown),this.setLabelShown(t.labelShown),this.eye=t.eye?t.eye.slice():null,this.look=t.look?t.look.slice():null,this.up=t.up?t.up.slice():null,this.projection=t.projection}_buildHTML(){if(!this._markerExternal){this._marker&&(this._container.removeChild(this._marker),this._marker=null);let e=this._markerHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._marker=t.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(()=>{this.plugin.fire("markerClicked",this)})),this._marker.addEventListener("mouseenter",(()=>{this.plugin.fire("markerMouseEnter",this)})),this._marker.addEventListener("mouseleave",(()=>{this.plugin.fire("markerMouseLeave",this)})),this._marker.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);let e=this._labelHTML||"

";m.isArray(e)&&(e=e.join("")),e=this._renderTemplate(e);const t=document.createRange().createContextualFragment(e);this._label=t.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(e=>{this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))}))}}_updatePosition(){const e=this.scene.canvas.boundary,t=e[0],s=e[1],n=this.canvasPos;this._marker.style.left=Math.floor(t+n[0])-12+"px",this._marker.style.top=Math.floor(s+n[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+n[0]+20)+"px",this._label.style.top=Math.floor(s+n[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}_renderTemplate(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){const s=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),s)}return e}setMarkerShown(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}getMarkerShown(){return this._markerShown}setLabelShown(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}getLabelShown(){return this._labelShown}setField(e,t){this._values[e]=t||"",this._htmlDirty=!0}getField(e){return this._values[e]}setValues(e){for(var t in e)if(e.hasOwnProperty(t)){const s=e[t];this.setField(t,s)}}getValues(){return this._values}destroy(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),super.destroy()}}const le=p.vec3(),oe=p.vec3(),ce=p.vec3();class ue extends r{constructor(e,t){super("Annotations",e),this._labelHTML=t.labelHTML||"
",this._markerHTML=t.markerHTML||"
",this._container=t.container||document.body,this._values=t.values||{},this.annotations={},this.surfaceOffset=t.surfaceOffset}getContainerElement(){return this._container}send(e,t){if("clearAnnotations"===e)this.clear()}set surfaceOffset(e){null==e&&(e=.3),this._surfaceOffset=e}get surfaceOffset(){return this._surfaceOffset}createAnnotation(e){var t,s;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){const n=e.pickResult;if(n.worldPos&&n.worldNormal){const e=p.normalizeVec3(n.worldNormal,le),i=p.mulVec3Scalar(e,this._surfaceOffset,oe);t=p.addVec3(n.worldPos,i,ce),s=n.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,s=e.entity;var n=null;e.markerElementId&&((n=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var i=null;e.labelElementId&&((i=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));const a=new re(this.viewer.scene,{id:e.id,plugin:this,entity:s,worldPos:t,container:this._container,markerElement:n,labelElement:i,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:m.apply(e.values,m.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[a.id]=a,a.on("destroyed",(()=>{delete this.annotations[a.id],this.fire("annotationDestroyed",a.id)})),this.fire("annotationCreated",a.id),a}destroyAnnotation(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}clear(){const e=Object.keys(this.annotations);for(var t=0,s=e.length;t
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}_injectDefaultCSS(){const e="xeokit-spinner-css";if(document.getElementById(e))return;const t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}_adjustPosition(){if(this._isCustom)return;const e=this._canvas,t=this._element,s=t.style;s.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",s.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}set processes(e){if(e=e||0,this._processes===e)return;if(e<0)return;const t=this._processes;this._processes=e;const s=this._element;s&&(s.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}get processes(){return this._processes}_destroy(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);const e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}const pe={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},Ae=document.createElement("canvas");if(Ae){const e=Ae.getContext("webgl",{antialias:!0})||Ae.getContext("experimental-webgl",{antialias:!0});pe.WEBGL=!!e,pe.WEBGL&&(pe.ANTIALIAS=e.getContextAttributes().antialias,e.getShaderPrecisionFormat?e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="highp":e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?pe.FS_MAX_FLOAT_PRECISION="mediump":pe.FS_MAX_FLOAT_PRECISION="lowp":pe.FS_MAX_FLOAT_PRECISION="mediump",pe.DEPTH_BUFFER_BITS=e.getParameter(e.DEPTH_BITS),pe.MAX_TEXTURE_SIZE=e.getParameter(e.MAX_TEXTURE_SIZE),pe.MAX_CUBE_MAP_SIZE=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),pe.MAX_RENDERBUFFER_SIZE=e.getParameter(e.MAX_RENDERBUFFER_SIZE),pe.MAX_TEXTURE_UNITS=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),pe.MAX_TEXTURE_IMAGE_UNITS=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),pe.MAX_VERTEX_ATTRIBS=e.getParameter(e.MAX_VERTEX_ATTRIBS),pe.MAX_VERTEX_UNIFORM_VECTORS=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),pe.MAX_FRAGMENT_UNIFORM_VECTORS=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),pe.MAX_VARYING_VECTORS=e.getParameter(e.MAX_VARYING_VECTORS),e.getSupportedExtensions().forEach((function(e){pe.SUPPORTED_EXTENSIONS[e]=!0})))}const de=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"];class fe extends _{constructor(e,t={}){super(e,t),this._backgroundColor=p.vec3([t.backgroundColor?t.backgroundColor[0]:1,t.backgroundColor?t.backgroundColor[1]:1,t.backgroundColor?t.backgroundColor[2]:1]),this._backgroundColorFromAmbientLight=!!t.backgroundColorFromAmbientLight,this.canvas=t.canvas,this.gl=null,this.webgl2=!1,this.transparent=!!t.transparent,this.contextAttr=t.contextAttr||{},this.contextAttr.alpha=this.transparent,this.contextAttr.preserveDrawingBuffer=!!this.contextAttr.preserveDrawingBuffer,this.contextAttr.stencil=!1,this.contextAttr.premultipliedAlpha=!!this.contextAttr.premultipliedAlpha,this.contextAttr.antialias=!1!==this.contextAttr.antialias,this.resolutionScale=t.resolutionScale,this.canvas.width=Math.round(this.canvas.clientWidth*this._resolutionScale),this.canvas.height=Math.round(this.canvas.clientHeight*this._resolutionScale),this.boundary=[this.canvas.offsetLeft,this.canvas.offsetTop,this.canvas.clientWidth,this.canvas.clientHeight],this._initWebGL(t);const s=this;this.canvas.addEventListener("webglcontextlost",this._webglcontextlostListener=function(e){console.time("webglcontextrestored"),s.scene._webglContextLost(),s.fire("webglcontextlost"),e.preventDefault()},!1),this.canvas.addEventListener("webglcontextrestored",this._webglcontextrestoredListener=function(e){s._initWebGL(),s.gl&&(s.scene._webglContextRestored(s.gl),s.fire("webglcontextrestored",s.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);let n=!0;new ResizeObserver((e=>{for(const t of e)t.contentBoxSize&&(n=!0)})).observe(this.canvas),this._tick=this.scene.on("tick",(()=>{n&&(n=!1,s.canvas.width=Math.round(s.canvas.clientWidth*s._resolutionScale),s.canvas.height=Math.round(s.canvas.clientHeight*s._resolutionScale),s.boundary[0]=s.canvas.offsetLeft,s.boundary[1]=s.canvas.offsetTop,s.boundary[2]=s.canvas.clientWidth,s.boundary[3]=s.canvas.clientHeight,s.fire("boundary",s.boundary))})),this._spinner=new he(this.scene,{canvas:this.canvas,elementId:t.spinnerElementId})}get type(){return"Canvas"}get backgroundColorFromAmbientLight(){return this._backgroundColorFromAmbientLight}set backgroundColorFromAmbientLight(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}get backgroundColor(){return this._backgroundColor}set backgroundColor(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}get resolutionScale(){return this._resolutionScale}set resolutionScale(e){if((e=e||1)===this._resolutionScale)return;this._resolutionScale=e;const t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}get spinner(){return this._spinner}_createCanvas(){const e="xeokit-canvas-"+p.createUUID(),t=document.getElementsByTagName("body")[0],s=document.createElement("div"),n=s.style;n.height="100%",n.width="100%",n.padding="0",n.margin="0",n.background="rgba(0,0,0,0);",n.float="left",n.left="0",n.top="0",n.position="absolute",n.opacity="1.0",n["z-index"]="-10000",s.innerHTML+='',t.appendChild(s),this.canvas=document.getElementById(e)}_getElementXY(e){let t=0,s=0;for(;e;)t+=e.offsetLeft-e.scrollLeft,s+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:s}}_initWebGL(){if(!this.gl)for(let e=0;!this.gl&&e0&&"/"===s.charAt(n+1)&&(s=s.substring(0,n)),t.push(s);return t.join("\n")}function Ee(e){console.error(e.join("\n"))}class be{constructor(e,t){this.id=ge.addItem({}),this.source=t,this.init(e)}init(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new me(e,e.VERTEX_SHADER,Te(this.source.vertex)),this._fragmentShader=new me(e,e.FRAGMENT_SHADER,Te(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void Ee(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void Ee(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void Ee(this.errors);let t,s,n,i,a;if(this.compiled=!0,this.handle=e.createProgram(),!this.handle)return void(this.errors=["Failed to allocate program"]);if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void Ee(this.errors);const r=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(s=0;sthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}setData(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}bind(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}unbind(){this.allocated&&this._gl.bindBuffer(this.type,null)}destroy(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}class Pe{constructor(e,t){this.scene=e,this.aabb=p.AABB3(),this.origin=p.vec3(t),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}addMarker(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}markerWorldPosUpdated(e){if(!this.markers[e.id])return;const t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}removeMarker(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}update(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}_buildMarkerList(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}_buildPositions(){let e=0;for(let t=0;t-t){s._setVisible(!1);continue}const r=s.canvasPos,l=r[0],o=r[1];l+10<0||o+10<0||l-10>n||o-10>i?s._setVisible(!1):!s.entity||s.entity.visible?s.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=s,this.pixels[a++]=l,this.pixels[a++]=o):s._setVisible(!0):s._setVisible(!1)}}_updateActiveSectionPlanes(){const e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(let s=0;s{this._occlusionTestListDirty=!0})),this._onCameraProjMatrix=e.camera.on("projMatrix",(()=>{this._occlusionTestListDirty=!0})),this._onCanvasBoundary=e.canvas.on("boundary",(()=>{this._occlusionTestListDirty=!0}))}addMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s||(s=new Pe(this._scene,e.origin),this._occlusionLayers[s.originHash]=s,this._occlusionLayersListDirty=!0),s.addMarker(e),this._markersToOcclusionLayersMap[e.id]=s,this._occlusionTestListDirty=!0}markerWorldPosUpdated(e){const t=this._markersToOcclusionLayersMap[e.id];if(!t)return void e.error("Marker has not been added to OcclusionTester");const s=e.origin.join();if(s!==t.originHash){1===t.numMarkers?(t.destroy(),delete this._occlusionLayers[t.originHash],this._occlusionLayersListDirty=!0):t.removeMarker(e);let n=this._occlusionLayers[s];n||(n=new Pe(this._scene,e.origin),this._occlusionLayers[s]=t,this._occlusionLayersListDirty=!0),n.addMarker(e),this._markersToOcclusionLayersMap[e.id]=n}else t.markerWorldPosUpdated(e)}removeMarker(e){const t=e.origin.join();let s=this._occlusionLayers[t];s&&(1===s.numMarkers?(s.destroy(),delete this._occlusionLayers[s.originHash],this._occlusionLayersListDirty=!0):s.removeMarker(e),delete this._markersToOcclusionLayersMap[e.id])}get needOcclusionTest(){return this._occlusionTestListDirty}bindRenderBuf(){const e=[this._scene.canvas.canvas.id,this._scene._sectionPlanesState.getHash()].join(";");if(e!==this._shaderSourceHash&&(this._shaderSourceHash=e,this._shaderSourceDirty=!0),this._shaderSourceDirty&&(this._buildShaderSource(),this._shaderSourceDirty=!1,this._programDirty=!0),this._programDirty&&(this._buildProgram(),this._programDirty=!1,this._occlusionTestListDirty=!0),this._occlusionLayersListDirty&&(this._buildOcclusionLayersList(),this._occlusionLayersListDirty=!1),this._occlusionTestListDirty){for(let e=0,t=this._occlusionLayersList.length;e0,s=[];return s.push("#version 300 es"),s.push("// OcclusionTester vertex shader"),s.push("in vec3 position;"),s.push("uniform mat4 modelMatrix;"),s.push("uniform mat4 viewMatrix;"),s.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(s.push("uniform float logDepthBufFC;"),s.push("out float vFragDepth;")),t&&s.push("out vec4 vWorldPosition;"),s.push("void main(void) {"),s.push("vec4 worldPosition = vec4(position, 1.0); "),s.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&s.push(" vWorldPosition = worldPosition;"),s.push(" vec4 clipPos = projMatrix * viewPosition;"),s.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?s.push("vFragDepth = 1.0 + clipPos.w;"):s.push("clipPos.z += -0.001;"),s.push(" gl_Position = clipPos;"),s.push("}"),s}_buildFragmentShaderSource(){const e=this._scene,t=e._sectionPlanesState,s=t.sectionPlanes.length>0,n=[];if(n.push("#version 300 es"),n.push("// OcclusionTester fragment shader"),n.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),n.push("precision highp float;"),n.push("precision highp int;"),n.push("#else"),n.push("precision mediump float;"),n.push("precision mediump int;"),n.push("#endif"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("in float vFragDepth;")),s){n.push("in vec4 vWorldPosition;");for(let e=0;e 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&n.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),n.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),n.push("}"),n}_buildProgram(){this._program&&this._program.destroy();const e=this._scene,t=e.canvas.gl,s=e._sectionPlanesState;if(this._program=new be(t,this._shaderSource),this._program.errors)return void(this.errors=this._program.errors);const n=this._program;this._uViewMatrix=n.getLocation("viewMatrix"),this._uProjMatrix=n.getLocation("projMatrix"),this._uSectionPlanes=[];for(let e=0,t=s.sectionPlanes.length;e0){const e=n.sectionPlanes;for(let n=0;n{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(n.camera.projMatrix,t),t)})());const t=this._scene.canvas.gl,s=this._program,n=this._scene,i=n.sao,a=t.drawingBufferWidth,r=t.drawingBufferHeight,l=n.camera.project._state,o=l.near,c=l.far,u=l.matrix,h=this._getInverseProjectMat(),A=Math.random(),d="perspective"===n.camera.projection;Be[0]=a,Be[1]=r,t.viewport(0,0,a,r),t.clearColor(0,0,0,1),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),t.frontFace(t.CCW),t.clear(t.COLOR_BUFFER_BIT),s.bind(),t.uniform1f(this._uCameraNear,o),t.uniform1f(this._uCameraFar,c),t.uniformMatrix4fv(this._uCameraProjectionMatrix,!1,u),t.uniformMatrix4fv(this._uCameraInverseProjectionMatrix,!1,h),t.uniform1i(this._uPerspective,d),t.uniform1f(this._uScale,i.scale*(c/5)),t.uniform1f(this._uIntensity,i.intensity),t.uniform1f(this._uBias,i.bias),t.uniform1f(this._uKernelRadius,i.kernelRadius),t.uniform1f(this._uMinResolution,i.minResolution),t.uniform2fv(this._uViewport,Be),t.uniform1f(this._uRandomSeed,A);const f=e.getDepthTexture();s.bindTexture(this._uDepthTexture,f,0),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),t.drawElements(t.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}_build(){let e=!1;const t=this._scene.sao;if(t.numSamples!==this._numSamples&&(this._numSamples=Math.floor(t.numSamples),e=!0),!e)return;const s=this._scene.canvas.gl;if(this._program&&(this._program.destroy(),this._program=null),this._program=new be(s,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV; \n \n out vec2 vUV;\n \n void main () {\n gl_Position = vec4(aPosition, 1.0);\n vUV = aUV;\n }"],fragment:[`#version 300 es \n precision highp float;\n precision highp int; \n \n #define NORMAL_TEXTURE 0\n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n #define NUM_SAMPLES ${this._numSamples}\n #define NUM_RINGS 4 \n \n in vec2 vUV;\n \n uniform sampler2D uDepthTexture;\n \n uniform float uCameraNear;\n uniform float uCameraFar;\n uniform mat4 uProjectMatrix;\n uniform mat4 uInverseProjectMatrix;\n \n uniform bool uPerspective;\n\n uniform float uScale;\n uniform float uIntensity;\n uniform float uBias;\n uniform float uKernelRadius;\n uniform float uMinResolution;\n uniform vec2 uViewport;\n uniform float uRandomSeed;\n\n float pow2( const in float x ) { return x*x; }\n \n highp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract(sin(sn) * c);\n }\n\n vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n }\n\n vec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n }\n\n const float packUpscale = 256. / 255.;\n const float unpackDownScale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. ); \n\n const float shiftRights = 1. / 256.;\n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float unpackRGBAToFloat( const in vec4 v ) { \n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unPackFactors );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - far );\n }\n\n float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( near - far ) - near;\n }\n \n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n if (uPerspective) {\n return perspectiveDepthToViewZ( depth, uCameraNear, uCameraFar );\n } else {\n return orthographicDepthToViewZ( depth, uCameraNear, uCameraFar );\n }\n }\n\n vec3 getViewPos( const in vec2 screenPos, const in float depth, const in float viewZ ) {\n \tfloat clipW = uProjectMatrix[2][3] * viewZ + uProjectMatrix[3][3];\n \tvec4 clipPosition = vec4( ( vec3( screenPos, depth ) - 0.5 ) * 2.0, 1.0 );\n \tclipPosition *= clipW; \n \treturn ( uInverseProjectMatrix * clipPosition ).xyz;\n }\n\n vec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPos ) { \n return normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n }\n\n float scaleDividedByCameraFar;\n float minResolutionMultipliedByCameraFar;\n\n float getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n \tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n \tfloat viewDistance = length( viewDelta );\n \tfloat scaledScreenDistance = scaleDividedByCameraFar * viewDistance;\n \treturn max(0.0, (dot(centerViewNormal, viewDelta) - minResolutionMultipliedByCameraFar) / scaledScreenDistance - uBias) / (1.0 + pow2( scaledScreenDistance ) );\n }\n\n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n float getAmbientOcclusion( const in vec3 centerViewPosition ) {\n \n \tscaleDividedByCameraFar = uScale / uCameraFar;\n \tminResolutionMultipliedByCameraFar = uMinResolution * uCameraFar;\n \tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUV );\n\n \tfloat angle = rand( vUV + uRandomSeed ) * PI2;\n \tvec2 radius = vec2( uKernelRadius * INV_NUM_SAMPLES ) / uViewport;\n \tvec2 radiusStep = radius;\n\n \tfloat occlusionSum = 0.0;\n \tfloat weightSum = 0.0;\n\n \tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n \t\tvec2 sampleUv = vUV + vec2( cos( angle ), sin( angle ) ) * radius;\n \t\tradius += radiusStep;\n \t\tangle += ANGLE_STEP;\n\n \t\tfloat sampleDepth = getDepth( sampleUv );\n \t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }`]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const n=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(s,s.ARRAY_BUFFER,i,i.length,3,s.STATIC_DRAW),this._uvBuf=new De(s,s.ARRAY_BUFFER,n,n.length,2,s.STATIC_DRAW),this._indicesBuf=new De(s,s.ELEMENT_ARRAY_BUFFER,a,a.length,1,s.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}destroy(){this._program&&(this._program.destroy(),this._program=null)}}const Se=new Float32Array(He(17,[0,1])),Ne=new Float32Array(He(17,[1,0])),xe=new Float32Array(function(e,t){const s=[];for(let n=0;n<=e;n++)s.push(Fe(n,t));return s}(17,4)),Le=new Float32Array(2);class Me{constructor(e){this._scene=e,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}init(){const e=this._scene.canvas.gl;if(this._program=new be(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS 16\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }"]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);const t=new Float32Array([1,1,0,1,0,0,1,0]),s=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),n=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new De(e,e.ARRAY_BUFFER,s,s.length,3,e.STATIC_DRAW),this._uvBuf=new De(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new De(e,e.ELEMENT_ARRAY_BUFFER,n,n.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}render(e,t,s){if(this._programError)return;this._getInverseProjectMat||(this._getInverseProjectMat=(()=>{let e=!0;this._scene.camera.on("projMatrix",(function(){e=!0}));const t=p.mat4();return()=>(e&&p.inverseMat4(a.camera.projMatrix,t),t)})());const n=this._scene.canvas.gl,i=this._program,a=this._scene,r=n.drawingBufferWidth,l=n.drawingBufferHeight,o=a.camera.project._state,c=o.near,u=o.far;n.viewport(0,0,r,l),n.clearColor(0,0,0,1),n.enable(n.DEPTH_TEST),n.disable(n.BLEND),n.frontFace(n.CCW),n.clear(n.COLOR_BUFFER_BIT|n.DEPTH_BUFFER_BIT),i.bind(),Le[0]=r,Le[1]=l,n.uniform2fv(this._uViewport,Le),n.uniform1f(this._uCameraNear,c),n.uniform1f(this._uCameraFar,u),n.uniform1f(this._uDepthCutoff,.01),0===s?n.uniform2fv(this._uSampleOffsets,Ne):n.uniform2fv(this._uSampleOffsets,Se),n.uniform1fv(this._uSampleWeights,xe);const h=e.getDepthTexture(),A=t.getTexture();i.bindTexture(this._uDepthTexture,h,0),i.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),n.drawElements(n.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}destroy(){this._program.destroy()}}function Fe(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function He(e,t){const s=[];for(let n=0;n<=e;n++)s.push(t[0]*n),s.push(t[1]*n);return s}class Ue{constructor(e,t,s){s=s||{},this.gl=t,this.allocated=!1,this.canvas=e,this.buffer=null,this.bound=!1,this.size=s.size,this._hasDepthTexture=!!s.depthTexture}setSize(e){this.size=e}webglContextRestored(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}bind(e=null){if(this._touch(e),this.bound)return;const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}_touch(e=null){let t,s;const n=this.gl;if(this.size?(t=this.size[0],s=this.size[1]):(t=n.drawingBufferWidth,s=n.drawingBufferHeight),this.buffer){if(this.buffer.width===t&&this.buffer.height===s)return;n.deleteTexture(this.buffer.texture),n.deleteFramebuffer(this.buffer.framebuf),n.deleteRenderbuffer(this.buffer.renderbuf)}const i=n.createTexture();let a;n.bindTexture(n.TEXTURE_2D,i),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e?n.texStorage2D(n.TEXTURE_2D,1,e,t,s):n.texImage2D(n.TEXTURE_2D,0,n.RGBA,t,s,0,n.RGBA,n.UNSIGNED_BYTE,null),this._hasDepthTexture&&(a=n.createTexture(),n.bindTexture(n.TEXTURE_2D,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.DEPTH_COMPONENT32F,t,s,0,n.DEPTH_COMPONENT,n.FLOAT,null));const r=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,r),n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_COMPONENT32F,t,s);const l=n.createFramebuffer();if(n.bindFramebuffer(n.FRAMEBUFFER,l),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,i,0),this._hasDepthTexture?n.framebufferTexture2D(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.TEXTURE_2D,a,0):n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,r),n.bindTexture(n.TEXTURE_2D,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,l),!n.isFramebuffer(l))throw"Invalid framebuffer";n.bindFramebuffer(n.FRAMEBUFFER,null);const o=n.checkFramebufferStatus(n.FRAMEBUFFER);switch(o){case n.FRAMEBUFFER_COMPLETE:break;case n.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case n.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case n.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+o}this.buffer={framebuf:l,renderbuf:r,texture:i,depthTexture:a,width:t,height:s},this.bound=!1}clear(){if(!this.bound)throw"Render buffer not bound";const e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}read(e,t,s=null,n=null,i=Uint8Array,a=4){const r=e,l=(this.buffer.height||this.gl.drawingBufferHeight)-t,o=new i(a),c=this.gl;return c.readPixels(r,l,1,1,s||c.RGBA,n||c.UNSIGNED_BYTE,o,0),o}readArray(e=null,t=null,s=Uint8Array,n=4){const i=new s(this.buffer.width*this.buffer.height*n),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}readImageAsCanvas(){const e=this.gl,t=this._getImageDataCache(),s=t.pixelData,n=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,s);const r=this.buffer.width,l=this.buffer.height,o=l/2|0,c=4*r,u=new Uint8Array(4*r);for(let e=0;e0)for(n.withSAO=!0,S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||k>0||H>0||U>0){if(a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):(a.blendEquation(a.FUNC_ADD),a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,l||a.depthMask(!1),(H>0||U>0)&&a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),U>0)for(S=0;S0)for(S=0;S0)for(S=0;S0)for(S=0;S0||W>0){if(n.lastProgramId=null,t.highlightMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),W>0)for(S=0;S0)for(S=0;S0||K>0||Q>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.enable(a.CULL_FACE),K>0)for(S=0;S0)for(S=0;S0||X>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),X>0)for(S=0;S0)for(S=0;S0||J>0){if(n.lastProgramId=null,t.selectedMaterial.glowThrough&&a.clear(a.DEPTH_BUFFER_BIT),a.enable(a.CULL_FACE),a.enable(a.BLEND),r?(a.blendEquation(a.FUNC_ADD),a.blendFuncSeparate(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA,a.ONE,a.ONE_MINUS_SRC_ALPHA)):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),J>0)for(S=0;S0)for(S=0;S0){const t=Math.floor(e/4),s=r.size[0];r.size[1];const n=t%s-Math.floor(s/2),i=Math.floor(t/s)-Math.floor(s/2),a=Math.sqrt(Math.pow(n,2)+Math.pow(i,2));m.push({x:n,y:i,dist:a,result:[d[e+0],d[e+1],d[e+2],d[e+3]]})}let v=null;if(m.length>0){m.sort(((e,t)=>e.dist-t.dist)),m=m[0].result;const e=A[m[3]],t=e.origin,s=e.coordinateScale;v=[m[0]*s[0]+t[0],m[1]*s[1]+t[1],m[2]*s[2]+t[2]]}if(null===f&&null==v)return null;let w=null;return null!==v&&(w=t.camera.projectWorldPos(v)),{worldPos:f,snappedWorldPos:v,snappedCanvasPos:w}},this.addMarker=function(e){this._occlusionTester=this._occlusionTester||new _e(t,g),this._occlusionTester.addMarker(e),t.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){D(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.enable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.disable(a.BLEND),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT);for(let e in c)if(c.hasOwnProperty(e)){const t=c[e].drawableList;for(let e=0,s=t.length;e{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!0:e.keyCode===this.KEY_ALT?this.altDown=!0:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!0),this.keyDown[e.keyCode]=!0,this.fire("keydown",e.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=e=>{this.enabled&&this.keyboardEnabled&&"INPUT"!==e.target.tagName&&"TEXTAREA"!==e.target.tagName&&(e.keyCode===this.KEY_CTRL?this.ctrlDown=!1:e.keyCode===this.KEY_ALT?this.altDown=!1:e.keyCode===this.KEY_SHIFT&&(this.shiftDown=!1),this.keyDown[e.keyCode]=!1,this.fire("keyup",e.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=e=>{this.enabled&&(this.mouseover=!0,this._getMouseCanvasPos(e),this.fire("mouseenter",this.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=e=>{this.enabled&&(this.mouseover=!1,this._getMouseCanvasPos(e),this.fire("mouseleave",this.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!0;break;case 2:this.mouseDownMiddle=!0;break;case 3:this.mouseDownRight=!0}this._getMouseCanvasPos(e),this.element.focus(),this.fire("mousedown",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=e=>{if(this.enabled){switch(e.which){case 1:this.mouseDownLeft=!1;break;case 2:this.mouseDownMiddle=!1;break;case 3:this.mouseDownRight=!1}this.fire("mouseup",this.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("click",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=e=>{if(this.enabled){switch(e.which){case 1:case 3:this.mouseDownLeft=!1,this.mouseDownRight=!1;break;case 2:this.mouseDownMiddle=!1}this._getMouseCanvasPos(e),this.fire("dblclick",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=e=>{this.enabled&&(this._getMouseCanvasPos(e),this.fire("mousemove",this.mouseCanvasPos,!0),this.mouseover&&e.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=(e,t)=>{if(!this.enabled)return;const s=Math.max(-1,Math.min(1,40*-e.deltaY));this.fire("mousewheel",s,!0)},{passive:!0});{let e,t;const s=2;this.on("mousedown",(s=>{e=s[0],t=s[1]})),this.on("mouseup",(n=>{e>=n[0]-s&&e<=n[0]+s&&t>=n[1]-s&&t<=n[1]+s&&this.fire("mouseclicked",n,!0)}))}this._eventsBound=!0}}_unbindEvents(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}_getMouseCanvasPos(e){if(e){let t=e.target,s=0,n=0;for(;t.offsetParent;)s+=t.offsetLeft,n+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-s,this.mouseCanvasPos[1]=e.pageY-n}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}setEnabled(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}getEnabled(){return this.enabled}setKeyboardEnabled(e){this.keyboardEnabled=e}getKeyboardEnabled(){return this.keyboardEnabled}destroy(){super.destroy(),this._unbindEvents()}}const Qe=new e({});class We{constructor(e){this.id=Qe.addItem({});for(const t in e)e.hasOwnProperty(t)&&(this[t]=e[t])}destroy(){Qe.removeItem(this.id)}}class ze extends _{get type(){return"Viewport"}constructor(e,t={}){super(e,t),this._state=new We({boundary:[0,0,100,100]}),this.boundary=t.boundary,this.autoBoundary=t.autoBoundary}set boundary(e){if(!this._autoBoundary){if(!e){const t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}get boundary(){return this._state.boundary}set autoBoundary(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){const t=e[2],s=e[3];this._state.boundary=[0,0,t,s],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}get autoBoundary(){return this._autoBoundary}_getState(){return this._state}destroy(){super.destroy(),this._state.destroy()}}class Ke extends _{get type(){return"Perspective"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this._fov=60,this._canvasResized=this.scene.canvas.on("boundary",this._needUpdate,this),this.fov=t.fov,this.fovAxis=t.fovAxis,this.near=t.near,this.far=t.far}_update(){const e=this.scene.canvas.boundary,t=e[2]/e[3],s=this._fovAxis;let n=this._fov;("x"===s||"min"===s&&t<1||"max"===s&&t>1)&&(n/=t),n=Math.min(n,120),p.perspectiveMat4(n*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}set fov(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}get fov(){return this._fov}set fovAxis(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}get fovAxis(){return this._fovAxis}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}class Ye extends _{get type(){return"Ortho"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4(),near:.1,far:2e3}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.scale=t.scale,this.near=t.near,this.far=t.far,this._onCanvasBoundary=this.scene.canvas.on("boundary",this._needUpdate,this)}_update(){const e=this.scene,t=.5*this._scale,s=e.canvas.boundary,n=s[2],i=s[3],a=n/i;let r,l,o,c;n>i?(r=-t,l=t,o=t/a,c=-t/a):(r=-t*a,l=t*a,o=t,c=-t),p.orthoMat4c(r,l,c,o,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set scale(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}get scale(){return this._scale}set near(e){const t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}get near(){return this._state.near}set far(e){const t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}class Xe extends _{get type(){return"Frustum"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4(),near:.1,far:1e4}),this._left=-1,this._right=1,this._bottom=-1,this._top=1,this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.top=t.top,this.near=t.near,this.far=t.far}_update(){p.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}set left(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}get left(){return this._left}set right(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}get right(){return this._right}set top(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}get top(){return this._top}set bottom(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}get bottom(){return this._bottom}set near(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}get near(){return this._state.near}set far(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}get far(){return this._state.far}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy(),super.destroy()}}class qe extends _{get type(){return"CustomProjection"}constructor(e,t={}){super(e,t),this.camera=e,this._state=new We({matrix:p.mat4(),inverseMatrix:p.mat4(),transposedMatrix:p.mat4()}),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!1,this.matrix=t.matrix}set matrix(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}get matrix(){return this._state.matrix}get inverseMatrix(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(p.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}get transposedMatrix(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(p.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}unproject(e,t,s,n,i){const a=this.scene.canvas.canvas,r=a.offsetWidth/2,l=a.offsetHeight/2;return s[0]=(e[0]-r)/r,s[1]=(e[1]-l)/l,s[2]=t,s[3]=1,p.mulMat4v4(this.inverseMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1,p.mulMat4v4(this.camera.inverseViewMatrix,n,i),i}destroy(){super.destroy(),this._state.destroy()}}const Je=p.vec3(),Ze=p.vec3(),$e=p.vec3(),et=p.vec3(),tt=p.vec3(),st=p.vec3(),nt=p.vec4(),it=p.vec4(),at=p.vec4(),rt=p.mat4(),lt=p.mat4(),ot=p.vec3(),ct=p.vec3(),ut=p.vec3(),ht=p.vec3();class pt extends _{get type(){return"Camera"}constructor(e,t={}){super(e,t),this._state=new We({deviceMatrix:p.mat4(),hasDeviceMatrix:!1,matrix:p.mat4(),normalMatrix:p.mat4(),inverseMatrix:p.mat4()}),this._perspective=new Ke(this),this._ortho=new Ye(this),this._frustum=new Xe(this),this._customProjection=new qe(this),this._project=this._perspective,this._eye=p.vec3([0,0,10]),this._look=p.vec3([0,0,0]),this._up=p.vec3([0,1,0]),this._worldUp=p.vec3([0,1,0]),this._worldRight=p.vec3([1,0,0]),this._worldForward=p.vec3([0,0,-1]),this.deviceMatrix=t.deviceMatrix,this.eye=t.eye,this.look=t.look,this.up=t.up,this.worldAxis=t.worldAxis,this.gimbalLock=t.gimbalLock,this.constrainPitch=t.constrainPitch,this.projection=t.projection,this._perspective.on("matrix",(()=>{"perspective"===this._projectionType&&this.fire("projMatrix",this._perspective.matrix)})),this._ortho.on("matrix",(()=>{"ortho"===this._projectionType&&this.fire("projMatrix",this._ortho.matrix)})),this._frustum.on("matrix",(()=>{"frustum"===this._projectionType&&this.fire("projMatrix",this._frustum.matrix)})),this._customProjection.on("matrix",(()=>{"customProjection"===this._projectionType&&this.fire("projMatrix",this._customProjection.matrix)}))}_update(){const e=this._state;let t;"ortho"===this.projection?(p.subVec3(this._eye,this._look,ot),p.normalizeVec3(ot,ct),p.mulVec3Scalar(ct,1e3,ut),p.addVec3(this._look,ut,ht),t=ht):t=this._eye,e.hasDeviceMatrix?(p.lookAtMat4v(t,this._look,this._up,lt),p.mulMat4(e.deviceMatrix,lt,e.matrix)):p.lookAtMat4v(t,this._look,this._up,e.matrix),p.inverseMat4(this._state.matrix,this._state.inverseMatrix),p.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}orbitYaw(e){let t=p.subVec3(this._eye,this._look,Je);p.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,rt),t=p.transformPoint3(rt,t,Ze),this.eye=p.addVec3(this._look,t,$e),this.up=p.transformPoint3(rt,this._up,et)}orbitPitch(e){if(this._constrainPitch&&(e=p.dotVec3(this._up,this._worldUp)/p.DEGTORAD)<1)return;let t=p.subVec3(this._eye,this._look,Je);const s=p.cross3Vec3(p.normalizeVec3(t,Ze),p.normalizeVec3(this._up,$e));p.rotationMat4v(.0174532925*e,s,rt),t=p.transformPoint3(rt,t,et),this.up=p.transformPoint3(rt,this._up,tt),this.eye=p.addVec3(t,this._look,st)}yaw(e){let t=p.subVec3(this._look,this._eye,Je);p.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,rt),t=p.transformPoint3(rt,t,Ze),this.look=p.addVec3(t,this._eye,$e),this._gimbalLock&&(this.up=p.transformPoint3(rt,this._up,et))}pitch(e){if(this._constrainPitch&&(e=p.dotVec3(this._up,this._worldUp)/p.DEGTORAD)<1)return;let t=p.subVec3(this._look,this._eye,Je);const s=p.cross3Vec3(p.normalizeVec3(t,Ze),p.normalizeVec3(this._up,$e));p.rotationMat4v(.0174532925*e,s,rt),this.up=p.transformPoint3(rt,this._up,st),t=p.transformPoint3(rt,t,et),this.look=p.addVec3(t,this._eye,tt)}pan(e){const t=p.subVec3(this._eye,this._look,Je),s=[0,0,0];let n;if(0!==e[0]){const i=p.cross3Vec3(p.normalizeVec3(t,[]),p.normalizeVec3(this._up,Ze));n=p.mulVec3Scalar(i,e[0]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]}0!==e[1]&&(n=p.mulVec3Scalar(p.normalizeVec3(this._up,$e),e[1]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),0!==e[2]&&(n=p.mulVec3Scalar(p.normalizeVec3(t,et),e[2]),s[0]+=n[0],s[1]+=n[1],s[2]+=n[2]),this.eye=p.addVec3(this._eye,s,tt),this.look=p.addVec3(this._look,s,st)}zoom(e){const t=p.subVec3(this._eye,this._look,Je),s=Math.abs(p.lenVec3(t,Ze)),n=Math.abs(s+e);if(n<.5)return;const i=p.normalizeVec3(t,$e);this.eye=p.addVec3(this._look,p.mulVec3Scalar(i,n),et)}set eye(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}get eye(){return this._eye}set look(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}get look(){return this._look}set up(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}get up(){return this._up}set deviceMatrix(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}get deviceMatrix(){return this._state.deviceMatrix}set worldAxis(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=p.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}get worldAxis(){return this._worldAxis}get worldUp(){return this._worldUp}get xUp(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}get yUp(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}get zUp(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}get worldRight(){return this._worldRight}get worldForward(){return this._worldForward}set gimbalLock(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}get gimbalLock(){return this._gimbalLock}set constrainPitch(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}get eyeLookDist(){return p.lenVec3(p.subVec3(this._look,this._eye,Je))}get matrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get viewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}get normalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get viewNormalMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}get inverseViewMatrix(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}get projMatrix(){return this[this.projection].matrix}get perspective(){return this._perspective}get ortho(){return this._ortho}get frustum(){return this._frustum}get customProjection(){return this._customProjection}set projection(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}get projection(){return this._projectionType}get project(){return this._project}projectWorldPos(e){const t=nt,s=it,n=at;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,p.mulMat4v4(this.viewMatrix,t,s),p.mulMat4v4(this.projMatrix,s,n),p.mulVec3Scalar(n,1/n[3]),n[3]=1,n[1]*=-1;const i=this.scene.canvas.canvas,a=i.offsetWidth/2,r=i.offsetHeight/2;return[n[0]*a+a,n[1]*r+r]}destroy(){super.destroy(),this._state.destroy()}}class At extends _{get type(){return"Light"}get isLight(){return!0}constructor(e,t={}){super(e,t)}}class dt extends At{get type(){return"DirLight"}constructor(e,t={}){super(e,t),this._shadowRenderBuf=null,this._shadowViewMatrix=null,this._shadowProjMatrix=null,this._shadowViewMatrixDirty=!0,this._shadowProjMatrixDirty=!0;const s=this.scene.camera,n=this.scene.canvas;this._onCameraViewMatrix=s.on("viewMatrix",(()=>{this._shadowViewMatrixDirty=!0})),this._onCameraProjMatrix=s.on("projMatrix",(()=>{this._shadowProjMatrixDirty=!0})),this._onCanvasBoundary=n.on("boundary",(()=>{this._shadowProjMatrixDirty=!0})),this._state=new We({type:"dir",dir:p.vec3([1,1,1]),color:p.vec3([.7,.7,.8]),intensity:1,space:t.space||"view",castsShadow:!1,getShadowViewMatrix:()=>{if(this._shadowViewMatrixDirty){this._shadowViewMatrix||(this._shadowViewMatrix=p.identityMat4());const e=this.scene.camera,t=this._state.dir,s=e.look,n=[s[0]-t[0],s[1]-t[1],s[2]-t[2]],i=[0,1,0];p.lookAtMat4v(n,s,i,this._shadowViewMatrix),this._shadowViewMatrixDirty=!1}return this._shadowViewMatrix},getShadowProjMatrix:()=>(this._shadowProjMatrixDirty&&(this._shadowProjMatrix||(this._shadowProjMatrix=p.identityMat4()),p.orthoMat4c(-40,40,-40,40,-40,80,this._shadowProjMatrix),this._shadowProjMatrixDirty=!1),this._shadowProjMatrix),getShadowRenderBuf:()=>(this._shadowRenderBuf||(this._shadowRenderBuf=new Ue(this.scene.canvas.canvas,this.scene.canvas.gl,{size:[1024,1024]})),this._shadowRenderBuf)}),this.dir=t.dir,this.color=t.color,this.intensity=t.intensity,this.castsShadow=t.castsShadow,this.scene._lightCreated(this)}set dir(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}get dir(){return this._state.dir}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}get intensity(){return this._state.intensity}set castsShadow(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}get castsShadow(){return this._state.castsShadow}destroy(){const e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),super.destroy(),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}class ft extends At{get type(){return"AmbientLight"}constructor(e,t={}){super(e,t),this._state={type:"ambient",color:p.vec3([.7,.7,.7]),intensity:1},this.color=t.color,this.intensity=t.intensity,this.scene._lightCreated(this)}set color(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}get color(){return this._state.color}set intensity(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}get intensity(){return this._state.intensity}destroy(){super.destroy(),this.scene._lightDestroyed(this)}}class It extends _{get type(){return"Geometry"}get isGeometry(){return!0}constructor(e,t={}){super(e,t),d.memory.meshes++}destroy(){super.destroy(),d.memory.meshes--}}var yt=function(){const e=[],t=[],s=[],n=[],i=[];let a=0;const r=new Uint16Array(3),l=new Uint16Array(3),o=new Uint16Array(3),c=p.vec3(),u=p.vec3(),h=p.vec3(),A=p.vec3(),d=p.vec3(),f=p.vec3(),I=p.vec3();return function(y,m,v,w){!function(i,a){const r={};let l,o,c,u;const h=Math.pow(10,4);let p,A,d=0;for(p=0,A=i.length;pT)||(N=s[_.index1],x=s[_.index2],(!L&&N>65535||x>65535)&&(L=!0),g.push(N),g.push(x));return L?new Uint32Array(g):new Uint16Array(g)}}();const mt=function(){const e=p.mat4(),t=p.mat4();return function(s,n){n=n||p.mat4();const i=s[0],a=s[1],r=s[2],l=s[3]-i,o=s[4]-a,c=s[5]-r,u=65535;return p.identityMat4(e),p.translationMat4v(s,e),p.identityMat4(t),p.scalingMat4v([l/u,o/u,c/u],t),p.mulMat4(e,t,n),n}}();var vt=function(){const e=p.mat4(),t=p.mat4();return function(s,n,i){const a=new Uint16Array(s.length),r=new Float32Array([i[0]!==n[0]?65535/(i[0]-n[0]):0,i[1]!==n[1]?65535/(i[1]-n[1]):0,i[2]!==n[2]?65535/(i[2]-n[2]):0]);let l;for(l=0;l=0?1:-1),t=(1-Math.abs(i))*(a>=0?1:-1);i=e,a=t}return new Int8Array([Math[s](127.5*i+(i<0?-1:0)),Math[n](127.5*a+(a<0?-1:0))])}function Tt(e){let t=e[0],s=e[1];t/=t<0?127:128,s/=s<0?127:128;const n=1-Math.abs(t)-Math.abs(s);n<0&&(t=(1-Math.abs(s))*(t>=0?1:-1),s=(1-Math.abs(t))*(s>=0?1:-1));const i=Math.sqrt(t*t+s*s+n*n);return[t/i,s/i,n/i]}function Et(e,t,s){return e[t]*s[0]+e[t+1]*s[1]+e[t+2]*s[2]}const bt={getPositionsBounds:function(e){const t=new Float32Array(3),s=new Float32Array(3);let n,i;for(n=0;n<3;n++)t[n]=Number.MAX_VALUE,s[n]=-Number.MAX_VALUE;for(n=0;nr&&(i=s,r=a),s=gt(e,l,"floor","ceil"),n=Tt(s),a=Et(e,l,n),a>r&&(i=s,r=a),s=gt(e,l,"ceil","ceil"),n=Tt(s),a=Et(e,l,n),a>r&&(i=s,r=a),t[l]=i[0],t[l+1]=i[1];return t},decompressNormals:function(e,t){for(let s=0,n=0,i=e.length;s=0?1:-1),a=(1-Math.abs(i))*(a>=0?1:-1));const l=Math.sqrt(i*i+a*a+r*r);t[n+0]=i/l,t[n+1]=a/l,t[n+2]=r/l,n+=3}return t},decompressNormal:function(e,t){let s=e[0],n=e[1];s=(2*s+1)/255,n=(2*n+1)/255;const i=1-Math.abs(s)-Math.abs(n);i<0&&(s=(1-Math.abs(n))*(s>=0?1:-1),n=(1-Math.abs(s))*(n>=0?1:-1));const a=Math.sqrt(s*s+n*n+i*i);return t[0]=s/a,t[1]=n/a,t[2]=i/a,t}},Dt=d.memory,Pt=p.AABB3();class Rt extends It{get type(){return"ReadableGeometry"}get isReadableGeometry(){return!0}constructor(e,t={}){super(e,t),this._state=new We({compressGeometry:!!t.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),this._numTriangles=0,this._edgeThreshold=t.edgeThreshold||10,this._edgeIndicesBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._aabbDirty=!0,this._boundingSphere=!0,this._aabb=null,this._aabbDirty=!0,this._obb=null,this._obbDirty=!0;const s=this._state,n=this.scene.canvas.gl;switch(t.primitive=t.primitive||"triangles",t.primitive){case"points":s.primitive=n.POINTS,s.primitiveName=t.primitive;break;case"lines":s.primitive=n.LINES,s.primitiveName=t.primitive;break;case"line-loop":s.primitive=n.LINE_LOOP,s.primitiveName=t.primitive;break;case"line-strip":s.primitive=n.LINE_STRIP,s.primitiveName=t.primitive;break;case"triangles":s.primitive=n.TRIANGLES,s.primitiveName=t.primitive;break;case"triangle-strip":s.primitive=n.TRIANGLE_STRIP,s.primitiveName=t.primitive;break;case"triangle-fan":s.primitive=n.TRIANGLE_FAN,s.primitiveName=t.primitive;break;default:this.error("Unsupported value for 'primitive': '"+t.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),s.primitive=n.TRIANGLES,s.primitiveName=t.primitive}if(t.positions)if(this._state.compressGeometry){const e=bt.getPositionsBounds(t.positions),n=bt.compressPositions(t.positions,e.min,e.max);s.positions=n.quantized,s.positionsDecodeMatrix=n.decodeMatrix}else s.positions=t.positions.constructor===Float32Array?t.positions:new Float32Array(t.positions);if(t.colors&&(s.colors=t.colors.constructor===Float32Array?t.colors:new Float32Array(t.colors)),t.uv)if(this._state.compressGeometry){const e=bt.getUVBounds(t.uv),n=bt.compressUVs(t.uv,e.min,e.max);s.uv=n.quantized,s.uvDecodeMatrix=n.decodeMatrix}else s.uv=t.uv.constructor===Float32Array?t.uv:new Float32Array(t.uv);t.normals&&(this._state.compressGeometry?s.normals=bt.compressNormals(t.normals):s.normals=t.normals.constructor===Float32Array?t.normals:new Float32Array(t.normals)),t.indices&&(s.indices=t.indices.constructor===Uint32Array||t.indices.constructor===Uint16Array?t.indices:new Uint32Array(t.indices),"triangles"===this._state.primitiveName&&(this._numTriangles=t.indices.length/3)),this._buildHash(),Dt.meshes++,this._buildVBOs()}_buildVBOs(){const e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),Dt.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new De(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),Dt.positions+=e.positionsBuf.numItems),e.normals){let s=e.compressGeometry;e.normalsBuf=new De(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,s),Dt.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new De(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),Dt.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new De(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),Dt.uvs+=e.uvBuf.numItems)}_buildHash(){const e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}_getEdgeIndices(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}_getPickTrianglePositions(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}_getPickTriangleColors(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}_buildEdgeIndices(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=yt(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new De(t,t.ELEMENT_ARRAY_BUFFER,s,s.length,1,t.STATIC_DRAW),Dt.indices+=this._edgeIndicesBuf.numItems}_buildPickTriangleVBOs(){const e=this._state;if(!e.positions||!e.indices)return;const t=this.scene.canvas.gl,s=p.buildPickTriangles(e.positions,e.indices,e.compressGeometry),n=s.positions,i=s.colors;this._pickTrianglePositionsBuf=new De(t,t.ARRAY_BUFFER,n,n.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new De(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),Dt.positions+=this._pickTrianglePositionsBuf.numItems,Dt.colors+=this._pickTriangleColorsBuf.numItems}_buildPickVertexVBOs(){}_webglContextLost(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}_webglContextRestored(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}get primitive(){return this._state.primitiveName}get compressGeometry(){return this._state.compressGeometry}get positions(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),bt.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null}set positions(e){const t=this._state,s=t.positions;if(s)if(s.length===e.length){if(this._state.compressGeometry){const s=bt.getPositionsBounds(e),n=bt.compressPositions(e,s.min,s.max);e=n.quantized,t.positionsDecodeMatrix=n.decodeMatrix}s.set(e),t.positionsBuf&&t.positionsBuf.setData(s),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}get normals(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){const e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),bt.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}}set normals(e){if(this._state.compressGeometry)return void this.error("can't update geometry normals - quantized geometry is immutable");const t=this._state,s=t.normals;s?s.length===e.length?(s.set(e),t.normalsBuf&&t.normalsBuf.setData(s),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}get uv(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),bt.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null}set uv(e){if(this._state.compressGeometry)return void this.error("can't update geometry UVs - quantized geometry is immutable");const t=this._state,s=t.uv;s?s.length===e.length?(s.set(e),t.uvBuf&&t.uvBuf.setData(s),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}get colors(){return this._state.colors}set colors(e){if(this._state.compressGeometry)return void this.error("can't update geometry colors - quantized geometry is immutable");const t=this._state,s=t.colors;s?s.length===e.length?(s.set(e),t.colorsBuf&&t.colorsBuf.setData(s),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}get indices(){return this._state.indices}get aabb(){return this._aabbDirty&&(this._aabb||(this._aabb=p.AABB3()),p.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}get obb(){return this._obbDirty&&(this._obb||(this._obb=p.OBB3()),p.positions3ToAABB3(this._state.positions,Pt,this._state.positionsDecodeMatrix),p.AABB3ToOBB3(Pt,this._obb),this._obbDirty=!1),this._obb}get numTriangles(){return this._numTriangles}_setAABBDirty(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}_getState(){return this._state}destroy(){super.destroy();const e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),Dt.meshes--}}function Ct(e={}){let t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);let s=e.ySize||1;s<0&&(console.error("negative ySize not allowed - will invert"),s*=-1);let n=e.zSize||1;n<0&&(console.error("negative zSize not allowed - will invert"),n*=-1);const i=e.center,a=i?i[0]:0,r=i?i[1]:0,l=i?i[2]:0,o=-t+a,c=-s+r,u=-n+l,h=t+a,p=s+r,A=n+l;return m.apply(e,{positions:[h,p,A,o,p,A,o,c,A,h,c,A,h,p,A,h,c,A,h,c,u,h,p,u,h,p,A,h,p,u,o,p,u,o,p,A,o,p,A,o,p,u,o,c,u,o,c,A,o,c,u,h,c,u,h,c,A,o,c,A,h,c,u,o,c,u,o,p,u,h,p,u],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}class _t extends _{get type(){return"Material"}constructor(e,t={}){super(e,t),d.memory.materials++}destroy(){super.destroy(),d.memory.materials--}}const Bt={opaque:0,mask:1,blend:2},Ot=["opaque","mask","blend"];class St extends _t{get type(){return"PhongMaterial"}constructor(e,t={}){super(e,t),this._state=new We({type:"PhongMaterial",ambient:p.vec3([1,1,1]),diffuse:p.vec3([1,1,1]),specular:p.vec3([1,1,1]),emissive:p.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),this.ambient=t.ambient,this.diffuse=t.diffuse,this.specular=t.specular,this.emissive=t.emissive,this.alpha=t.alpha,this.shininess=t.shininess,this.reflectivity=t.reflectivity,this.lineWidth=t.lineWidth,this.pointSize=t.pointSize,t.ambientMap&&(this._ambientMap=this._checkComponent("Texture",t.ambientMap)),t.diffuseMap&&(this._diffuseMap=this._checkComponent("Texture",t.diffuseMap)),t.specularMap&&(this._specularMap=this._checkComponent("Texture",t.specularMap)),t.emissiveMap&&(this._emissiveMap=this._checkComponent("Texture",t.emissiveMap)),t.alphaMap&&(this._alphaMap=this._checkComponent("Texture",t.alphaMap)),t.reflectivityMap&&(this._reflectivityMap=this._checkComponent("Texture",t.reflectivityMap)),t.normalMap&&(this._normalMap=this._checkComponent("Texture",t.normalMap)),t.occlusionMap&&(this._occlusionMap=this._checkComponent("Texture",t.occlusionMap)),t.diffuseFresnel&&(this._diffuseFresnel=this._checkComponent("Fresnel",t.diffuseFresnel)),t.specularFresnel&&(this._specularFresnel=this._checkComponent("Fresnel",t.specularFresnel)),t.emissiveFresnel&&(this._emissiveFresnel=this._checkComponent("Fresnel",t.emissiveFresnel)),t.alphaFresnel&&(this._alphaFresnel=this._checkComponent("Fresnel",t.alphaFresnel)),t.reflectivityFresnel&&(this._reflectivityFresnel=this._checkComponent("Fresnel",t.reflectivityFresnel)),this.alphaMode=t.alphaMode,this.alphaCutoff=t.alphaCutoff,this.backfaces=t.backfaces,this.frontface=t.frontface,this._makeHash()}_makeHash(){const e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}set ambient(e){let t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get ambient(){return this._state.ambient}set diffuse(e){let t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get diffuse(){return this._state.diffuse}set specular(e){let t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}get specular(){return this._state.specular}set emissive(e){let t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}get emissive(){return this._state.emissive}set alpha(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}get alpha(){return this._state.alpha}set shininess(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}get shininess(){return this._state.shininess}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set pointSize(e){this._state.pointSize=e||1,this.glRedraw()}get pointSize(){return this._state.pointSize}set reflectivity(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}get reflectivity(){return this._state.reflectivity}get normalMap(){return this._normalMap}get ambientMap(){return this._ambientMap}get diffuseMap(){return this._diffuseMap}get specularMap(){return this._specularMap}get emissiveMap(){return this._emissiveMap}get alphaMap(){return this._alphaMap}get reflectivityMap(){return this._reflectivityMap}get occlusionMap(){return this._occlusionMap}get diffuseFresnel(){return this._diffuseFresnel}get specularFresnel(){return this._specularFresnel}get emissiveFresnel(){return this._emissiveFresnel}get alphaFresnel(){return this._alphaFresnel}get reflectivityFresnel(){return this._reflectivityFresnel}set alphaMode(e){let t=Bt[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}get alphaMode(){return Ot[this._state.alphaMode]}set alphaCutoff(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}get alphaCutoff(){return this._state.alphaCutoff}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set frontface(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}get frontface(){return this._state.frontface?"ccw":"cw"}destroy(){super.destroy(),this._state.destroy()}}const Nt={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}};class xt extends _t{get type(){return"EmphasisMaterial"}get presets(){return Nt}constructor(e,t={}){super(e,t),this._state=new We({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),this._preset="default",t.preset?(this.preset=t.preset,void 0!==t.fill&&(this.fill=t.fill),t.fillColor&&(this.fillColor=t.fillColor),void 0!==t.fillAlpha&&(this.fillAlpha=t.fillAlpha),void 0!==t.edges&&(this.edges=t.edges),t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth),void 0!==t.backfaces&&(this.backfaces=t.backfaces),void 0!==t.glowThrough&&(this.glowThrough=t.glowThrough)):(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.backfaces=t.backfaces,this.glowThrough=t.glowThrough)}set fill(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}get fill(){return this._state.fill}set fillColor(e){let t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}get fillColor(){return this._state.fillColor}set fillAlpha(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}get fillAlpha(){return this._state.fillAlpha}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set backfaces(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}get backfaces(){return this._state.backfaces}set glowThrough(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}get glowThrough(){return this._state.glowThrough}set preset(e){if(e=e||"default",this._preset===e)return;const t=Nt[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Nt).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Lt={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}};class Mt extends _t{get type(){return"EdgeMaterial"}get presets(){return Lt}constructor(e,t={}){super(e,t),this._state=new We({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),this._preset="default",t.preset?(this.preset=t.preset,t.edgeColor&&(this.edgeColor=t.edgeColor),void 0!==t.edgeAlpha&&(this.edgeAlpha=t.edgeAlpha),void 0!==t.edgeWidth&&(this.edgeWidth=t.edgeWidth)):(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth),this.edges=!1!==t.edges}set edges(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}get edges(){return this._state.edges}set edgeColor(e){let t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}get edgeColor(){return this._state.edgeColor}set edgeAlpha(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}get edgeAlpha(){return this._state.edgeAlpha}set edgeWidth(e){this._state.edgeWidth=e||1,this.glRedraw()}get edgeWidth(){return this._state.edgeWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=Lt[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Lt).join(", "))}get preset(){return this._preset}destroy(){super.destroy(),this._state.destroy()}}const Ft={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}};class Ht extends _{constructor(e,t={}){super(e,t),this._units="meters",this._scale=1,this._origin=p.vec3([0,0,0]),this.units=t.units,this.scale=t.scale,this.origin=t.origin}get unitsInfo(){return Ft}set units(e){e||(e="meters");Ft[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}get units(){return this._units}set scale(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}get scale(){return this._scale}set origin(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}get origin(){return this._origin}worldToRealPos(e,t=p.vec3(3)){t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}realToWorldPos(e,t=p.vec3(3)){return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}class Ut extends _{constructor(e,t={}){super(e,t),this._supported=pe.SUPPORTED_EXTENSIONS.OES_standard_derivatives,this.enabled=t.enabled,this.kernelRadius=t.kernelRadius,this.intensity=t.intensity,this.bias=t.bias,this.scale=t.scale,this.minResolution=t.minResolution,this.numSamples=t.numSamples,this.blur=t.blur,this.blendCutoff=t.blendCutoff,this.blendFactor=t.blendFactor}get supported(){return this._supported}set enabled(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}get enabled(){return this._enabled}get possible(){if(!this._supported)return!1;if(!this._enabled)return!1;const e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}get active(){return this._active}set kernelRadius(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}get kernelRadius(){return this._kernelRadius}set intensity(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}get intensity(){return this._intensity}set bias(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}get bias(){return this._bias}set scale(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}get scale(){return this._scale}set minResolution(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}get minResolution(){return this._minResolution}set numSamples(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}get numSamples(){return this._numSamples}set blur(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}get blur(){return this._blur}set blendCutoff(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}get blendCutoff(){return this._blendCutoff}set blendFactor(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}get blendFactor(){return this._blendFactor}destroy(){super.destroy()}}const Gt={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}};class Vt extends _t{get type(){return"PointsMaterial"}get presets(){return Gt}constructor(e,t={}){super(e,t),this._state=new We({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),t.preset?(this.preset=t.preset,void 0!==t.pointSize&&(this.pointSize=t.pointSize),void 0!==t.roundPoints&&(this.roundPoints=t.roundPoints),void 0!==t.perspectivePoints&&(this.perspectivePoints=t.perspectivePoints),void 0!==t.minPerspectivePointSize&&(this.minPerspectivePointSize=t.minPerspectivePointSize),void 0!==t.maxPerspectivePointSize&&(this.maxPerspectivePointSize=t.minPerspectivePointSize)):(this._preset="default",this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize),this.filterIntensity=t.filterIntensity,this.minIntensity=t.minIntensity,this.maxIntensity=t.maxIntensity}set pointSize(e){this._state.pointSize=e||2,this.glRedraw()}get pointSize(){return this._state.pointSize}set roundPoints(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}get roundPoints(){return this._state.roundPoints}set perspectivePoints(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}get perspectivePoints(){return this._state.perspectivePoints}set minPerspectivePointSize(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}get minPerspectivePointSize(){return this._state.minPerspectivePointSize}set maxPerspectivePointSize(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}get maxPerspectivePointSize(){return this._state.maxPerspectivePointSize}set filterIntensity(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}get filterIntensity(){return this._state.filterIntensity}set minIntensity(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}get minIntensity(){return this._state.minIntensity}set maxIntensity(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}get maxIntensity(){return this._state.maxIntensity}set preset(e){if(e=e||"default",this._preset===e)return;const t=Gt[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Gt).join(", "))}get preset(){return this._preset}get hash(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}destroy(){super.destroy(),this._state.destroy()}}const jt={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}};class kt extends _t{get type(){return"LinesMaterial"}get presets(){return jt}constructor(e,t={}){super(e,t),this._state=new We({type:"LinesMaterial",lineWidth:null}),t.preset?(this.preset=t.preset,void 0!==t.lineWidth&&(this.lineWidth=t.lineWidth)):(this._preset="default",this.lineWidth=t.lineWidth)}set lineWidth(e){this._state.lineWidth=e||1,this.glRedraw()}get lineWidth(){return this._state.lineWidth}set preset(e){if(e=e||"default",this._preset===e)return;const t=jt[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(jt).join(", "))}get preset(){return this._preset}get hash(){return[""+this.lineWidth].join(";")}destroy(){super.destroy(),this._state.destroy()}}const Qt=p.vec3(),Wt=p.vec3(),zt=p.mat4();class Kt{constructor(){this.normal=p.vec3(),this.offset=0,this.testVertex=p.vec3()}set(e,t,s,n){const i=1/Math.sqrt(e*e+t*t+s*s);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=s*i,this.offset=n*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}class Yt{constructor(){this.planes=[new Kt,new Kt,new Kt,new Kt,new Kt,new Kt]}}function Xt(e,t,s){const n=p.mulMat4(s,t,zt),i=n[0],a=n[1],r=n[2],l=n[3],o=n[4],c=n[5],u=n[6],h=n[7],A=n[8],d=n[9],f=n[10],I=n[11],y=n[12],m=n[13],v=n[14],w=n[15];e.planes[0].set(l-i,h-o,I-A,w-y),e.planes[1].set(l+i,h+o,I+A,w+y),e.planes[2].set(l-a,h-c,I-d,w-m),e.planes[3].set(l+a,h+c,I+d,w+m),e.planes[4].set(l-r,h-u,I-f,w-v),e.planes[5].set(l+r,h+u,I+f,w+v)}function qt(e,t){let s=Yt.INSIDE;const n=Qt,i=Wt;n[0]=t[0],n[1]=t[1],n[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];const a=[n,i];for(let t=0;t<6;++t){const n=e.planes[t];if(n.normal[0]*a[n.testVertex[0]][0]+n.normal[1]*a[n.testVertex[1]][1]+n.normal[2]*a[n.testVertex[2]][2]+n.offset<0)return Yt.OUTSIDE;n.normal[0]*a[1-n.testVertex[0]][0]+n.normal[1]*a[1-n.testVertex[1]][1]+n.normal[2]*a[1-n.testVertex[2]][2]+n.offset<0&&(s=Yt.INTERSECT)}return s}Yt.INSIDE=0,Yt.INTERSECT=1,Yt.OUTSIDE=2;class Jt{constructor(e,t){this.primLODLevels=e,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=t,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}initializeLodState(e){const t=Object.values(e.objects);if(0===t.length)return;const s={},n={};for(let e=0,i=t.length;e=this.primLODLevels[r]);r++);const l=this.primLODLevels[r]||0;l in s||(s[l]=[]),s[l].push(i),l in n||(n[l]=0),n[l]+=i.numPrimitives}this.entitiesInLOD=s,this.primCountInLOD=n}}class Zt{constructor(e,t,s,n){this.id=t.id,this.scene=e,this.sceneModel=t,this.lodState=new Jt(s,n),this.lodState.initializeLodState(t)}_increaseLODLevelIndex(){const e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;const t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[];for(let e=0,s=t.length;e0&&(t.consecutiveFramesWithoutTargetFps=0,s=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,s=this._decreaseLODLevelIndex()),s}resetLodCulling(){let e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}class $t extends _{constructor(e,t={}){super(e,t),this._scene=e,this._lodLevels=[2e3,600,150,80,20],this._lodManagers={},this._lodManagerList=[],this.enabled=t.enabled,this.targetFPS=t.targetFPS,this._init()}_init(){const e=new Array(4);let t=0,s=-1,n=Date.now(),i=0,a=0,r=a;this._scene.on("rendering",(()=>{if(-1!==s)for(let e=0,t=this._lodManagerList.length;e{n=Date.now(),window.requestAnimationFrame((()=>{t++;const a=Date.now();i=a-n,n=a,e[t%4]=i;let r=0;if(t>4){for(let t=0;t<4;t++)r+=e[t];s=4/r*1e3}}))})),this._scene.camera.on("matrix",(()=>{r=a})),this._scene.on("tick",(()=>{if(a-r>3)for(let e=0,t=this._lodManagerList.length;e=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},s.boxRayIntersects=function(e,t,s,n,i,a,r){var l=(e.minX-t)*i,o=(e.maxX-t)*i,c=(e.minY-s)*a,u=(e.maxY-s)*a,h=(e.minZ-n)*r,p=(e.maxZ-n)*r,A=Math.min(h,p),d=Math.max(h,p),f=Math.min(c,u),I=Math.max(c,u),y=Math.min(l,o),m=Math.max(l,o),v=Math.max(0,y,f,A);return Math.min(m,I,d)>=v?v:1/0};var g=function(e,t,s,i,a){for(var r,l=[t,s];l.length;)(s=l.pop())-(t=l.pop())<=i||(r=t+Math.ceil((s-t)/i/2)*i,n(e,r,t,s,a),l.push(t,r,r,s))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var s=this.data,n=[];if(!e(s,h(s)))return n;for(var i=[];s;){for(var a=0,r=s.children.length;a1){for(d=0,f=(u=u[u.length-1]).length;d=t)break;var i=n+1;if(i0;){var n=s-1>>1;if(A[n].dist<=A[s].dist)break;d(s,n),s=n}},y=l;A.length&&A[0].dist=t;l--){o=e.children[l];f(a,o),r+=y(a)}return r},e.prototype.adjustParentBBoxes=function(e,t,s){for(var n=s;n>=0;n--)f(t[n],e)},e.prototype.condense=function(e){for(var t=e.length-1,s=void 0;t>=0;t--)0===e[t].children.length?t>0?((s=e[t-1].children).splice(s.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,s){var n=[],i=this.chooseSubtree(e,this.data,t,n);for(i.children.push(e),f(i,e);t>=0&&n[t].children.length>this.maxEntries;)this.split(n,t),t--;this.adjustParentBBoxes(e,n,t)},e.pool=[],e}();s.RBush3D=D},{quickselect:2}],2:[function(e,t,s){!function(e,n){"object"==typeof s&&void 0!==t?t.exports=n():e.quickselect=n()}(this,(function(){function e(s,n,i,a,r){for(;a>i;){if(a-i>600){var l=a-i+1,o=n-i+1,c=Math.log(l),u=.5*Math.exp(2*c/3),h=.5*Math.sqrt(c*u*(l-u)/l)*(o-l/2<0?-1:1);e(s,n,Math.max(i,Math.floor(n-o*u/l+h)),Math.min(a,Math.floor(n+(l-o)*u/l+h)),r)}var p=s[n],A=i,d=a;for(t(s,i,n),r(s[a],p)>0&&t(s,i,a);A0;)d--}0===r(s[i],p)?t(s,i,d):t(s,++d,a),d<=n&&(i=d+1),n<=d&&(a=d-1)}}function t(e,t,s){var n=e[t];e[t]=e[s],e[s]=n}function s(e,t){return et?1:0}return function(t,n,i,a,r){e(t,n,i||0,a||t.length-1,r||s)}}))},{}]},{},[1])(1)}));var ss=es.exports.RBush3D,ns=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function s(e,t){var s={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function n(){(0==s.dir&&s.pos.x+1>=s.right||1==s.dir&&s.pos.y+1>=s.bottom||2==s.dir&&s.pos.x-1<=s.left-1||3==s.dir&&s.pos.y-1<=s.top-1)&&(s.dir=(s.dir+1)%4,0==s.dir&&s.left++,1==s.dir&&s.top++,2==s.dir&&s.right--,3==s.dir&&s.bottom--),0==s.dir&&s.pos.x++,1==s.dir&&s.pos.y++,2==s.dir&&s.pos.x--,3==s.dir&&s.pos.y--}for(var i=[],a=e*t;i.lengthp&&(u.push(h),h=[],p=l),h.push(d),p-=f}}while(Ap&&(u.push(A),A=[],p=l),A.push(e),p-=s})),A.length&&u.push(A);var d={};return u.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:u,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,n.maxPolygonsPerCluster),{clusters:{total:r.clusters.length},clusteringResult:r});l+=o.clusters.total,console.log("Total clusters: "+l);var c=[];return o.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){c.push(e.id)}))})),o.orderedEntityIds=c,o}; /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT diff --git a/dist/xeokit-sdk.min.es5.js b/dist/xeokit-sdk.min.es5.js index 39393d7d50..b52370f7a9 100644 --- a/dist/xeokit-sdk.min.es5.js +++ b/dist/xeokit-sdk.min.es5.js @@ -1,4 +1,4 @@ -var e,t=l().mark(eT),n=l().mark(tT),r=l().mark(pD);function i(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||A(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var o=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(o&&l){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:P(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},e}function u(e,t,n,r,i,a,s){try{var o=e[a](s),l=o.value}catch(e){return void n(e)}o.done?t(l):Promise.resolve(l).then(r,i)}function c(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){u(a,r,i,s,o,"next",e)}function o(e){u(a,r,i,s,o,"throw",e)}s(void 0)}))}}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._id=k.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==n.hideOnMouseDown&&(document.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r0,c=t._getNextId(),f=a.getTitle||function(){return a.title||""},p=a.doAction||a.callback||function(){},A=a.getEnabled||function(){return!0},d=a.getShown||function(){return!0},v=new Q(c,f,p,A,d);if(v.parentMenu=i,l.items.push(v),u){var h=e(s);v.subMenu=h,h.parentItem=v}t._itemList.push(v),t._itemMap[v.id]=v},c=0,f=o.length;c'),r.push("
    "),n)for(var i=0,a=n.length;i'+A+" [MORE]"):r.push('
  • '+A+"
  • ")}}r.push("
"),r.push("");var d=r.join("");document.body.insertAdjacentHTML("beforeend",d);var v=document.querySelector("."+e.id);e.menuElement=v,v.style["border-radius"]="4px",v.style.display="none",v.style["z-index"]=3e5,v.style.background="white",v.style.border="1px solid black",v.style["box-shadow"]="0 4px 5px 0 gray",v.oncontextmenu=function(e){e.preventDefault()};var h=this,I=null;if(n)for(var y=0,m=n.length;ywindow.innerWidth?h._showMenu(t.id,a.left-200,a.top-1):h._showMenu(t.id,a.right-5,a.top-1),I=t}}else I&&(h._hideMenu(I.id),I=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),h._context&&!1!==r.enabled&&(r.doAction&&r.doAction(h._context),t._hideOnAction?h.hide():(h._updateItemsTitles(),h._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(h._context)})))},T=0,E=w.length;Twindow.innerHeight&&(n=window.innerHeight-r),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=n+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),z=function(){function e(t,n,r){b(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return P(e,[{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),K=!0,Y=K?Float64Array:Float32Array,X=new Y(16),q=new Y(16),J=new Y(4),Z={setDoublePrecisionEnabled:function(e){Y=(K=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return K},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new Y(e||2)},vec3:function(e){return new Y(e||3)},vec4:function(e){return new Y(e||4)},mat3:function(e){return new Y(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Y(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new Y(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,n){for(var r=new Y(2),i=0,a=e.length;i>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new Y(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=Z.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=Z.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=Z.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n0&&void 0!==arguments[0]?arguments[0]:new Y(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Y(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return Z.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],a=e[2],s=e[3],o=e[4],l=e[5],u=e[6],c=e[7],f=e[8],p=e[9],A=e[10],d=e[11],v=e[12],h=e[13],I=e[14],y=e[15],m=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],L=t[15];return n[0]=m*r+w*o+g*f+T*v,n[1]=m*i+w*l+g*p+T*h,n[2]=m*a+w*u+g*A+T*I,n[3]=m*s+w*c+g*d+T*y,n[4]=E*r+b*o+D*f+P*v,n[5]=E*i+b*l+D*p+P*h,n[6]=E*a+b*u+D*A+P*I,n[7]=E*s+b*c+D*d+P*y,n[8]=R*r+C*o+_*f+B*v,n[9]=R*i+C*l+_*p+B*h,n[10]=R*a+C*u+_*A+B*I,n[11]=R*s+C*c+_*d+B*y,n[12]=O*r+S*o+N*f+L*v,n[13]=O*i+S*l+N*p+L*h,n[14]=O*a+S*u+N*A+L*I,n[15]=O*s+S*c+N*d+L*y,n},mulMat3:function(e,t,n){n||(n=new Y(9));var r=e[0],i=e[3],a=e[6],s=e[1],o=e[4],l=e[7],u=e[2],c=e[5],f=e[8],p=t[0],A=t[3],d=t[6],v=t[1],h=t[4],I=t[7],y=t[2],m=t[5],w=t[8];return n[0]=r*p+i*v+a*y,n[3]=r*A+i*h+a*m,n[6]=r*d+i*I+a*w,n[1]=s*p+o*v+l*y,n[4]=s*A+o*h+l*m,n[7]=s*d+o*I+l*w,n[2]=u*p+c*v+f*y,n[5]=u*A+c*h+f*m,n[8]=u*d+c*I+f*w,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=t[0],i=t[1],a=t[2],s=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12]*s,n[1]=e[1]*r+e[5]*i+e[9]*a+e[13]*s,n[2]=e[2]*r+e[6]*i+e[10]*a+e[14]*s,n[3]=e[3]*r+e[7]*i+e[11]*a+e[15]*s,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],a=e[13],s=e[12],o=e[9];if(!t||e===t){var l=e[1],u=e[2],c=e[3],f=e[6],p=e[7],A=e[11];return e[1]=n,e[2]=i,e[3]=s,e[4]=l,e[6]=o,e[7]=a,e[8]=u,e[9]=f,e[11]=r,e[12]=c,e[13]=p,e[14]=A,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=s,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],s=e[5],o=e[6],l=e[7],u=e[8],c=e[9],f=e[10],p=e[11],A=e[12],d=e[13],v=e[14],h=e[15];return A*c*o*i-u*d*o*i-A*s*f*i+a*d*f*i+u*s*v*i-a*c*v*i-A*c*r*l+u*d*r*l+A*n*f*l-t*d*f*l-u*n*v*l+t*c*v*l+A*s*r*p-a*d*r*p-A*n*o*p+t*d*o*p+a*n*v*p-t*s*v*p-u*s*r*h+a*c*r*h+u*n*o*h-t*c*o*h-a*n*f*h+t*s*f*h},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],a=e[3],s=e[4],o=e[5],l=e[6],u=e[7],c=e[8],f=e[9],p=e[10],A=e[11],d=e[12],v=e[13],h=e[14],I=e[15],y=n*o-r*s,m=n*l-i*s,w=n*u-a*s,g=r*l-i*o,T=r*u-a*o,E=i*u-a*l,b=c*v-f*d,D=c*h-p*d,P=c*I-A*d,R=f*h-p*v,C=f*I-A*v,_=p*I-A*h,B=1/(y*_-m*C+w*R+g*P-T*D+E*b);return t[0]=(o*_-l*C+u*R)*B,t[1]=(-r*_+i*C-a*R)*B,t[2]=(v*E-h*T+I*g)*B,t[3]=(-f*E+p*T-A*g)*B,t[4]=(-s*_+l*P-u*D)*B,t[5]=(n*_-i*P+a*D)*B,t[6]=(-d*E+h*w-I*m)*B,t[7]=(c*E-p*w+A*m)*B,t[8]=(s*C-o*P+u*b)*B,t[9]=(-n*C+r*P-a*b)*B,t[10]=(d*T-v*w+I*y)*B,t[11]=(-c*T+f*w-A*y)*B,t[12]=(-s*R+o*D-l*b)*B,t[13]=(n*R-r*D+i*b)*B,t[14]=(-d*g+v*m-h*y)*B,t[15]=(c*g-f*m+p*y)*B,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||Z.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||Z.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(H=new Y(3),function(e,t,n,r){return H[0]=e,H[1]=t,H[2]=n,Z.translationMat4v(H,r)}),translationMat4s:function(e,t){return Z.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return Z.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var a=r[7];r[4]+=a*e,r[5]+=a*t,r[6]+=a*n;var s=r[11];r[8]+=s*e,r[9]+=s*t,r[10]+=s*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,a,s,o,l,u=Z.normalizeVec4([t[0],t[1],t[2],0],[]),c=Math.sin(e),f=Math.cos(e),p=1-f,A=u[0],d=u[1],v=u[2];return r=A*d,i=d*v,a=v*A,s=A*c,o=d*c,l=v*c,(n=n||Z.mat4())[0]=p*A*A+f,n[1]=p*r+l,n[2]=p*a-o,n[3]=0,n[4]=p*r-l,n[5]=p*d*d+f,n[6]=p*i+s,n[7]=0,n[8]=p*a+o,n[9]=p*i-s,n[10]=p*v*v+f,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return Z.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new Y(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,Z.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return Z.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.mat4(),r=e[0],i=e[1],a=e[2],s=e[3],o=r+r,l=i+i,u=a+a,c=r*o,f=r*l,p=r*u,A=i*l,d=i*u,v=a*u,h=s*o,I=s*l,y=s*u;return n[0]=1-(A+v),n[1]=f+y,n[2]=p-I,n[3]=0,n[4]=f-y,n[5]=1-(c+v),n[6]=d+h,n[7]=0,n[8]=p+I,n[9]=d-h,n[10]=1-(c+A),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Z.clamp,i=e[0],a=e[4],s=e[8],o=e[1],l=e[5],u=e[9],c=e[2],f=e[6],p=e[10];return"XYZ"===t?(n[1]=Math.asin(r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(-u,p),n[2]=Math.atan2(-a,i)):(n[0]=Math.atan2(f,l),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(s,p),n[2]=Math.atan2(o,l)):(n[1]=Math.atan2(-c,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(f,-1,1)),Math.abs(f)<.99999?(n[1]=Math.atan2(-c,p),n[2]=Math.atan2(-a,l)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[0]=Math.atan2(f,p),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-a,l))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-u,l),n[1]=Math.atan2(-c,i)):(n[0]=0,n[1]=Math.atan2(s,p))):"XZY"===t&&(n[2]=Math.asin(-r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(f,l),n[1]=Math.atan2(s,i)):(n[0]=Math.atan2(-u,p),n[1]=0)),n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.mat4();return Z.quaternionToRotationMat4(t,r),Z.scaleMat4v(n,r),Z.translateMat4v(e,r),r},decomposeMat4:function(){var e=new Y(3),t=new Y(16);return function(n,r,i,a){e[0]=n[0],e[1]=n[1],e[2]=n[2];var s=Z.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=Z.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var l=Z.lenVec3(e);Z.determinantMat4(n)<0&&(s=-s),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var u=1/s,c=1/o,f=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=f,t[9]*=f,t[10]*=f,Z.mat4ToQuaternion(t,i),a[0]=s,a[1]=o,a[2]=l,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=Z.mat4());var i,a,s,o,l,u,c,f,p,A,d=e[0],v=e[1],h=e[2],I=n[0],y=n[1],m=n[2],w=t[0],g=t[1],T=t[2];return d===w&&v===g&&h===T?Z.identityMat4():(i=d-w,a=v-g,s=h-T,o=y*(s*=A=1/Math.sqrt(i*i+a*a+s*s))-m*(a*=A),l=m*(i*=A)-I*s,u=I*a-y*i,(A=Math.sqrt(o*o+l*l+u*u))?(o*=A=1/A,l*=A,u*=A):(o=0,l=0,u=0),c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,(A=Math.sqrt(c*c+f*f+p*p))?(c*=A=1/A,f*=A,p*=A):(c=0,f=0,p=0),r[0]=o,r[1]=c,r[2]=i,r[3]=0,r[4]=l,r[5]=f,r[6]=a,r[7]=0,r[8]=u,r[9]=p,r[10]=s,r[11]=0,r[12]=-(o*d+l*v+u*h),r[13]=-(c*d+f*v+p*h),r[14]=-(i*d+a*v+s*h),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,a,s,o,l){return Z.lookAtMat4v([e,t,n],[r,i,a],[s,o,l],[])},orthoMat4c:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2/l,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=-2/u,s[11]=0,s[12]=-(e+t)/o,s[13]=-(r+n)/l,s[14]=-(a+i)/u,s[15]=1,s},frustumMat4v:function(e,t,n){n||(n=Z.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];Z.addVec4(i,r,X),Z.subVec4(i,r,q);var a=2*r[2],s=q[0],o=q[1],l=q[2];return n[0]=a/s,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=a/o,n[6]=0,n[7]=0,n[8]=X[0]/s,n[9]=X[1]/o,n[10]=-X[2]/l,n[11]=-1,n[12]=0,n[13]=0,n[14]=-a*i[2]/l,n[15]=0,n},frustumMat4:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2*i/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*i/l,s[6]=0,s[7]=0,s[8]=(t+e)/o,s[9]=(r+n)/l,s[10]=-(a+i)/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i*2/u,s[15]=0,s},perspectiveMat4:function(e,t,n,r,i){var a=[],s=[];return a[2]=n,s[2]=r,s[1]=a[2]*Math.tan(e/2),a[1]=-s[1],s[0]=s[1]*t,a[0]=-s[0],Z.frustumMat4v(a,s,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12],n[1]=e[1]*r+e[5]*i+e[9]*a+e[13],n[2]=e[2]*r+e[6]*i+e[10]*a+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,a,s,o,l=n||[],u=t.length,c=e[0],f=e[1],p=e[2],A=e[3],d=e[4],v=e[5],h=e[6],I=e[7],y=e[8],m=e[9],w=e[10],g=e[11],T=e[12],E=e[13],b=e[14],D=e[15],P=0;P2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2];e[3];var f=e[4],p=e[5],A=e[6];e[7];var d=e[8],v=e[9],h=e[10];e[11];var I=e[12],y=e[13],m=e[14];for(e[15],n=0;n2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),a=Math.sin(n),s=e[0]-t[0],o=e[1]-t[1];return r[0]=s*i-o*a+t[0],r[1]=s*a+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||Z.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(x=new Y(16),M=new Y(16),F=new Y(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,x),this.inverseMat4(n,M),F),e,r)}),lerpVec3:function(e,t,n,r,i,a){var s=a||Z.vec3(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s},lerpMat4:function(e,t,n,r,i,a){var s=a||Z.mat4(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s[3]=r[3]+o*(i[3]-r[3]),s[4]=r[4]+o*(i[4]-r[4]),s[5]=r[5]+o*(i[5]-r[5]),s[6]=r[6]+o*(i[6]-r[6]),s[7]=r[7]+o*(i[7]-r[7]),s[8]=r[8]+o*(i[8]-r[8]),s[9]=r[9]+o*(i[9]-r[9]),s[10]=r[10]+o*(i[10]-r[10]),s[11]=r[11]+o*(i[11]-r[11]),s[12]=r[12]+o*(i[12]-r[12]),s[13]=r[13]+o*(i[13]-r[13]),s[14]=r[14]+o*(i[14]-r[14]),s[15]=r[15]+o*(i[15]-r[15]),s},flatten:function(e){var t,n,r,i,a,s=[];for(t=0,n=e.length;t0&&void 0!==arguments[0]?arguments[0]:Z.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0]*Z.DEGTORAD/2,i=e[1]*Z.DEGTORAD/2,a=e[2]*Z.DEGTORAD/2,s=Math.cos(r),o=Math.cos(i),l=Math.cos(a),u=Math.sin(r),c=Math.sin(i),f=Math.sin(a);return"XYZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"YXZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"ZXY"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"ZYX"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"YZX"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l-u*c*f):"XZY"===t&&(n[0]=u*o*l-s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l+u*c*f),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),r=e[0],i=e[4],a=e[8],s=e[1],o=e[5],l=e[9],u=e[2],c=e[6],f=e[10],p=r+o+f;return p>0?(t=.5/Math.sqrt(p+1),n[3]=.25/t,n[0]=(c-l)*t,n[1]=(a-u)*t,n[2]=(s-i)*t):r>o&&r>f?(t=2*Math.sqrt(1+r-o-f),n[3]=(c-l)/t,n[0]=.25*t,n[1]=(i+s)/t,n[2]=(a+u)/t):o>f?(t=2*Math.sqrt(1+o-r-f),n[3]=(a-u)/t,n[0]=(i+s)/t,n[1]=.25*t,n[2]=(l+c)/t):(t=2*Math.sqrt(1+f-r-o),n[3]=(s-i)/t,n[0]=(a+u)/t,n[1]=(l+c)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Math.sqrt(Z.dotVec3(e,e)*Z.dotVec3(t,t)),i=r+Z.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):Z.cross3Vec3(e,t,n),n[3]=i,Z.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new Y(16);return function(t,n,r){return r=r||Z.vec3(),Z.quaternionToRotationMat4(t,e),Z.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0],i=e[1],a=e[2],s=e[3],o=t[0],l=t[1],u=t[2],c=t[3];return n[0]=s*o+r*c+i*u-a*l,n[1]=s*l+i*c+a*o-r*u,n[2]=s*u+a*c+r*l-i*o,n[3]=s*c-r*o-i*l-a*u,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2],s=e[0],o=e[1],l=e[2],u=e[3],c=u*r+o*a-l*i,f=u*i+l*r-s*a,p=u*a+s*i-o*r,A=-s*r-o*i-l*a;return n[0]=c*u+A*-s+f*-l-p*-o,n[1]=f*u+A*-o+p*-s-c*-l,n[2]=p*u+A*-l+c*-o-f*-s,n},quaternionToMat4:function(e,t){t=Z.identityMat4(t);var n=e[0],r=e[1],i=e[2],a=e[3],s=2*n,o=2*r,l=2*i,u=s*a,c=o*a,f=l*a,p=s*n,A=o*n,d=l*n,v=o*r,h=l*r,I=l*i;return t[0]=1-(v+I),t[1]=A+f,t[2]=d-c,t[4]=A-f,t[5]=1-(p+I),t[6]=h+u,t[8]=d+c,t[9]=h-u,t[10]=1-(p+v),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],s=n+n,o=r+r,l=i+i,u=n*s,c=n*o,f=n*l,p=r*o,A=r*l,d=i*l,v=a*s,h=a*o,I=a*l;return t[0]=1-(p+d),t[4]=c-I,t[8]=f+h,t[1]=c+I,t[5]=1-(u+d),t[9]=A-v,t[2]=f-h,t[6]=A+v,t[10]=1-(u+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=Z.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return Z.normalizeQuaternion(Z.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=(e=Z.normalizeQuaternion(e,J))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new Y(e||6)},AABB2:function(e){return new Y(e||4)},OBB3:function(e){return new Y(e||32)},OBB2:function(e){return new Y(e||16)},Sphere3:function(e,t,n,r){return new Y([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;no?s:o,a[1]+=l>u?l:u,a[2]+=c>f?c:f,Math.abs(Z.lenVec3(a))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||Z.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||Z.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Z.AABB3();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MAX_DOUBLE,e[3]=Z.MIN_DOUBLE,e[4]=Z.MIN_DOUBLE,e[5]=Z.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new Y(3);return function(t,n,r){n=n||Z.AABB3();for(var i,a,s,o=Z.MAX_DOUBLE,l=Z.MAX_DOUBLE,u=Z.MAX_DOUBLE,c=Z.MIN_DOUBLE,f=Z.MIN_DOUBLE,p=Z.MIN_DOUBLE,A=0,d=t.length;Ac&&(c=i),a>f&&(f=a),s>p&&(p=s);return n[0]=o,n[1]=l,n[2]=u,n[3]=c,n[4]=f,n[5]=p,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToSphere3:function(){var e=new Y(3);return function(t,n){n=n||Z.vec4();var r,i=0,a=0,s=0,o=t.length;for(r=0;ru&&(u=l);return n[3]=u,n}}(),positions3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=0;for(i=0;iu&&(u=c);return r[3]=u,r}}(),OBB3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=l/4;for(i=0;if&&(f=c);return r[3]=f,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(),n=0,r=0,i=0,a=0,s=e.length;at[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]0&&void 0!==arguments[0]?arguments[0]:Z.AABB2();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MIN_DOUBLE,e[3]=Z.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB2(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MIN_DOUBLE,l=Z.MIN_DOUBLE,u=0,c=e.length;uo&&(o=t),n>l&&(l=n);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),a=.5*(e[1]+1),s=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(s*t),r[3]=n-Math.floor(a*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var a=.5*(n-e),s=.5*(r-t),o=i*i;return(2*t-2*n+a+s)*(i*o)+(-3*t+3*n-2*a-s)*o+a*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.vec3(),i=t[0]-e[0],a=t[1]-e[1],s=t[2]-e[2],o=n[0]-e[0],l=n[1]-e[1],u=n[2]-e[2],c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,A=Math.sqrt(c*c+f*f+p*p);return 0===A?(r[0]=0,r[1]=0,r[2]=0):(r[0]=c/A,r[1]=f/A,r[2]=p/A),r},rayTriangleIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3),i=new Y(3);return function(a,s,o,l,u,c){c=c||Z.vec3();var f=Z.subVec3(l,o,e),p=Z.subVec3(u,o,t),A=Z.cross3Vec3(s,p,n),d=Z.dotVec3(f,A);if(d<1e-6)return null;var v=Z.subVec3(a,o,r),h=Z.dotVec3(v,A);if(h<0||h>d)return null;var I=Z.cross3Vec3(v,f,i),y=Z.dotVec3(s,I);if(y<0||h+y>d)return null;var m=Z.dotVec3(p,I)/d;return c[0]=a[0]+m*s[0],c[1]=a[1]+m*s[1],c[2]=a[2]+m*s[2],c}}(),rayPlaneIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3);return function(i,a,s,o,l,u){u=u||Z.vec3(),a=Z.normalizeVec3(a,e);var c=Z.subVec3(o,s,t),f=Z.subVec3(l,s,n),p=Z.cross3Vec3(c,f,r);Z.normalizeVec3(p,p);var A=-Z.dotVec3(s,p),d=-(Z.dotVec3(i,p)+A)/Z.dotVec3(a,p);return u[0]=i[0]+d*a[0],u[1]=i[1]+d*a[1],u[2]=i[2]+d*a[2],u}}(),cartesianToBarycentric:function(){var e=new Y(3),t=new Y(3),n=new Y(3);return function(r,i,a,s,o){var l=Z.subVec3(s,i,e),u=Z.subVec3(a,i,t),c=Z.subVec3(r,i,n),f=Z.dotVec3(l,l),p=Z.dotVec3(l,u),A=Z.dotVec3(l,c),d=Z.dotVec3(u,u),v=Z.dotVec3(u,c),h=f*d-p*p;if(0===h)return null;var I=1/h,y=(d*A-p*v)*I,m=(f*v-p*A)*I;return o[0]=1-y-m,o[1]=m,o[2]=y,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Z.vec3(),a=e[0],s=e[1],o=e[2];return i[0]=t[0]*a+n[0]*s+r[0]*o,i[1]=t[1]*a+n[1]*s+r[1]*o,i[2]=t[2]*a+n[2]*s+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,a,s,o,l,u,c={},f=[],p=[],A=t?[]:null,d=n?[]:null,v=[],h=Math.pow(10,4),I=0;for(l=0,u=e.length;l>24&255,s=f>>16&255,a=f>>8&255,i=255&f,r=3*t[d],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+1],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+2],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,f++;return{positions:u,colors:c}},faceToVertexNormals:function(e,t){var n,r,i,a,s,o,l,u,c,f,p,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=A.smoothNormalsAngleThreshold||20,v={},h=[],I={},y=4,m=Math.pow(10,y);for(l=0,c=e.length;ll[3]&&(l[3]=i[p]),i[p+1]l[4]&&(l[4]=i[p+1]),i[p+2]l[5]&&(l[5]=i[p+2])}if(n.length<20||a>10)return u.triangles=n,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var A=0;e[1]>e[A]&&(A=1),e[2]>e[A]&&(A=2),u.splitDim=A;var d=(l[A]+l[A+3])/2,v=new Array(n.length),h=0,I=new Array(n.length),y=0;for(s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t}};Z.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var $=function(){function e(){b(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return P(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),ee={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var te=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;le.length>0&&(n<0||r0&&ie>0){var n=1e3/ie;pe+=n,ce.push(n),ce.length>=30&&(pe-=ce.shift()),ee.frame.fps=Math.round(pe/ce.length)}!function(e){var t=Ae.runTasks(e+10),n=Ae.getNumTasks();ee.frame.tasksRun=t,ee.frame.tasksScheduled=n,ee.frame.tasksBudget=10}(t),function(e){for(var t in ue.time=e,Ae.scenes)if(Ae.scenes.hasOwnProperty(t)){var n=Ae.scenes[t];ue.sceneId=t,ue.startTime=n.startTime,ue.deltaTime=null!=ue.prevTime?ue.time-ue.prevTime:0,n.fire("tick",ue,!0)}ue.prevTime=e}(t),function(){var e,t,n,r,i,a=Ae.scenes,s=!1;for(i in a)a.hasOwnProperty(i)&&(e=a[i],(t=se[i])||(t=se[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(s),t.renderCountdown=r))}(),fe=t,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(e):requestAnimationFrame(e)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(de):requestAnimationFrame(de);var ve=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return P(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+ae.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,a=e.type,s=e.on,o=!1!==e.recompiles;if(n&&(ae.isNumeric(n)||ae.isString(n))){var l=n;if(!(n=this.scene.components[l]))return void this.error("Component not found: "+ae.inQuotes(l))}if(!n)if(!0===i){var u=this.scene.types[a];for(var c in u)if(u.hasOwnProperty){n=u[c];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+ae.inQuotes(n.id));if(a&&!n.isType(a))return void this.error("Expected a "+a+" type or subtype: "+n.type+" "+ae.inQuotes(n.id))}this._attachments||(this._attachments={});var f,p,A,d=this._attached[t];if(d){if(n&&d.id===n.id)return;var v=this._attachments[d.id];for(p=0,A=(f=v.subs).length;p3&&void 0!==arguments[3]?arguments[3]:1e3,i=Z.getPositionsCenter(e,he),a=Math.round(i[0]/r)*r,s=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=a,n[1]=s,n[2]=o;var l=0!==n[0]||0!==n[1]||0!==n[2];if(l)for(var u=0,c=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,a=this.meshes.length;i1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._color=r.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=r.thickness||1,this._thicknessClickable=r.thicknessClickable||6;var i=this._wire,a=i.style;a.border="solid "+this._thickness+"px "+this._color,a.position="absolute",a["z-index"]=void 0===r.zIndex?"2000001":r.zIndex,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._wireClickable,o=s.style;o.border="solid "+this._thicknessClickable+"px "+this._color,o.position="absolute",o["z-index"]=void 0===r.zIndex?"2000002":r.zIndex+1,o.width="0px",o.height="0px",o.visibility="visible",o.top="0px",o.left="0px",o["-webkit-transform-origin"]="0 0",o["-moz-transform-origin"]="0 0",o["-ms-transform-origin"]="0 0",o["-o-transform-origin"]="0 0",o["transform-origin"]="0 0",o["-webkit-transform"]="rotate(0deg)",o["-moz-transform"]="rotate(0deg)",o["-ms-transform"]="rotate(0deg)",o["-o-transform"]="rotate(0deg)",o.transform="rotate(0deg)",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return P(e,[{key:"_visible",get:function(){return"visible"===this._wire.style.visibility}},{key:"_update",value:function(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,n=this._wire.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)";var r=this._wireClickable.style;r.width=Math.round(e)+"px",r.left=Math.round(this._x1)+"px",r.top=Math.round(this._y1)+"px",r["-webkit-transform"]="rotate("+t+"deg)",r["-moz-transform"]="rotate("+t+"deg)",r["-ms-transform"]="rotate("+t+"deg)",r["-o-transform"]="rotate("+t+"deg)",r.transform="rotate("+t+"deg)"}},{key:"setStartAndEnd",value:function(e,t,n,r){this._x1=e,this._y1=t,this._x2=n,this._y2=r,this._update()}},{key:"setColor",value:function(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}},{key:"setOpacity",value:function(e){this._wire.style.opacity=e}},{key:"setVisible",value:function(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}},{key:"setClickable",value:function(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}},{key:"destroy",value:function(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}]),e}(),He=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var i=this._dot,a=i.style;a["border-radius"]="25px",a.border="solid 2px white",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"40000005":r.zIndex,a.width="8px",a.height="8px",a.visibility=!1!==r.visible?"visible":"hidden",a.top="0px",a.left="0px",a["box-shadow"]="0 2px 5px 0 #182A3D;",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._dotClickable,o=s.style;o["border-radius"]="35px",o.border="solid 10px white",o.position="absolute",o["z-index"]=void 0===r.zIndex?"40000007":r.zIndex+1,o.width="8px",o.height="8px",o.visibility="visible",o.top="0px",o.left="0px",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.borderColor)}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._dot.style;n.left=Math.round(e)-4+"px",n.top=Math.round(t)-4+"px";var r=this._dotClickable.style;r.left=Math.round(e)-9+"px",r.top=Math.round(t)-9+"px"}},{key:"setFillColor",value:function(e){this._dot.style.background=e||"lightgreen"}},{key:"setBorderColor",value:function(e){this._dot.style.border="solid 2px"+(e||"black")}},{key:"setOpacity",value:function(e){this._dot.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}},{key:"setClickable",value:function(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}},{key:"destroy",value:function(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}]),e}(),Ue=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=r.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var i=this._label,a=i.style;a["border-radius"]="5px",a.color="white",a.padding="4px",a.border="solid 1px",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"5000005":r.zIndex,a.width="auto",a.height="auto",a.visibility="visible",a.top="0px",a.left="0px",a["pointer-events"]="all",a.opacity=1,r.onContextMenu,i.innerText="",t.appendChild(i),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.fillColor),this.setText(r.text),r.onMouseOver&&i.addEventListener("mouseover",(function(e){r.onMouseOver(e,n),e.preventDefault()})),r.onMouseLeave&&i.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n),e.preventDefault()})),r.onMouseWheel&&i.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&i.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()}))}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._label.style;n.left=Math.round(e)-20+"px",n.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,n,r){var i=e+.5*(n-e),a=t+.5*(r-t),s=this._label.style;s.left=Math.round(i)-20+"px",s.top=Math.round(a)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,n,r,i,a){var s=(e+n+i)/3,o=(t+r+a)/3,l=this._label.style;l.left=Math.round(s)-20+"px",l.top=Math.round(o)-12+"px"}},{key:"setText",value:function(e){this._label.innerHTML=this._prefix+(e||"")}},{key:"setFillColor",value:function(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}},{key:"setBorderColor",value:function(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}},{key:"setOpacity",value:function(e){this._label.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}},{key:"setClickable",value:function(e){this._label.style["pointer-events"]=e?"all":"none"}},{key:"destroy",value:function(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}]),e}(),Ge=Z.vec3(),ke=Z.vec3(),Ve=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._color=i.color||e.defaultColor;var a=r.plugin.viewer.scene;r._originMarker=new Me(a,i.origin),r._cornerMarker=new Me(a,i.corner),r._targetMarker=new Me(a,i.target),r._originWorld=Z.vec3(),r._cornerWorld=Z.vec3(),r._targetWorld=Z.vec3(),r._wp=new Float64Array(12),r._vp=new Float64Array(12),r._pp=new Float64Array(12),r._cp=new Int16Array(6);var s=i.onMouseOver?function(e){i.onMouseOver(e,g(r))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,g(r))}:null,l=i.onContextMenu?function(e){i.onContextMenu(e,g(r))}:null,u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._cornerDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._originWire=new Fe(r._container,{color:r._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetWire=new Fe(r._container,{color:r._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._angleLabel=new Ue(r._container,{fillColor:r._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._cornerVisible=!1,r._targetVisible=!1,r._originWireVisible=!1,r._targetWireVisible=!1,r._angleVisible=!1,r._labelsVisible=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._cornerMarker.on("worldPos",(function(e){r._cornerWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.cornerVisible=i.cornerVisible,r.targetVisible=i.targetVisible,r.originWireVisible=i.originWireVisible,r.targetWireVisible=i.targetWireVisible,r.angleVisible=i.angleVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(Z.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){var t=-.3,n=this._originMarker.viewPos[2],r=this._cornerMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(n>t||r>t||i>t)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);Z.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var a=this._pp,s=this._cp,o=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=o.top-l.top,c=o.left-l.left,f=e.canvas.boundary,p=f[2],A=f[3],d=0,v=0,h=a.length;vt+5||r[0]n+5||r[1]p[0]+5||A[0]p[1]+5||A[1]1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"AngleMeasurements",e))._container=i.container||document.body,r._control=new je(g(r)),r._measurements={},r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.zIndex=i.zIndex||1e4,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"control",get:function(){return this._control}},{key:"measurements",get:function(){return this._measurements}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var n=t.origin,r=t.corner,i=t.target,a=new Ve(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},corner:{entity:r.entity,worldPos:r.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:t.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[a.id]=a,a.on("destroyed",(function(){delete e._measurements[a.id]})),this.fire("measurementCreated",a),a}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,n=Object.entries(this.measurements);t

";ae.isArray(t)&&(t=t.join("")),t=this._renderTemplate(t);var n=document.createRange().createContextualFragment(t);this._marker=n.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(function(){e.plugin.fire("markerClicked",e)})),this._marker.addEventListener("mouseenter",(function(){e.plugin.fire("markerMouseEnter",e)})),this._marker.addEventListener("mouseleave",(function(){e.plugin.fire("markerMouseLeave",e)})),this._marker.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);var r=this._labelHTML||"

";ae.isArray(r)&&(r=r.join("")),r=this._renderTemplate(r);var i=document.createRange().createContextualFragment(r);this._label=i.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}}},{key:"_updatePosition",value:function(){var e=this.scene.canvas.boundary,t=e[0],n=e[1],r=this.canvasPos;this._marker.style.left=Math.floor(t+r[0])-12+"px",this._marker.style.top=Math.floor(n+r[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+r[0]+20)+"px",this._label.style.top=Math.floor(n+r[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}},{key:"_renderTemplate",value:function(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){var n=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),n)}return e}},{key:"setMarkerShown",value:function(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}},{key:"getMarkerShown",value:function(){return this._markerShown}},{key:"setLabelShown",value:function(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}},{key:"getLabelShown",value:function(){return this._labelShown}},{key:"setField",value:function(e,t){this._values[e]=t||"",this._htmlDirty=!0}},{key:"getField",value:function(e){return this._values[e]}},{key:"setValues",value:function(e){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];this.setField(t,n)}}},{key:"getValues",value:function(){return this._values}},{key:"destroy",value:function(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ke=Z.vec3(),Ye=Z.vec3(),Xe=Z.vec3(),qe=function(e){I(n,z);var t=m(n);function n(e,r){var i;return b(this,n),(i=t.call(this,"Annotations",e))._labelHTML=r.labelHTML||"
",i._markerHTML=r.markerHTML||"
",i._container=r.container||document.body,i._values=r.values||{},i.annotations={},i.surfaceOffset=r.surfaceOffset,i}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){if("clearAnnotations"===e)this.clear()}},{key:"surfaceOffset",get:function(){return this._surfaceOffset},set:function(e){null==e&&(e=.3),this._surfaceOffset=e}},{key:"createAnnotation",value:function(e){var t,n,r=this;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){var i=e.pickResult;if(i.worldPos&&i.worldNormal){var a=Z.normalizeVec3(i.worldNormal,Ke),s=Z.mulVec3Scalar(a,this._surfaceOffset,Ye);t=Z.addVec3(i.worldPos,s,Xe),n=i.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,n=e.entity;var o=null;e.markerElementId&&((o=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var l=null;e.labelElementId&&((l=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));var u=new ze(this.viewer.scene,{id:e.id,plugin:this,entity:n,worldPos:t,container:this._container,markerElement:o,labelElement:l,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:ae.apply(e.values,ae.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[u.id]=u,u.on("destroyed",(function(){delete r.annotations[u.id],r.fire("annotationDestroyed",u.id)})),this.fire("annotationCreated",u.id),u}},{key:"destroyAnnotation",value:function(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}},{key:"clear",value:function(){for(var e=Object.keys(this.annotations),t=0,n=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return P(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),Ze={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},$e=document.createElement("canvas");if($e){var et=$e.getContext("webgl",{antialias:!0})||$e.getContext("experimental-webgl",{antialias:!0});Ze.WEBGL=!!et,Ze.WEBGL&&(Ze.ANTIALIAS=et.getContextAttributes().antialias,et.getShaderPrecisionFormat?et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.HIGH_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="highp":et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.MEDIUM_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="mediump":Ze.FS_MAX_FLOAT_PRECISION="lowp":Ze.FS_MAX_FLOAT_PRECISION="mediump",Ze.DEPTH_BUFFER_BITS=et.getParameter(et.DEPTH_BITS),Ze.MAX_TEXTURE_SIZE=et.getParameter(et.MAX_TEXTURE_SIZE),Ze.MAX_CUBE_MAP_SIZE=et.getParameter(et.MAX_CUBE_MAP_TEXTURE_SIZE),Ze.MAX_RENDERBUFFER_SIZE=et.getParameter(et.MAX_RENDERBUFFER_SIZE),Ze.MAX_TEXTURE_UNITS=et.getParameter(et.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ze.MAX_TEXTURE_IMAGE_UNITS=et.getParameter(et.MAX_TEXTURE_IMAGE_UNITS),Ze.MAX_VERTEX_ATTRIBS=et.getParameter(et.MAX_VERTEX_ATTRIBS),Ze.MAX_VERTEX_UNIFORM_VECTORS=et.getParameter(et.MAX_VERTEX_UNIFORM_VECTORS),Ze.MAX_FRAGMENT_UNIFORM_VECTORS=et.getParameter(et.MAX_FRAGMENT_UNIFORM_VECTORS),Ze.MAX_VARYING_VECTORS=et.getParameter(et.MAX_VARYING_VECTORS),et.getSupportedExtensions().forEach((function(e){Ze.SUPPORTED_EXTENSIONS[e]=!0})))}var tt=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],nt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._backgroundColor=Z.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var a=g(r);r.canvas.addEventListener("webglcontextlost",r._webglcontextlostListener=function(e){console.time("webglcontextrestored"),a.scene._webglContextLost(),a.fire("webglcontextlost"),e.preventDefault()},!1),r.canvas.addEventListener("webglcontextrestored",r._webglcontextrestoredListener=function(e){a._initWebGL(),a.gl&&(a.scene._webglContextRestored(a.gl),a.fire("webglcontextrestored",a.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var s=!0,o=new ResizeObserver((function(e){var t,n=f(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(s=!0)}}catch(e){n.e(e)}finally{n.f()}}));return o.observe(r.canvas),r._tick=r.scene.on("tick",(function(){s&&(s=!1,a.canvas.width=Math.round(a.canvas.clientWidth*a._resolutionScale),a.canvas.height=Math.round(a.canvas.clientHeight*a._resolutionScale),a.boundary[0]=a.canvas.offsetLeft,a.boundary[1]=a.canvas.offsetTop,a.boundary[2]=a.canvas.clientWidth,a.boundary[3]=a.canvas.clientHeight,a.fire("boundary",a.boundary))})),r._spinner=new Je(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return P(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+Z.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e0&&"/"===t.charAt(n+1)&&(t=t.substring(0,n)),r.push(t);return r.join("\n")}function ct(e){console.error(e.join("\n"))}var ft=function(){function e(t,n){b(this,e),this.id=lt.addItem({}),this.source=n,this.init(t)}return P(e,[{key:"init",value:function(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new at(e,e.VERTEX_SHADER,ut(this.source.vertex)),this._fragmentShader=new at(e,e.FRAGMENT_SHADER,ut(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ct(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ct(this.errors);var t,n,r,i,a;if(this.compiled=!0,this.handle=e.createProgram(),this.handle){if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ct(this.errors);var s=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(n=0;nthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),At=function(){function e(t,n){b(this,e),this.scene=t,this.aabb=Z.AABB3(),this.origin=Z.vec3(n),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}return P(e,[{key:"addMarker",value:function(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}},{key:"markerWorldPosUpdated",value:function(e){if(this.markers[e.id]){var t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}}},{key:"removeMarker",value:function(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}},{key:"update",value:function(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}},{key:"_buildMarkerList",value:function(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}},{key:"_buildPositions",value:function(){for(var e=0,t=0;t-t)o._setVisible(!1);else{var l=o.canvasPos,u=l[0],c=l[1];u+10<0||c+10<0||u-10>r||c-10>i?o._setVisible(!1):!o.entity||o.entity.visible?o.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=o,this.pixels[a++]=u,this.pixels[a++]=c):o._setVisible(!0):o._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n0,n=[];return n.push("#version 300 es"),n.push("// OcclusionTester vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("vec4 worldPosition = vec4(position, 1.0); "),n.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&n.push(" vWorldPosition = worldPosition;"),n.push(" vec4 clipPos = projMatrix * viewPosition;"),n.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?n.push("vFragDepth = 1.0 + clipPos.w;"):n.push("clipPos.z += -0.001;"),n.push(" gl_Position = clipPos;"),n.push("}"),n}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// OcclusionTester fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),r.push("}"),r}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,n=e._sectionPlanesState;if(this._program=new ft(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=n.sectionPlanes.length;i0)for(var p=r.sectionPlanes,A=0;A= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var r=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),this._uvBuf=new pt(n,n.ARRAY_BUFFER,r,r.length,2,n.STATIC_DRAW),this._indicesBuf=new pt(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}}},{key:"destroy",value:function(){this._program&&(this._program.destroy(),this._program=null)}}]),e}(),mt=new Float32Array(Dt(17,[0,1])),wt=new Float32Array(Dt(17,[1,0])),gt=new Float32Array(function(e,t){for(var n=[],r=0;r<=e;r++)n.push(bt(r,t));return n}(17,4)),Tt=new Float32Array(2),Et=function(){function e(t){b(this,e),this._scene=t,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}return P(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new ft(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS ".concat(16,"\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var t=new Float32Array([1,1,0,1,0,0,1,0]),n=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),r=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(e,e.ARRAY_BUFFER,n,n.length,3,e.STATIC_DRAW),this._uvBuf=new pt(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new pt(e,e.ELEMENT_ARRAY_BUFFER,r,r.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}},{key:"render",value:function(e,t,n){var r=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;r._scene.camera.on("projMatrix",(function(){e=!0}));var t=Z.mat4();return function(){return e&&Z.inverseMat4(s.camera.projMatrix,t),t}}());var i=this._scene.canvas.gl,a=this._program,s=this._scene,o=i.drawingBufferWidth,l=i.drawingBufferHeight,u=s.camera.project._state,c=u.near,f=u.far;i.viewport(0,0,o,l),i.clearColor(0,0,0,1),i.enable(i.DEPTH_TEST),i.disable(i.BLEND),i.frontFace(i.CCW),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),a.bind(),Tt[0]=o,Tt[1]=l,i.uniform2fv(this._uViewport,Tt),i.uniform1f(this._uCameraNear,c),i.uniform1f(this._uCameraFar,f),i.uniform1f(this._uDepthCutoff,.01),0===n?i.uniform2fv(this._uSampleOffsets,wt):i.uniform2fv(this._uSampleOffsets,mt),i.uniform1fv(this._uSampleWeights,gt);var p=e.getDepthTexture(),A=t.getTexture();a.bindTexture(this._uDepthTexture,p,0),a.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),i.drawElements(i.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function bt(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Dt(e,t){for(var n=[],r=0;r<=e;r++)n.push(t[0]*r),n.push(t[1]*r);return n}var Pt=function(){function e(t,n,r){b(this,e),r=r||{},this.gl=n,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=r.size,this._hasDepthTexture=!!r.depthTexture}return P(e,[{key:"setSize",value:function(e){this.size=e}},{key:"webglContextRestored",value:function(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}},{key:"bind",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(this._touch(e),!this.bound){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_touch",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=r.drawingBufferWidth,t=r.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;r.deleteTexture(this.buffer.texture),r.deleteFramebuffer(this.buffer.framebuf),r.deleteRenderbuffer(this.buffer.renderbuf)}var i,a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),this._hasDepthTexture&&(i=r.createTexture(),r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null));var s=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,s),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var o=r.createFramebuffer();if(r.bindFramebuffer(r.FRAMEBUFFER,o),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0),this._hasDepthTexture?r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,i,0):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,s),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,o),!r.isFramebuffer(o))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var l=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(l){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={framebuf:o,renderbuf:s,texture:a,depthTexture:i,width:e,height:t},this.bound=!1}},{key:"clear",value:function(){if(!this.bound)throw"Render buffer not bound";var e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,s=e,o=(this.buffer.height||this.gl.drawingBufferHeight)-t,l=new i(a),u=this.gl;return u.readPixels(s,o,1,1,n||u.RGBA,r||u.UNSIGNED_BYTE,l,0),l}},{key:"readArray",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,i=new n(this.buffer.width*this.buffer.height*r),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),n=t.pixelData,r=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,n);for(var s=this.buffer.width,o=this.buffer.height,l=o/2|0,u=4*s,c=new Uint8Array(4*s),f=0;f0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,n=this.buffer.width,r=this.buffer.height,i=this._imageDataCache;if(i&&(i.width===n&&i.height===r||(this._imageDataCache=null,i=null)),!i){var a=document.createElement("canvas"),s=a.getContext("2d");a.width=n,a.height=r,i={pixelData:new e(n*r*t),canvas:a,context:s,imageData:s.createImageData(n,r),width:n,height:r},this._imageDataCache=i}return i.context.resetTransform(),i}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=this;return this._texture||(this._texture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.texture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.texture),!0)},unbind:function(t){e.buffer&&e.buffer.texture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"hasDepthTexture",value:function(){return this._hasDepthTexture}},{key:"getDepthTexture",value:function(){if(!this._hasDepthTexture)return null;var e=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.depthTexture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.depthTexture),!0)},unbind:function(t){e.buffer&&e.buffer.depthTexture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"destroy",value:function(){if(this.allocated){var e=this.gl;e.deleteTexture(this.buffer.texture),e.deleteTexture(this.buffer.depthTexture),e.deleteFramebuffer(this.buffer.framebuf),e.deleteRenderbuffer(this.buffer.renderbuf),this.allocated=!1,this.buffer=null,this.bound=!1}this._imageDataCache=null,this._texture=null,this._depthTexture=null}}]),e}(),Rt=function(){function e(t){b(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return P(e,[{key:"getRenderBuffer",value:function(e,t){var n=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,r=n[e];return r||(r=new Pt(this.scene.canvas.canvas,this.scene.canvas.gl,t),n[e]=r),r}},{key:"destroy",value:function(){for(var e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(var t in this._renderBuffersScaled)this._renderBuffersScaled[t].destroy()}}]),e}();function Ct(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}var _t=function(e,t){t=t||{};var n=new rt(e),r=e.canvas.canvas,i=e.canvas.gl,a=!!t.transparent,s=t.alphaDepthMask,o=new G({}),l={},u={},c=!0,f=!0,p=!0,A=!0,d=!0,v=!0,h=!0,I=!0,y=new Rt(e),m=!1,w=new yt(e),g=new Et(e);function T(){c&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e],n=t.drawableMap,r=t.drawableListPreCull,i=0;for(var a in n)n.hasOwnProperty(a)&&(r[i++]=n[a]);r.length=i}}(),c=!1,f=!0),f&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),f=!1,p=!0),p&&function(){for(var e in l)if(l.hasOwnProperty(e)){for(var t=l[e],n=t.drawableListPreCull,r=t.drawableList,i=0,a=0,s=n.length;a0)for(n.withSAO=!0,O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||Q>0||U>0||G>0){if(i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):(i.blendEquation(i.FUNC_ADD),i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,s||i.depthMask(!1),(U>0||G>0)&&i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),G>0)for(O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||z>0){if(n.lastProgramId=null,e.highlightMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),z>0)for(O=0;O0)for(O=0;O0||Y>0||W>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),i.enable(i.CULL_FACE),Y>0)for(O=0;O0)for(O=0;O0||q>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),q>0)for(O=0;O0)for(O=0;O0||Z>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),Z>0)for(O=0;O0)for(O=0;O1&&void 0!==arguments[1]?arguments[1]:o;v.reset(),T();var h=null,I=null;if(v.pickSurface=A.pickSurface,A.canvasPos)c[0]=A.canvasPos[0],c[1]=A.canvasPos[1],h=e.camera.viewMatrix,I=e.camera.projMatrix,v.canvasPos=A.canvasPos;else{var m=Z.frustumMat4(-1,1,-1,1,.01,e.camera.project.far,n);A.matrix?(h=A.matrix,I=m):(f.set(A.origin||[0,0,0]),p.set(A.direction||[0,0,1]),d=Z.addVec3(f,p,t),a[0]=Math.random(),a[1]=Math.random(),a[2]=Math.random(),Z.normalizeVec3(a),Z.cross3Vec3(p,a,s),h=Z.lookAtMat4v(f,d,s,i),I=m,v.origin=f,v.direction=p),c[0]=.5*r.clientWidth,c[1]=.5*r.clientHeight}for(var w in l)if(l.hasOwnProperty(w))for(var g=l[w].drawableList,E=0,R=g.length;E1&&void 0!==arguments[1]?arguments[1]:50,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"vertex";n.reset(),n.backfaces=!0,n.frontface=!0,n.pickZNear=e.camera.project.near,n.pickZFar=e.camera.project.far;var s=y.getRenderBuffer("uniquePickColors-aabs",{depthTexture:!0,size:[2*r+1,2*r+1]});n.snapVectorA=[_(t[0],i.drawingBufferWidth),B(t[1],i.drawingBufferHeight)],n.snapInvVectorAB=[i.drawingBufferWidth/(2*r),i.drawingBufferHeight/(2*r)],n.snapMode=a,s.bind(i.RGBA32I),i.viewport(0,0,s.size[0],s.size[1]),i.enable(i.DEPTH_TEST),i.frontFace(i.CCW),i.disable(i.CULL_FACE),i.depthMask(!0),i.disable(i.BLEND),i.depthFunc(i.LESS),i.clear(i.DEPTH_BUFFER_BIT),i.clearBufferiv(i.COLOR,0,new Int32Array([0,0,0,0]));var o=e.camera.viewMatrix,u=e.camera.projMatrix;for(var c in l)if(l.hasOwnProperty(c))for(var f=l[c].drawableList,p=0,A=f.length;p0){var N=Math.floor(S/4),L=s.size[0];s.size[1];var x=N%L-Math.floor(L/2),M=Math.floor(N/L)-Math.floor(L/2),F=Math.sqrt(Math.pow(x,2)+Math.pow(M,2));O.push({x:x,y:M,dist:F,result:[I[S+0],I[S+1],I[S+2],I[S+3]]})}var H=null;if(O.length>0){O.sort((function(e,t){return e.dist-t.dist}));var U=h[(O=O[0].result)[3]],G=U.origin,k=U.coordinateScale;H=[O[0]*k[0]+G[0],O[1]*k[1]+G[1],O[2]*k[2]+G[2]]}if(null===m&&null==H)return null;var V=null;return null!==H&&(V=e.camera.projectWorldPos(H)),{worldPos:m,snappedWorldPos:H,snappedCanvasPos:V}},this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new ht(e,y),this._occlusionTester.addMarker(t),e.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){for(var e in T(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,i.viewport(0,0,i.drawingBufferWidth,i.drawingBufferHeight),i.clearColor(0,0,0,0),i.enable(i.DEPTH_TEST),i.disable(i.CULL_FACE),i.disable(i.BLEND),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),l)if(l.hasOwnProperty(e))for(var t=l[e].drawableList,r=0,a=t.length;r0&&void 0!==arguments[0]?arguments[0]:{},t=y.getRenderBuffer("snapshot");e.width&&e.height&&t.setSize([e.width,e.height]),t.bind(),t.clear(),m=!0},this.renderSnapshot=function(){m&&(y.getRenderBuffer("snapshot").clear(),this.render({force:!0,opaqueOnly:!1}),p=!0)},this.readSnapshot=function(e){return y.getRenderBuffer("snapshot").readImage(e)},this.readSnapshotAsCanvas=function(){return y.getRenderBuffer("snapshot").readImageAsCanvas()},this.endSnapshot=function(){m&&(y.getRenderBuffer("snapshot").unbind(),m=!1)},this.destroy=function(){l={},u={},y.destroy(),w.destroy(),g.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},Bt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).KEY_BACKSPACE=8,r.KEY_TAB=9,r.KEY_ENTER=13,r.KEY_SHIFT=16,r.KEY_CTRL=17,r.KEY_ALT=18,r.KEY_PAUSE_BREAK=19,r.KEY_CAPS_LOCK=20,r.KEY_ESCAPE=27,r.KEY_PAGE_UP=33,r.KEY_PAGE_DOWN=34,r.KEY_END=35,r.KEY_HOME=36,r.KEY_LEFT_ARROW=37,r.KEY_UP_ARROW=38,r.KEY_RIGHT_ARROW=39,r.KEY_DOWN_ARROW=40,r.KEY_INSERT=45,r.KEY_DELETE=46,r.KEY_NUM_0=48,r.KEY_NUM_1=49,r.KEY_NUM_2=50,r.KEY_NUM_3=51,r.KEY_NUM_4=52,r.KEY_NUM_5=53,r.KEY_NUM_6=54,r.KEY_NUM_7=55,r.KEY_NUM_8=56,r.KEY_NUM_9=57,r.KEY_A=65,r.KEY_B=66,r.KEY_C=67,r.KEY_D=68,r.KEY_E=69,r.KEY_F=70,r.KEY_G=71,r.KEY_H=72,r.KEY_I=73,r.KEY_J=74,r.KEY_K=75,r.KEY_L=76,r.KEY_M=77,r.KEY_N=78,r.KEY_O=79,r.KEY_P=80,r.KEY_Q=81,r.KEY_R=82,r.KEY_S=83,r.KEY_T=84,r.KEY_U=85,r.KEY_V=86,r.KEY_W=87,r.KEY_X=88,r.KEY_Y=89,r.KEY_Z=90,r.KEY_LEFT_WINDOW=91,r.KEY_RIGHT_WINDOW=92,r.KEY_SELECT_KEY=93,r.KEY_NUMPAD_0=96,r.KEY_NUMPAD_1=97,r.KEY_NUMPAD_2=98,r.KEY_NUMPAD_3=99,r.KEY_NUMPAD_4=100,r.KEY_NUMPAD_5=101,r.KEY_NUMPAD_6=102,r.KEY_NUMPAD_7=103,r.KEY_NUMPAD_8=104,r.KEY_NUMPAD_9=105,r.KEY_MULTIPLY=106,r.KEY_ADD=107,r.KEY_SUBTRACT=109,r.KEY_DECIMAL_POINT=110,r.KEY_DIVIDE=111,r.KEY_F1=112,r.KEY_F2=113,r.KEY_F3=114,r.KEY_F4=115,r.KEY_F5=116,r.KEY_F6=117,r.KEY_F7=118,r.KEY_F8=119,r.KEY_F9=120,r.KEY_F10=121,r.KEY_F11=122,r.KEY_F12=123,r.KEY_NUM_LOCK=144,r.KEY_SCROLL_LOCK=145,r.KEY_SEMI_COLON=186,r.KEY_EQUAL_SIGN=187,r.KEY_COMMA=188,r.KEY_DASH=189,r.KEY_PERIOD=190,r.KEY_FORWARD_SLASH=191,r.KEY_GRAVE_ACCENT=192,r.KEY_OPEN_BRACKET=219,r.KEY_BACK_SLASH=220,r.KEY_CLOSE_BRACKET=221,r.KEY_SINGLE_QUOTE=222,r.KEY_SPACE=32,r.element=i.element,r.altDown=!1,r.ctrlDown=!1,r.mouseDownLeft=!1,r.mouseDownMiddle=!1,r.mouseDownRight=!1,r.keyDown=[],r.enabled=!0,r.keyboardEnabled=!0,r.mouseover=!1,r.mouseCanvasPos=Z.vec2(),r._keyboardEventsElement=i.keyboardEventsElement||document,r._bindEvents(),r}return P(n,[{key:"_bindEvents",value:function(){var e=this;if(!this._eventsBound){this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!0:t.keyCode===e.KEY_ALT?e.altDown=!0:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!0),e.keyDown[t.keyCode]=!0,e.fire("keydown",t.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!1:t.keyCode===e.KEY_ALT?e.altDown=!1:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!1),e.keyDown[t.keyCode]=!1,e.fire("keyup",t.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=function(t){e.enabled&&(e.mouseover=!0,e._getMouseCanvasPos(t),e.fire("mouseenter",e.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=function(t){e.enabled&&(e.mouseover=!1,e._getMouseCanvasPos(t),e.fire("mouseleave",e.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!0;break;case 2:e.mouseDownMiddle=!0;break;case 3:e.mouseDownRight=!0}e._getMouseCanvasPos(t),e.element.focus(),e.fire("mousedown",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!1;break;case 2:e.mouseDownMiddle=!1;break;case 3:e.mouseDownRight=!1}e.fire("mouseup",e.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("click",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("dblclick",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=function(t){e.enabled&&(e._getMouseCanvasPos(t),e.fire("mousemove",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=function(t,n){if(e.enabled){var r=Math.max(-1,Math.min(1,40*-t.deltaY));e.fire("mousewheel",r,!0)}},{passive:!0});var t,n;this.on("mousedown",(function(e){t=e[0],n=e[1]})),this.on("mouseup",(function(r){t>=r[0]-2&&t<=r[0]+2&&n>=r[1]-2&&n<=r[1]+2&&e.fire("mouseclicked",r,!0)})),this._eventsBound=!0}}},{key:"_unbindEvents",value:function(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}},{key:"_getMouseCanvasPos",value:function(e){if(e){for(var t=e.target,n=0,r=0;t.offsetParent;)n+=t.offsetLeft,r+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-n,this.mouseCanvasPos[1]=e.pageY-r}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}},{key:"setEnabled",value:function(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}},{key:"getEnabled",value:function(){return this.enabled}},{key:"setKeyboardEnabled",value:function(e){this.keyboardEnabled=e}},{key:"getKeyboardEnabled",value:function(){return this.keyboardEnabled}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._unbindEvents()}}]),n}(),Ot=new G({}),St=function(){function e(t){for(var n in b(this,e),this.id=Ot.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return P(e,[{key:"destroy",value:function(){Ot.removeItem(this.id)}}]),e}(),Nt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({boundary:[0,0,100,100]}),r.boundary=i.boundary,r.autoBoundary=i.autoBoundary,r}return P(n,[{key:"type",get:function(){return"Viewport"}},{key:"boundary",get:function(){return this._state.boundary},set:function(e){if(!this._autoBoundary){if(!e){var t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}},{key:"autoBoundary",get:function(){return this._autoBoundary},set:function(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){var t=e[2],n=e[3];this._state.boundary=[0,0,t,n],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Lt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r._fov=60,r._canvasResized=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r.fov=i.fov,r.fovAxis=i.fovAxis,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.viewport.boundary,t=e[2]/e[3],n=this._fovAxis,r=this._fov;("x"===n||"min"===n&&t<1||"max"===n&&t>1)&&(r/=t),r=Math.min(r,120),Z.perspectiveMat4(r*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}},{key:"fov",get:function(){return this._fov},set:function(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}},{key:"fovAxis",get:function(){return this._fovAxis},set:function(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),n}(),xt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.scale=i.scale,r.near=i.near,r.far=i.far,r._onCanvasBoundary=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r}return P(n,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,n,r,i=this.scene,a=.5*this._scale,s=i.viewport.boundary,o=s[2],l=s[3],u=o/l;o>l?(e=-a,t=a,n=a/u,r=-a/u):(e=-a*u,t=a*u,n=a,r=-a),Z.orthoMat4c(e,t,r,n,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),n}(),Mt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4(),near:.1,far:1e4}),r._left=-1,r._right=1,r._bottom=-1,r._top=1,r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.left=i.left,r.right=i.right,r.bottom=i.bottom,r.top=i.top,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){Z.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"left",get:function(){return this._left},set:function(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}},{key:"right",get:function(){return this._right},set:function(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}},{key:"top",get:function(){return this._top},set:function(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}},{key:"bottom",get:function(){return this._bottom},set:function(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}},{key:"near",get:function(){return this._state.near},set:function(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}},{key:"far",get:function(){return this._state.far},set:function(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ft=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4()}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!1,r.matrix=i.matrix,r}return P(n,[{key:"type",get:function(){return"CustomProjection"}},{key:"matrix",get:function(){return this._state.matrix},set:function(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ht=Z.vec3(),Ut=Z.vec3(),Gt=Z.vec3(),kt=Z.vec3(),Vt=Z.vec3(),jt=Z.vec3(),Qt=Z.vec4(),Wt=Z.vec4(),zt=Z.vec4(),Kt=Z.mat4(),Yt=Z.mat4(),Xt=Z.vec3(),qt=Z.vec3(),Jt=Z.vec3(),Zt=Z.vec3(),$t=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({deviceMatrix:Z.mat4(),hasDeviceMatrix:!1,matrix:Z.mat4(),normalMatrix:Z.mat4(),inverseMatrix:Z.mat4()}),r._perspective=new Lt(g(r)),r._ortho=new xt(g(r)),r._frustum=new Mt(g(r)),r._customProjection=new Ft(g(r)),r._project=r._perspective,r._eye=Z.vec3([0,0,10]),r._look=Z.vec3([0,0,0]),r._up=Z.vec3([0,1,0]),r._worldUp=Z.vec3([0,1,0]),r._worldRight=Z.vec3([1,0,0]),r._worldForward=Z.vec3([0,0,-1]),r.deviceMatrix=i.deviceMatrix,r.eye=i.eye,r.look=i.look,r.up=i.up,r.worldAxis=i.worldAxis,r.gimbalLock=i.gimbalLock,r.constrainPitch=i.constrainPitch,r.projection=i.projection,r._perspective.on("matrix",(function(){"perspective"===r._projectionType&&r.fire("projMatrix",r._perspective.matrix)})),r._ortho.on("matrix",(function(){"ortho"===r._projectionType&&r.fire("projMatrix",r._ortho.matrix)})),r._frustum.on("matrix",(function(){"frustum"===r._projectionType&&r.fire("projMatrix",r._frustum.matrix)})),r._customProjection.on("matrix",(function(){"customProjection"===r._projectionType&&r.fire("projMatrix",r._customProjection.matrix)})),r}return P(n,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection?(Z.subVec3(this._eye,this._look,Xt),Z.normalizeVec3(Xt,qt),Z.mulVec3Scalar(qt,1e3,Jt),Z.addVec3(this._look,Jt,Zt),e=Zt):e=this._eye,t.hasDeviceMatrix?(Z.lookAtMat4v(e,this._look,this._up,Yt),Z.mulMat4(t.deviceMatrix,Yt,t.matrix)):Z.lookAtMat4v(e,this._look,this._up,t.matrix),Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),Z.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}},{key:"orbitYaw",value:function(e){var t=Z.subVec3(this._eye,this._look,Ht);Z.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Kt),t=Z.transformPoint3(Kt,t,Ut),this.eye=Z.addVec3(this._look,t,Gt),this.up=Z.transformPoint3(Kt,this._up,kt)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=Z.dotVec3(this._up,this._worldUp)/Z.DEGTORAD)<1)){var t=Z.subVec3(this._eye,this._look,Ht),n=Z.cross3Vec3(Z.normalizeVec3(t,Ut),Z.normalizeVec3(this._up,Gt));Z.rotationMat4v(.0174532925*e,n,Kt),t=Z.transformPoint3(Kt,t,kt),this.up=Z.transformPoint3(Kt,this._up,Vt),this.eye=Z.addVec3(t,this._look,jt)}}},{key:"yaw",value:function(e){var t=Z.subVec3(this._look,this._eye,Ht);Z.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Kt),t=Z.transformPoint3(Kt,t,Ut),this.look=Z.addVec3(t,this._eye,Gt),this._gimbalLock&&(this.up=Z.transformPoint3(Kt,this._up,kt))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=Z.dotVec3(this._up,this._worldUp)/Z.DEGTORAD)<1)){var t=Z.subVec3(this._look,this._eye,Ht),n=Z.cross3Vec3(Z.normalizeVec3(t,Ut),Z.normalizeVec3(this._up,Gt));Z.rotationMat4v(.0174532925*e,n,Kt),this.up=Z.transformPoint3(Kt,this._up,jt),t=Z.transformPoint3(Kt,t,kt),this.look=Z.addVec3(t,this._eye,Vt)}}},{key:"pan",value:function(e){var t,n=Z.subVec3(this._eye,this._look,Ht),r=[0,0,0];if(0!==e[0]){var i=Z.cross3Vec3(Z.normalizeVec3(n,[]),Z.normalizeVec3(this._up,Ut));t=Z.mulVec3Scalar(i,e[0]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]}0!==e[1]&&(t=Z.mulVec3Scalar(Z.normalizeVec3(this._up,Gt),e[1]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),0!==e[2]&&(t=Z.mulVec3Scalar(Z.normalizeVec3(n,kt),e[2]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),this.eye=Z.addVec3(this._eye,r,Vt),this.look=Z.addVec3(this._look,r,jt)}},{key:"zoom",value:function(e){var t=Z.subVec3(this._eye,this._look,Ht),n=Math.abs(Z.lenVec3(t,Ut)),r=Math.abs(n+e);if(!(r<.5)){var i=Z.normalizeVec3(t,Gt);this.eye=Z.addVec3(this._look,Z.mulVec3Scalar(i,r),kt)}}},{key:"eye",get:function(){return this._eye},set:function(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}},{key:"look",get:function(){return this._look},set:function(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}},{key:"up",get:function(){return this._up},set:function(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}},{key:"deviceMatrix",get:function(){return this._state.deviceMatrix},set:function(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}},{key:"worldAxis",get:function(){return this._worldAxis},set:function(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=Z.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}},{key:"worldUp",get:function(){return this._worldUp}},{key:"xUp",get:function(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}},{key:"yUp",get:function(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}},{key:"zUp",get:function(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}},{key:"worldRight",get:function(){return this._worldRight}},{key:"worldForward",get:function(){return this._worldForward}},{key:"gimbalLock",get:function(){return this._gimbalLock},set:function(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}},{key:"constrainPitch",set:function(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}},{key:"eyeLookDist",get:function(){return Z.lenVec3(Z.subVec3(this._look,this._eye,Ht))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"viewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"normalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"viewNormalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"inverseViewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}},{key:"projMatrix",get:function(){return this[this.projection].matrix}},{key:"perspective",get:function(){return this._perspective}},{key:"ortho",get:function(){return this._ortho}},{key:"frustum",get:function(){return this._frustum}},{key:"customProjection",get:function(){return this._customProjection}},{key:"projection",get:function(){return this._projectionType},set:function(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}},{key:"project",get:function(){return this._project}},{key:"projectWorldPos",value:function(e){var t=Qt,n=Wt,r=zt;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,Z.mulMat4v4(this.viewMatrix,t,n),Z.mulMat4v4(this.projMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1;var i=this.scene.canvas.canvas,a=i.offsetWidth/2,s=i.offsetHeight/2;return[r[0]*a+a,r[1]*s+s]}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),en=function(e){I(n,ve);var t=m(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),n}(),tn=function(e){I(n,en);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var a=r.scene.camera,s=r.scene.canvas;return r._onCameraViewMatrix=a.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=a.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=s.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new St({type:"dir",dir:Z.vec3([1,1,1]),color:Z.vec3([.7,.7,.8]),intensity:1,space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(r._shadowViewMatrixDirty){r._shadowViewMatrix||(r._shadowViewMatrix=Z.identityMat4());var e=r.scene.camera,t=r._state.dir,n=e.look,i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];Z.lookAtMat4v(i,n,[0,1,0],r._shadowViewMatrix),r._shadowViewMatrixDirty=!1}return r._shadowViewMatrix},getShadowProjMatrix:function(){return r._shadowProjMatrixDirty&&(r._shadowProjMatrix||(r._shadowProjMatrix=Z.identityMat4()),Z.orthoMat4c(-40,40,-40,40,-40,80,r._shadowProjMatrix),r._shadowProjMatrixDirty=!1),r._shadowProjMatrix},getShadowRenderBuf:function(){return r._shadowRenderBuf||(r._shadowRenderBuf=new Pt(r.scene.canvas.canvas,r.scene.canvas.gl,{size:[1024,1024]})),r._shadowRenderBuf}}),r.dir=i.dir,r.color=i.color,r.intensity=i.intensity,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"DirLight"}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}(),nn=function(e){I(n,en);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state={type:"ambient",color:Z.vec3([.7,.7,.7]),intensity:1},r.color=i.color,r.intensity=i.intensity,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"AmbientLight"}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),n}(),rn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),ee.memory.meshes++,r}return P(n,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),ee.memory.meshes--}}]),n}(),an=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var sn=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r){r=r||Z.mat4();var i=n[0],a=n[1],s=n[2],o=n[3]-i,l=n[4]-a,u=n[5]-s,c=65535;return Z.identityMat4(e),Z.translationMat4v(n,e),Z.identityMat4(t),Z.scalingMat4v([o/c,l/c,u/c],t),Z.mulMat4(e,t,r),r}}(),on=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r,i){var a,s=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(a=0;a=0?1:-1),o=(1-Math.abs(i))*(a>=0?1:-1);i=s,a=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*a+(a<0?-1:0))])}function cn(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function fn(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var pn={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;ri&&(n=t,i=r),(r=fn(e,s,cn(t=un(e,s,"floor","ceil"))))>i&&(n=t,i=r),(r=fn(e,s,cn(t=un(e,s,"ceil","ceil"))))>i&&(n=t,i=r),a[s]=n[0],a[s+1]=n[1];return a},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t}},An=ee.memory,dn=Z.AABB3(),vn=function(e){I(n,rn);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new St({compressGeometry:!!i.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._edgeIndicesBuf=null,r._pickTrianglePositionsBuf=null,r._pickTriangleColorsBuf=null,r._aabbDirty=!0,r._boundingSphere=!0,r._aabb=null,r._aabbDirty=!0,r._obb=null,r._obbDirty=!0;var a=r._state,s=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":a.primitive=s.POINTS,a.primitiveName=i.primitive;break;case"lines":a.primitive=s.LINES,a.primitiveName=i.primitive;break;case"line-loop":a.primitive=s.LINE_LOOP,a.primitiveName=i.primitive;break;case"line-strip":a.primitive=s.LINE_STRIP,a.primitiveName=i.primitive;break;case"triangles":a.primitive=s.TRIANGLES,a.primitiveName=i.primitive;break;case"triangle-strip":a.primitive=s.TRIANGLE_STRIP,a.primitiveName=i.primitive;break;case"triangle-fan":a.primitive=s.TRIANGLE_FAN,a.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),a.primitive=s.TRIANGLES,a.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var o=pn.getPositionsBounds(i.positions),l=pn.compressPositions(i.positions,o.min,o.max);a.positions=l.quantized,a.positionsDecodeMatrix=l.decodeMatrix}else a.positions=i.positions.constructor===Float32Array?i.positions:new Float32Array(i.positions);if(i.colors&&(a.colors=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors)),i.uv)if(r._state.compressGeometry){var u=pn.getUVBounds(i.uv),c=pn.compressUVs(i.uv,u.min,u.max);a.uv=c.quantized,a.uvDecodeMatrix=c.decodeMatrix}else a.uv=i.uv.constructor===Float32Array?i.uv:new Float32Array(i.uv);return i.normals&&(r._state.compressGeometry?a.normals=pn.compressNormals(i.normals):a.normals=i.normals.constructor===Float32Array?i.normals:new Float32Array(i.normals)),i.indices&&(a.indices=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3)),r._buildHash(),An.meshes++,r._buildVBOs(),r}return P(n,[{key:"type",get:function(){return"ReadableGeometry"}},{key:"isReadableGeometry",get:function(){return!0}},{key:"_buildVBOs",value:function(){var e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),An.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new pt(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),An.positions+=e.positionsBuf.numItems),e.normals){var n=e.compressGeometry;e.normalsBuf=new pt(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,n),An.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new pt(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),An.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new pt(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),An.uvs+=e.uvBuf.numItems)}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}},{key:"_getPickTrianglePositions",value:function(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}},{key:"_getPickTriangleColors",value:function(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}},{key:"_buildEdgeIndices",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=an(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,n,n.length,1,t.STATIC_DRAW),An.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=Z.buildPickTriangles(e.positions,e.indices,e.compressGeometry),r=n.positions,i=n.colors;this._pickTrianglePositionsBuf=new pt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new pt(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),An.positions+=this._pickTrianglePositionsBuf.numItems,An.colors+=this._pickTriangleColorsBuf.numItems}}},{key:"_buildPickVertexVBOs",value:function(){}},{key:"_webglContextLost",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}},{key:"_webglContextRestored",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"compressGeometry",get:function(){return this._state.compressGeometry}},{key:"positions",get:function(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),pn.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,n=t.positions;if(n)if(n.length===e.length){if(this._state.compressGeometry){var r=pn.getPositionsBounds(e),i=pn.compressPositions(e,r.min,r.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}n.set(e),t.positionsBuf&&t.positionsBuf.setData(n),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}},{key:"normals",get:function(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){var e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),pn.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry normals - quantized geometry is immutable");else{var t=this._state,n=t.normals;n?n.length===e.length?(n.set(e),t.normalsBuf&&t.normalsBuf.setData(n),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}}},{key:"uv",get:function(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),pn.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry UVs - quantized geometry is immutable");else{var t=this._state,n=t.uv;n?n.length===e.length?(n.set(e),t.uvBuf&&t.uvBuf.setData(n),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}}},{key:"colors",get:function(){return this._state.colors},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry colors - quantized geometry is immutable");else{var t=this._state,n=t.colors;n?n.length===e.length?(n.set(e),t.colorsBuf&&t.colorsBuf.setData(n),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}}},{key:"indices",get:function(){return this._state.indices}},{key:"aabb",get:function(){return this._aabbDirty&&(this._aabb||(this._aabb=Z.AABB3()),Z.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}},{key:"obb",get:function(){return this._obbDirty&&(this._obb||(this._obb=Z.OBB3()),Z.positions3ToAABB3(this._state.positions,dn,this._state.positionsDecodeMatrix),Z.AABB3ToOBB3(dn,this._obb),this._obbDirty=!1),this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_setAABBDirty",value:function(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),An.meshes--}}]),n}();function hn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return ae.apply(e,{positions:[f,p,A,l,p,A,l,u,A,f,u,A,f,p,A,f,u,A,f,u,c,f,p,c,f,p,A,f,p,c,l,p,c,l,p,A,l,p,A,l,p,c,l,u,c,l,u,A,l,u,c,f,u,c,f,u,A,l,u,A,f,u,c,l,u,c,l,p,c,f,p,c],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}var In=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),ee.memory.materials++,r}return P(n,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),ee.memory.materials--}}]),n}(),yn={opaque:0,mask:1,blend:2},mn=["opaque","mask","blend"],wn=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"PhongMaterial",ambient:Z.vec3([1,1,1]),diffuse:Z.vec3([1,1,1]),specular:Z.vec3([1,1,1]),emissive:Z.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.ambient=i.ambient,r.diffuse=i.diffuse,r.specular=i.specular,r.emissive=i.emissive,r.alpha=i.alpha,r.shininess=i.shininess,r.reflectivity=i.reflectivity,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,i.ambientMap&&(r._ambientMap=r._checkComponent("Texture",i.ambientMap)),i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.reflectivityMap&&(r._reflectivityMap=r._checkComponent("Texture",i.reflectivityMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.diffuseFresnel&&(r._diffuseFresnel=r._checkComponent("Fresnel",i.diffuseFresnel)),i.specularFresnel&&(r._specularFresnel=r._checkComponent("Fresnel",i.specularFresnel)),i.emissiveFresnel&&(r._emissiveFresnel=r._checkComponent("Fresnel",i.emissiveFresnel)),i.alphaFresnel&&(r._alphaFresnel=r._checkComponent("Fresnel",i.alphaFresnel)),i.reflectivityFresnel&&(r._reflectivityFresnel=r._checkComponent("Fresnel",i.reflectivityFresnel)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"PhongMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"shininess",get:function(){return this._state.shininess},set:function(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"reflectivity",get:function(){return this._state.reflectivity},set:function(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}},{key:"normalMap",get:function(){return this._normalMap}},{key:"ambientMap",get:function(){return this._ambientMap}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specularMap",get:function(){return this._specularMap}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"reflectivityMap",get:function(){return this._reflectivityMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"diffuseFresnel",get:function(){return this._diffuseFresnel}},{key:"specularFresnel",get:function(){return this._specularFresnel}},{key:"emissiveFresnel",get:function(){return this._emissiveFresnel}},{key:"alphaFresnel",get:function(){return this._alphaFresnel}},{key:"reflectivityFresnel",get:function(){return this._reflectivityFresnel}},{key:"alphaMode",get:function(){return mn[this._state.alphaMode]},set:function(e){var t=yn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),gn={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},Tn=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),r._preset="default",i.preset?(r.preset=i.preset,void 0!==i.fill&&(r.fill=i.fill),i.fillColor&&(r.fillColor=i.fillColor),void 0!==i.fillAlpha&&(r.fillAlpha=i.fillAlpha),void 0!==i.edges&&(r.edges=i.edges),i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth),void 0!==i.backfaces&&(r.backfaces=i.backfaces),void 0!==i.glowThrough&&(r.glowThrough=i.glowThrough)):(r.fill=i.fill,r.fillColor=i.fillColor,r.fillAlpha=i.fillAlpha,r.edges=i.edges,r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth,r.backfaces=i.backfaces,r.glowThrough=i.glowThrough),r}return P(n,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return gn}},{key:"fill",get:function(){return this._state.fill},set:function(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}},{key:"fillColor",get:function(){return this._state.fillColor},set:function(e){var t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}},{key:"fillAlpha",get:function(){return this._state.fillAlpha},set:function(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"glowThrough",get:function(){return this._state.glowThrough},set:function(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=gn[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(gn).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),En={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}},bn=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),r._preset="default",i.preset?(r.preset=i.preset,i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth)):(r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth),r.edges=!1!==i.edges,r}return P(n,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return En}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=En[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(En).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Dn={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}},Pn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._units="meters",r._scale=1,r._origin=Z.vec3([0,0,0]),r.units=i.units,r.scale=i.scale,r.origin=i.origin,r}return P(n,[{key:"unitsInfo",get:function(){return Dn}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),Dn[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}},{key:"scale",get:function(){return this._scale},set:function(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}},{key:"origin",get:function(){return this._origin},set:function(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}},{key:"worldToRealPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(3);t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}},{key:"realToWorldPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(3);return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}]),n}(),Rn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._supported=Ze.SUPPORTED_EXTENSIONS.OES_standard_derivatives,r.enabled=i.enabled,r.kernelRadius=i.kernelRadius,r.intensity=i.intensity,r.bias=i.bias,r.scale=i.scale,r.minResolution=i.minResolution,r.numSamples=i.numSamples,r.blur=i.blur,r.blendCutoff=i.blendCutoff,r.blendFactor=i.blendFactor,r}return P(n,[{key:"supported",get:function(){return this._supported}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"possible",get:function(){if(!this._supported)return!1;if(!this._enabled)return!1;var e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}},{key:"active",get:function(){return this._active}},{key:"kernelRadius",get:function(){return this._kernelRadius},set:function(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}},{key:"intensity",get:function(){return this._intensity},set:function(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}},{key:"bias",get:function(){return this._bias},set:function(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}},{key:"minResolution",get:function(){return this._minResolution},set:function(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}},{key:"numSamples",get:function(){return this._numSamples},set:function(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}},{key:"blur",get:function(){return this._blur},set:function(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}},{key:"blendCutoff",get:function(){return this._blendCutoff},set:function(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}},{key:"blendFactor",get:function(){return this._blendFactor},set:function(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Cn={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},_n=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),i.preset?(r.preset=i.preset,void 0!==i.pointSize&&(r.pointSize=i.pointSize),void 0!==i.roundPoints&&(r.roundPoints=i.roundPoints),void 0!==i.perspectivePoints&&(r.perspectivePoints=i.perspectivePoints),void 0!==i.minPerspectivePointSize&&(r.minPerspectivePointSize=i.minPerspectivePointSize),void 0!==i.maxPerspectivePointSize&&(r.maxPerspectivePointSize=i.minPerspectivePointSize)):(r._preset="default",r.pointSize=i.pointSize,r.roundPoints=i.roundPoints,r.perspectivePoints=i.perspectivePoints,r.minPerspectivePointSize=i.minPerspectivePointSize,r.maxPerspectivePointSize=i.maxPerspectivePointSize),r.filterIntensity=i.filterIntensity,r.minIntensity=i.minIntensity,r.maxIntensity=i.maxIntensity,r}return P(n,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return Cn}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||2,this.glRedraw()}},{key:"roundPoints",get:function(){return this._state.roundPoints},set:function(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"perspectivePoints",get:function(){return this._state.perspectivePoints},set:function(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minPerspectivePointSize",get:function(){return this._state.minPerspectivePointSize},set:function(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}},{key:"maxPerspectivePointSize",get:function(){return this._state.maxPerspectivePointSize},set:function(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}},{key:"filterIntensity",get:function(){return this._state.filterIntensity},set:function(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minIntensity",get:function(){return this._state.minIntensity},set:function(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}},{key:"maxIntensity",get:function(){return this._state.maxIntensity},set:function(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Cn[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Cn).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Bn={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},On=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"LinesMaterial",lineWidth:null}),i.preset?(r.preset=i.preset,void 0!==i.lineWidth&&(r.lineWidth=i.lineWidth)):(r._preset="default",r.lineWidth=i.lineWidth),r}return P(n,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return Bn}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Bn[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Bn).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Sn=Z.vec3(),Nn=Z.vec3(),Ln=Z.mat4(),xn=function(){function e(){b(this,e),this.normal=Z.vec3(),this.offset=0,this.testVertex=Z.vec3()}return P(e,[{key:"set",value:function(e,t,n,r){var i=1/Math.sqrt(e*e+t*t+n*n);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=n*i,this.offset=r*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),Mn=P((function e(){b(this,e),this.planes=[new xn,new xn,new xn,new xn,new xn,new xn]}));function Fn(e,t,n){var r=Z.mulMat4(n,t,Ln),i=r[0],a=r[1],s=r[2],o=r[3],l=r[4],u=r[5],c=r[6],f=r[7],p=r[8],A=r[9],d=r[10],v=r[11],h=r[12],I=r[13],y=r[14],m=r[15];e.planes[0].set(o-i,f-l,v-p,m-h),e.planes[1].set(o+i,f+l,v+p,m+h),e.planes[2].set(o-a,f-u,v-A,m-I),e.planes[3].set(o+a,f+u,v+A,m+I),e.planes[4].set(o-s,f-c,v-d,m-y),e.planes[5].set(o+s,f+c,v+d,m+y)}function Hn(e,t){var n=Mn.INSIDE,r=Sn,i=Nn;r[0]=t[0],r[1]=t[1],r[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];for(var a=[r,i],s=0;s<6;++s){var o=e.planes[s];if(o.normal[0]*a[o.testVertex[0]][0]+o.normal[1]*a[o.testVertex[1]][1]+o.normal[2]*a[o.testVertex[2]][2]+o.offset<0)return Mn.OUTSIDE;o.normal[0]*a[1-o.testVertex[0]][0]+o.normal[1]*a[1-o.testVertex[1]][1]+o.normal[2]*a[1-o.testVertex[2]][2]+o.offset<0&&(n=Mn.INTERSECT)}return n}Mn.INSIDE=0,Mn.INTERSECT=1,Mn.OUTSIDE=2;var Un=function(){function e(t,n){b(this,e),this.primLODLevels=t,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=n,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}return P(e,[{key:"initializeLodState",value:function(e){var t=Object.values(e.objects);if(0!==t.length){for(var n={},r={},i=0,a=t.length;i=this.primLODLevels[l]);l++);var u=this.primLODLevels[l]||0;u in n||(n[u]=[]),n[u].push(s),u in r||(r[u]=0),r[u]+=s.numPrimitives}this.entitiesInLOD=n,this.primCountInLOD=r}}}]),e}(),Gn=function(){function e(t,n,r,i){b(this,e),this.id=n.id,this.scene=t,this.sceneModel=n,this.lodState=new Un(r,i),this.lodState.initializeLodState(n)}return P(e,[{key:"_increaseLODLevelIndex",value:function(){var e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;for(var t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[],n=0,r=t.length;n0&&(t.consecutiveFramesWithoutTargetFps=0,n=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,n=this._decreaseLODLevelIndex()),n}},{key:"resetLodCulling",value:function(){var e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}]),e}(),kn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._lodLevels=[2e3,600,150,80,20],r._lodManagers={},r._lodManagerList=[],r.enabled=i.enabled,r.targetFPS=i.targetFPS,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this,t=new Array(4),n=0,r=-1,i=Date.now(),a=0,s=0,o=s;this._scene.on("rendering",(function(){if(-1!==r)for(var t=0,n=e._lodManagerList.length;t4){for(var o=0;o<4;o++)s+=t[o];r=4/s*1e3}}))})),this._scene.camera.on("matrix",(function(){o=s})),this._scene.on("tick",(function(){if(s-o>3)for(var t=0,n=e._lodManagerList.length;t=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},n.boxRayIntersects=function(e,t,n,r,i,a,s){var o=(e.minX-t)*i,l=(e.maxX-t)*i,u=(e.minY-n)*a,c=(e.maxY-n)*a,f=(e.minZ-r)*s,p=(e.maxZ-r)*s,A=Math.min(f,p),d=Math.max(f,p),v=Math.min(u,c),h=Math.max(u,c),I=Math.min(o,l),y=Math.max(o,l),m=Math.max(0,I,v,A);return Math.min(y,h,d)>=m?m:1/0};var g=function(e,t,n,i,a){for(var s,o=[t,n];o.length;)(n=o.pop())-(t=o.pop())<=i||(s=t+Math.ceil((n-t)/i/2)*i,r(e,s,t,n,a),o.push(t,s,s,n))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var n=this.data,r=[];if(!e(n,f(n)))return r;for(var i=[];n;){for(var a=0,s=n.children.length;a1){for(d=0,v=(c=c[c.length-1]).length;d=t)break;var i=r+1;if(i0;){var r=n-1>>1;if(A[r].dist<=A[n].dist)break;d(n,r),n=r}},I=o;A.length&&A[0].dist=t;o--){l=e.children[o];v(a,l),s+=I(a)}return s},e.prototype.adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)v(t[r],e)},e.prototype.condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)0===e[t].children.length?t>0?((n=e[t-1].children).splice(n.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,n){var r=[],i=this.chooseSubtree(e,this.data,t,r);for(i.children.push(e),v(i,e);t>=0&&r[t].children.length>this.maxEntries;)this.split(r,t),t--;this.adjustParentBBoxes(e,r,t)},e.pool=[],e}();n.RBush3D=D},{quickselect:2}],2:[function(e,t,n){!function(e,r){"object"===E(n)&&void 0!==t?t.exports=r():e.quickselect=r()}(this,(function(){function e(n,r,i,a,s){for(;a>i;){if(a-i>600){var o=a-i+1,l=r-i+1,u=Math.log(o),c=.5*Math.exp(2*u/3),f=.5*Math.sqrt(u*c*(o-c)/o)*(l-o/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-l*c/o+f)),Math.min(a,Math.floor(r+(o-l)*c/o+f)),s)}var p=n[r],A=i,d=a;for(t(n,i,r),s(n[a],p)>0&&t(n,i,a);A0;)d--}0===s(n[i],p)?t(n,i,d):t(n,++d,a),d<=r&&(i=d+1),r<=d&&(a=d-1)}}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return et?1:0}return function(t,r,i,a,s){e(t,r,i||0,a||t.length-1,s||n)}}))},{}]},{},[1])(1)}));var Qn=Vn.exports.RBush3D,Wn=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function n(e,t){var n={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function r(){(0==n.dir&&n.pos.x+1>=n.right||1==n.dir&&n.pos.y+1>=n.bottom||2==n.dir&&n.pos.x-1<=n.left-1||3==n.dir&&n.pos.y-1<=n.top-1)&&(n.dir=(n.dir+1)%4,0==n.dir&&n.left++,1==n.dir&&n.top++,2==n.dir&&n.right--,3==n.dir&&n.bottom--),0==n.dir&&n.pos.x++,1==n.dir&&n.pos.y++,2==n.dir&&n.pos.x--,3==n.dir&&n.pos.y--}for(var i=[],a=e*t;i.lengthp&&(c.push(f),f=[],p=o),f.push(d),p-=v}}while(Ap&&(c.push(A),A=[],p=o),A.push(e),p-=n})),A.length&&c.push(A);var d={};return c.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:c,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,r.maxPolygonsPerCluster),{clusters:{total:s.clusters.length},clusteringResult:s});o+=l.clusters.total,console.log("Total clusters: "+o);var u=[];return l.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){u.push(e.id)}))})),l.orderedEntityIds=u,l}; +var e,t=l().mark(eT),n=l().mark(tT),r=l().mark(pD);function i(e){return function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||A(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var o=n.call(a,"catchLoc"),l=n.call(a,"finallyLoc");if(o&&l){if(this.prev=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),b(n),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;b(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:P(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},e}function u(e,t,n,r,i,a,s){try{var o=e[a](s),l=o.value}catch(e){return void n(e)}o.done?t(l):Promise.resolve(l).then(r,i)}function c(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var a=e.apply(t,n);function s(e){u(a,r,i,s,o,"next",e)}function o(e){u(a,r,i,s,o,"throw",e)}s(void 0)}))}}function f(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw a}}}}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,a=[],s=!0,o=!1;try{for(n=n.call(e);!(s=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);s=!0);}catch(e){o=!0,i=e}finally{try{s||null==n.return||n.return()}finally{if(o)throw i}}return a}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function A(e,t){if(e){if("string"==typeof e)return d(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?d(e,t):void 0}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0&&void 0!==arguments[0]?arguments[0]:{};b(this,e),this._id=k.addItem(),this._context=null,this._enabled=!1,this._itemsCfg=[],this._rootMenu=null,this._menuList=[],this._menuMap={},this._itemList=[],this._itemMap={},this._shown=!1,this._nextId=0,this._eventSubs={},!1!==n.hideOnMouseDown&&(document.addEventListener("mousedown",(function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),document.addEventListener("touchstart",this._canvasTouchStartHandler=function(e){e.target.classList.contains("xeokit-context-menu-item")||t.hide()})),n.items&&(this.items=n.items),this._hideOnAction=!1!==n.hideOnAction,this.context=n.context,this.enabled=!1!==n.enabled,this.hide()}return P(e,[{key:"on",value:function(e,t){var n=this._eventSubs[e];n||(n=[],this._eventSubs[e]=n),n.push(t)}},{key:"fire",value:function(e,t){var n=this._eventSubs[e];if(n)for(var r=0,i=n.length;r0,c=t._getNextId(),f=a.getTitle||function(){return a.title||""},p=a.doAction||a.callback||function(){},A=a.getEnabled||function(){return!0},d=a.getShown||function(){return!0},v=new Q(c,f,p,A,d);if(v.parentMenu=i,l.items.push(v),u){var h=e(s);v.subMenu=h,h.parentItem=v}t._itemList.push(v),t._itemMap[v.id]=v},c=0,f=o.length;c'),r.push("
    "),n)for(var i=0,a=n.length;i'+A+" [MORE]"):r.push('
  • '+A+"
  • ")}}r.push("
"),r.push("");var d=r.join("");document.body.insertAdjacentHTML("beforeend",d);var v=document.querySelector("."+e.id);e.menuElement=v,v.style["border-radius"]="4px",v.style.display="none",v.style["z-index"]=3e5,v.style.background="white",v.style.border="1px solid black",v.style["box-shadow"]="0 4px 5px 0 gray",v.oncontextmenu=function(e){e.preventDefault()};var h=this,I=null;if(n)for(var y=0,m=n.length;ywindow.innerWidth?h._showMenu(t.id,a.left-200,a.top-1):h._showMenu(t.id,a.right-5,a.top-1),I=t}}else I&&(h._hideMenu(I.id),I=null)})),i||(r.itemElement.addEventListener("click",(function(e){e.preventDefault(),h._context&&!1!==r.enabled&&(r.doAction&&r.doAction(h._context),t._hideOnAction?h.hide():(h._updateItemsTitles(),h._updateItemsEnabledStatus()))})),r.itemElement.addEventListener("mouseenter",(function(e){e.preventDefault(),!1!==r.enabled&&r.doHover&&r.doHover(h._context)})))},T=0,E=w.length;Twindow.innerHeight&&(n=window.innerHeight-r),t+i>window.innerWidth&&(t=window.innerWidth-i),e.style.left=t+"px",e.style.top=n+"px"}},{key:"_hideMenuElement",value:function(e){e.style.display="none"}}]),e}(),z=function(){function e(t,n,r){b(this,e),this.id=r&&r.id?r.id:t,this.viewer=n,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,n.addPlugin(this)}return P(e,[{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){console.log("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"warn",value:function(e){console.warn("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"error",value:function(e){console.error("[xeokit plugin ".concat(this.id,"]: ").concat(e))}},{key:"send",value:function(e,t){}},{key:"destroy",value:function(){this.viewer.removePlugin(this)}}]),e}(),K=!0,Y=K?Float64Array:Float32Array,X=new Y(16),q=new Y(16),J=new Y(4),Z={setDoublePrecisionEnabled:function(e){Y=(K=e)?Float64Array:Float32Array},getDoublePrecisionEnabled:function(){return K},MIN_DOUBLE:-Number.MAX_SAFE_INTEGER,MAX_DOUBLE:Number.MAX_SAFE_INTEGER,MAX_INT:1e7,DEGTORAD:.0174532925,RADTODEG:57.295779513,unglobalizeObjectId:function(e,t){var n=t.indexOf("#");return n===e.length&&t.startsWith(e)?t.substring(n+1):t},globalizeObjectId:function(e,t){return e+"#"+t},safeInv:function(e){var t=1/e;return isNaN(t)||!isFinite(t)?1:t},vec2:function(e){return new Y(e||2)},vec3:function(e){return new Y(e||3)},vec4:function(e){return new Y(e||4)},mat3:function(e){return new Y(e||9)},mat3ToMat4:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Y(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=0,t[4]=e[3],t[5]=e[4],t[6]=e[5],t[7]=0,t[8]=e[6],t[9]=e[7],t[10]=e[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},mat4:function(e){return new Y(e||16)},mat4ToMat3:function(e,t){},doublesToFloats:function(e,t,n){for(var r=new Y(2),i=0,a=e.length;i>8&255]+e[t>>16&255]+e[t>>24&255],"-").concat(e[255&n]).concat(e[n>>8&255],"-").concat(e[n>>16&15|64]).concat(e[n>>24&255],"-").concat(e[63&r|128]).concat(e[r>>8&255],"-").concat(e[r>>16&255]).concat(e[r>>24&255]).concat(e[255&i]).concat(e[i>>8&255]).concat(e[i>>16&255]).concat(e[i>>24&255])}}(),clamp:function(e,t,n){return Math.max(t,Math.min(n,e))},fmod:function(e,t){if(e1?1:n,Math.acos(n)},vec3FromMat4Scale:function(){var e=new Y(3);return function(t,n){return e[0]=t[0],e[1]=t[1],e[2]=t[2],n[0]=Z.lenVec3(e),e[0]=t[4],e[1]=t[5],e[2]=t[6],n[1]=Z.lenVec3(e),e[0]=t[8],e[1]=t[9],e[2]=t[10],n[2]=Z.lenVec3(e),n}}(),vecToArray:function(){function e(e){return Math.round(1e5*e)/1e5}return function(t){for(var n=0,r=(t=Array.prototype.slice.call(t)).length;n0&&void 0!==arguments[0]?arguments[0]:new Y(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},identityMat3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Y(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},isIdentityMat4:function(e){return 1===e[0]&&0===e[1]&&0===e[2]&&0===e[3]&&0===e[4]&&1===e[5]&&0===e[6]&&0===e[7]&&0===e[8]&&0===e[9]&&1===e[10]&&0===e[11]&&0===e[12]&&0===e[13]&&0===e[14]&&1===e[15]},negateMat4:function(e,t){return t||(t=e),t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t[4]=-e[4],t[5]=-e[5],t[6]=-e[6],t[7]=-e[7],t[8]=-e[8],t[9]=-e[9],t[10]=-e[10],t[11]=-e[11],t[12]=-e[12],t[13]=-e[13],t[14]=-e[14],t[15]=-e[15],t},addMat4:function(e,t,n){return n||(n=e),n[0]=e[0]+t[0],n[1]=e[1]+t[1],n[2]=e[2]+t[2],n[3]=e[3]+t[3],n[4]=e[4]+t[4],n[5]=e[5]+t[5],n[6]=e[6]+t[6],n[7]=e[7]+t[7],n[8]=e[8]+t[8],n[9]=e[9]+t[9],n[10]=e[10]+t[10],n[11]=e[11]+t[11],n[12]=e[12]+t[12],n[13]=e[13]+t[13],n[14]=e[14]+t[14],n[15]=e[15]+t[15],n},addMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]+t,n[1]=e[1]+t,n[2]=e[2]+t,n[3]=e[3]+t,n[4]=e[4]+t,n[5]=e[5]+t,n[6]=e[6]+t,n[7]=e[7]+t,n[8]=e[8]+t,n[9]=e[9]+t,n[10]=e[10]+t,n[11]=e[11]+t,n[12]=e[12]+t,n[13]=e[13]+t,n[14]=e[14]+t,n[15]=e[15]+t,n},addScalarMat4:function(e,t,n){return Z.addMat4Scalar(t,e,n)},subMat4:function(e,t,n){return n||(n=e),n[0]=e[0]-t[0],n[1]=e[1]-t[1],n[2]=e[2]-t[2],n[3]=e[3]-t[3],n[4]=e[4]-t[4],n[5]=e[5]-t[5],n[6]=e[6]-t[6],n[7]=e[7]-t[7],n[8]=e[8]-t[8],n[9]=e[9]-t[9],n[10]=e[10]-t[10],n[11]=e[11]-t[11],n[12]=e[12]-t[12],n[13]=e[13]-t[13],n[14]=e[14]-t[14],n[15]=e[15]-t[15],n},subMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]-t,n[1]=e[1]-t,n[2]=e[2]-t,n[3]=e[3]-t,n[4]=e[4]-t,n[5]=e[5]-t,n[6]=e[6]-t,n[7]=e[7]-t,n[8]=e[8]-t,n[9]=e[9]-t,n[10]=e[10]-t,n[11]=e[11]-t,n[12]=e[12]-t,n[13]=e[13]-t,n[14]=e[14]-t,n[15]=e[15]-t,n},subScalarMat4:function(e,t,n){return n||(n=t),n[0]=e-t[0],n[1]=e-t[1],n[2]=e-t[2],n[3]=e-t[3],n[4]=e-t[4],n[5]=e-t[5],n[6]=e-t[6],n[7]=e-t[7],n[8]=e-t[8],n[9]=e-t[9],n[10]=e-t[10],n[11]=e-t[11],n[12]=e-t[12],n[13]=e-t[13],n[14]=e-t[14],n[15]=e-t[15],n},mulMat4:function(e,t,n){n||(n=e);var r=e[0],i=e[1],a=e[2],s=e[3],o=e[4],l=e[5],u=e[6],c=e[7],f=e[8],p=e[9],A=e[10],d=e[11],v=e[12],h=e[13],I=e[14],y=e[15],m=t[0],w=t[1],g=t[2],T=t[3],E=t[4],b=t[5],D=t[6],P=t[7],R=t[8],C=t[9],_=t[10],B=t[11],O=t[12],S=t[13],N=t[14],L=t[15];return n[0]=m*r+w*o+g*f+T*v,n[1]=m*i+w*l+g*p+T*h,n[2]=m*a+w*u+g*A+T*I,n[3]=m*s+w*c+g*d+T*y,n[4]=E*r+b*o+D*f+P*v,n[5]=E*i+b*l+D*p+P*h,n[6]=E*a+b*u+D*A+P*I,n[7]=E*s+b*c+D*d+P*y,n[8]=R*r+C*o+_*f+B*v,n[9]=R*i+C*l+_*p+B*h,n[10]=R*a+C*u+_*A+B*I,n[11]=R*s+C*c+_*d+B*y,n[12]=O*r+S*o+N*f+L*v,n[13]=O*i+S*l+N*p+L*h,n[14]=O*a+S*u+N*A+L*I,n[15]=O*s+S*c+N*d+L*y,n},mulMat3:function(e,t,n){n||(n=new Y(9));var r=e[0],i=e[3],a=e[6],s=e[1],o=e[4],l=e[7],u=e[2],c=e[5],f=e[8],p=t[0],A=t[3],d=t[6],v=t[1],h=t[4],I=t[7],y=t[2],m=t[5],w=t[8];return n[0]=r*p+i*v+a*y,n[3]=r*A+i*h+a*m,n[6]=r*d+i*I+a*w,n[1]=s*p+o*v+l*y,n[4]=s*A+o*h+l*m,n[7]=s*d+o*I+l*w,n[2]=u*p+c*v+f*y,n[5]=u*A+c*h+f*m,n[8]=u*d+c*I+f*w,n},mulMat4Scalar:function(e,t,n){return n||(n=e),n[0]=e[0]*t,n[1]=e[1]*t,n[2]=e[2]*t,n[3]=e[3]*t,n[4]=e[4]*t,n[5]=e[5]*t,n[6]=e[6]*t,n[7]=e[7]*t,n[8]=e[8]*t,n[9]=e[9]*t,n[10]=e[10]*t,n[11]=e[11]*t,n[12]=e[12]*t,n[13]=e[13]*t,n[14]=e[14]*t,n[15]=e[15]*t,n},mulMat4v4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=t[0],i=t[1],a=t[2],s=t[3];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12]*s,n[1]=e[1]*r+e[5]*i+e[9]*a+e[13]*s,n[2]=e[2]*r+e[6]*i+e[10]*a+e[14]*s,n[3]=e[3]*r+e[7]*i+e[11]*a+e[15]*s,n},transposeMat4:function(e,t){var n=e[4],r=e[14],i=e[8],a=e[13],s=e[12],o=e[9];if(!t||e===t){var l=e[1],u=e[2],c=e[3],f=e[6],p=e[7],A=e[11];return e[1]=n,e[2]=i,e[3]=s,e[4]=l,e[6]=o,e[7]=a,e[8]=u,e[9]=f,e[11]=r,e[12]=c,e[13]=p,e[14]=A,e}return t[0]=e[0],t[1]=n,t[2]=i,t[3]=s,t[4]=e[1],t[5]=e[5],t[6]=o,t[7]=a,t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=r,t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15],t},transposeMat3:function(e,t){if(t===e){var n=e[1],r=e[2],i=e[5];t[1]=e[3],t[2]=e[6],t[3]=n,t[5]=e[7],t[6]=r,t[7]=i}else t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8];return t},determinantMat4:function(e){var t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],s=e[5],o=e[6],l=e[7],u=e[8],c=e[9],f=e[10],p=e[11],A=e[12],d=e[13],v=e[14],h=e[15];return A*c*o*i-u*d*o*i-A*s*f*i+a*d*f*i+u*s*v*i-a*c*v*i-A*c*r*l+u*d*r*l+A*n*f*l-t*d*f*l-u*n*v*l+t*c*v*l+A*s*r*p-a*d*r*p-A*n*o*p+t*d*o*p+a*n*v*p-t*s*v*p-u*s*r*h+a*c*r*h+u*n*o*h-t*c*o*h-a*n*f*h+t*s*f*h},inverseMat4:function(e,t){t||(t=e);var n=e[0],r=e[1],i=e[2],a=e[3],s=e[4],o=e[5],l=e[6],u=e[7],c=e[8],f=e[9],p=e[10],A=e[11],d=e[12],v=e[13],h=e[14],I=e[15],y=n*o-r*s,m=n*l-i*s,w=n*u-a*s,g=r*l-i*o,T=r*u-a*o,E=i*u-a*l,b=c*v-f*d,D=c*h-p*d,P=c*I-A*d,R=f*h-p*v,C=f*I-A*v,_=p*I-A*h,B=1/(y*_-m*C+w*R+g*P-T*D+E*b);return t[0]=(o*_-l*C+u*R)*B,t[1]=(-r*_+i*C-a*R)*B,t[2]=(v*E-h*T+I*g)*B,t[3]=(-f*E+p*T-A*g)*B,t[4]=(-s*_+l*P-u*D)*B,t[5]=(n*_-i*P+a*D)*B,t[6]=(-d*E+h*w-I*m)*B,t[7]=(c*E-p*w+A*m)*B,t[8]=(s*C-o*P+u*b)*B,t[9]=(-n*C+r*P-a*b)*B,t[10]=(d*T-v*w+I*y)*B,t[11]=(-c*T+f*w-A*y)*B,t[12]=(-s*R+o*D-l*b)*B,t[13]=(n*R-r*D+i*b)*B,t[14]=(-d*g+v*m-h*y)*B,t[15]=(c*g-f*m+p*y)*B,t},traceMat4:function(e){return e[0]+e[5]+e[10]+e[15]},translationMat4v:function(e,t){var n=t||Z.identityMat4();return n[12]=e[0],n[13]=e[1],n[14]=e[2],n},translationMat3v:function(e,t){var n=t||Z.identityMat3();return n[6]=e[0],n[7]=e[1],n},translationMat4c:(H=new Y(3),function(e,t,n,r){return H[0]=e,H[1]=t,H[2]=n,Z.translationMat4v(H,r)}),translationMat4s:function(e,t){return Z.translationMat4c(e,e,e,t)},translateMat4v:function(e,t){return Z.translateMat4c(e[0],e[1],e[2],t)},translateMat4c:function(e,t,n,r){var i=r[3];r[0]+=i*e,r[1]+=i*t,r[2]+=i*n;var a=r[7];r[4]+=a*e,r[5]+=a*t,r[6]+=a*n;var s=r[11];r[8]+=s*e,r[9]+=s*t,r[10]+=s*n;var o=r[15];return r[12]+=o*e,r[13]+=o*t,r[14]+=o*n,r},setMat4Translation:function(e,t,n){return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=e[15],n},rotationMat4v:function(e,t,n){var r,i,a,s,o,l,u=Z.normalizeVec4([t[0],t[1],t[2],0],[]),c=Math.sin(e),f=Math.cos(e),p=1-f,A=u[0],d=u[1],v=u[2];return r=A*d,i=d*v,a=v*A,s=A*c,o=d*c,l=v*c,(n=n||Z.mat4())[0]=p*A*A+f,n[1]=p*r+l,n[2]=p*a-o,n[3]=0,n[4]=p*r-l,n[5]=p*d*d+f,n[6]=p*i+s,n[7]=0,n[8]=p*a+o,n[9]=p*i-s,n[10]=p*v*v+f,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,n},rotationMat4c:function(e,t,n,r,i){return Z.rotationMat4v(e,[t,n,r],i)},scalingMat4v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat4();return t[0]=e[0],t[5]=e[1],t[10]=e[2],t},scalingMat3v:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.identityMat3();return t[0]=e[0],t[4]=e[1],t},scalingMat4c:function(){var e=new Y(3);return function(t,n,r,i){return e[0]=t,e[1]=n,e[2]=r,Z.scalingMat4v(e,i)}}(),scaleMat4c:function(e,t,n,r){return r[0]*=e,r[4]*=t,r[8]*=n,r[1]*=e,r[5]*=t,r[9]*=n,r[2]*=e,r[6]*=t,r[10]*=n,r[3]*=e,r[7]*=t,r[11]*=n,r},scaleMat4v:function(e,t){var n=e[0],r=e[1],i=e[2];return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,t},scalingMat4s:function(e){return Z.scalingMat4c(e,e,e)},rotationTranslationMat4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.mat4(),r=e[0],i=e[1],a=e[2],s=e[3],o=r+r,l=i+i,u=a+a,c=r*o,f=r*l,p=r*u,A=i*l,d=i*u,v=a*u,h=s*o,I=s*l,y=s*u;return n[0]=1-(A+v),n[1]=f+y,n[2]=p-I,n[3]=0,n[4]=f-y,n[5]=1-(c+v),n[6]=d+h,n[7]=0,n[8]=p+I,n[9]=d-h,n[10]=1-(c+A),n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},mat4ToEuler:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Z.clamp,i=e[0],a=e[4],s=e[8],o=e[1],l=e[5],u=e[9],c=e[2],f=e[6],p=e[10];return"XYZ"===t?(n[1]=Math.asin(r(s,-1,1)),Math.abs(s)<.99999?(n[0]=Math.atan2(-u,p),n[2]=Math.atan2(-a,i)):(n[0]=Math.atan2(f,l),n[2]=0)):"YXZ"===t?(n[0]=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(n[1]=Math.atan2(s,p),n[2]=Math.atan2(o,l)):(n[1]=Math.atan2(-c,i),n[2]=0)):"ZXY"===t?(n[0]=Math.asin(r(f,-1,1)),Math.abs(f)<.99999?(n[1]=Math.atan2(-c,p),n[2]=Math.atan2(-a,l)):(n[1]=0,n[2]=Math.atan2(o,i))):"ZYX"===t?(n[1]=Math.asin(-r(c,-1,1)),Math.abs(c)<.99999?(n[0]=Math.atan2(f,p),n[2]=Math.atan2(o,i)):(n[0]=0,n[2]=Math.atan2(-a,l))):"YZX"===t?(n[2]=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(n[0]=Math.atan2(-u,l),n[1]=Math.atan2(-c,i)):(n[0]=0,n[1]=Math.atan2(s,p))):"XZY"===t&&(n[2]=Math.asin(-r(a,-1,1)),Math.abs(a)<.99999?(n[0]=Math.atan2(f,l),n[1]=Math.atan2(s,i)):(n[0]=Math.atan2(-u,p),n[1]=0)),n},composeMat4:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.mat4();return Z.quaternionToRotationMat4(t,r),Z.scaleMat4v(n,r),Z.translateMat4v(e,r),r},decomposeMat4:function(){var e=new Y(3),t=new Y(16);return function(n,r,i,a){e[0]=n[0],e[1]=n[1],e[2]=n[2];var s=Z.lenVec3(e);e[0]=n[4],e[1]=n[5],e[2]=n[6];var o=Z.lenVec3(e);e[8]=n[8],e[9]=n[9],e[10]=n[10];var l=Z.lenVec3(e);Z.determinantMat4(n)<0&&(s=-s),r[0]=n[12],r[1]=n[13],r[2]=n[14],t.set(n);var u=1/s,c=1/o,f=1/l;return t[0]*=u,t[1]*=u,t[2]*=u,t[4]*=c,t[5]*=c,t[6]*=c,t[8]*=f,t[9]*=f,t[10]*=f,Z.mat4ToQuaternion(t,i),a[0]=s,a[1]=o,a[2]=l,this}}(),getColMat4:function(e,t){var n=4*t;return[e[n],e[n+1],e[n+2],e[n+3]]},setRowMat4:function(e,t,n){e[t]=n[0],e[t+4]=n[1],e[t+8]=n[2],e[t+12]=n[3]},lookAtMat4v:function(e,t,n,r){r||(r=Z.mat4());var i,a,s,o,l,u,c,f,p,A,d=e[0],v=e[1],h=e[2],I=n[0],y=n[1],m=n[2],w=t[0],g=t[1],T=t[2];return d===w&&v===g&&h===T?Z.identityMat4():(i=d-w,a=v-g,s=h-T,o=y*(s*=A=1/Math.sqrt(i*i+a*a+s*s))-m*(a*=A),l=m*(i*=A)-I*s,u=I*a-y*i,(A=Math.sqrt(o*o+l*l+u*u))?(o*=A=1/A,l*=A,u*=A):(o=0,l=0,u=0),c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,(A=Math.sqrt(c*c+f*f+p*p))?(c*=A=1/A,f*=A,p*=A):(c=0,f=0,p=0),r[0]=o,r[1]=c,r[2]=i,r[3]=0,r[4]=l,r[5]=f,r[6]=a,r[7]=0,r[8]=u,r[9]=p,r[10]=s,r[11]=0,r[12]=-(o*d+l*v+u*h),r[13]=-(c*d+f*v+p*h),r[14]=-(i*d+a*v+s*h),r[15]=1,r)},lookAtMat4c:function(e,t,n,r,i,a,s,o,l){return Z.lookAtMat4v([e,t,n],[r,i,a],[s,o,l],[])},orthoMat4c:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2/l,s[6]=0,s[7]=0,s[8]=0,s[9]=0,s[10]=-2/u,s[11]=0,s[12]=-(e+t)/o,s[13]=-(r+n)/l,s[14]=-(a+i)/u,s[15]=1,s},frustumMat4v:function(e,t,n){n||(n=Z.mat4());var r=[e[0],e[1],e[2],0],i=[t[0],t[1],t[2],0];Z.addVec4(i,r,X),Z.subVec4(i,r,q);var a=2*r[2],s=q[0],o=q[1],l=q[2];return n[0]=a/s,n[1]=0,n[2]=0,n[3]=0,n[4]=0,n[5]=a/o,n[6]=0,n[7]=0,n[8]=X[0]/s,n[9]=X[1]/o,n[10]=-X[2]/l,n[11]=-1,n[12]=0,n[13]=0,n[14]=-a*i[2]/l,n[15]=0,n},frustumMat4:function(e,t,n,r,i,a,s){s||(s=Z.mat4());var o=t-e,l=r-n,u=a-i;return s[0]=2*i/o,s[1]=0,s[2]=0,s[3]=0,s[4]=0,s[5]=2*i/l,s[6]=0,s[7]=0,s[8]=(t+e)/o,s[9]=(r+n)/l,s[10]=-(a+i)/u,s[11]=-1,s[12]=0,s[13]=0,s[14]=-a*i*2/u,s[15]=0,s},perspectiveMat4:function(e,t,n,r,i){var a=[],s=[];return a[2]=n,s[2]=r,s[1]=a[2]*Math.tan(e/2),a[1]=-s[1],s[0]=s[1]*t,a[0]=-s[0],Z.frustumMat4v(a,s,i)},compareMat4:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},transformPoint3:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2];return n[0]=e[0]*r+e[4]*i+e[8]*a+e[12],n[1]=e[1]*r+e[5]*i+e[9]*a+e[13],n[2]=e[2]*r+e[6]*i+e[10]*a+e[14],n},transformPoint4:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4();return n[0]=e[0]*t[0]+e[4]*t[1]+e[8]*t[2]+e[12]*t[3],n[1]=e[1]*t[0]+e[5]*t[1]+e[9]*t[2]+e[13]*t[3],n[2]=e[2]*t[0]+e[6]*t[1]+e[10]*t[2]+e[14]*t[3],n[3]=e[3]*t[0]+e[7]*t[1]+e[11]*t[2]+e[15]*t[3],n},transformPoints3:function(e,t,n){for(var r,i,a,s,o,l=n||[],u=t.length,c=e[0],f=e[1],p=e[2],A=e[3],d=e[4],v=e[5],h=e[6],I=e[7],y=e[8],m=e[9],w=e[10],g=e[11],T=e[12],E=e[13],b=e[14],D=e[15],P=0;P2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2];e[3];var f=e[4],p=e[5],A=e[6];e[7];var d=e[8],v=e[9],h=e[10];e[11];var I=e[12],y=e[13],m=e[14];for(e[15],n=0;n2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;n3&&void 0!==arguments[3]?arguments[3]:e,i=Math.cos(n),a=Math.sin(n),s=e[0]-t[0],o=e[1]-t[1];return r[0]=s*i-o*a+t[0],r[1]=s*a+o*i+t[1],e},rotateVec3X:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Y:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},rotateVec3Z:function(e,t,n,r){var i=[],a=[];return i[0]=e[0]-t[0],i[1]=e[1]-t[1],i[2]=e[2]-t[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[2],r[0]=a[0]+t[0],r[1]=a[1]+t[1],r[2]=a[2]+t[2],r},projectVec4:function(e,t){var n=1/e[3];return(t=t||Z.vec2())[0]=e[0]*n,t[1]=e[1]*n,t},unprojectVec3:(x=new Y(16),M=new Y(16),F=new Y(16),function(e,t,n,r){return this.transformVec3(this.mulMat4(this.inverseMat4(t,x),this.inverseMat4(n,M),F),e,r)}),lerpVec3:function(e,t,n,r,i,a){var s=a||Z.vec3(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s},lerpMat4:function(e,t,n,r,i,a){var s=a||Z.mat4(),o=(e-t)/(n-t);return s[0]=r[0]+o*(i[0]-r[0]),s[1]=r[1]+o*(i[1]-r[1]),s[2]=r[2]+o*(i[2]-r[2]),s[3]=r[3]+o*(i[3]-r[3]),s[4]=r[4]+o*(i[4]-r[4]),s[5]=r[5]+o*(i[5]-r[5]),s[6]=r[6]+o*(i[6]-r[6]),s[7]=r[7]+o*(i[7]-r[7]),s[8]=r[8]+o*(i[8]-r[8]),s[9]=r[9]+o*(i[9]-r[9]),s[10]=r[10]+o*(i[10]-r[10]),s[11]=r[11]+o*(i[11]-r[11]),s[12]=r[12]+o*(i[12]-r[12]),s[13]=r[13]+o*(i[13]-r[13]),s[14]=r[14]+o*(i[14]-r[14]),s[15]=r[15]+o*(i[15]-r[15]),s},flatten:function(e){var t,n,r,i,a,s=[];for(t=0,n=e.length;t0&&void 0!==arguments[0]?arguments[0]:Z.vec4();return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},eulerToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0]*Z.DEGTORAD/2,i=e[1]*Z.DEGTORAD/2,a=e[2]*Z.DEGTORAD/2,s=Math.cos(r),o=Math.cos(i),l=Math.cos(a),u=Math.sin(r),c=Math.sin(i),f=Math.sin(a);return"XYZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"YXZ"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"ZXY"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l-u*c*f):"ZYX"===t?(n[0]=u*o*l-s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l+u*c*f):"YZX"===t?(n[0]=u*o*l+s*c*f,n[1]=s*c*l+u*o*f,n[2]=s*o*f-u*c*l,n[3]=s*o*l-u*c*f):"XZY"===t&&(n[0]=u*o*l-s*c*f,n[1]=s*c*l-u*o*f,n[2]=s*o*f+u*c*l,n[3]=s*o*l+u*c*f),n},mat4ToQuaternion:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),r=e[0],i=e[4],a=e[8],s=e[1],o=e[5],l=e[9],u=e[2],c=e[6],f=e[10],p=r+o+f;return p>0?(t=.5/Math.sqrt(p+1),n[3]=.25/t,n[0]=(c-l)*t,n[1]=(a-u)*t,n[2]=(s-i)*t):r>o&&r>f?(t=2*Math.sqrt(1+r-o-f),n[3]=(c-l)/t,n[0]=.25*t,n[1]=(i+s)/t,n[2]=(a+u)/t):o>f?(t=2*Math.sqrt(1+o-r-f),n[3]=(a-u)/t,n[0]=(i+s)/t,n[1]=.25*t,n[2]=(l+c)/t):(t=2*Math.sqrt(1+f-r-o),n[3]=(s-i)/t,n[0]=(a+u)/t,n[1]=(l+c)/t,n[2]=.25*t),n},vec3PairToQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=Math.sqrt(Z.dotVec3(e,e)*Z.dotVec3(t,t)),i=r+Z.dotVec3(e,t);return i<1e-8*r?(i=0,Math.abs(e[0])>Math.abs(e[2])?(n[0]=-e[1],n[1]=e[0],n[2]=0):(n[0]=0,n[1]=-e[2],n[2]=e[1])):Z.cross3Vec3(e,t,n),n[3]=i,Z.normalizeQuaternion(n)},angleAxisToQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=e[3]/2,r=Math.sin(n);return t[0]=r*e[0],t[1]=r*e[1],t[2]=r*e[2],t[3]=Math.cos(n),t},quaternionToEuler:function(){var e=new Y(16);return function(t,n,r){return r=r||Z.vec3(),Z.quaternionToRotationMat4(t,e),Z.mat4ToEuler(e,n,r),r}}(),mulQuaternions:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec4(),r=e[0],i=e[1],a=e[2],s=e[3],o=t[0],l=t[1],u=t[2],c=t[3];return n[0]=s*o+r*c+i*u-a*l,n[1]=s*l+i*c+a*o-r*u,n[2]=s*u+a*c+r*l-i*o,n[3]=s*c-r*o-i*l-a*u,n},vec3ApplyQuaternion:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Z.vec3(),r=t[0],i=t[1],a=t[2],s=e[0],o=e[1],l=e[2],u=e[3],c=u*r+o*a-l*i,f=u*i+l*r-s*a,p=u*a+s*i-o*r,A=-s*r-o*i-l*a;return n[0]=c*u+A*-s+f*-l-p*-o,n[1]=f*u+A*-o+p*-s-c*-l,n[2]=p*u+A*-l+c*-o-f*-s,n},quaternionToMat4:function(e,t){t=Z.identityMat4(t);var n=e[0],r=e[1],i=e[2],a=e[3],s=2*n,o=2*r,l=2*i,u=s*a,c=o*a,f=l*a,p=s*n,A=o*n,d=l*n,v=o*r,h=l*r,I=l*i;return t[0]=1-(v+I),t[1]=A+f,t[2]=d-c,t[4]=A-f,t[5]=1-(p+I),t[6]=h+u,t[8]=d+c,t[9]=h-u,t[10]=1-(p+v),t},quaternionToRotationMat4:function(e,t){var n=e[0],r=e[1],i=e[2],a=e[3],s=n+n,o=r+r,l=i+i,u=n*s,c=n*o,f=n*l,p=r*o,A=r*l,d=i*l,v=a*s,h=a*o,I=a*l;return t[0]=1-(p+d),t[4]=c-I,t[8]=f+h,t[1]=c+I,t[5]=1-(u+d),t[9]=A-v,t[2]=f-h,t[6]=A+v,t[10]=1-(u+p),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},normalizeQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,n=Z.lenVec4([e[0],e[1],e[2],e[3]]);return t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n,t[3]=e[3]/n,t},conjugateQuaternion:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t},inverseQuaternion:function(e,t){return Z.normalizeQuaternion(Z.conjugateQuaternion(e,t))},quaternionToAngleAxis:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec4(),n=(e=Z.normalizeQuaternion(e,J))[3],r=2*Math.acos(n),i=Math.sqrt(1-n*n);return i<.001?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t[3]=r,t},AABB3:function(e){return new Y(e||6)},AABB2:function(e){return new Y(e||4)},OBB3:function(e){return new Y(e||32)},OBB2:function(e){return new Y(e||16)},Sphere3:function(e,t,n,r){return new Y([e,t,n,r])},transformOBB3:function(e,t){var n,r,i,a,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,o=t.length,l=e[0],u=e[1],c=e[2],f=e[3],p=e[4],A=e[5],d=e[6],v=e[7],h=e[8],I=e[9],y=e[10],m=e[11],w=e[12],g=e[13],T=e[14],E=e[15];for(n=0;no?s:o,a[1]+=l>u?l:u,a[2]+=c>f?c:f,Math.abs(Z.lenVec3(a))}}(),getAABB3Area:function(e){return(e[3]-e[0])*(e[4]-e[1])*(e[5]-e[2])},getAABB3Center:function(e,t){var n=t||Z.vec3();return n[0]=(e[0]+e[3])/2,n[1]=(e[1]+e[4])/2,n[2]=(e[2]+e[5])/2,n},getAABB2Center:function(e,t){var n=t||Z.vec2();return n[0]=(e[2]+e[0])/2,n[1]=(e[3]+e[1])/2,n},collapseAABB3:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Z.AABB3();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MAX_DOUBLE,e[3]=Z.MIN_DOUBLE,e[4]=Z.MIN_DOUBLE,e[5]=Z.MIN_DOUBLE,e},AABB3ToOBB3:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.OBB3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,t[4]=e[3],t[5]=e[1],t[6]=e[2],t[7]=1,t[8]=e[3],t[9]=e[4],t[10]=e[2],t[11]=1,t[12]=e[0],t[13]=e[4],t[14]=e[2],t[15]=1,t[16]=e[0],t[17]=e[1],t[18]=e[5],t[19]=1,t[20]=e[3],t[21]=e[1],t[22]=e[5],t[23]=1,t[24]=e[3],t[25]=e[4],t[26]=e[5],t[27]=1,t[28]=e[0],t[29]=e[4],t[30]=e[5],t[31]=1,t},positions3ToAABB3:function(){var e=new Y(3);return function(t,n,r){n=n||Z.AABB3();for(var i,a,s,o=Z.MAX_DOUBLE,l=Z.MAX_DOUBLE,u=Z.MAX_DOUBLE,c=Z.MIN_DOUBLE,f=Z.MIN_DOUBLE,p=Z.MIN_DOUBLE,A=0,d=t.length;Ac&&(c=i),a>f&&(f=a),s>p&&(p=s);return n[0]=o,n[1]=l,n[2]=u,n[3]=c,n[4]=f,n[5]=p,n}}(),OBB3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToAABB3:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB3(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MAX_DOUBLE,l=Z.MIN_DOUBLE,u=Z.MIN_DOUBLE,c=Z.MIN_DOUBLE,f=0,p=e.length;fl&&(l=t),n>u&&(u=n),r>c&&(c=r);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i[4]=u,i[5]=c,i},points3ToSphere3:function(){var e=new Y(3);return function(t,n){n=n||Z.vec4();var r,i=0,a=0,s=0,o=t.length;for(r=0;ru&&(u=l);return n[3]=u,n}}(),positions3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=0;for(i=0;iu&&(u=c);return r[3]=u,r}}(),OBB3ToSphere3:function(){var e=new Y(3),t=new Y(3);return function(n,r){r=r||Z.vec4();var i,a=0,s=0,o=0,l=n.length,u=l/4;for(i=0;if&&(f=c);return r[3]=f,r}}(),getSphere3Center:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3();return t[0]=e[0],t[1]=e[1],t[2]=e[2],t},getPositionsCenter:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(),n=0,r=0,i=0,a=0,s=e.length;at[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]>t[2]&&(e[2]=t[2]),e[3]n&&(e[0]=n),e[1]>r&&(e[1]=r),e[2]>i&&(e[2]=i),e[3]0&&void 0!==arguments[0]?arguments[0]:Z.AABB2();return e[0]=Z.MAX_DOUBLE,e[1]=Z.MAX_DOUBLE,e[2]=Z.MIN_DOUBLE,e[3]=Z.MIN_DOUBLE,e},point3AABB3Intersect:function(e,t){return e[0]>t[0]||e[3]t[1]||e[4]t[2]||e[5]0?(r=e[0]*n[0],i=e[0]*n[3]):(r=e[0]*n[3],i=e[0]*n[0]),e[1]>0?(r+=e[1]*n[1],i+=e[1]*n[4]):(r+=e[1]*n[4],i+=e[1]*n[1]),e[2]>0?(r+=e[2]*n[2],i+=e[2]*n[5]):(r+=e[2]*n[5],i+=e[2]*n[2]),r<=-t&&i<=-t?-1:r>=-t&&i>=-t?1:0},OBB3ToAABB2:function(e){for(var t,n,r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.AABB2(),a=Z.MAX_DOUBLE,s=Z.MAX_DOUBLE,o=Z.MIN_DOUBLE,l=Z.MIN_DOUBLE,u=0,c=e.length;uo&&(o=t),n>l&&(l=n);return i[0]=a,i[1]=s,i[2]=o,i[3]=l,i},expandAABB2:function(e,t){return e[0]>t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]t[0]&&(e[0]=t[0]),e[1]>t[1]&&(e[1]=t[1]),e[2]3&&void 0!==arguments[3]?arguments[3]:e,i=.5*(e[0]+1),a=.5*(e[1]+1),s=.5*(e[2]+1),o=.5*(e[3]+1);return r[0]=Math.floor(i*t),r[1]=n-Math.floor(o*n),r[2]=Math.floor(s*t),r[3]=n-Math.floor(a*n),r},tangentQuadraticBezier:function(e,t,n,r){return 2*(1-e)*(n-t)+2*e*(r-n)},tangentQuadraticBezier3:function(e,t,n,r,i){return-3*t*(1-e)*(1-e)+3*n*(1-e)*(1-e)-6*e*n*(1-e)+6*e*r*(1-e)-3*e*e*r+3*e*e*i},tangentSpline:function(e){return 6*e*e-6*e+(3*e*e-4*e+1)+(-6*e*e+6*e)+(3*e*e-2*e)},catmullRomInterpolate:function(e,t,n,r,i){var a=.5*(n-e),s=.5*(r-t),o=i*i;return(2*t-2*n+a+s)*(i*o)+(-3*t+3*n-2*a-s)*o+a*i+t},b2p0:function(e,t){var n=1-e;return n*n*t},b2p1:function(e,t){return 2*(1-e)*e*t},b2p2:function(e,t){return e*e*t},b2:function(e,t,n,r){return this.b2p0(e,t)+this.b2p1(e,n)+this.b2p2(e,r)},b3p0:function(e,t){var n=1-e;return n*n*n*t},b3p1:function(e,t){var n=1-e;return 3*n*n*e*t},b3p2:function(e,t){return 3*(1-e)*e*e*t},b3p3:function(e,t){return e*e*e*t},b3:function(e,t,n,r,i){return this.b3p0(e,t)+this.b3p1(e,n)+this.b3p2(e,r)+this.b3p3(e,i)},triangleNormal:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Z.vec3(),i=t[0]-e[0],a=t[1]-e[1],s=t[2]-e[2],o=n[0]-e[0],l=n[1]-e[1],u=n[2]-e[2],c=a*u-s*l,f=s*o-i*u,p=i*l-a*o,A=Math.sqrt(c*c+f*f+p*p);return 0===A?(r[0]=0,r[1]=0,r[2]=0):(r[0]=c/A,r[1]=f/A,r[2]=p/A),r},rayTriangleIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3),i=new Y(3);return function(a,s,o,l,u,c){c=c||Z.vec3();var f=Z.subVec3(l,o,e),p=Z.subVec3(u,o,t),A=Z.cross3Vec3(s,p,n),d=Z.dotVec3(f,A);if(d<1e-6)return null;var v=Z.subVec3(a,o,r),h=Z.dotVec3(v,A);if(h<0||h>d)return null;var I=Z.cross3Vec3(v,f,i),y=Z.dotVec3(s,I);if(y<0||h+y>d)return null;var m=Z.dotVec3(p,I)/d;return c[0]=a[0]+m*s[0],c[1]=a[1]+m*s[1],c[2]=a[2]+m*s[2],c}}(),rayPlaneIntersect:function(){var e=new Y(3),t=new Y(3),n=new Y(3),r=new Y(3);return function(i,a,s,o,l,u){u=u||Z.vec3(),a=Z.normalizeVec3(a,e);var c=Z.subVec3(o,s,t),f=Z.subVec3(l,s,n),p=Z.cross3Vec3(c,f,r);Z.normalizeVec3(p,p);var A=-Z.dotVec3(s,p),d=-(Z.dotVec3(i,p)+A)/Z.dotVec3(a,p);return u[0]=i[0]+d*a[0],u[1]=i[1]+d*a[1],u[2]=i[2]+d*a[2],u}}(),cartesianToBarycentric:function(){var e=new Y(3),t=new Y(3),n=new Y(3);return function(r,i,a,s,o){var l=Z.subVec3(s,i,e),u=Z.subVec3(a,i,t),c=Z.subVec3(r,i,n),f=Z.dotVec3(l,l),p=Z.dotVec3(l,u),A=Z.dotVec3(l,c),d=Z.dotVec3(u,u),v=Z.dotVec3(u,c),h=f*d-p*p;if(0===h)return null;var I=1/h,y=(d*A-p*v)*I,m=(f*v-p*A)*I;return o[0]=1-y-m,o[1]=m,o[2]=y,o}}(),barycentricInsideTriangle:function(e){var t=e[1],n=e[2];return n>=0&&t>=0&&n+t<1},barycentricToCartesian:function(e,t,n,r){var i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Z.vec3(),a=e[0],s=e[1],o=e[2];return i[0]=t[0]*a+n[0]*s+r[0]*o,i[1]=t[1]*a+n[1]*s+r[1]*o,i[2]=t[2]*a+n[2]*s+r[2]*o,i},mergeVertices:function(e,t,n,r){var i,a,s,o,l,u,c={},f=[],p=[],A=t?[]:null,d=n?[]:null,v=[],h=Math.pow(10,4),I=0;for(l=0,u=e.length;l>24&255,s=f>>16&255,a=f>>8&255,i=255&f,r=3*t[d],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+1],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,r=3*t[d+2],u[p++]=e[r],u[p++]=e[r+1],u[p++]=e[r+2],c[A++]=i,c[A++]=a,c[A++]=s,c[A++]=o,f++;return{positions:u,colors:c}},faceToVertexNormals:function(e,t){var n,r,i,a,s,o,l,u,c,f,p,A=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=A.smoothNormalsAngleThreshold||20,v={},h=[],I={},y=4,m=Math.pow(10,y);for(l=0,c=e.length;ll[3]&&(l[3]=i[p]),i[p+1]l[4]&&(l[4]=i[p+1]),i[p+2]l[5]&&(l[5]=i[p+2])}if(n.length<20||a>10)return u.triangles=n,u.leaf=!0,u;e[0]=l[3]-l[0],e[1]=l[4]-l[1],e[2]=l[5]-l[2];var A=0;e[1]>e[A]&&(A=1),e[2]>e[A]&&(A=2),u.splitDim=A;var d=(l[A]+l[A+3])/2,v=new Array(n.length),h=0,I=new Array(n.length),y=0;for(s=0,o=n.length;s2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t},octDecodeVec2s:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t}};Z.buildEdgeIndices=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var $=function(){function e(){b(this,e),this._head=[],this._headLength=0,this._tail=[],this._index=0,this._length=0}return P(e,[{key:"length",get:function(){return this._length}},{key:"shift",value:function(){if(this._index>=this._headLength){var e=this._head;if(e.length=0,this._head=this._tail,this._tail=e,this._index=0,this._headLength=this._head.length,!this._headLength)return}var t=this._head[this._index];return this._index<0?delete this._head[this._index++]:this._head[this._index++]=void 0,this._length--,t}},{key:"push",value:function(e){return this._length++,this._tail.push(e),this}},{key:"unshift",value:function(e){return this._head[--this._index]=e,this._length++,this}}]),e}(),ee={build:{version:"0.8"},client:{browser:navigator&&navigator.userAgent?navigator.userAgent:"n/a"},components:{scenes:0,models:0,meshes:0,objects:0},memory:{meshes:0,positions:0,colors:0,normals:0,uvs:0,indices:0,textures:0,transforms:0,materials:0,programs:0},frame:{frameCount:0,fps:0,useProgram:0,bindTexture:0,bindArray:0,drawElements:0,drawArrays:0,tasksRun:0,tasksScheduled:0}};var te=[["0",10],["A",26],["a",26],["_",1],["$",1]].map((function(e){for(var t=[],n=e[0].charCodeAt(0),r=n+e[1],i=n;i0&&void 0!==arguments[0]?arguments[0]:-1,r=(new Date).getTime(),i=0;le.length>0&&(n<0||r0&&ie>0){var n=1e3/ie;pe+=n,ce.push(n),ce.length>=30&&(pe-=ce.shift()),ee.frame.fps=Math.round(pe/ce.length)}!function(e){var t=Ae.runTasks(e+10),n=Ae.getNumTasks();ee.frame.tasksRun=t,ee.frame.tasksScheduled=n,ee.frame.tasksBudget=10}(t),function(e){for(var t in ue.time=e,Ae.scenes)if(Ae.scenes.hasOwnProperty(t)){var n=Ae.scenes[t];ue.sceneId=t,ue.startTime=n.startTime,ue.deltaTime=null!=ue.prevTime?ue.time-ue.prevTime:0,n.fire("tick",ue,!0)}ue.prevTime=e}(t),function(){var e,t,n,r,i,a=Ae.scenes,s=!1;for(i in a)a.hasOwnProperty(i)&&(e=a[i],(t=se[i])||(t=se[i]={}),n=e.ticksPerOcclusionTest,t.ticksPerOcclusionTest!==n&&(t.ticksPerOcclusionTest=n,t.renderCountdown=n),--e.occlusionTestCountdown<=0&&(e.doOcclusionTest(),e.occlusionTestCountdown=n),r=e.ticksPerRender,t.ticksPerRender!==r&&(t.ticksPerRender=r,t.renderCountdown=r),0==--t.renderCountdown&&(e.render(s),t.renderCountdown=r))}(),fe=t,void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(e):requestAnimationFrame(e)};void 0!==window.requestPostAnimationFrame?window.requestPostAnimationFrame(de):requestAnimationFrame(de);var ve=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,e),this.scene=null,"Scene"===this.type)this.scene=this,this.viewer=n.viewer;else{if("Scene"===t.type)this.scene=t;else{if(!(t instanceof e))throw"Invalid param: owner must be a Component";this.scene=t.scene}this._owner=t}this._dontClear=!!n.dontClear,this._renderer=this.scene._renderer,this.meta=n.meta||{},this.id=n.id,this.destroyed=!1,this._attached={},this._attachments=null,this._subIdMap=null,this._subIdEvents=null,this._eventSubs=null,this._eventSubsNum=null,this._events=null,this._eventCallDepth=0,this._ownedComponents=null,this!==this.scene&&this.scene._addComponent(this),this._updateScheduled=!1,t&&t._own(this)}return P(e,[{key:"type",get:function(){return"Component"}},{key:"isComponent",get:function(){return!0}},{key:"glRedraw",value:function(){this._renderer&&(this._renderer.imageDirty(),this.castsShadow&&this._renderer.shadowsDirty())}},{key:"glResort",value:function(){this._renderer&&this._renderer.needStateSort()}},{key:"owner",get:function(){return this._owner}},{key:"isType",value:function(e){return this.type===e}},{key:"fire",value:function(e,t,n){this._events||(this._events={}),this._eventSubs||(this._eventSubs={},this._eventSubsNum={}),!0!==n&&(this._events[e]=t||!0);var r,i=this._eventSubs[e];if(i)for(var a in i)i.hasOwnProperty(a)&&(r=i[a],this._eventCallDepth++,this._eventCallDepth<300?r.callback.call(r.scope,t):this.error("fire: potential stack overflow from recursive event '"+e+"' - dropping this event"),this._eventCallDepth--)}},{key:"on",value:function(e,t,n){this._events||(this._events={}),this._subIdMap||(this._subIdMap=new G),this._subIdEvents||(this._subIdEvents={}),this._eventSubs||(this._eventSubs={}),this._eventSubsNum||(this._eventSubsNum={});var r=this._eventSubs[e];r?this._eventSubsNum[e]++:(r={},this._eventSubs[e]=r,this._eventSubsNum[e]=1);var i=this._subIdMap.addItem();r[i]={callback:t,scope:n||this},this._subIdEvents[i]=e;var a=this._events[e];return void 0!==a&&t.call(n||this,a),i}},{key:"off",value:function(e){if(null!=e&&this._subIdEvents){var t=this._subIdEvents[e];if(t){delete this._subIdEvents[e];var n=this._eventSubs[t];n&&(delete n[e],this._eventSubsNum[t]--),this._subIdMap.removeItem(e)}}}},{key:"once",value:function(e,t,n){var r=this,i=this.on(e,(function(e){r.off(i),t.call(n||this,e)}),n)}},{key:"hasSubs",value:function(e){return this._eventSubsNum&&this._eventSubsNum[e]>0}},{key:"log",value:function(e){e="[LOG]"+this._message(e),window.console.log(e),this.scene.fire("log",e)}},{key:"_message",value:function(e){return" ["+this.type+" "+ae.inQuotes(this.id)+"]: "+e}},{key:"warn",value:function(e){e="[WARN]"+this._message(e),window.console.warn(e),this.scene.fire("warn",e)}},{key:"error",value:function(e){e="[ERROR]"+this._message(e),window.console.error(e),this.scene.fire("error",e)}},{key:"_attach",value:function(e){var t=e.name;if(t){var n=e.component,r=e.sceneDefault,i=e.sceneSingleton,a=e.type,s=e.on,o=!1!==e.recompiles;if(n&&(ae.isNumeric(n)||ae.isString(n))){var l=n;if(!(n=this.scene.components[l]))return void this.error("Component not found: "+ae.inQuotes(l))}if(!n)if(!0===i){var u=this.scene.types[a];for(var c in u)if(u.hasOwnProperty){n=u[c];break}if(!n)return this.error("Scene has no default component for '"+t+"'"),null}else if(!0===r&&!(n=this.scene[t]))return this.error("Scene has no default component for '"+t+"'"),null;if(n){if(n.scene.id!==this.scene.id)return void this.error("Not in same scene: "+n.type+" "+ae.inQuotes(n.id));if(a&&!n.isType(a))return void this.error("Expected a "+a+" type or subtype: "+n.type+" "+ae.inQuotes(n.id))}this._attachments||(this._attachments={});var f,p,A,d=this._attached[t];if(d){if(n&&d.id===n.id)return;var v=this._attachments[d.id];for(p=0,A=(f=v.subs).length;p3&&void 0!==arguments[3]?arguments[3]:1e3,i=Z.getPositionsCenter(e,he),a=Math.round(i[0]/r)*r,s=Math.round(i[1]/r)*r,o=Math.round(i[2]/r)*r;n[0]=a,n[1]=s,n[2]=o;var l=0!==n[0]||0!==n[1]||0!==n[2];if(l)for(var u=0,c=e.length;u0?this.meshes[0]._colorize[3]/255:1},set:function(e){if(0!==this.meshes.length){var t=null!=e,n=this.meshes[0]._colorize[3],r=255;if(t){if(e<0?e=0:e>1&&(e=1),n===(r=Math.floor(255*e)))return}else if(n===(r=255))return;for(var i=0,a=this.meshes.length;i1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._color=r.color||"black",this._highlightClass="viewer-ruler-wire-highlighted",this._wire=document.createElement("div"),this._wire.className+=this._wire.className?" viewer-ruler-wire":"viewer-ruler-wire",this._wireClickable=document.createElement("div"),this._wireClickable.className+=this._wireClickable.className?" viewer-ruler-wire-clickable":"viewer-ruler-wire-clickable",this._thickness=r.thickness||1,this._thicknessClickable=r.thicknessClickable||6;var i=this._wire,a=i.style;a.border="solid "+this._thickness+"px "+this._color,a.position="absolute",a["z-index"]=void 0===r.zIndex?"2000001":r.zIndex,a.width="0px",a.height="0px",a.visibility="visible",a.top="0px",a.left="0px",a["-webkit-transform-origin"]="0 0",a["-moz-transform-origin"]="0 0",a["-ms-transform-origin"]="0 0",a["-o-transform-origin"]="0 0",a["transform-origin"]="0 0",a["-webkit-transform"]="rotate(0deg)",a["-moz-transform"]="rotate(0deg)",a["-ms-transform"]="rotate(0deg)",a["-o-transform"]="rotate(0deg)",a.transform="rotate(0deg)",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._wireClickable,o=s.style;o.border="solid "+this._thicknessClickable+"px "+this._color,o.position="absolute",o["z-index"]=void 0===r.zIndex?"2000002":r.zIndex+1,o.width="0px",o.height="0px",o.visibility="visible",o.top="0px",o.left="0px",o["-webkit-transform-origin"]="0 0",o["-moz-transform-origin"]="0 0",o["-ms-transform-origin"]="0 0",o["-o-transform-origin"]="0 0",o["transform-origin"]="0 0",o["-webkit-transform"]="rotate(0deg)",o["-moz-transform"]="rotate(0deg)",o["-ms-transform"]="rotate(0deg)",o["-o-transform"]="rotate(0deg)",o.transform="rotate(0deg)",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this._x1=0,this._y1=0,this._x2=0,this._y2=0,this._update()}return P(e,[{key:"_visible",get:function(){return"visible"===this._wire.style.visibility}},{key:"_update",value:function(){var e=Math.abs(Math.sqrt((this._x1-this._x2)*(this._x1-this._x2)+(this._y1-this._y2)*(this._y1-this._y2))),t=180*Math.atan2(this._y2-this._y1,this._x2-this._x1)/Math.PI,n=this._wire.style;n.width=Math.round(e)+"px",n.left=Math.round(this._x1)+"px",n.top=Math.round(this._y1)+"px",n["-webkit-transform"]="rotate("+t+"deg)",n["-moz-transform"]="rotate("+t+"deg)",n["-ms-transform"]="rotate("+t+"deg)",n["-o-transform"]="rotate("+t+"deg)",n.transform="rotate("+t+"deg)";var r=this._wireClickable.style;r.width=Math.round(e)+"px",r.left=Math.round(this._x1)+"px",r.top=Math.round(this._y1)+"px",r["-webkit-transform"]="rotate("+t+"deg)",r["-moz-transform"]="rotate("+t+"deg)",r["-ms-transform"]="rotate("+t+"deg)",r["-o-transform"]="rotate("+t+"deg)",r.transform="rotate("+t+"deg)"}},{key:"setStartAndEnd",value:function(e,t,n,r){this._x1=e,this._y1=t,this._x2=n,this._y2=r,this._update()}},{key:"setColor",value:function(e){this._color=e||"black",this._wire.style.border="solid "+this._thickness+"px "+this._color}},{key:"setOpacity",value:function(e){this._wire.style.opacity=e}},{key:"setVisible",value:function(e){e=!!e,this._visible!==e&&(this._wire.style.visibility=e?"visible":"hidden")}},{key:"setClickable",value:function(e){this._wireClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._wire.classList.add(this._highlightClass):this._wire.classList.remove(this._highlightClass))}},{key:"destroy",value:function(e){this._wire.parentElement&&this._wire.parentElement.removeChild(this._wire),this._wireClickable.parentElement&&this._wireClickable.parentElement.removeChild(this._wireClickable)}}]),e}(),He=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-dot-highlighted",this._x=0,this._y=0,this._visible=!0,this._dot=document.createElement("div"),this._dot.className+=this._dot.className?" viewer-ruler-dot":"viewer-ruler-dot",this._dotClickable=document.createElement("div"),this._dotClickable.className+=this._dotClickable.className?" viewer-ruler-dot-clickable":"viewer-ruler-dot-clickable";var i=this._dot,a=i.style;a["border-radius"]="25px",a.border="solid 2px white",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"40000005":r.zIndex,a.width="8px",a.height="8px",a.visibility=!1!==r.visible?"visible":"hidden",a.top="0px",a.left="0px",a["box-shadow"]="0 2px 5px 0 #182A3D;",a.opacity=1,a["pointer-events"]="none",r.onContextMenu,t.appendChild(i);var s=this._dotClickable,o=s.style;o["border-radius"]="35px",o.border="solid 10px white",o.position="absolute",o["z-index"]=void 0===r.zIndex?"40000007":r.zIndex+1,o.width="8px",o.height="8px",o.visibility="visible",o.top="0px",o.left="0px",o.opacity=0,o["pointer-events"]="none",r.onContextMenu,t.appendChild(s),r.onMouseOver&&s.addEventListener("mouseover",(function(e){r.onMouseOver(e,n)})),r.onMouseLeave&&s.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n)})),r.onMouseWheel&&s.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&s.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()})),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.borderColor)}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._dot.style;n.left=Math.round(e)-4+"px",n.top=Math.round(t)-4+"px";var r=this._dotClickable.style;r.left=Math.round(e)-9+"px",r.top=Math.round(t)-9+"px"}},{key:"setFillColor",value:function(e){this._dot.style.background=e||"lightgreen"}},{key:"setBorderColor",value:function(e){this._dot.style.border="solid 2px"+(e||"black")}},{key:"setOpacity",value:function(e){this._dot.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._dot.style.visibility=this._visible?"visible":"hidden")}},{key:"setClickable",value:function(e){this._dotClickable.style["pointer-events"]=e?"all":"none"}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._dot.classList.add(this._highlightClass):this._dot.classList.remove(this._highlightClass))}},{key:"destroy",value:function(){this.setVisible(!1),this._dot.parentElement&&this._dot.parentElement.removeChild(this._dot),this._dotClickable.parentElement&&this._dotClickable.parentElement.removeChild(this._dotClickable)}}]),e}(),Ue=function(){function e(t){var n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,e),this._highlightClass="viewer-ruler-label-highlighted",this._prefix=r.prefix||"",this._x=0,this._y=0,this._visible=!0,this._culled=!1,this._label=document.createElement("div"),this._label.className+=this._label.className?" viewer-ruler-label":"viewer-ruler-label";var i=this._label,a=i.style;a["border-radius"]="5px",a.color="white",a.padding="4px",a.border="solid 1px",a.background="lightgreen",a.position="absolute",a["z-index"]=void 0===r.zIndex?"5000005":r.zIndex,a.width="auto",a.height="auto",a.visibility="visible",a.top="0px",a.left="0px",a["pointer-events"]="all",a.opacity=1,r.onContextMenu,i.innerText="",t.appendChild(i),this.setPos(r.x||0,r.y||0),this.setFillColor(r.fillColor),this.setBorderColor(r.fillColor),this.setText(r.text),r.onMouseOver&&i.addEventListener("mouseover",(function(e){r.onMouseOver(e,n),e.preventDefault()})),r.onMouseLeave&&i.addEventListener("mouseleave",(function(e){r.onMouseLeave(e,n),e.preventDefault()})),r.onMouseWheel&&i.addEventListener("wheel",(function(e){r.onMouseWheel(e,n)})),r.onContextMenu&&i.addEventListener("contextmenu",(function(e){r.onContextMenu(e,n),e.preventDefault()}))}return P(e,[{key:"setPos",value:function(e,t){this._x=e,this._y=t;var n=this._label.style;n.left=Math.round(e)-20+"px",n.top=Math.round(t)-12+"px"}},{key:"setPosOnWire",value:function(e,t,n,r){var i=e+.5*(n-e),a=t+.5*(r-t),s=this._label.style;s.left=Math.round(i)-20+"px",s.top=Math.round(a)-12+"px"}},{key:"setPosBetweenWires",value:function(e,t,n,r,i,a){var s=(e+n+i)/3,o=(t+r+a)/3,l=this._label.style;l.left=Math.round(s)-20+"px",l.top=Math.round(o)-12+"px"}},{key:"setText",value:function(e){this._label.innerHTML=this._prefix+(e||"")}},{key:"setFillColor",value:function(e){this._fillColor=e||"lightgreen",this._label.style.background=this._fillColor}},{key:"setBorderColor",value:function(e){this._borderColor=e||"black",this._label.style.border="solid 1px "+this._borderColor}},{key:"setOpacity",value:function(e){this._label.style.opacity=e}},{key:"setVisible",value:function(e){this._visible!==e&&(this._visible=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setCulled",value:function(e){this._culled!==e&&(this._culled=!!e,this._label.style.visibility=this._visible&&!this._culled?"visible":"hidden")}},{key:"setHighlighted",value:function(e){this._highlighted!==e&&(this._highlighted=!!e,this._highlighted?this._label.classList.add(this._highlightClass):this._label.classList.remove(this._highlightClass))}},{key:"setClickable",value:function(e){this._label.style["pointer-events"]=e?"all":"none"}},{key:"destroy",value:function(){this._label.parentElement&&this._label.parentElement.removeChild(this._label)}}]),e}(),Ge=Z.vec3(),ke=Z.vec3(),Ve=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(b(this,n),(r=t.call(this,e.viewer.scene,i)).plugin=e,r._container=i.container,!r._container)throw"config missing: container";r._color=i.color||e.defaultColor;var a=r.plugin.viewer.scene;r._originMarker=new Me(a,i.origin),r._cornerMarker=new Me(a,i.corner),r._targetMarker=new Me(a,i.target),r._originWorld=Z.vec3(),r._cornerWorld=Z.vec3(),r._targetWorld=Z.vec3(),r._wp=new Float64Array(12),r._vp=new Float64Array(12),r._pp=new Float64Array(12),r._cp=new Int16Array(6);var s=i.onMouseOver?function(e){i.onMouseOver(e,g(r))}:null,o=i.onMouseLeave?function(e){i.onMouseLeave(e,g(r))}:null,l=i.onContextMenu?function(e){i.onContextMenu(e,g(r))}:null,u=function(e){r.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",e))};return r._originDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._cornerDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetDot=new He(r._container,{fillColor:r._color,zIndex:void 0!==e.zIndex?e.zIndex+2:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._originWire=new Fe(r._container,{color:r._color||"blue",thickness:1,zIndex:e.zIndex,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._targetWire=new Fe(r._container,{color:r._color||"red",thickness:1,zIndex:void 0!==e.zIndex?e.zIndex+1:void 0,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._angleLabel=new Ue(r._container,{fillColor:r._color||"#00BBFF",prefix:"",text:"",zIndex:e.zIndex+2,onMouseOver:s,onMouseLeave:o,onMouseWheel:u,onContextMenu:l}),r._wpDirty=!1,r._vpDirty=!1,r._cpDirty=!1,r._visible=!1,r._originVisible=!1,r._cornerVisible=!1,r._targetVisible=!1,r._originWireVisible=!1,r._targetWireVisible=!1,r._angleVisible=!1,r._labelsVisible=!1,r._clickable=!1,r._originMarker.on("worldPos",(function(e){r._originWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._cornerMarker.on("worldPos",(function(e){r._cornerWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._targetMarker.on("worldPos",(function(e){r._targetWorld.set(e||[0,0,0]),r._wpDirty=!0,r._needUpdate(0)})),r._onViewMatrix=a.camera.on("viewMatrix",(function(){r._vpDirty=!0,r._needUpdate(0)})),r._onProjMatrix=a.camera.on("projMatrix",(function(){r._cpDirty=!0,r._needUpdate()})),r._onCanvasBoundary=a.canvas.on("boundary",(function(){r._cpDirty=!0,r._needUpdate(0)})),r.approximate=i.approximate,r.visible=i.visible,r.originVisible=i.originVisible,r.cornerVisible=i.cornerVisible,r.targetVisible=i.targetVisible,r.originWireVisible=i.originWireVisible,r.targetWireVisible=i.targetWireVisible,r.angleVisible=i.angleVisible,r.labelsVisible=i.labelsVisible,r}return P(n,[{key:"_update",value:function(){if(this._visible){var e=this.plugin.viewer.scene;if(this._wpDirty&&(this._wp[0]=this._originWorld[0],this._wp[1]=this._originWorld[1],this._wp[2]=this._originWorld[2],this._wp[3]=1,this._wp[4]=this._cornerWorld[0],this._wp[5]=this._cornerWorld[1],this._wp[6]=this._cornerWorld[2],this._wp[7]=1,this._wp[8]=this._targetWorld[0],this._wp[9]=this._targetWorld[1],this._wp[10]=this._targetWorld[2],this._wp[11]=1,this._wpDirty=!1,this._vpDirty=!0),this._vpDirty&&(Z.transformPositions4(e.camera.viewMatrix,this._wp,this._vp),this._vp[3]=1,this._vp[7]=1,this._vp[11]=1,this._vpDirty=!1,this._cpDirty=!0),this._cpDirty){var t=-.3,n=this._originMarker.viewPos[2],r=this._cornerMarker.viewPos[2],i=this._targetMarker.viewPos[2];if(n>t||r>t||i>t)return this._originDot.setVisible(!1),this._cornerDot.setVisible(!1),this._targetDot.setVisible(!1),this._originWire.setVisible(!1),this._targetWire.setVisible(!1),void this._angleLabel.setCulled(!0);Z.transformPositions4(e.camera.project.matrix,this._vp,this._pp);for(var a=this._pp,s=this._cp,o=e.canvas.canvas.getBoundingClientRect(),l=this._container.getBoundingClientRect(),u=o.top-l.top,c=o.left-l.left,f=e.canvas.boundary,p=f[2],A=f[3],d=0,v=0,h=a.length;vt+5||r[0]n+5||r[1]p[0]+5||A[0]p[1]+5||A[1]1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,"AngleMeasurements",e))._container=i.container||document.body,r._control=new je(g(r)),r._measurements={},r.defaultColor=void 0!==i.defaultColor?i.defaultColor:"#00BBFF",r.defaultLabelsVisible=!1!==i.defaultLabelsVisible,r.zIndex=i.zIndex||1e4,r._onMouseOver=function(e,t){r.fire("mouseOver",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onMouseLeave=function(e,t){r.fire("mouseLeave",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r._onContextMenu=function(e,t){r.fire("contextMenu",{plugin:g(r),angleMeasurement:t,measurement:t,event:e})},r}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){}},{key:"control",get:function(){return this._control}},{key:"measurements",get:function(){return this._measurements}},{key:"createMeasurement",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.viewer.scene.components[t.id]&&(this.error("Viewer scene component with this ID already exists: "+t.id),delete t.id);var n=t.origin,r=t.corner,i=t.target,a=new Ve(this,{id:t.id,plugin:this,container:this._container,origin:{entity:n.entity,worldPos:n.worldPos},corner:{entity:r.entity,worldPos:r.worldPos},target:{entity:i.entity,worldPos:i.worldPos},visible:t.visible,originVisible:!0,originWireVisible:!0,cornerVisible:!0,targetWireVisible:!0,targetVisible:!0,onMouseOver:this._onMouseOver,onMouseLeave:this._onMouseLeave,onContextMenu:this._onContextMenu});return this._measurements[a.id]=a,a.on("destroyed",(function(){delete e._measurements[a.id]})),this.fire("measurementCreated",a),a}},{key:"destroyMeasurement",value:function(e){var t=this._measurements[e];t?(t.destroy(),this.fire("measurementDestroyed",t)):this.log("AngleMeasurement not found: "+e)}},{key:"setLabelsShown",value:function(e){for(var t=0,n=Object.entries(this.measurements);t

";ae.isArray(t)&&(t=t.join("")),t=this._renderTemplate(t);var n=document.createRange().createContextualFragment(t);this._marker=n.firstChild,this._container.appendChild(this._marker),this._marker.style.visibility=this._markerShown?"visible":"hidden",this._marker.addEventListener("click",(function(){e.plugin.fire("markerClicked",e)})),this._marker.addEventListener("mouseenter",(function(){e.plugin.fire("markerMouseEnter",e)})),this._marker.addEventListener("mouseleave",(function(){e.plugin.fire("markerMouseLeave",e)})),this._marker.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}if(!this._labelExternal){this._label&&(this._container.removeChild(this._label),this._label=null);var r=this._labelHTML||"

";ae.isArray(r)&&(r=r.join("")),r=this._renderTemplate(r);var i=document.createRange().createContextualFragment(r);this._label=i.firstChild,this._container.appendChild(this._label),this._label.style.visibility=this._markerShown&&this._labelShown?"visible":"hidden",this._label.addEventListener("wheel",(function(t){e.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent("wheel",t))}))}}},{key:"_updatePosition",value:function(){var e=this.scene.canvas.boundary,t=e[0],n=e[1],r=this.canvasPos;this._marker.style.left=Math.floor(t+r[0])-12+"px",this._marker.style.top=Math.floor(n+r[1])-12+"px",this._marker.style["z-index"]=90005+Math.floor(this._viewPos[2])+1;this._label.style.left=20+Math.floor(t+r[0]+20)+"px",this._label.style.top=Math.floor(n+r[1]+-17)+"px",this._label.style["z-index"]=90005+Math.floor(this._viewPos[2])+1}},{key:"_renderTemplate",value:function(e){for(var t in this._values)if(this._values.hasOwnProperty(t)){var n=this._values[t];e=e.replace(new RegExp("{{"+t+"}}","g"),n)}return e}},{key:"setMarkerShown",value:function(e){e=!!e,this._markerShown!==e&&(this._markerShown=e,this._visibilityDirty=!0)}},{key:"getMarkerShown",value:function(){return this._markerShown}},{key:"setLabelShown",value:function(e){e=!!e,this._labelShown!==e&&(this._labelShown=e,this._visibilityDirty=!0)}},{key:"getLabelShown",value:function(){return this._labelShown}},{key:"setField",value:function(e,t){this._values[e]=t||"",this._htmlDirty=!0}},{key:"getField",value:function(e){return this._values[e]}},{key:"setValues",value:function(e){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];this.setField(t,n)}}},{key:"getValues",value:function(){return this._values}},{key:"destroy",value:function(){this._marker&&(this._markerExternal?(this._marker.removeEventListener("click",this._onMouseClickedExternalMarker),this._marker.removeEventListener("mouseenter",this._onMouseEnterExternalMarker),this._marker.removeEventListener("mouseleave",this._onMouseLeaveExternalMarker),this._marker=null):this._marker.parentNode.removeChild(this._marker)),this._label&&(this._labelExternal||this._label.parentNode.removeChild(this._label),this._label=null),this.scene.off(this._onTick),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ke=Z.vec3(),Ye=Z.vec3(),Xe=Z.vec3(),qe=function(e){I(n,z);var t=m(n);function n(e,r){var i;return b(this,n),(i=t.call(this,"Annotations",e))._labelHTML=r.labelHTML||"
",i._markerHTML=r.markerHTML||"
",i._container=r.container||document.body,i._values=r.values||{},i.annotations={},i.surfaceOffset=r.surfaceOffset,i}return P(n,[{key:"getContainerElement",value:function(){return this._container}},{key:"send",value:function(e,t){if("clearAnnotations"===e)this.clear()}},{key:"surfaceOffset",get:function(){return this._surfaceOffset},set:function(e){null==e&&(e=.3),this._surfaceOffset=e}},{key:"createAnnotation",value:function(e){var t,n,r=this;if(this.viewer.scene.components[e.id]&&(this.error("Viewer component with this ID already exists: "+e.id),delete e.id),e.pickResult=e.pickResult||e.pickRecord,e.pickResult){var i=e.pickResult;if(i.worldPos&&i.worldNormal){var a=Z.normalizeVec3(i.worldNormal,Ke),s=Z.mulVec3Scalar(a,this._surfaceOffset,Ye);t=Z.addVec3(i.worldPos,s,Xe),n=i.entity}else this.error("Param 'pickResult' does not have both worldPos and worldNormal")}else t=e.worldPos,n=e.entity;var o=null;e.markerElementId&&((o=document.getElementById(e.markerElementId))||this.error("Can't find DOM element for 'markerElementId' value '"+e.markerElementId+"' - defaulting to internally-generated empty DIV"));var l=null;e.labelElementId&&((l=document.getElementById(e.labelElementId))||this.error("Can't find DOM element for 'labelElementId' value '"+e.labelElementId+"' - defaulting to internally-generated empty DIV"));var u=new ze(this.viewer.scene,{id:e.id,plugin:this,entity:n,worldPos:t,container:this._container,markerElement:o,labelElement:l,markerHTML:e.markerHTML||this._markerHTML,labelHTML:e.labelHTML||this._labelHTML,occludable:e.occludable,values:ae.apply(e.values,ae.apply(this._values,{})),markerShown:e.markerShown,labelShown:e.labelShown,eye:e.eye,look:e.look,up:e.up,projection:e.projection,visible:!1!==e.visible});return this.annotations[u.id]=u,u.on("destroyed",(function(){delete r.annotations[u.id],r.fire("annotationDestroyed",u.id)})),this.fire("annotationCreated",u.id),u}},{key:"destroyAnnotation",value:function(e){var t=this.annotations[e];t?t.destroy():this.log("Annotation not found: "+e)}},{key:"clear",value:function(){for(var e=Object.keys(this.annotations),t=0,n=e.length;t1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._canvas=i.canvas,r._element=null,r._isCustom=!1,i.elementId&&(r._element=document.getElementById(i.elementId),r._element?r._adjustPosition():r.error("Can't find given Spinner HTML element: '"+i.elementId+"' - will automatically create default element")),r._element||r._createDefaultSpinner(),r.processes=0,r}return P(n,[{key:"type",get:function(){return"Spinner"}},{key:"_createDefaultSpinner",value:function(){this._injectDefaultCSS();var e=document.createElement("div"),t=e.style;t["z-index"]="9000",t.position="absolute",e.innerHTML='
',this._canvas.parentElement.appendChild(e),this._element=e,this._isCustom=!1,this._adjustPosition()}},{key:"_injectDefaultCSS",value:function(){var e="xeokit-spinner-css";if(!document.getElementById(e)){var t=document.createElement("style");t.innerHTML=".sk-fading-circle { background: transparent; margin: 20px auto; width: 50px; height:50px; position: relative; } .sk-fading-circle .sk-circle { width: 120%; height: 120%; position: absolute; left: 0; top: 0; } .sk-fading-circle .sk-circle:before { content: ''; display: block; margin: 0 auto; width: 15%; height: 15%; background-color: #ff8800; border-radius: 100%; -webkit-animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; animation: sk-circleFadeDelay 1.2s infinite ease-in-out both; } .sk-fading-circle .sk-circle2 { -webkit-transform: rotate(30deg); -ms-transform: rotate(30deg); transform: rotate(30deg); } .sk-fading-circle .sk-circle3 { -webkit-transform: rotate(60deg); -ms-transform: rotate(60deg); transform: rotate(60deg); } .sk-fading-circle .sk-circle4 { -webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-fading-circle .sk-circle5 { -webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-fading-circle .sk-circle6 { -webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-fading-circle .sk-circle7 { -webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-fading-circle .sk-circle8 { -webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-fading-circle .sk-circle9 { -webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-fading-circle .sk-circle10 { -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-fading-circle .sk-circle11 { -webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-fading-circle .sk-circle12 { -webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-fading-circle .sk-circle2:before { -webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-fading-circle .sk-circle3:before { -webkit-animation-delay: -1s; animation-delay: -1s; } .sk-fading-circle .sk-circle4:before { -webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-fading-circle .sk-circle5:before { -webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-fading-circle .sk-circle6:before { -webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-fading-circle .sk-circle7:before { -webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-fading-circle .sk-circle8:before { -webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-fading-circle .sk-circle9:before { -webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-fading-circle .sk-circle10:before { -webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-fading-circle .sk-circle11:before { -webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-fading-circle .sk-circle12:before { -webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } } @keyframes sk-circleFadeDelay { 0%, 39%, 100% { opacity: 0; } 40% { opacity: 1; } }",t.id=e,document.body.appendChild(t)}}},{key:"_adjustPosition",value:function(){if(!this._isCustom){var e=this._canvas,t=this._element,n=t.style;n.left=e.offsetLeft+.5*e.clientWidth-.5*t.clientWidth+"px",n.top=e.offsetTop+.5*e.clientHeight-.5*t.clientHeight+"px"}}},{key:"processes",get:function(){return this._processes},set:function(e){if(e=e||0,this._processes!==e&&!(e<0)){var t=this._processes;this._processes=e;var n=this._element;n&&(n.style.visibility=this._processes>0?"visible":"hidden"),this.fire("processes",this._processes),0===this._processes&&this._processes!==t&&this.fire("zeroProcesses",this._processes)}}},{key:"_destroy",value:function(){this._element&&!this._isCustom&&(this._element.parentNode.removeChild(this._element),this._element=null);var e=document.getElementById("xeokit-spinner-css");e&&e.parentNode.removeChild(e)}}]),n}(),Ze={WEBGL:!1,SUPPORTED_EXTENSIONS:{}},$e=document.createElement("canvas");if($e){var et=$e.getContext("webgl",{antialias:!0})||$e.getContext("experimental-webgl",{antialias:!0});Ze.WEBGL=!!et,Ze.WEBGL&&(Ze.ANTIALIAS=et.getContextAttributes().antialias,et.getShaderPrecisionFormat?et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.HIGH_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="highp":et.getShaderPrecisionFormat(et.FRAGMENT_SHADER,et.MEDIUM_FLOAT).precision>0?Ze.FS_MAX_FLOAT_PRECISION="mediump":Ze.FS_MAX_FLOAT_PRECISION="lowp":Ze.FS_MAX_FLOAT_PRECISION="mediump",Ze.DEPTH_BUFFER_BITS=et.getParameter(et.DEPTH_BITS),Ze.MAX_TEXTURE_SIZE=et.getParameter(et.MAX_TEXTURE_SIZE),Ze.MAX_CUBE_MAP_SIZE=et.getParameter(et.MAX_CUBE_MAP_TEXTURE_SIZE),Ze.MAX_RENDERBUFFER_SIZE=et.getParameter(et.MAX_RENDERBUFFER_SIZE),Ze.MAX_TEXTURE_UNITS=et.getParameter(et.MAX_COMBINED_TEXTURE_IMAGE_UNITS),Ze.MAX_TEXTURE_IMAGE_UNITS=et.getParameter(et.MAX_TEXTURE_IMAGE_UNITS),Ze.MAX_VERTEX_ATTRIBS=et.getParameter(et.MAX_VERTEX_ATTRIBS),Ze.MAX_VERTEX_UNIFORM_VECTORS=et.getParameter(et.MAX_VERTEX_UNIFORM_VECTORS),Ze.MAX_FRAGMENT_UNIFORM_VECTORS=et.getParameter(et.MAX_FRAGMENT_UNIFORM_VECTORS),Ze.MAX_VARYING_VECTORS=et.getParameter(et.MAX_VARYING_VECTORS),et.getSupportedExtensions().forEach((function(e){Ze.SUPPORTED_EXTENSIONS[e]=!0})))}var tt=["webgl2","experimental-webgl","webkit-3d","moz-webgl","moz-glweb20"],nt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._backgroundColor=Z.vec3([i.backgroundColor?i.backgroundColor[0]:1,i.backgroundColor?i.backgroundColor[1]:1,i.backgroundColor?i.backgroundColor[2]:1]),r._backgroundColorFromAmbientLight=!!i.backgroundColorFromAmbientLight,r.canvas=i.canvas,r.gl=null,r.webgl2=!1,r.transparent=!!i.transparent,r.contextAttr=i.contextAttr||{},r.contextAttr.alpha=r.transparent,r.contextAttr.preserveDrawingBuffer=!!r.contextAttr.preserveDrawingBuffer,r.contextAttr.stencil=!1,r.contextAttr.premultipliedAlpha=!!r.contextAttr.premultipliedAlpha,r.contextAttr.antialias=!1!==r.contextAttr.antialias,r.resolutionScale=i.resolutionScale,r.canvas.width=Math.round(r.canvas.clientWidth*r._resolutionScale),r.canvas.height=Math.round(r.canvas.clientHeight*r._resolutionScale),r.boundary=[r.canvas.offsetLeft,r.canvas.offsetTop,r.canvas.clientWidth,r.canvas.clientHeight],r._initWebGL(i);var a=g(r);r.canvas.addEventListener("webglcontextlost",r._webglcontextlostListener=function(e){console.time("webglcontextrestored"),a.scene._webglContextLost(),a.fire("webglcontextlost"),e.preventDefault()},!1),r.canvas.addEventListener("webglcontextrestored",r._webglcontextrestoredListener=function(e){a._initWebGL(),a.gl&&(a.scene._webglContextRestored(a.gl),a.fire("webglcontextrestored",a.gl),e.preventDefault()),console.timeEnd("webglcontextrestored")},!1);var s=!0,o=new ResizeObserver((function(e){var t,n=f(e);try{for(n.s();!(t=n.n()).done;){t.value.contentBoxSize&&(s=!0)}}catch(e){n.e(e)}finally{n.f()}}));return o.observe(r.canvas),r._tick=r.scene.on("tick",(function(){s&&(s=!1,a.canvas.width=Math.round(a.canvas.clientWidth*a._resolutionScale),a.canvas.height=Math.round(a.canvas.clientHeight*a._resolutionScale),a.boundary[0]=a.canvas.offsetLeft,a.boundary[1]=a.canvas.offsetTop,a.boundary[2]=a.canvas.clientWidth,a.boundary[3]=a.canvas.clientHeight,a.fire("boundary",a.boundary))})),r._spinner=new Je(r.scene,{canvas:r.canvas,elementId:i.spinnerElementId}),r}return P(n,[{key:"type",get:function(){return"Canvas"}},{key:"backgroundColorFromAmbientLight",get:function(){return this._backgroundColorFromAmbientLight},set:function(e){this._backgroundColorFromAmbientLight=!1!==e,this.glRedraw()}},{key:"backgroundColor",get:function(){return this._backgroundColor},set:function(e){e?(this._backgroundColor[0]=e[0],this._backgroundColor[1]=e[1],this._backgroundColor[2]=e[2]):(this._backgroundColor[0]=1,this._backgroundColor[1]=1,this._backgroundColor[2]=1),this.glRedraw()}},{key:"resolutionScale",get:function(){return this._resolutionScale},set:function(e){if((e=e||1)!==this._resolutionScale){this._resolutionScale=e;var t=this.canvas;t.width=Math.round(t.clientWidth*this._resolutionScale),t.height=Math.round(t.clientHeight*this._resolutionScale),this.glRedraw()}}},{key:"spinner",get:function(){return this._spinner}},{key:"_createCanvas",value:function(){var e="xeokit-canvas-"+Z.createUUID(),t=document.getElementsByTagName("body")[0],n=document.createElement("div"),r=n.style;r.height="100%",r.width="100%",r.padding="0",r.margin="0",r.background="rgba(0,0,0,0);",r.float="left",r.left="0",r.top="0",r.position="absolute",r.opacity="1.0",r["z-index"]="-10000",n.innerHTML+='',t.appendChild(n),this.canvas=document.getElementById(e)}},{key:"_getElementXY",value:function(e){for(var t=0,n=0;e;)t+=e.offsetLeft-e.scrollLeft,n+=e.offsetTop-e.scrollTop,e=e.offsetParent;return{x:t,y:n}}},{key:"_initWebGL",value:function(){if(!this.gl)for(var e=0;!this.gl&&e0&&"/"===t.charAt(n+1)&&(t=t.substring(0,n)),r.push(t);return r.join("\n")}function ct(e){console.error(e.join("\n"))}var ft=function(){function e(t,n){b(this,e),this.id=lt.addItem({}),this.source=n,this.init(t)}return P(e,[{key:"init",value:function(e){if(this.gl=e,this.allocated=!1,this.compiled=!1,this.linked=!1,this.validated=!1,this.errors=null,this.uniforms={},this.samplers={},this.attributes={},this._vertexShader=new at(e,e.VERTEX_SHADER,ut(this.source.vertex)),this._fragmentShader=new at(e,e.FRAGMENT_SHADER,ut(this.source.fragment)),!this._vertexShader.allocated)return this.errors=["Vertex shader failed to allocate"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.allocated)return this.errors=["Fragment shader failed to allocate"].concat(this._fragmentShader.errors),void ct(this.errors);if(this.allocated=!0,!this._vertexShader.compiled)return this.errors=["Vertex shader failed to compile"].concat(this._vertexShader.errors),void ct(this.errors);if(!this._fragmentShader.compiled)return this.errors=["Fragment shader failed to compile"].concat(this._fragmentShader.errors),void ct(this.errors);var t,n,r,i,a;if(this.compiled=!0,this.handle=e.createProgram(),this.handle){if(e.attachShader(this.handle,this._vertexShader.handle),e.attachShader(this.handle,this._fragmentShader.handle),e.linkProgram(this.handle),this.linked=e.getProgramParameter(this.handle,e.LINK_STATUS),this.validated=!0,!this.linked||!this.validated)return this.errors=[],this.errors.push(""),this.errors.push(e.getProgramInfoLog(this.handle)),this.errors.push("\nVertex shader:\n"),this.errors=this.errors.concat(this.source.vertex),this.errors.push("\nFragment shader:\n"),this.errors=this.errors.concat(this.source.fragment),void ct(this.errors);var s=e.getProgramParameter(this.handle,e.ACTIVE_UNIFORMS);for(n=0;nthis.dataLength?e.slice(0,this.dataLength):e,this.usage),this._gl.bindBuffer(this.type,null),this.length=e.length,this.numItems=this.length/this.itemSize,this.allocated=!0)}},{key:"setData",value:function(e,t){this.allocated&&(e.length+(t||0)>this.length?(this.destroy(),this._allocate(e)):(this._gl.bindBuffer(this.type,this._handle),t||0===t?this._gl.bufferSubData(this.type,t*this.itemByteSize,e):this._gl.bufferData(this.type,e,this.usage),this._gl.bindBuffer(this.type,null)))}},{key:"bind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,this._handle)}},{key:"unbind",value:function(){this.allocated&&this._gl.bindBuffer(this.type,null)}},{key:"destroy",value:function(){this.allocated&&(this._gl.deleteBuffer(this._handle),this._handle=null,this.allocated=!1)}}]),e}(),At=function(){function e(t,n){b(this,e),this.scene=t,this.aabb=Z.AABB3(),this.origin=Z.vec3(n),this.originHash=this.origin.join(),this.numMarkers=0,this.markers={},this.markerList=[],this.markerIndices={},this.positions=[],this.indices=[],this.positionsBuf=null,this.lenPositionsBuf=0,this.indicesBuf=null,this.sectionPlanesActive=[],this.culledBySectionPlanes=!1,this.occlusionTestList=[],this.lenOcclusionTestList=0,this.pixels=[],this.aabbDirty=!1,this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!1}return P(e,[{key:"addMarker",value:function(e){this.markers[e.id]=e,this.markerListDirty=!0,this.numMarkers++}},{key:"markerWorldPosUpdated",value:function(e){if(this.markers[e.id]){var t=this.markerIndices[e.id];this.positions[3*t+0]=e.worldPos[0],this.positions[3*t+1]=e.worldPos[1],this.positions[3*t+2]=e.worldPos[2],this.positionsDirty=!0}}},{key:"removeMarker",value:function(e){delete this.markers[e.id],this.markerListDirty=!0,this.numMarkers--}},{key:"update",value:function(){this.markerListDirty&&(this._buildMarkerList(),this.markerListDirty=!1,this.positionsDirty=!0,this.occlusionTestListDirty=!0),this.positionsDirty&&(this._buildPositions(),this.positionsDirty=!1,this.aabbDirty=!0,this.vbosDirty=!0),this.aabbDirty&&(this._buildAABB(),this.aabbDirty=!1),this.vbosDirty&&(this._buildVBOs(),this.vbosDirty=!1),this.occlusionTestListDirty&&this._buildOcclusionTestList(),this._updateActiveSectionPlanes()}},{key:"_buildMarkerList",value:function(){for(var e in this.numMarkers=0,this.markers)this.markers.hasOwnProperty(e)&&(this.markerList[this.numMarkers]=this.markers[e],this.markerIndices[e]=this.numMarkers,this.numMarkers++);this.markerList.length=this.numMarkers}},{key:"_buildPositions",value:function(){for(var e=0,t=0;t-t)o._setVisible(!1);else{var l=o.canvasPos,u=l[0],c=l[1];u+10<0||c+10<0||u-10>r||c-10>i?o._setVisible(!1):!o.entity||o.entity.visible?o.occludable?(this.occlusionTestList[this.lenOcclusionTestList++]=o,this.pixels[a++]=u,this.pixels[a++]=c):o._setVisible(!0):o._setVisible(!1)}}}},{key:"_updateActiveSectionPlanes",value:function(){var e=this.scene._sectionPlanesState.sectionPlanes,t=e.length;if(t>0)for(var n=0;n0,n=[];return n.push("#version 300 es"),n.push("// OcclusionTester vertex shader"),n.push("in vec3 position;"),n.push("uniform mat4 modelMatrix;"),n.push("uniform mat4 viewMatrix;"),n.push("uniform mat4 projMatrix;"),e.logarithmicDepthBufferEnabled&&(n.push("uniform float logDepthBufFC;"),n.push("out float vFragDepth;")),t&&n.push("out vec4 vWorldPosition;"),n.push("void main(void) {"),n.push("vec4 worldPosition = vec4(position, 1.0); "),n.push(" vec4 viewPosition = viewMatrix * worldPosition;"),t&&n.push(" vWorldPosition = worldPosition;"),n.push(" vec4 clipPos = projMatrix * viewPosition;"),n.push(" gl_PointSize = 20.0;"),e.logarithmicDepthBufferEnabled?n.push("vFragDepth = 1.0 + clipPos.w;"):n.push("clipPos.z += -0.001;"),n.push(" gl_Position = clipPos;"),n.push("}"),n}},{key:"_buildFragmentShaderSource",value:function(){var e=this._scene,t=e._sectionPlanesState,n=t.sectionPlanes.length>0,r=[];if(r.push("#version 300 es"),r.push("// OcclusionTester fragment shader"),r.push("#ifdef GL_FRAGMENT_PRECISION_HIGH"),r.push("precision highp float;"),r.push("precision highp int;"),r.push("#else"),r.push("precision mediump float;"),r.push("precision mediump int;"),r.push("#endif"),e.logarithmicDepthBufferEnabled&&(r.push("uniform float logDepthBufFC;"),r.push("in float vFragDepth;")),n){r.push("in vec4 vWorldPosition;");for(var i=0;i 0.0) { discard; }")}return e.logarithmicDepthBufferEnabled&&r.push("gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;"),r.push(" outColor = vec4(1.0, 0.0, 0.0, 1.0); "),r.push("}"),r}},{key:"_buildProgram",value:function(){this._program&&this._program.destroy();var e=this._scene,t=e.canvas.gl,n=e._sectionPlanesState;if(this._program=new ft(t,this._shaderSource),this._program.errors)this.errors=this._program.errors;else{var r=this._program;this._uViewMatrix=r.getLocation("viewMatrix"),this._uProjMatrix=r.getLocation("projMatrix"),this._uSectionPlanes=[];for(var i=0,a=n.sectionPlanes.length;i0)for(var p=r.sectionPlanes,A=0;A= ( 1.0 - EPSILON ) ) {\n \t\t\tcontinue;\n \t\t}\n\n \t\tfloat sampleViewZ = getViewZ( sampleDepth );\n \t\tvec3 sampleViewPosition = getViewPos( sampleUv, sampleDepth, sampleViewZ );\n \t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n \t\tweightSum += 1.0;\n \t}\n\n \tif( weightSum == 0.0 ) discard;\n\n \treturn occlusionSum * ( uIntensity / weightSum );\n }\n\n out vec4 outColor;\n \n void main() {\n \n \tfloat centerDepth = getDepth( vUV );\n \t\n \tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n \t\tdiscard;\n \t}\n\n \tfloat centerViewZ = getViewZ( centerDepth );\n \tvec3 viewPosition = getViewPos( vUV, centerDepth, centerViewZ );\n\n \tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n \n \toutColor = packFloatToRGBA( 1.0- ambientOcclusion );\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var r=new Float32Array([1,1,0,1,0,0,1,0]),i=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),a=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(n,n.ARRAY_BUFFER,i,i.length,3,n.STATIC_DRAW),this._uvBuf=new pt(n,n.ARRAY_BUFFER,r,r.length,2,n.STATIC_DRAW),this._indicesBuf=new pt(n,n.ELEMENT_ARRAY_BUFFER,a,a.length,1,n.STATIC_DRAW),this._program.bind(),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uCameraProjectionMatrix=this._program.getLocation("uProjectMatrix"),this._uCameraInverseProjectionMatrix=this._program.getLocation("uInverseProjectMatrix"),this._uPerspective=this._program.getLocation("uPerspective"),this._uScale=this._program.getLocation("uScale"),this._uIntensity=this._program.getLocation("uIntensity"),this._uBias=this._program.getLocation("uBias"),this._uKernelRadius=this._program.getLocation("uKernelRadius"),this._uMinResolution=this._program.getLocation("uMinResolution"),this._uViewport=this._program.getLocation("uViewport"),this._uRandomSeed=this._program.getLocation("uRandomSeed"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV"),this._dirty=!1}}},{key:"destroy",value:function(){this._program&&(this._program.destroy(),this._program=null)}}]),e}(),mt=new Float32Array(Dt(17,[0,1])),wt=new Float32Array(Dt(17,[1,0])),gt=new Float32Array(function(e,t){for(var n=[],r=0;r<=e;r++)n.push(bt(r,t));return n}(17,4)),Tt=new Float32Array(2),Et=function(){function e(t){b(this,e),this._scene=t,this._program=null,this._programError=!1,this._aPosition=null,this._aUV=null,this._uDepthTexture="uDepthTexture",this._uOcclusionTexture="uOcclusionTexture",this._uViewport=null,this._uCameraNear=null,this._uCameraFar=null,this._uCameraProjectionMatrix=null,this._uCameraInverseProjectionMatrix=null,this._uvBuf=null,this._positionsBuf=null,this._indicesBuf=null,this.init()}return P(e,[{key:"init",value:function(){var e=this._scene.canvas.gl;if(this._program=new ft(e,{vertex:["#version 300 es\n precision highp float;\n precision highp int;\n \n in vec3 aPosition;\n in vec2 aUV;\n uniform vec2 uViewport;\n out vec2 vUV;\n out vec2 vInvSize;\n void main () {\n vUV = aUV;\n vInvSize = 1.0 / uViewport;\n gl_Position = vec4(aPosition, 1.0);\n }"],fragment:["#version 300 es\n precision highp float;\n precision highp int;\n \n #define PI 3.14159265359\n #define PI2 6.28318530718\n #define EPSILON 1e-6\n\n #define KERNEL_RADIUS ".concat(16,"\n\n in vec2 vUV;\n in vec2 vInvSize;\n \n uniform sampler2D uDepthTexture;\n uniform sampler2D uOcclusionTexture; \n \n uniform float uCameraNear;\n uniform float uCameraFar; \n uniform float uDepthCutoff;\n\n uniform vec2 uSampleOffsets[ KERNEL_RADIUS + 1 ];\n uniform float uSampleWeights[ KERNEL_RADIUS + 1 ];\n\n const float unpackDownscale = 255. / 256.; \n\n const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\n const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. ); \n\n const float packUpscale = 256. / 255.;\n \n const float shiftRights = 1. / 256.;\n \n float unpackRGBAToFloat( const in vec4 v ) {\n return dot( floor( v * 255.0 + 0.5 ) / 255.0, unpackFactors );\n } \n\n vec4 packFloatToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * packFactors ), v );\n r.yzw -= r.xyz * shiftRights; \n return r * packUpscale;\n }\n\n float viewZToOrthographicDepth( const in float viewZ) {\n return ( viewZ + uCameraNear ) / ( uCameraNear - uCameraFar );\n }\n \n float orthographicDepthToViewZ( const in float linearClipZ) {\n return linearClipZ * ( uCameraNear - uCameraFar ) - uCameraNear;\n }\n\n float viewZToPerspectiveDepth( const in float viewZ) {\n return (( uCameraNear + viewZ ) * uCameraFar ) / (( uCameraFar - uCameraNear ) * viewZ );\n }\n \n float perspectiveDepthToViewZ( const in float invClipZ) {\n return ( uCameraNear * uCameraFar ) / ( ( uCameraFar - uCameraNear ) * invClipZ - uCameraFar );\n }\n\n float getDepth( const in vec2 screenPosition ) {\n return vec4(texture(uDepthTexture, screenPosition)).r;\n }\n\n float getViewZ( const in float depth ) {\n return perspectiveDepthToViewZ( depth );\n }\n\n out vec4 outColor;\n \n void main() {\n \n float depth = getDepth( vUV );\n if( depth >= ( 1.0 - EPSILON ) ) {\n discard;\n }\n\n float centerViewZ = -getViewZ( depth );\n bool rBreak = false;\n bool lBreak = false;\n\n float weightSum = uSampleWeights[0];\n float occlusionSum = unpackRGBAToFloat(texture( uOcclusionTexture, vUV )) * weightSum;\n\n for( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n float sampleWeight = uSampleWeights[i];\n vec2 sampleUVOffset = uSampleOffsets[i] * vInvSize;\n\n vec2 sampleUV = vUV + sampleUVOffset;\n float viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n rBreak = true;\n }\n\n if( ! rBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n\n sampleUV = vUV - sampleUVOffset;\n viewZ = -getViewZ( getDepth( sampleUV ) );\n\n if( abs( viewZ - centerViewZ ) > uDepthCutoff ) {\n lBreak = true;\n }\n\n if( ! lBreak ) {\n occlusionSum += unpackRGBAToFloat(texture( uOcclusionTexture, sampleUV )) * sampleWeight;\n weightSum += sampleWeight;\n }\n }\n\n outColor = packFloatToRGBA(occlusionSum / weightSum);\n }")]}),this._program.errors)return console.error(this._program.errors.join("\n")),void(this._programError=!0);var t=new Float32Array([1,1,0,1,0,0,1,0]),n=new Float32Array([1,1,0,-1,1,0,-1,-1,0,1,-1,0]),r=new Uint32Array([0,1,2,0,2,3]);this._positionsBuf=new pt(e,e.ARRAY_BUFFER,n,n.length,3,e.STATIC_DRAW),this._uvBuf=new pt(e,e.ARRAY_BUFFER,t,t.length,2,e.STATIC_DRAW),this._indicesBuf=new pt(e,e.ELEMENT_ARRAY_BUFFER,r,r.length,1,e.STATIC_DRAW),this._program.bind(),this._uViewport=this._program.getLocation("uViewport"),this._uCameraNear=this._program.getLocation("uCameraNear"),this._uCameraFar=this._program.getLocation("uCameraFar"),this._uDepthCutoff=this._program.getLocation("uDepthCutoff"),this._uSampleOffsets=e.getUniformLocation(this._program.handle,"uSampleOffsets"),this._uSampleWeights=e.getUniformLocation(this._program.handle,"uSampleWeights"),this._aPosition=this._program.getAttribute("aPosition"),this._aUV=this._program.getAttribute("aUV")}},{key:"render",value:function(e,t,n){var r=this;if(!this._programError){this._getInverseProjectMat||(this._getInverseProjectMat=function(){var e=!0;r._scene.camera.on("projMatrix",(function(){e=!0}));var t=Z.mat4();return function(){return e&&Z.inverseMat4(s.camera.projMatrix,t),t}}());var i=this._scene.canvas.gl,a=this._program,s=this._scene,o=i.drawingBufferWidth,l=i.drawingBufferHeight,u=s.camera.project._state,c=u.near,f=u.far;i.viewport(0,0,o,l),i.clearColor(0,0,0,1),i.enable(i.DEPTH_TEST),i.disable(i.BLEND),i.frontFace(i.CCW),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),a.bind(),Tt[0]=o,Tt[1]=l,i.uniform2fv(this._uViewport,Tt),i.uniform1f(this._uCameraNear,c),i.uniform1f(this._uCameraFar,f),i.uniform1f(this._uDepthCutoff,.01),0===n?i.uniform2fv(this._uSampleOffsets,wt):i.uniform2fv(this._uSampleOffsets,mt),i.uniform1fv(this._uSampleWeights,gt);var p=e.getDepthTexture(),A=t.getTexture();a.bindTexture(this._uDepthTexture,p,0),a.bindTexture(this._uOcclusionTexture,A,1),this._aUV.bindArrayBuffer(this._uvBuf),this._aPosition.bindArrayBuffer(this._positionsBuf),this._indicesBuf.bind(),i.drawElements(i.TRIANGLES,this._indicesBuf.numItems,this._indicesBuf.itemType,0)}}},{key:"destroy",value:function(){this._program.destroy()}}]),e}();function bt(e,t){return Math.exp(-e*e/(t*t*2))/(Math.sqrt(2*Math.PI)*t)}function Dt(e,t){for(var n=[],r=0;r<=e;r++)n.push(t[0]*r),n.push(t[1]*r);return n}var Pt=function(){function e(t,n,r){b(this,e),r=r||{},this.gl=n,this.allocated=!1,this.canvas=t,this.buffer=null,this.bound=!1,this.size=r.size,this._hasDepthTexture=!!r.depthTexture}return P(e,[{key:"setSize",value:function(e){this.size=e}},{key:"webglContextRestored",value:function(e){this.gl=e,this.buffer=null,this.allocated=!1,this.bound=!1}},{key:"bind",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if(this._touch(e),!this.bound){var t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,this.buffer.framebuf),this.bound=!0}}},{key:"_touch",value:function(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=this.gl;if(this.size?(e=this.size[0],t=this.size[1]):(e=r.drawingBufferWidth,t=r.drawingBufferHeight),this.buffer){if(this.buffer.width===e&&this.buffer.height===t)return;r.deleteTexture(this.buffer.texture),r.deleteFramebuffer(this.buffer.framebuf),r.deleteRenderbuffer(this.buffer.renderbuf)}var i,a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),n?r.texStorage2D(r.TEXTURE_2D,1,n,e,t):r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),this._hasDepthTexture&&(i=r.createTexture(),r.bindTexture(r.TEXTURE_2D,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.DEPTH_COMPONENT32F,e,t,0,r.DEPTH_COMPONENT,r.FLOAT,null));var s=r.createRenderbuffer();r.bindRenderbuffer(r.RENDERBUFFER,s),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT32F,e,t);var o=r.createFramebuffer();if(r.bindFramebuffer(r.FRAMEBUFFER,o),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,a,0),this._hasDepthTexture?r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,i,0):r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,s),r.bindTexture(r.TEXTURE_2D,null),r.bindRenderbuffer(r.RENDERBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.FRAMEBUFFER,o),!r.isFramebuffer(o))throw"Invalid framebuffer";r.bindFramebuffer(r.FRAMEBUFFER,null);var l=r.checkFramebufferStatus(r.FRAMEBUFFER);switch(l){case r.FRAMEBUFFER_COMPLETE:break;case r.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case r.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:throw"Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case r.FRAMEBUFFER_UNSUPPORTED:throw"Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED";default:throw"Incomplete framebuffer: "+l}this.buffer={framebuf:o,renderbuf:s,texture:a,depthTexture:i,width:e,height:t},this.bound=!1}},{key:"clear",value:function(){if(!this.bound)throw"Render buffer not bound";var e=this.gl;e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}},{key:"read",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:Uint8Array,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,s=e,o=(this.buffer.height||this.gl.drawingBufferHeight)-t,l=new i(a),u=this.gl;return u.readPixels(s,o,1,1,n||u.RGBA,r||u.UNSIGNED_BYTE,l,0),l}},{key:"readArray",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Uint8Array,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:4,i=new n(this.buffer.width*this.buffer.height*r),a=this.gl;return a.readPixels(0,0,this.buffer.width,this.buffer.height,e||a.RGBA,t||a.UNSIGNED_BYTE,i,0),i}},{key:"readImageAsCanvas",value:function(){var e=this.gl,t=this._getImageDataCache(),n=t.pixelData,r=t.canvas,i=t.imageData,a=t.context;e.readPixels(0,0,this.buffer.width,this.buffer.height,e.RGBA,e.UNSIGNED_BYTE,n);for(var s=this.buffer.width,o=this.buffer.height,l=o/2|0,u=4*s,c=new Uint8Array(4*s),f=0;f0&&void 0!==arguments[0]?arguments[0]:Uint8Array,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,n=this.buffer.width,r=this.buffer.height,i=this._imageDataCache;if(i&&(i.width===n&&i.height===r||(this._imageDataCache=null,i=null)),!i){var a=document.createElement("canvas"),s=a.getContext("2d");a.width=n,a.height=r,i={pixelData:new e(n*r*t),canvas:a,context:s,imageData:s.createImageData(n,r),width:n,height:r},this._imageDataCache=i}return i.context.resetTransform(),i}},{key:"unbind",value:function(){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.bound=!1}},{key:"getTexture",value:function(){var e=this;return this._texture||(this._texture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.texture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.texture),!0)},unbind:function(t){e.buffer&&e.buffer.texture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"hasDepthTexture",value:function(){return this._hasDepthTexture}},{key:"getDepthTexture",value:function(){if(!this._hasDepthTexture)return null;var e=this;return this._depthTexture||(this._dethTexture={renderBuffer:this,bind:function(t){return!(!e.buffer||!e.buffer.depthTexture)&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,e.buffer.depthTexture),!0)},unbind:function(t){e.buffer&&e.buffer.depthTexture&&(e.gl.activeTexture(e.gl["TEXTURE"+t]),e.gl.bindTexture(e.gl.TEXTURE_2D,null))}})}},{key:"destroy",value:function(){if(this.allocated){var e=this.gl;e.deleteTexture(this.buffer.texture),e.deleteTexture(this.buffer.depthTexture),e.deleteFramebuffer(this.buffer.framebuf),e.deleteRenderbuffer(this.buffer.renderbuf),this.allocated=!1,this.buffer=null,this.bound=!1}this._imageDataCache=null,this._texture=null,this._depthTexture=null}}]),e}(),Rt=function(){function e(t){b(this,e),this.scene=t,this._renderBuffersBasic={},this._renderBuffersScaled={}}return P(e,[{key:"getRenderBuffer",value:function(e,t){var n=1===this.scene.canvas.resolutionScale?this._renderBuffersBasic:this._renderBuffersScaled,r=n[e];return r||(r=new Pt(this.scene.canvas.canvas,this.scene.canvas.gl,t),n[e]=r),r}},{key:"destroy",value:function(){for(var e in this._renderBuffersBasic)this._renderBuffersBasic[e].destroy();for(var t in this._renderBuffersScaled)this._renderBuffersScaled[t].destroy()}}]),e}();function Ct(e,t){if(void 0===e._cachedExtensions&&(e._cachedExtensions={}),void 0!==e._cachedExtensions[t])return e._cachedExtensions[t];var n;switch(t){case"WEBGL_depth_texture":n=e.getExtension("WEBGL_depth_texture")||e.getExtension("MOZ_WEBGL_depth_texture")||e.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=e.getExtension("EXT_texture_filter_anisotropic")||e.getExtension("MOZ_EXT_texture_filter_anisotropic")||e.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=e.getExtension(t)}return e._cachedExtensions[t]=n,n}var _t=function(e,t){t=t||{};var n=new rt(e),r=e.canvas.canvas,i=e.canvas.gl,a=!!t.transparent,s=t.alphaDepthMask,o=new G({}),l={},u={},c=!0,f=!0,p=!0,A=!0,d=!0,v=!0,h=!0,I=!0,y=new Rt(e),m=!1,w=new yt(e),g=new Et(e);function T(){c&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e],n=t.drawableMap,r=t.drawableListPreCull,i=0;for(var a in n)n.hasOwnProperty(a)&&(r[i++]=n[a]);r.length=i}}(),c=!1,f=!0),f&&(!function(){for(var e in l)if(l.hasOwnProperty(e)){var t=l[e];t.isStateSortable&&t.drawableListPreCull.sort(t.stateSortCompare)}}(),f=!1,p=!0),p&&function(){for(var e in l)if(l.hasOwnProperty(e)){for(var t=l[e],n=t.drawableListPreCull,r=t.drawableList,i=0,a=0,s=n.length;a0)for(n.withSAO=!0,O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||Q>0||U>0||G>0){if(i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):(i.blendEquation(i.FUNC_ADD),i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA)),n.backfaces=!1,s||i.depthMask(!1),(U>0||G>0)&&i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),G>0)for(O=0;O0)for(O=0;O0)for(O=0;O0)for(O=0;O0||z>0){if(n.lastProgramId=null,e.highlightMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),z>0)for(O=0;O0)for(O=0;O0||Y>0||W>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),i.enable(i.CULL_FACE),Y>0)for(O=0;O0)for(O=0;O0||q>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),q>0)for(O=0;O0)for(O=0;O0||Z>0){if(n.lastProgramId=null,e.selectedMaterial.glowThrough&&i.clear(i.DEPTH_BUFFER_BIT),i.enable(i.CULL_FACE),i.enable(i.BLEND),a?(i.blendEquation(i.FUNC_ADD),i.blendFuncSeparate(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)):i.blendFunc(i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA),Z>0)for(O=0;O0)for(O=0;O1&&void 0!==arguments[1]?arguments[1]:o;v.reset(),T();var h=null,I=null;if(v.pickSurface=A.pickSurface,A.canvasPos)c[0]=A.canvasPos[0],c[1]=A.canvasPos[1],h=e.camera.viewMatrix,I=e.camera.projMatrix,v.canvasPos=A.canvasPos;else{var m=Z.frustumMat4(-1,1,-1,1,.01,e.camera.project.far,n);A.matrix?(h=A.matrix,I=m):(f.set(A.origin||[0,0,0]),p.set(A.direction||[0,0,1]),d=Z.addVec3(f,p,t),a[0]=Math.random(),a[1]=Math.random(),a[2]=Math.random(),Z.normalizeVec3(a),Z.cross3Vec3(p,a,s),h=Z.lookAtMat4v(f,d,s,i),I=m,v.origin=f,v.direction=p),c[0]=.5*r.clientWidth,c[1]=.5*r.clientHeight}for(var w in l)if(l.hasOwnProperty(w))for(var g=l[w].drawableList,E=0,R=g.length;E1&&void 0!==arguments[1]?arguments[1]:50,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"vertex";n.reset(),n.backfaces=!0,n.frontface=!0,n.pickZNear=e.camera.project.near,n.pickZFar=e.camera.project.far;var s=y.getRenderBuffer("uniquePickColors-aabs",{depthTexture:!0,size:[2*r+1,2*r+1]});n.snapVectorA=[_(t[0],i.drawingBufferWidth),B(t[1],i.drawingBufferHeight)],n.snapInvVectorAB=[i.drawingBufferWidth/(2*r),i.drawingBufferHeight/(2*r)],n.snapMode=a,s.bind(i.RGBA32I),i.viewport(0,0,s.size[0],s.size[1]),i.enable(i.DEPTH_TEST),i.frontFace(i.CCW),i.disable(i.CULL_FACE),i.depthMask(!0),i.disable(i.BLEND),i.depthFunc(i.LESS),i.clear(i.DEPTH_BUFFER_BIT),i.clearBufferiv(i.COLOR,0,new Int32Array([0,0,0,0]));var o=e.camera.viewMatrix,u=e.camera.projMatrix;for(var c in l)if(l.hasOwnProperty(c))for(var f=l[c].drawableList,p=0,A=f.length;p0){var N=Math.floor(S/4),L=s.size[0];s.size[1];var x=N%L-Math.floor(L/2),M=Math.floor(N/L)-Math.floor(L/2),F=Math.sqrt(Math.pow(x,2)+Math.pow(M,2));O.push({x:x,y:M,dist:F,result:[I[S+0],I[S+1],I[S+2],I[S+3]]})}var H=null;if(O.length>0){O.sort((function(e,t){return e.dist-t.dist}));var U=h[(O=O[0].result)[3]],G=U.origin,k=U.coordinateScale;H=[O[0]*k[0]+G[0],O[1]*k[1]+G[1],O[2]*k[2]+G[2]]}if(null===m&&null==H)return null;var V=null;return null!==H&&(V=e.camera.projectWorldPos(H)),{worldPos:m,snappedWorldPos:H,snappedCanvasPos:V}},this.addMarker=function(t){this._occlusionTester=this._occlusionTester||new ht(e,y),this._occlusionTester.addMarker(t),e.occlusionTestCountdown=0},this.markerWorldPosUpdated=function(e){this._occlusionTester.markerWorldPosUpdated(e)},this.removeMarker=function(e){this._occlusionTester.removeMarker(e)},this.doOcclusionTest=function(){if(this._occlusionTester&&this._occlusionTester.needOcclusionTest){for(var e in T(),this._occlusionTester.bindRenderBuf(),n.reset(),n.backfaces=!0,n.frontface=!0,i.viewport(0,0,i.drawingBufferWidth,i.drawingBufferHeight),i.clearColor(0,0,0,0),i.enable(i.DEPTH_TEST),i.disable(i.CULL_FACE),i.disable(i.BLEND),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),l)if(l.hasOwnProperty(e))for(var t=l[e].drawableList,r=0,a=t.length;r0&&void 0!==arguments[0]?arguments[0]:{},t=y.getRenderBuffer("snapshot");e.width&&e.height&&t.setSize([e.width,e.height]),t.bind(),t.clear(),m=!0},this.renderSnapshot=function(){m&&(y.getRenderBuffer("snapshot").clear(),this.render({force:!0,opaqueOnly:!1}),p=!0)},this.readSnapshot=function(e){return y.getRenderBuffer("snapshot").readImage(e)},this.readSnapshotAsCanvas=function(){return y.getRenderBuffer("snapshot").readImageAsCanvas()},this.endSnapshot=function(){m&&(y.getRenderBuffer("snapshot").unbind(),m=!1)},this.destroy=function(){l={},u={},y.destroy(),w.destroy(),g.destroy(),this._occlusionTester&&this._occlusionTester.destroy()}},Bt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).KEY_BACKSPACE=8,r.KEY_TAB=9,r.KEY_ENTER=13,r.KEY_SHIFT=16,r.KEY_CTRL=17,r.KEY_ALT=18,r.KEY_PAUSE_BREAK=19,r.KEY_CAPS_LOCK=20,r.KEY_ESCAPE=27,r.KEY_PAGE_UP=33,r.KEY_PAGE_DOWN=34,r.KEY_END=35,r.KEY_HOME=36,r.KEY_LEFT_ARROW=37,r.KEY_UP_ARROW=38,r.KEY_RIGHT_ARROW=39,r.KEY_DOWN_ARROW=40,r.KEY_INSERT=45,r.KEY_DELETE=46,r.KEY_NUM_0=48,r.KEY_NUM_1=49,r.KEY_NUM_2=50,r.KEY_NUM_3=51,r.KEY_NUM_4=52,r.KEY_NUM_5=53,r.KEY_NUM_6=54,r.KEY_NUM_7=55,r.KEY_NUM_8=56,r.KEY_NUM_9=57,r.KEY_A=65,r.KEY_B=66,r.KEY_C=67,r.KEY_D=68,r.KEY_E=69,r.KEY_F=70,r.KEY_G=71,r.KEY_H=72,r.KEY_I=73,r.KEY_J=74,r.KEY_K=75,r.KEY_L=76,r.KEY_M=77,r.KEY_N=78,r.KEY_O=79,r.KEY_P=80,r.KEY_Q=81,r.KEY_R=82,r.KEY_S=83,r.KEY_T=84,r.KEY_U=85,r.KEY_V=86,r.KEY_W=87,r.KEY_X=88,r.KEY_Y=89,r.KEY_Z=90,r.KEY_LEFT_WINDOW=91,r.KEY_RIGHT_WINDOW=92,r.KEY_SELECT_KEY=93,r.KEY_NUMPAD_0=96,r.KEY_NUMPAD_1=97,r.KEY_NUMPAD_2=98,r.KEY_NUMPAD_3=99,r.KEY_NUMPAD_4=100,r.KEY_NUMPAD_5=101,r.KEY_NUMPAD_6=102,r.KEY_NUMPAD_7=103,r.KEY_NUMPAD_8=104,r.KEY_NUMPAD_9=105,r.KEY_MULTIPLY=106,r.KEY_ADD=107,r.KEY_SUBTRACT=109,r.KEY_DECIMAL_POINT=110,r.KEY_DIVIDE=111,r.KEY_F1=112,r.KEY_F2=113,r.KEY_F3=114,r.KEY_F4=115,r.KEY_F5=116,r.KEY_F6=117,r.KEY_F7=118,r.KEY_F8=119,r.KEY_F9=120,r.KEY_F10=121,r.KEY_F11=122,r.KEY_F12=123,r.KEY_NUM_LOCK=144,r.KEY_SCROLL_LOCK=145,r.KEY_SEMI_COLON=186,r.KEY_EQUAL_SIGN=187,r.KEY_COMMA=188,r.KEY_DASH=189,r.KEY_PERIOD=190,r.KEY_FORWARD_SLASH=191,r.KEY_GRAVE_ACCENT=192,r.KEY_OPEN_BRACKET=219,r.KEY_BACK_SLASH=220,r.KEY_CLOSE_BRACKET=221,r.KEY_SINGLE_QUOTE=222,r.KEY_SPACE=32,r.element=i.element,r.altDown=!1,r.ctrlDown=!1,r.mouseDownLeft=!1,r.mouseDownMiddle=!1,r.mouseDownRight=!1,r.keyDown=[],r.enabled=!0,r.keyboardEnabled=!0,r.mouseover=!1,r.mouseCanvasPos=Z.vec2(),r._keyboardEventsElement=i.keyboardEventsElement||document,r._bindEvents(),r}return P(n,[{key:"_bindEvents",value:function(){var e=this;if(!this._eventsBound){this._keyboardEventsElement.addEventListener("keydown",this._keyDownListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!0:t.keyCode===e.KEY_ALT?e.altDown=!0:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!0),e.keyDown[t.keyCode]=!0,e.fire("keydown",t.keyCode,!0))},!1),this._keyboardEventsElement.addEventListener("keyup",this._keyUpListener=function(t){e.enabled&&e.keyboardEnabled&&"INPUT"!==t.target.tagName&&"TEXTAREA"!==t.target.tagName&&(t.keyCode===e.KEY_CTRL?e.ctrlDown=!1:t.keyCode===e.KEY_ALT?e.altDown=!1:t.keyCode===e.KEY_SHIFT&&(e.shiftDown=!1),e.keyDown[t.keyCode]=!1,e.fire("keyup",t.keyCode,!0))}),this.element.addEventListener("mouseenter",this._mouseEnterListener=function(t){e.enabled&&(e.mouseover=!0,e._getMouseCanvasPos(t),e.fire("mouseenter",e.mouseCanvasPos,!0))}),this.element.addEventListener("mouseleave",this._mouseLeaveListener=function(t){e.enabled&&(e.mouseover=!1,e._getMouseCanvasPos(t),e.fire("mouseleave",e.mouseCanvasPos,!0))}),this.element.addEventListener("mousedown",this._mouseDownListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!0;break;case 2:e.mouseDownMiddle=!0;break;case 3:e.mouseDownRight=!0}e._getMouseCanvasPos(t),e.element.focus(),e.fire("mousedown",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("mouseup",this._mouseUpListener=function(t){if(e.enabled){switch(t.which){case 1:e.mouseDownLeft=!1;break;case 2:e.mouseDownMiddle=!1;break;case 3:e.mouseDownRight=!1}e.fire("mouseup",e.mouseCanvasPos,!0)}},!0),document.addEventListener("click",this._clickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("click",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),document.addEventListener("dblclick",this._dblClickListener=function(t){if(e.enabled){switch(t.which){case 1:case 3:e.mouseDownLeft=!1,e.mouseDownRight=!1;break;case 2:e.mouseDownMiddle=!1}e._getMouseCanvasPos(t),e.fire("dblclick",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault()}}),this.element.addEventListener("mousemove",this._mouseMoveListener=function(t){e.enabled&&(e._getMouseCanvasPos(t),e.fire("mousemove",e.mouseCanvasPos,!0),e.mouseover&&t.preventDefault())}),this.element.addEventListener("wheel",this._mouseWheelListener=function(t,n){if(e.enabled){var r=Math.max(-1,Math.min(1,40*-t.deltaY));e.fire("mousewheel",r,!0)}},{passive:!0});var t,n;this.on("mousedown",(function(e){t=e[0],n=e[1]})),this.on("mouseup",(function(r){t>=r[0]-2&&t<=r[0]+2&&n>=r[1]-2&&n<=r[1]+2&&e.fire("mouseclicked",r,!0)})),this._eventsBound=!0}}},{key:"_unbindEvents",value:function(){this._eventsBound&&(this._keyboardEventsElement.removeEventListener("keydown",this._keyDownListener),this._keyboardEventsElement.removeEventListener("keyup",this._keyUpListener),this.element.removeEventListener("mouseenter",this._mouseEnterListener),this.element.removeEventListener("mouseleave",this._mouseLeaveListener),this.element.removeEventListener("mousedown",this._mouseDownListener),document.removeEventListener("mouseup",this._mouseDownListener),document.removeEventListener("click",this._clickListener),document.removeEventListener("dblclick",this._dblClickListener),this.element.removeEventListener("mousemove",this._mouseMoveListener),this.element.removeEventListener("wheel",this._mouseWheelListener),window.OrientationChangeEvent&&window.removeEventListener("orientationchange",this._orientationchangedListener),window.DeviceMotionEvent&&window.removeEventListener("devicemotion",this._deviceMotionListener),window.DeviceOrientationEvent&&window.removeEventListener("deviceorientation",this._deviceOrientListener),this._eventsBound=!1)}},{key:"_getMouseCanvasPos",value:function(e){if(e){for(var t=e.target,n=0,r=0;t.offsetParent;)n+=t.offsetLeft,r+=t.offsetTop,t=t.offsetParent;this.mouseCanvasPos[0]=e.pageX-n,this.mouseCanvasPos[1]=e.pageY-r}else e=window.event,this.mouseCanvasPos[0]=e.x,this.mouseCanvasPos[1]=e.y}},{key:"setEnabled",value:function(e){this.enabled!==e&&this.fire("enabled",this.enabled=e)}},{key:"getEnabled",value:function(){return this.enabled}},{key:"setKeyboardEnabled",value:function(e){this.keyboardEnabled=e}},{key:"getKeyboardEnabled",value:function(){return this.keyboardEnabled}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._unbindEvents()}}]),n}(),Ot=new G({}),St=function(){function e(t){for(var n in b(this,e),this.id=Ot.addItem({}),t)t.hasOwnProperty(n)&&(this[n]=t[n])}return P(e,[{key:"destroy",value:function(){Ot.removeItem(this.id)}}]),e}(),Nt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({boundary:[0,0,100,100]}),r.boundary=i.boundary,r.autoBoundary=i.autoBoundary,r}return P(n,[{key:"type",get:function(){return"Viewport"}},{key:"boundary",get:function(){return this._state.boundary},set:function(e){if(!this._autoBoundary){if(!e){var t=this.scene.canvas.boundary;e=[0,0,t[2],t[3]]}this._state.boundary=e,this.glRedraw(),this.fire("boundary",this._state.boundary)}}},{key:"autoBoundary",get:function(){return this._autoBoundary},set:function(e){(e=!!e)!==this._autoBoundary&&(this._autoBoundary=e,this._autoBoundary?this._onCanvasSize=this.scene.canvas.on("boundary",(function(e){var t=e[2],n=e[3];this._state.boundary=[0,0,t,n],this.glRedraw(),this.fire("boundary",this._state.boundary)}),this):this._onCanvasSize&&(this.scene.canvas.off(this._onCanvasSize),this._onCanvasSize=null),this.fire("autoBoundary",this._autoBoundary))}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Lt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r._fov=60,r._canvasResized=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r.fov=i.fov,r.fovAxis=i.fovAxis,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Perspective"}},{key:"_update",value:function(){var e=this.scene.canvas.boundary,t=e[2]/e[3],n=this._fovAxis,r=this._fov;("x"===n||"min"===n&&t<1||"max"===n&&t>1)&&(r/=t),r=Math.min(r,120),Z.perspectiveMat4(r*(Math.PI/180),t,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.camera._updateScheduled=!0,this.fire("matrix",this._state.matrix)}},{key:"fov",get:function(){return this._fov},set:function(e){(e=null!=e?e:60)!==this._fov&&(this._fov=e,this._needUpdate(0),this.fire("fov",this._fov))}},{key:"fovAxis",get:function(){return this._fovAxis},set:function(e){e=e||"min",this._fovAxis!==e&&("x"!==e&&"y"!==e&&"min"!==e&&(this.error("Unsupported value for 'fovAxis': "+e+" - defaulting to 'min'"),e="min"),this._fovAxis=e,this._needUpdate(0),this.fire("fovAxis",this._fovAxis))}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._canvasResized)}}]),n}(),xt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4(),near:.1,far:2e3}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.scale=i.scale,r.near=i.near,r.far=i.far,r._onCanvasBoundary=r.scene.canvas.on("boundary",r._needUpdate,g(r)),r}return P(n,[{key:"type",get:function(){return"Ortho"}},{key:"_update",value:function(){var e,t,n,r,i=this.scene,a=.5*this._scale,s=i.canvas.boundary,o=s[2],l=s[3],u=o/l;o>l?(e=-a,t=a,n=a/u,r=-a/u):(e=-a*u,t=a*u,n=a,r=-a),Z.orthoMat4c(e,t,r,n,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),e<=0&&(e=.01),this._scale=e,this._needUpdate(0),this.fire("scale",this._scale)}},{key:"near",get:function(){return this._state.near},set:function(e){var t=null!=e?e:.1;this._state.near!==t&&(this._state.near=t,this._needUpdate(0),this.fire("near",this._state.near))}},{key:"far",get:function(){return this._state.far},set:function(e){var t=null!=e?e:2e3;this._state.far!==t&&(this._state.far=t,this._needUpdate(0),this.fire("far",this._state.far))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this.scene.canvas.off(this._onCanvasBoundary)}}]),n}(),Mt=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4(),near:.1,far:1e4}),r._left=-1,r._right=1,r._bottom=-1,r._top=1,r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!0,r.left=i.left,r.right=i.right,r.bottom=i.bottom,r.top=i.top,r.near=i.near,r.far=i.far,r}return P(n,[{key:"type",get:function(){return"Frustum"}},{key:"_update",value:function(){Z.frustumMat4(this._left,this._right,this._bottom,this._top,this._state.near,this._state.far,this._state.matrix),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"left",get:function(){return this._left},set:function(e){this._left=null!=e?e:-1,this._needUpdate(0),this.fire("left",this._left)}},{key:"right",get:function(){return this._right},set:function(e){this._right=null!=e?e:1,this._needUpdate(0),this.fire("right",this._right)}},{key:"top",get:function(){return this._top},set:function(e){this._top=null!=e?e:1,this._needUpdate(0),this.fire("top",this._top)}},{key:"bottom",get:function(){return this._bottom},set:function(e){this._bottom=null!=e?e:-1,this._needUpdate(0),this.fire("bottom",this._bottom)}},{key:"near",get:function(){return this._state.near},set:function(e){this._state.near=null!=e?e:.1,this._needUpdate(0),this.fire("near",this._state.near)}},{key:"far",get:function(){return this._state.far},set:function(e){this._state.far=null!=e?e:1e4,this._needUpdate(0),this.fire("far",this._state.far)}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Ft=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i)).camera=e,r._state=new St({matrix:Z.mat4(),inverseMatrix:Z.mat4(),transposedMatrix:Z.mat4()}),r._inverseMatrixDirty=!0,r._transposedMatrixDirty=!1,r.matrix=i.matrix,r}return P(n,[{key:"type",get:function(){return"CustomProjection"}},{key:"matrix",get:function(){return this._state.matrix},set:function(e){this._state.matrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._inverseMatrixDirty=!0,this._transposedMatrixDirty=!0,this.glRedraw(),this.fire("matrix",this._state.matrix)}},{key:"inverseMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._inverseMatrixDirty&&(Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),this._inverseMatrixDirty=!1),this._state.inverseMatrix}},{key:"transposedMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._transposedMatrixDirty&&(Z.transposeMat4(this._state.matrix,this._state.transposedMatrix),this._transposedMatrixDirty=!1),this._state.transposedMatrix}},{key:"unproject",value:function(e,t,n,r,i){var a=this.scene.canvas.canvas,s=a.offsetWidth/2,o=a.offsetHeight/2;return n[0]=(e[0]-s)/s,n[1]=(e[1]-o)/o,n[2]=t,n[3]=1,Z.mulMat4v4(this.inverseMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1,Z.mulMat4v4(this.camera.inverseViewMatrix,r,i),i}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Ht=Z.vec3(),Ut=Z.vec3(),Gt=Z.vec3(),kt=Z.vec3(),Vt=Z.vec3(),jt=Z.vec3(),Qt=Z.vec4(),Wt=Z.vec4(),zt=Z.vec4(),Kt=Z.mat4(),Yt=Z.mat4(),Xt=Z.vec3(),qt=Z.vec3(),Jt=Z.vec3(),Zt=Z.vec3(),$t=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({deviceMatrix:Z.mat4(),hasDeviceMatrix:!1,matrix:Z.mat4(),normalMatrix:Z.mat4(),inverseMatrix:Z.mat4()}),r._perspective=new Lt(g(r)),r._ortho=new xt(g(r)),r._frustum=new Mt(g(r)),r._customProjection=new Ft(g(r)),r._project=r._perspective,r._eye=Z.vec3([0,0,10]),r._look=Z.vec3([0,0,0]),r._up=Z.vec3([0,1,0]),r._worldUp=Z.vec3([0,1,0]),r._worldRight=Z.vec3([1,0,0]),r._worldForward=Z.vec3([0,0,-1]),r.deviceMatrix=i.deviceMatrix,r.eye=i.eye,r.look=i.look,r.up=i.up,r.worldAxis=i.worldAxis,r.gimbalLock=i.gimbalLock,r.constrainPitch=i.constrainPitch,r.projection=i.projection,r._perspective.on("matrix",(function(){"perspective"===r._projectionType&&r.fire("projMatrix",r._perspective.matrix)})),r._ortho.on("matrix",(function(){"ortho"===r._projectionType&&r.fire("projMatrix",r._ortho.matrix)})),r._frustum.on("matrix",(function(){"frustum"===r._projectionType&&r.fire("projMatrix",r._frustum.matrix)})),r._customProjection.on("matrix",(function(){"customProjection"===r._projectionType&&r.fire("projMatrix",r._customProjection.matrix)})),r}return P(n,[{key:"type",get:function(){return"Camera"}},{key:"_update",value:function(){var e,t=this._state;"ortho"===this.projection?(Z.subVec3(this._eye,this._look,Xt),Z.normalizeVec3(Xt,qt),Z.mulVec3Scalar(qt,1e3,Jt),Z.addVec3(this._look,Jt,Zt),e=Zt):e=this._eye,t.hasDeviceMatrix?(Z.lookAtMat4v(e,this._look,this._up,Yt),Z.mulMat4(t.deviceMatrix,Yt,t.matrix)):Z.lookAtMat4v(e,this._look,this._up,t.matrix),Z.inverseMat4(this._state.matrix,this._state.inverseMatrix),Z.transposeMat4(this._state.inverseMatrix,this._state.normalMatrix),this.glRedraw(),this.fire("matrix",this._state.matrix),this.fire("viewMatrix",this._state.matrix)}},{key:"orbitYaw",value:function(e){var t=Z.subVec3(this._eye,this._look,Ht);Z.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Kt),t=Z.transformPoint3(Kt,t,Ut),this.eye=Z.addVec3(this._look,t,Gt),this.up=Z.transformPoint3(Kt,this._up,kt)}},{key:"orbitPitch",value:function(e){if(!(this._constrainPitch&&(e=Z.dotVec3(this._up,this._worldUp)/Z.DEGTORAD)<1)){var t=Z.subVec3(this._eye,this._look,Ht),n=Z.cross3Vec3(Z.normalizeVec3(t,Ut),Z.normalizeVec3(this._up,Gt));Z.rotationMat4v(.0174532925*e,n,Kt),t=Z.transformPoint3(Kt,t,kt),this.up=Z.transformPoint3(Kt,this._up,Vt),this.eye=Z.addVec3(t,this._look,jt)}}},{key:"yaw",value:function(e){var t=Z.subVec3(this._look,this._eye,Ht);Z.rotationMat4v(.0174532925*e,this._gimbalLock?this._worldUp:this._up,Kt),t=Z.transformPoint3(Kt,t,Ut),this.look=Z.addVec3(t,this._eye,Gt),this._gimbalLock&&(this.up=Z.transformPoint3(Kt,this._up,kt))}},{key:"pitch",value:function(e){if(!(this._constrainPitch&&(e=Z.dotVec3(this._up,this._worldUp)/Z.DEGTORAD)<1)){var t=Z.subVec3(this._look,this._eye,Ht),n=Z.cross3Vec3(Z.normalizeVec3(t,Ut),Z.normalizeVec3(this._up,Gt));Z.rotationMat4v(.0174532925*e,n,Kt),this.up=Z.transformPoint3(Kt,this._up,jt),t=Z.transformPoint3(Kt,t,kt),this.look=Z.addVec3(t,this._eye,Vt)}}},{key:"pan",value:function(e){var t,n=Z.subVec3(this._eye,this._look,Ht),r=[0,0,0];if(0!==e[0]){var i=Z.cross3Vec3(Z.normalizeVec3(n,[]),Z.normalizeVec3(this._up,Ut));t=Z.mulVec3Scalar(i,e[0]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]}0!==e[1]&&(t=Z.mulVec3Scalar(Z.normalizeVec3(this._up,Gt),e[1]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),0!==e[2]&&(t=Z.mulVec3Scalar(Z.normalizeVec3(n,kt),e[2]),r[0]+=t[0],r[1]+=t[1],r[2]+=t[2]),this.eye=Z.addVec3(this._eye,r,Vt),this.look=Z.addVec3(this._look,r,jt)}},{key:"zoom",value:function(e){var t=Z.subVec3(this._eye,this._look,Ht),n=Math.abs(Z.lenVec3(t,Ut)),r=Math.abs(n+e);if(!(r<.5)){var i=Z.normalizeVec3(t,Gt);this.eye=Z.addVec3(this._look,Z.mulVec3Scalar(i,r),kt)}}},{key:"eye",get:function(){return this._eye},set:function(e){this._eye.set(e||[0,0,10]),this._needUpdate(0),this.fire("eye",this._eye)}},{key:"look",get:function(){return this._look},set:function(e){this._look.set(e||[0,0,0]),this._needUpdate(0),this.fire("look",this._look)}},{key:"up",get:function(){return this._up},set:function(e){this._up.set(e||[0,1,0]),this._needUpdate(0),this.fire("up",this._up)}},{key:"deviceMatrix",get:function(){return this._state.deviceMatrix},set:function(e){this._state.deviceMatrix.set(e||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this._state.hasDeviceMatrix=!!e,this._needUpdate(0),this.fire("deviceMatrix",this._state.deviceMatrix)}},{key:"worldAxis",get:function(){return this._worldAxis},set:function(e){e=e||[1,0,0,0,1,0,0,0,1],this._worldAxis?this._worldAxis.set(e):this._worldAxis=Z.vec3(e),this._worldRight[0]=this._worldAxis[0],this._worldRight[1]=this._worldAxis[1],this._worldRight[2]=this._worldAxis[2],this._worldUp[0]=this._worldAxis[3],this._worldUp[1]=this._worldAxis[4],this._worldUp[2]=this._worldAxis[5],this._worldForward[0]=this._worldAxis[6],this._worldForward[1]=this._worldAxis[7],this._worldForward[2]=this._worldAxis[8],this.fire("worldAxis",this._worldAxis)}},{key:"worldUp",get:function(){return this._worldUp}},{key:"xUp",get:function(){return this._worldUp[0]>this._worldUp[1]&&this._worldUp[0]>this._worldUp[2]}},{key:"yUp",get:function(){return this._worldUp[1]>this._worldUp[0]&&this._worldUp[1]>this._worldUp[2]}},{key:"zUp",get:function(){return this._worldUp[2]>this._worldUp[0]&&this._worldUp[2]>this._worldUp[1]}},{key:"worldRight",get:function(){return this._worldRight}},{key:"worldForward",get:function(){return this._worldForward}},{key:"gimbalLock",get:function(){return this._gimbalLock},set:function(e){this._gimbalLock=!1!==e,this.fire("gimbalLock",this._gimbalLock)}},{key:"constrainPitch",set:function(e){this._constrainPitch=!!e,this.fire("constrainPitch",this._constrainPitch)}},{key:"eyeLookDist",get:function(){return Z.lenVec3(Z.subVec3(this._look,this._eye,Ht))}},{key:"matrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"viewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.matrix}},{key:"normalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"viewNormalMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.normalMatrix}},{key:"inverseViewMatrix",get:function(){return this._updateScheduled&&this._doUpdate(),this._state.inverseMatrix}},{key:"projMatrix",get:function(){return this[this.projection].matrix}},{key:"perspective",get:function(){return this._perspective}},{key:"ortho",get:function(){return this._ortho}},{key:"frustum",get:function(){return this._frustum}},{key:"customProjection",get:function(){return this._customProjection}},{key:"projection",get:function(){return this._projectionType},set:function(e){e=e||"perspective",this._projectionType!==e&&("perspective"===e?this._project=this._perspective:"ortho"===e?this._project=this._ortho:"frustum"===e?this._project=this._frustum:"customProjection"===e?this._project=this._customProjection:(this.error("Unsupported value for 'projection': "+e+" defaulting to 'perspective'"),this._project=this._perspective,e="perspective"),this._project._update(),this._projectionType=e,this.glRedraw(),this._update(),this.fire("dirty"),this.fire("projection",this._projectionType),this.fire("projMatrix",this._project.matrix))}},{key:"project",get:function(){return this._project}},{key:"projectWorldPos",value:function(e){var t=Qt,n=Wt,r=zt;t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=1,Z.mulMat4v4(this.viewMatrix,t,n),Z.mulMat4v4(this.projMatrix,n,r),Z.mulVec3Scalar(r,1/r[3]),r[3]=1,r[1]*=-1;var i=this.scene.canvas.canvas,a=i.offsetWidth/2,s=i.offsetHeight/2;return[r[0]*a+a,r[1]*s+s]}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),en=function(e){I(n,ve);var t=m(n);function n(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),t.call(this,e,r)}return P(n,[{key:"type",get:function(){return"Light"}},{key:"isLight",get:function(){return!0}}]),n}(),tn=function(e){I(n,en);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._shadowRenderBuf=null,r._shadowViewMatrix=null,r._shadowProjMatrix=null,r._shadowViewMatrixDirty=!0,r._shadowProjMatrixDirty=!0;var a=r.scene.camera,s=r.scene.canvas;return r._onCameraViewMatrix=a.on("viewMatrix",(function(){r._shadowViewMatrixDirty=!0})),r._onCameraProjMatrix=a.on("projMatrix",(function(){r._shadowProjMatrixDirty=!0})),r._onCanvasBoundary=s.on("boundary",(function(){r._shadowProjMatrixDirty=!0})),r._state=new St({type:"dir",dir:Z.vec3([1,1,1]),color:Z.vec3([.7,.7,.8]),intensity:1,space:i.space||"view",castsShadow:!1,getShadowViewMatrix:function(){if(r._shadowViewMatrixDirty){r._shadowViewMatrix||(r._shadowViewMatrix=Z.identityMat4());var e=r.scene.camera,t=r._state.dir,n=e.look,i=[n[0]-t[0],n[1]-t[1],n[2]-t[2]];Z.lookAtMat4v(i,n,[0,1,0],r._shadowViewMatrix),r._shadowViewMatrixDirty=!1}return r._shadowViewMatrix},getShadowProjMatrix:function(){return r._shadowProjMatrixDirty&&(r._shadowProjMatrix||(r._shadowProjMatrix=Z.identityMat4()),Z.orthoMat4c(-40,40,-40,40,-40,80,r._shadowProjMatrix),r._shadowProjMatrixDirty=!1),r._shadowProjMatrix},getShadowRenderBuf:function(){return r._shadowRenderBuf||(r._shadowRenderBuf=new Pt(r.scene.canvas.canvas,r.scene.canvas.gl,{size:[1024,1024]})),r._shadowRenderBuf}}),r.dir=i.dir,r.color=i.color,r.intensity=i.intensity,r.castsShadow=i.castsShadow,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"DirLight"}},{key:"dir",get:function(){return this._state.dir},set:function(e){this._state.dir.set(e||[1,1,1]),this._shadowViewMatrixDirty=!0,this.glRedraw()}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){e=void 0!==e?e:1,this._state.intensity=e,this.glRedraw()}},{key:"castsShadow",get:function(){return this._state.castsShadow},set:function(e){e=!!e,this._state.castsShadow!==e&&(this._state.castsShadow=e,this._shadowViewMatrixDirty=!0,this.glRedraw())}},{key:"destroy",value:function(){var e=this.scene.camera,t=this.scene.canvas;e.off(this._onCameraViewMatrix),e.off(this._onCameraProjMatrix),t.off(this._onCanvasBoundary),v(T(n.prototype),"destroy",this).call(this),this._state.destroy(),this._shadowRenderBuf&&this._shadowRenderBuf.destroy(),this.scene._lightDestroyed(this),this.glRedraw()}}]),n}(),nn=function(e){I(n,en);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state={type:"ambient",color:Z.vec3([.7,.7,.7]),intensity:1},r.color=i.color,r.intensity=i.intensity,r.scene._lightCreated(g(r)),r}return P(n,[{key:"type",get:function(){return"AmbientLight"}},{key:"color",get:function(){return this._state.color},set:function(e){this._state.color.set(e||[.7,.7,.8]),this.glRedraw()}},{key:"intensity",get:function(){return this._state.intensity},set:function(e){this._state.intensity=void 0!==e?e:1,this.glRedraw()}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this.scene._lightDestroyed(this)}}]),n}(),rn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),ee.memory.meshes++,r}return P(n,[{key:"type",get:function(){return"Geometry"}},{key:"isGeometry",get:function(){return!0}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),ee.memory.meshes--}}]),n}(),an=function(){var e=[],t=[],n=[],r=[],i=[],a=0,s=new Uint16Array(3),o=new Uint16Array(3),l=new Uint16Array(3),u=Z.vec3(),c=Z.vec3(),f=Z.vec3(),p=Z.vec3(),A=Z.vec3(),d=Z.vec3(),v=Z.vec3();return function(h,I,y,m){!function(i,a){var s,o,l,u,c,f,p={},A=Math.pow(10,4),d=0;for(c=0,f=i.length;cO)||(C=n[D.index1],_=n[D.index2],(!N&&C>65535||_>65535)&&(N=!0),B.push(C),B.push(_));return N?new Uint32Array(B):new Uint16Array(B)}}();var sn=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r){r=r||Z.mat4();var i=n[0],a=n[1],s=n[2],o=n[3]-i,l=n[4]-a,u=n[5]-s,c=65535;return Z.identityMat4(e),Z.translationMat4v(n,e),Z.identityMat4(t),Z.scalingMat4v([o/c,l/c,u/c],t),Z.mulMat4(e,t,r),r}}(),on=function(){var e=Z.mat4(),t=Z.mat4();return function(n,r,i){var a,s=new Uint16Array(n.length),o=new Float32Array([i[0]!==r[0]?65535/(i[0]-r[0]):0,i[1]!==r[1]?65535/(i[1]-r[1]):0,i[2]!==r[2]?65535/(i[2]-r[2]):0]);for(a=0;a=0?1:-1),o=(1-Math.abs(i))*(a>=0?1:-1);i=s,a=o}return new Int8Array([Math[n](127.5*i+(i<0?-1:0)),Math[r](127.5*a+(a<0?-1:0))])}function cn(e){var t=e[0],n=e[1];t/=t<0?127:128,n/=n<0?127:128;var r=1-Math.abs(t)-Math.abs(n);r<0&&(t=(1-Math.abs(n))*(t>=0?1:-1),n=(1-Math.abs(t))*(n>=0?1:-1));var i=Math.sqrt(t*t+n*n+r*r);return[t/i,n/i,r/i]}function fn(e,t,n){return e[t]*n[0]+e[t+1]*n[1]+e[t+2]*n[2]}var pn={getPositionsBounds:function(e){var t,n,r=new Float32Array(3),i=new Float32Array(3);for(t=0;t<3;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;r2&&void 0!==arguments[2]?arguments[2]:e;return n[0]=e[0]*t[0]+t[12],n[1]=e[1]*t[5]+t[13],n[2]=e[2]*t[10]+t[14],n[3]=e[3]*t[0]+t[12],n[4]=e[4]*t[5]+t[13],n[5]=e[5]*t[10]+t[14],n},getUVBounds:function(e){var t,n,r=new Float32Array(2),i=new Float32Array(2);for(t=0;t<2;t++)r[t]=Number.MAX_VALUE,i[t]=-Number.MAX_VALUE;for(t=0;t2&&void 0!==arguments[2]?arguments[2]:new Float32Array(e.length),r=0,i=e.length;ri&&(n=t,i=r),(r=fn(e,s,cn(t=un(e,s,"floor","ceil"))))>i&&(n=t,i=r),(r=fn(e,s,cn(t=un(e,s,"ceil","ceil"))))>i&&(n=t,i=r),a[s]=n[0],a[s+1]=n[1];return a},decompressNormals:function(e,t){for(var n=0,r=0,i=e.length;n=0?1:-1),s=(1-Math.abs(a))*(s>=0?1:-1));var l=Math.sqrt(a*a+s*s+o*o);t[r+0]=a/l,t[r+1]=s/l,t[r+2]=o/l,r+=3}return t},decompressNormal:function(e,t){var n=e[0],r=e[1];n=(2*n+1)/255,r=(2*r+1)/255;var i=1-Math.abs(n)-Math.abs(r);i<0&&(n=(1-Math.abs(r))*(n>=0?1:-1),r=(1-Math.abs(n))*(r>=0?1:-1));var a=Math.sqrt(n*n+r*r+i*i);return t[0]=n/a,t[1]=r/a,t[2]=i/a,t}},An=ee.memory,dn=Z.AABB3(),vn=function(e){I(n,rn);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};b(this,n),(r=t.call(this,e,i))._state=new St({compressGeometry:!!i.compressGeometry,primitive:null,primitiveName:null,positions:null,normals:null,colors:null,uv:null,indices:null,positionsDecodeMatrix:null,uvDecodeMatrix:null,positionsBuf:null,normalsBuf:null,colorsbuf:null,uvBuf:null,indicesBuf:null,hash:""}),r._numTriangles=0,r._edgeThreshold=i.edgeThreshold||10,r._edgeIndicesBuf=null,r._pickTrianglePositionsBuf=null,r._pickTriangleColorsBuf=null,r._aabbDirty=!0,r._boundingSphere=!0,r._aabb=null,r._aabbDirty=!0,r._obb=null,r._obbDirty=!0;var a=r._state,s=r.scene.canvas.gl;switch(i.primitive=i.primitive||"triangles",i.primitive){case"points":a.primitive=s.POINTS,a.primitiveName=i.primitive;break;case"lines":a.primitive=s.LINES,a.primitiveName=i.primitive;break;case"line-loop":a.primitive=s.LINE_LOOP,a.primitiveName=i.primitive;break;case"line-strip":a.primitive=s.LINE_STRIP,a.primitiveName=i.primitive;break;case"triangles":a.primitive=s.TRIANGLES,a.primitiveName=i.primitive;break;case"triangle-strip":a.primitive=s.TRIANGLE_STRIP,a.primitiveName=i.primitive;break;case"triangle-fan":a.primitive=s.TRIANGLE_FAN,a.primitiveName=i.primitive;break;default:r.error("Unsupported value for 'primitive': '"+i.primitive+"' - supported values are 'points', 'lines', 'line-loop', 'line-strip', 'triangles', 'triangle-strip' and 'triangle-fan'. Defaulting to 'triangles'."),a.primitive=s.TRIANGLES,a.primitiveName=i.primitive}if(i.positions)if(r._state.compressGeometry){var o=pn.getPositionsBounds(i.positions),l=pn.compressPositions(i.positions,o.min,o.max);a.positions=l.quantized,a.positionsDecodeMatrix=l.decodeMatrix}else a.positions=i.positions.constructor===Float32Array?i.positions:new Float32Array(i.positions);if(i.colors&&(a.colors=i.colors.constructor===Float32Array?i.colors:new Float32Array(i.colors)),i.uv)if(r._state.compressGeometry){var u=pn.getUVBounds(i.uv),c=pn.compressUVs(i.uv,u.min,u.max);a.uv=c.quantized,a.uvDecodeMatrix=c.decodeMatrix}else a.uv=i.uv.constructor===Float32Array?i.uv:new Float32Array(i.uv);return i.normals&&(r._state.compressGeometry?a.normals=pn.compressNormals(i.normals):a.normals=i.normals.constructor===Float32Array?i.normals:new Float32Array(i.normals)),i.indices&&(a.indices=i.indices.constructor===Uint32Array||i.indices.constructor===Uint16Array?i.indices:new Uint32Array(i.indices),"triangles"===r._state.primitiveName&&(r._numTriangles=i.indices.length/3)),r._buildHash(),An.meshes++,r._buildVBOs(),r}return P(n,[{key:"type",get:function(){return"ReadableGeometry"}},{key:"isReadableGeometry",get:function(){return!0}},{key:"_buildVBOs",value:function(){var e=this._state,t=this.scene.canvas.gl;if(e.indices&&(e.indicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,e.indices,e.indices.length,1,t.STATIC_DRAW),An.indices+=e.indicesBuf.numItems),e.positions&&(e.positionsBuf=new pt(t,t.ARRAY_BUFFER,e.positions,e.positions.length,3,t.STATIC_DRAW),An.positions+=e.positionsBuf.numItems),e.normals){var n=e.compressGeometry;e.normalsBuf=new pt(t,t.ARRAY_BUFFER,e.normals,e.normals.length,3,t.STATIC_DRAW,n),An.normals+=e.normalsBuf.numItems}e.colors&&(e.colorsBuf=new pt(t,t.ARRAY_BUFFER,e.colors,e.colors.length,4,t.STATIC_DRAW),An.colors+=e.colorsBuf.numItems),e.uv&&(e.uvBuf=new pt(t,t.ARRAY_BUFFER,e.uv,e.uv.length,2,t.STATIC_DRAW),An.uvs+=e.uvBuf.numItems)}},{key:"_buildHash",value:function(){var e=this._state,t=["/g"];t.push("/"+e.primitive+";"),e.positions&&t.push("p"),e.colors&&t.push("c"),(e.normals||e.autoVertexNormals)&&t.push("n"),e.uv&&t.push("u"),e.compressGeometry&&t.push("cp"),t.push(";"),e.hash=t.join("")}},{key:"_getEdgeIndices",value:function(){return this._edgeIndicesBuf||this._buildEdgeIndices(),this._edgeIndicesBuf}},{key:"_getPickTrianglePositions",value:function(){return this._pickTrianglePositionsBuf||this._buildPickTriangleVBOs(),this._pickTrianglePositionsBuf}},{key:"_getPickTriangleColors",value:function(){return this._pickTriangleColorsBuf||this._buildPickTriangleVBOs(),this._pickTriangleColorsBuf}},{key:"_buildEdgeIndices",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=an(e.positions,e.indices,e.positionsDecodeMatrix,this._edgeThreshold);this._edgeIndicesBuf=new pt(t,t.ELEMENT_ARRAY_BUFFER,n,n.length,1,t.STATIC_DRAW),An.indices+=this._edgeIndicesBuf.numItems}}},{key:"_buildPickTriangleVBOs",value:function(){var e=this._state;if(e.positions&&e.indices){var t=this.scene.canvas.gl,n=Z.buildPickTriangles(e.positions,e.indices,e.compressGeometry),r=n.positions,i=n.colors;this._pickTrianglePositionsBuf=new pt(t,t.ARRAY_BUFFER,r,r.length,3,t.STATIC_DRAW),this._pickTriangleColorsBuf=new pt(t,t.ARRAY_BUFFER,i,i.length,4,t.STATIC_DRAW,!0),An.positions+=this._pickTrianglePositionsBuf.numItems,An.colors+=this._pickTriangleColorsBuf.numItems}}},{key:"_buildPickVertexVBOs",value:function(){}},{key:"_webglContextLost",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextLost()}},{key:"_webglContextRestored",value:function(){this._sceneVertexBufs&&this._sceneVertexBufs.webglContextRestored(),this._buildVBOs(),this._edgeIndicesBuf=null,this._pickVertexPositionsBuf=null,this._pickTrianglePositionsBuf=null,this._pickTriangleColorsBuf=null,this._pickVertexPositionsBuf=null,this._pickVertexColorsBuf=null}},{key:"primitive",get:function(){return this._state.primitiveName}},{key:"compressGeometry",get:function(){return this._state.compressGeometry}},{key:"positions",get:function(){return this._state.positions?this._state.compressGeometry?(this._decompressedPositions||(this._decompressedPositions=new Float32Array(this._state.positions.length),pn.decompressPositions(this._state.positions,this._state.positionsDecodeMatrix,this._decompressedPositions)),this._decompressedPositions):this._state.positions:null},set:function(e){var t=this._state,n=t.positions;if(n)if(n.length===e.length){if(this._state.compressGeometry){var r=pn.getPositionsBounds(e),i=pn.compressPositions(e,r.min,r.max);e=i.quantized,t.positionsDecodeMatrix=i.decodeMatrix}n.set(e),t.positionsBuf&&t.positionsBuf.setData(n),this._setAABBDirty(),this.glRedraw()}else this.error("can't update geometry positions - new positions are wrong length");else this.error("can't update geometry positions - geometry has no positions")}},{key:"normals",get:function(){if(this._state.normals){if(!this._state.compressGeometry)return this._state.normals;if(!this._decompressedNormals){var e=this._state.normals.length,t=e+e/2;this._decompressedNormals=new Float32Array(t),pn.decompressNormals(this._state.normals,this._decompressedNormals)}return this._decompressedNormals}},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry normals - quantized geometry is immutable");else{var t=this._state,n=t.normals;n?n.length===e.length?(n.set(e),t.normalsBuf&&t.normalsBuf.setData(n),this.glRedraw()):this.error("can't update geometry normals - new normals are wrong length"):this.error("can't update geometry normals - geometry has no normals")}}},{key:"uv",get:function(){return this._state.uv?this._state.compressGeometry?(this._decompressedUV||(this._decompressedUV=new Float32Array(this._state.uv.length),pn.decompressUVs(this._state.uv,this._state.uvDecodeMatrix,this._decompressedUV)),this._decompressedUV):this._state.uv:null},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry UVs - quantized geometry is immutable");else{var t=this._state,n=t.uv;n?n.length===e.length?(n.set(e),t.uvBuf&&t.uvBuf.setData(n),this.glRedraw()):this.error("can't update geometry UVs - new UVs are wrong length"):this.error("can't update geometry UVs - geometry has no UVs")}}},{key:"colors",get:function(){return this._state.colors},set:function(e){if(this._state.compressGeometry)this.error("can't update geometry colors - quantized geometry is immutable");else{var t=this._state,n=t.colors;n?n.length===e.length?(n.set(e),t.colorsBuf&&t.colorsBuf.setData(n),this.glRedraw()):this.error("can't update geometry colors - new colors are wrong length"):this.error("can't update geometry colors - geometry has no colors")}}},{key:"indices",get:function(){return this._state.indices}},{key:"aabb",get:function(){return this._aabbDirty&&(this._aabb||(this._aabb=Z.AABB3()),Z.positions3ToAABB3(this._state.positions,this._aabb,this._state.positionsDecodeMatrix),this._aabbDirty=!1),this._aabb}},{key:"obb",get:function(){return this._obbDirty&&(this._obb||(this._obb=Z.OBB3()),Z.positions3ToAABB3(this._state.positions,dn,this._state.positionsDecodeMatrix),Z.AABB3ToOBB3(dn,this._obb),this._obbDirty=!1),this._obb}},{key:"numTriangles",get:function(){return this._numTriangles}},{key:"_setAABBDirty",value:function(){this._aabbDirty||(this._aabbDirty=!0,this._aabbDirty=!0,this._obbDirty=!0)}},{key:"_getState",value:function(){return this._state}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this);var e=this._state;e.indicesBuf&&e.indicesBuf.destroy(),e.positionsBuf&&e.positionsBuf.destroy(),e.normalsBuf&&e.normalsBuf.destroy(),e.uvBuf&&e.uvBuf.destroy(),e.colorsBuf&&e.colorsBuf.destroy(),this._edgeIndicesBuf&&this._edgeIndicesBuf.destroy(),this._pickTrianglePositionsBuf&&this._pickTrianglePositionsBuf.destroy(),this._pickTriangleColorsBuf&&this._pickTriangleColorsBuf.destroy(),this._pickVertexPositionsBuf&&this._pickVertexPositionsBuf.destroy(),this._pickVertexColorsBuf&&this._pickVertexColorsBuf.destroy(),e.destroy(),An.meshes--}}]),n}();function hn(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.xSize||1;t<0&&(console.error("negative xSize not allowed - will invert"),t*=-1);var n=e.ySize||1;n<0&&(console.error("negative ySize not allowed - will invert"),n*=-1);var r=e.zSize||1;r<0&&(console.error("negative zSize not allowed - will invert"),r*=-1);var i=e.center,a=i?i[0]:0,s=i?i[1]:0,o=i?i[2]:0,l=-t+a,u=-n+s,c=-r+o,f=t+a,p=n+s,A=r+o;return ae.apply(e,{positions:[f,p,A,l,p,A,l,u,A,f,u,A,f,p,A,f,u,A,f,u,c,f,p,c,f,p,A,f,p,c,l,p,c,l,p,A,l,p,A,l,p,c,l,u,c,l,u,A,l,u,c,f,u,c,f,u,A,l,u,A,f,u,c,l,u,c,l,p,c,f,p,c],normals:[0,0,1,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1],uv:[1,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,1,1,0,0,0,0,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0],indices:[0,1,2,0,2,3,4,5,6,4,6,7,8,9,10,8,10,11,12,13,14,12,14,15,16,17,18,16,18,19,20,21,22,20,22,23]})}var In=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),r=t.call(this,e,i),ee.memory.materials++,r}return P(n,[{key:"type",get:function(){return"Material"}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),ee.memory.materials--}}]),n}(),yn={opaque:0,mask:1,blend:2},mn=["opaque","mask","blend"],wn=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"PhongMaterial",ambient:Z.vec3([1,1,1]),diffuse:Z.vec3([1,1,1]),specular:Z.vec3([1,1,1]),emissive:Z.vec3([0,0,0]),alpha:null,shininess:null,reflectivity:null,alphaMode:null,alphaCutoff:null,lineWidth:null,pointSize:null,backfaces:null,frontface:null,hash:null}),r.ambient=i.ambient,r.diffuse=i.diffuse,r.specular=i.specular,r.emissive=i.emissive,r.alpha=i.alpha,r.shininess=i.shininess,r.reflectivity=i.reflectivity,r.lineWidth=i.lineWidth,r.pointSize=i.pointSize,i.ambientMap&&(r._ambientMap=r._checkComponent("Texture",i.ambientMap)),i.diffuseMap&&(r._diffuseMap=r._checkComponent("Texture",i.diffuseMap)),i.specularMap&&(r._specularMap=r._checkComponent("Texture",i.specularMap)),i.emissiveMap&&(r._emissiveMap=r._checkComponent("Texture",i.emissiveMap)),i.alphaMap&&(r._alphaMap=r._checkComponent("Texture",i.alphaMap)),i.reflectivityMap&&(r._reflectivityMap=r._checkComponent("Texture",i.reflectivityMap)),i.normalMap&&(r._normalMap=r._checkComponent("Texture",i.normalMap)),i.occlusionMap&&(r._occlusionMap=r._checkComponent("Texture",i.occlusionMap)),i.diffuseFresnel&&(r._diffuseFresnel=r._checkComponent("Fresnel",i.diffuseFresnel)),i.specularFresnel&&(r._specularFresnel=r._checkComponent("Fresnel",i.specularFresnel)),i.emissiveFresnel&&(r._emissiveFresnel=r._checkComponent("Fresnel",i.emissiveFresnel)),i.alphaFresnel&&(r._alphaFresnel=r._checkComponent("Fresnel",i.alphaFresnel)),i.reflectivityFresnel&&(r._reflectivityFresnel=r._checkComponent("Fresnel",i.reflectivityFresnel)),r.alphaMode=i.alphaMode,r.alphaCutoff=i.alphaCutoff,r.backfaces=i.backfaces,r.frontface=i.frontface,r._makeHash(),r}return P(n,[{key:"type",get:function(){return"PhongMaterial"}},{key:"_makeHash",value:function(){var e=this._state,t=["/p"];this._normalMap&&(t.push("/nm"),this._normalMap.hasMatrix&&t.push("/mat")),this._ambientMap&&(t.push("/am"),this._ambientMap.hasMatrix&&t.push("/mat"),t.push("/"+this._ambientMap.encoding)),this._diffuseMap&&(t.push("/dm"),this._diffuseMap.hasMatrix&&t.push("/mat"),t.push("/"+this._diffuseMap.encoding)),this._specularMap&&(t.push("/sm"),this._specularMap.hasMatrix&&t.push("/mat")),this._emissiveMap&&(t.push("/em"),this._emissiveMap.hasMatrix&&t.push("/mat"),t.push("/"+this._emissiveMap.encoding)),this._alphaMap&&(t.push("/opm"),this._alphaMap.hasMatrix&&t.push("/mat")),this._reflectivityMap&&(t.push("/rm"),this._reflectivityMap.hasMatrix&&t.push("/mat")),this._occlusionMap&&(t.push("/ocm"),this._occlusionMap.hasMatrix&&t.push("/mat")),this._diffuseFresnel&&t.push("/df"),this._specularFresnel&&t.push("/sf"),this._emissiveFresnel&&t.push("/ef"),this._alphaFresnel&&t.push("/of"),this._reflectivityFresnel&&t.push("/rf"),t.push(";"),e.hash=t.join("")}},{key:"ambient",get:function(){return this._state.ambient},set:function(e){var t=this._state.ambient;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.ambient=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"diffuse",get:function(){return this._state.diffuse},set:function(e){var t=this._state.diffuse;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.diffuse=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"specular",get:function(){return this._state.specular},set:function(e){var t=this._state.specular;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.specular=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=1,t[1]=1,t[2]=1),this.glRedraw()}},{key:"emissive",get:function(){return this._state.emissive},set:function(e){var t=this._state.emissive;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.emissive=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=0,t[1]=0,t[2]=0),this.glRedraw()}},{key:"alpha",get:function(){return this._state.alpha},set:function(e){e=null!=e?e:1,this._state.alpha!==e&&(this._state.alpha=e,this.glRedraw())}},{key:"shininess",get:function(){return this._state.shininess},set:function(e){this._state.shininess=void 0!==e?e:80,this.glRedraw()}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||1,this.glRedraw()}},{key:"reflectivity",get:function(){return this._state.reflectivity},set:function(e){this._state.reflectivity=void 0!==e?e:1,this.glRedraw()}},{key:"normalMap",get:function(){return this._normalMap}},{key:"ambientMap",get:function(){return this._ambientMap}},{key:"diffuseMap",get:function(){return this._diffuseMap}},{key:"specularMap",get:function(){return this._specularMap}},{key:"emissiveMap",get:function(){return this._emissiveMap}},{key:"alphaMap",get:function(){return this._alphaMap}},{key:"reflectivityMap",get:function(){return this._reflectivityMap}},{key:"occlusionMap",get:function(){return this._occlusionMap}},{key:"diffuseFresnel",get:function(){return this._diffuseFresnel}},{key:"specularFresnel",get:function(){return this._specularFresnel}},{key:"emissiveFresnel",get:function(){return this._emissiveFresnel}},{key:"alphaFresnel",get:function(){return this._alphaFresnel}},{key:"reflectivityFresnel",get:function(){return this._reflectivityFresnel}},{key:"alphaMode",get:function(){return mn[this._state.alphaMode]},set:function(e){var t=yn[e=e||"opaque"];void 0===t&&(this.error("Unsupported value for 'alphaMode': "+e+" - defaulting to 'opaque'"),t="opaque"),this._state.alphaMode!==t&&(this._state.alphaMode=t,this.glRedraw())}},{key:"alphaCutoff",get:function(){return this._state.alphaCutoff},set:function(e){null==e&&(e=.5),this._state.alphaCutoff!==e&&(this._state.alphaCutoff=e)}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"frontface",get:function(){return this._state.frontface?"ccw":"cw"},set:function(e){e="cw"!==e,this._state.frontface!==e&&(this._state.frontface=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),gn={default:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultWhiteBG:{fill:!0,fillColor:[1,1,1],fillAlpha:.6,edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.2,.2,.2],edgeAlpha:.5,edgeWidth:1},defaultDarkBG:{fill:!0,fillColor:[.4,.4,.4],fillAlpha:.2,edges:!0,edgeColor:[.5,.5,.5],edgeAlpha:.5,edgeWidth:1},phosphorous:{fill:!0,fillColor:[0,0,0],fillAlpha:.4,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:2},sunset:{fill:!0,fillColor:[.9,.9,.6],fillAlpha:.2,edges:!0,edgeColor:[.9,.9,.9],edgeAlpha:.5,edgeWidth:1},vectorscope:{fill:!0,fillColor:[0,0,0],fillAlpha:.7,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:2},battlezone:{fill:!0,fillColor:[0,0,0],fillAlpha:1,edges:!0,edgeColor:[.2,1,.2],edgeAlpha:1,edgeWidth:3},sepia:{fill:!0,fillColor:[.970588207244873,.7965892553329468,.6660899519920349],fillAlpha:.4,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},yellowHighlight:{fill:!0,fillColor:[1,1,0],fillAlpha:.5,edges:!0,edgeColor:[.529411792755127,.4577854573726654,.4100345969200134],edgeAlpha:1,edgeWidth:1},greenSelected:{fill:!0,fillColor:[0,1,0],fillAlpha:.5,edges:!0,edgeColor:[.4577854573726654,.529411792755127,.4100345969200134],edgeAlpha:1,edgeWidth:1},gamegrid:{fill:!0,fillColor:[.2,.2,.7],fillAlpha:.9,edges:!0,edgeColor:[.4,.4,1.6],edgeAlpha:.8,edgeWidth:3}},Tn=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"EmphasisMaterial",fill:null,fillColor:null,fillAlpha:null,edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null,backfaces:!0,glowThrough:!0}),r._preset="default",i.preset?(r.preset=i.preset,void 0!==i.fill&&(r.fill=i.fill),i.fillColor&&(r.fillColor=i.fillColor),void 0!==i.fillAlpha&&(r.fillAlpha=i.fillAlpha),void 0!==i.edges&&(r.edges=i.edges),i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth),void 0!==i.backfaces&&(r.backfaces=i.backfaces),void 0!==i.glowThrough&&(r.glowThrough=i.glowThrough)):(r.fill=i.fill,r.fillColor=i.fillColor,r.fillAlpha=i.fillAlpha,r.edges=i.edges,r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth,r.backfaces=i.backfaces,r.glowThrough=i.glowThrough),r}return P(n,[{key:"type",get:function(){return"EmphasisMaterial"}},{key:"presets",get:function(){return gn}},{key:"fill",get:function(){return this._state.fill},set:function(e){e=!1!==e,this._state.fill!==e&&(this._state.fill=e,this.glRedraw())}},{key:"fillColor",get:function(){return this._state.fillColor},set:function(e){var t=this._state.fillColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.fillColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.4,t[1]=.4,t[2]=.4),this.glRedraw()}},{key:"fillAlpha",get:function(){return this._state.fillAlpha},set:function(e){e=null!=e?e:.2,this._state.fillAlpha!==e&&(this._state.fillAlpha=e,this.glRedraw())}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:.5,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"backfaces",get:function(){return this._state.backfaces},set:function(e){e=!!e,this._state.backfaces!==e&&(this._state.backfaces=e,this.glRedraw())}},{key:"glowThrough",get:function(){return this._state.glowThrough},set:function(e){e=!1!==e,this._state.glowThrough!==e&&(this._state.glowThrough=e,this.glRedraw())}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=gn[e];t?(this.fill=t.fill,this.fillColor=t.fillColor,this.fillAlpha=t.fillAlpha,this.edges=t.edges,this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this.glowThrough=t.glowThrough,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(gn).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),En={default:{edgeColor:[0,0,0],edgeAlpha:1,edgeWidth:1},defaultWhiteBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultLightBG:{edgeColor:[.2,.2,.2],edgeAlpha:1,edgeWidth:1},defaultDarkBG:{edgeColor:[.5,.5,.5],edgeAlpha:1,edgeWidth:1}},bn=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"EdgeMaterial",edges:null,edgeColor:null,edgeAlpha:null,edgeWidth:null}),r._preset="default",i.preset?(r.preset=i.preset,i.edgeColor&&(r.edgeColor=i.edgeColor),void 0!==i.edgeAlpha&&(r.edgeAlpha=i.edgeAlpha),void 0!==i.edgeWidth&&(r.edgeWidth=i.edgeWidth)):(r.edgeColor=i.edgeColor,r.edgeAlpha=i.edgeAlpha,r.edgeWidth=i.edgeWidth),r.edges=!1!==i.edges,r}return P(n,[{key:"type",get:function(){return"EdgeMaterial"}},{key:"presets",get:function(){return En}},{key:"edges",get:function(){return this._state.edges},set:function(e){e=!1!==e,this._state.edges!==e&&(this._state.edges=e,this.glRedraw())}},{key:"edgeColor",get:function(){return this._state.edgeColor},set:function(e){var t=this._state.edgeColor;if(t){if(e&&t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2])return}else t=this._state.edgeColor=new Float32Array(3);e?(t[0]=e[0],t[1]=e[1],t[2]=e[2]):(t[0]=.2,t[1]=.2,t[2]=.2),this.glRedraw()}},{key:"edgeAlpha",get:function(){return this._state.edgeAlpha},set:function(e){e=null!=e?e:1,this._state.edgeAlpha!==e&&(this._state.edgeAlpha=e,this.glRedraw())}},{key:"edgeWidth",get:function(){return this._state.edgeWidth},set:function(e){this._state.edgeWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=En[e];t?(this.edgeColor=t.edgeColor,this.edgeAlpha=t.edgeAlpha,this.edgeWidth=t.edgeWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(En).join(", "))}}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Dn={meters:{abbrev:"m"},metres:{abbrev:"m"},centimeters:{abbrev:"cm"},centimetres:{abbrev:"cm"},millimeters:{abbrev:"mm"},millimetres:{abbrev:"mm"},yards:{abbrev:"yd"},feet:{abbrev:"ft"},inches:{abbrev:"in"}},Pn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._units="meters",r._scale=1,r._origin=Z.vec3([0,0,0]),r.units=i.units,r.scale=i.scale,r.origin=i.origin,r}return P(n,[{key:"unitsInfo",get:function(){return Dn}},{key:"units",get:function(){return this._units},set:function(e){e||(e="meters"),Dn[e]||(this.error("Unsupported value for 'units': "+e+" defaulting to 'meters'"),e="meters"),this._units=e,this.fire("units",this._units)}},{key:"scale",get:function(){return this._scale},set:function(e){(e=e||1)<=0?this.error("scale value should be larger than zero"):(this._scale=e,this.fire("scale",this._scale))}},{key:"origin",get:function(){return this._origin},set:function(e){if(!e)return this._origin[0]=0,this._origin[1]=0,void(this._origin[2]=0);this._origin[0]=e[0],this._origin[1]=e[1],this._origin[2]=e[2],this.fire("origin",this._origin)}},{key:"worldToRealPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(3);t[0]=this._origin[0]+this._scale*e[0],t[1]=this._origin[1]+this._scale*e[1],t[2]=this._origin[2]+this._scale*e[2]}},{key:"realToWorldPos",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Z.vec3(3);return t[0]=(e[0]-this._origin[0])/this._scale,t[1]=(e[1]-this._origin[1])/this._scale,t[2]=(e[2]-this._origin[2])/this._scale,t}}]),n}(),Rn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._supported=Ze.SUPPORTED_EXTENSIONS.OES_standard_derivatives,r.enabled=i.enabled,r.kernelRadius=i.kernelRadius,r.intensity=i.intensity,r.bias=i.bias,r.scale=i.scale,r.minResolution=i.minResolution,r.numSamples=i.numSamples,r.blur=i.blur,r.blendCutoff=i.blendCutoff,r.blendFactor=i.blendFactor,r}return P(n,[{key:"supported",get:function(){return this._supported}},{key:"enabled",get:function(){return this._enabled},set:function(e){e=!!e,this._enabled!==e&&(this._enabled=e,this.glRedraw())}},{key:"possible",get:function(){if(!this._supported)return!1;if(!this._enabled)return!1;var e=this.scene.camera.projection;return"customProjection"!==e&&"frustum"!==e}},{key:"active",get:function(){return this._active}},{key:"kernelRadius",get:function(){return this._kernelRadius},set:function(e){null==e&&(e=100),this._kernelRadius!==e&&(this._kernelRadius=e,this.glRedraw())}},{key:"intensity",get:function(){return this._intensity},set:function(e){null==e&&(e=.15),this._intensity!==e&&(this._intensity=e,this.glRedraw())}},{key:"bias",get:function(){return this._bias},set:function(e){null==e&&(e=.5),this._bias!==e&&(this._bias=e,this.glRedraw())}},{key:"scale",get:function(){return this._scale},set:function(e){null==e&&(e=1),this._scale!==e&&(this._scale=e,this.glRedraw())}},{key:"minResolution",get:function(){return this._minResolution},set:function(e){null==e&&(e=0),this._minResolution!==e&&(this._minResolution=e,this.glRedraw())}},{key:"numSamples",get:function(){return this._numSamples},set:function(e){null==e&&(e=10),this._numSamples!==e&&(this._numSamples=e,this.glRedraw())}},{key:"blur",get:function(){return this._blur},set:function(e){e=!1!==e,this._blur!==e&&(this._blur=e,this.glRedraw())}},{key:"blendCutoff",get:function(){return this._blendCutoff},set:function(e){null==e&&(e=.3),this._blendCutoff!==e&&(this._blendCutoff=e,this.glRedraw())}},{key:"blendFactor",get:function(){return this._blendFactor},set:function(e){null==e&&(e=1),this._blendFactor!==e&&(this._blendFactor=e,this.glRedraw())}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this)}}]),n}(),Cn={default:{pointSize:4,roundPoints:!0,perspectivePoints:!0},square:{pointSize:4,roundPoints:!1,perspectivePoints:!0},round:{pointSize:4,roundPoints:!0,perspectivePoints:!0}},_n=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"PointsMaterial",pointSize:null,roundPoints:null,perspectivePoints:null,minPerspectivePointSize:null,maxPerspectivePointSize:null,filterIntensity:null,minIntensity:null,maxIntensity:null}),i.preset?(r.preset=i.preset,void 0!==i.pointSize&&(r.pointSize=i.pointSize),void 0!==i.roundPoints&&(r.roundPoints=i.roundPoints),void 0!==i.perspectivePoints&&(r.perspectivePoints=i.perspectivePoints),void 0!==i.minPerspectivePointSize&&(r.minPerspectivePointSize=i.minPerspectivePointSize),void 0!==i.maxPerspectivePointSize&&(r.maxPerspectivePointSize=i.minPerspectivePointSize)):(r._preset="default",r.pointSize=i.pointSize,r.roundPoints=i.roundPoints,r.perspectivePoints=i.perspectivePoints,r.minPerspectivePointSize=i.minPerspectivePointSize,r.maxPerspectivePointSize=i.maxPerspectivePointSize),r.filterIntensity=i.filterIntensity,r.minIntensity=i.minIntensity,r.maxIntensity=i.maxIntensity,r}return P(n,[{key:"type",get:function(){return"PointsMaterial"}},{key:"presets",get:function(){return Cn}},{key:"pointSize",get:function(){return this._state.pointSize},set:function(e){this._state.pointSize=e||2,this.glRedraw()}},{key:"roundPoints",get:function(){return this._state.roundPoints},set:function(e){e=!1!==e,this._state.roundPoints!==e&&(this._state.roundPoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"perspectivePoints",get:function(){return this._state.perspectivePoints},set:function(e){e=!1!==e,this._state.perspectivePoints!==e&&(this._state.perspectivePoints=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minPerspectivePointSize",get:function(){return this._state.minPerspectivePointSize},set:function(e){this._state.minPerspectivePointSize=e||1,this.scene._needRecompile=!0,this.glRedraw()}},{key:"maxPerspectivePointSize",get:function(){return this._state.maxPerspectivePointSize},set:function(e){this._state.maxPerspectivePointSize=e||6,this.scene._needRecompile=!0,this.glRedraw()}},{key:"filterIntensity",get:function(){return this._state.filterIntensity},set:function(e){e=!1!==e,this._state.filterIntensity!==e&&(this._state.filterIntensity=e,this.scene._needRecompile=!0,this.glRedraw())}},{key:"minIntensity",get:function(){return this._state.minIntensity},set:function(e){this._state.minIntensity=null!=e?e:0,this.glRedraw()}},{key:"maxIntensity",get:function(){return this._state.maxIntensity},set:function(e){this._state.maxIntensity=null!=e?e:1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Cn[e];t?(this.pointSize=t.pointSize,this.roundPoints=t.roundPoints,this.perspectivePoints=t.perspectivePoints,this.minPerspectivePointSize=t.minPerspectivePointSize,this.maxPerspectivePointSize=t.maxPerspectivePointSize,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Cn).join(", "))}}},{key:"hash",get:function(){return[this.pointSize,this.roundPoints,this.perspectivePoints,this.minPerspectivePointSize,this.maxPerspectivePointSize,this.filterIntensity].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Bn={default:{lineWidth:1},thick:{lineWidth:2},thicker:{lineWidth:4}},On=function(e){I(n,In);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._state=new St({type:"LinesMaterial",lineWidth:null}),i.preset?(r.preset=i.preset,void 0!==i.lineWidth&&(r.lineWidth=i.lineWidth)):(r._preset="default",r.lineWidth=i.lineWidth),r}return P(n,[{key:"type",get:function(){return"LinesMaterial"}},{key:"presets",get:function(){return Bn}},{key:"lineWidth",get:function(){return this._state.lineWidth},set:function(e){this._state.lineWidth=e||1,this.glRedraw()}},{key:"preset",get:function(){return this._preset},set:function(e){if(e=e||"default",this._preset!==e){var t=Bn[e];t?(this.lineWidth=t.lineWidth,this._preset=e):this.error("unsupported preset: '"+e+"' - supported values are "+Object.keys(Bn).join(", "))}}},{key:"hash",get:function(){return[""+this.lineWidth].join(";")}},{key:"destroy",value:function(){v(T(n.prototype),"destroy",this).call(this),this._state.destroy()}}]),n}(),Sn=Z.vec3(),Nn=Z.vec3(),Ln=Z.mat4(),xn=function(){function e(){b(this,e),this.normal=Z.vec3(),this.offset=0,this.testVertex=Z.vec3()}return P(e,[{key:"set",value:function(e,t,n,r){var i=1/Math.sqrt(e*e+t*t+n*n);this.normal[0]=e*i,this.normal[1]=t*i,this.normal[2]=n*i,this.offset=r*i,this.testVertex[0]=this.normal[0]>=0?1:0,this.testVertex[1]=this.normal[1]>=0?1:0,this.testVertex[2]=this.normal[2]>=0?1:0}}]),e}(),Mn=P((function e(){b(this,e),this.planes=[new xn,new xn,new xn,new xn,new xn,new xn]}));function Fn(e,t,n){var r=Z.mulMat4(n,t,Ln),i=r[0],a=r[1],s=r[2],o=r[3],l=r[4],u=r[5],c=r[6],f=r[7],p=r[8],A=r[9],d=r[10],v=r[11],h=r[12],I=r[13],y=r[14],m=r[15];e.planes[0].set(o-i,f-l,v-p,m-h),e.planes[1].set(o+i,f+l,v+p,m+h),e.planes[2].set(o-a,f-u,v-A,m-I),e.planes[3].set(o+a,f+u,v+A,m+I),e.planes[4].set(o-s,f-c,v-d,m-y),e.planes[5].set(o+s,f+c,v+d,m+y)}function Hn(e,t){var n=Mn.INSIDE,r=Sn,i=Nn;r[0]=t[0],r[1]=t[1],r[2]=t[2],i[0]=t[3],i[1]=t[4],i[2]=t[5];for(var a=[r,i],s=0;s<6;++s){var o=e.planes[s];if(o.normal[0]*a[o.testVertex[0]][0]+o.normal[1]*a[o.testVertex[1]][1]+o.normal[2]*a[o.testVertex[2]][2]+o.offset<0)return Mn.OUTSIDE;o.normal[0]*a[1-o.testVertex[0]][0]+o.normal[1]*a[1-o.testVertex[1]][1]+o.normal[2]*a[1-o.testVertex[2]][2]+o.offset<0&&(n=Mn.INTERSECT)}return n}Mn.INSIDE=0,Mn.INTERSECT=1,Mn.OUTSIDE=2;var Un=function(){function e(t,n){b(this,e),this.primLODLevels=t,this.entitiesInLOD={},this.primCountInLOD={},this.targetFps=n,this.lodLevelIndex=0,this.consecutiveFramesWithTargetFps=0,this.consecutiveFramesWithoutTargetFps=0}return P(e,[{key:"initializeLodState",value:function(e){var t=Object.values(e.objects);if(0!==t.length){for(var n={},r={},i=0,a=t.length;i=this.primLODLevels[l]);l++);var u=this.primLODLevels[l]||0;u in n||(n[u]=[]),n[u].push(s),u in r||(r[u]=0),r[u]+=s.numPrimitives}this.entitiesInLOD=n,this.primCountInLOD=r}}}]),e}(),Gn=function(){function e(t,n,r,i){b(this,e),this.id=n.id,this.scene=t,this.sceneModel=n,this.lodState=new Un(r,i),this.lodState.initializeLodState(n)}return P(e,[{key:"_increaseLODLevelIndex",value:function(){var e=this.lodState;if(e.lodLevelIndex===e.primLODLevels.length)return!1;for(var t=e.entitiesInLOD[e.primLODLevels[e.lodLevelIndex]]||[],n=0,r=t.length;n0&&(t.consecutiveFramesWithoutTargetFps=0,n=this._increaseLODLevelIndex()):e>t.targetFps+4&&++t.consecutiveFramesWithTargetFps>1&&(t.consecutiveFramesWithTargetFps=0,n=this._decreaseLODLevelIndex()),n}},{key:"resetLodCulling",value:function(){var e=!1,t=!1;do{e|=t=this._decreaseLODLevelIndex()}while(t);return e}}]),e}(),kn=function(e){I(n,ve);var t=m(n);function n(e){var r,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return b(this,n),(r=t.call(this,e,i))._scene=e,r._lodLevels=[2e3,600,150,80,20],r._lodManagers={},r._lodManagerList=[],r.enabled=i.enabled,r.targetFPS=i.targetFPS,r._init(),r}return P(n,[{key:"_init",value:function(){var e=this,t=new Array(4),n=0,r=-1,i=Date.now(),a=0,s=0,o=s;this._scene.on("rendering",(function(){if(-1!==r)for(var t=0,n=e._lodManagerList.length;t4){for(var o=0;o<4;o++)s+=t[o];r=4/s*1e3}}))})),this._scene.camera.on("matrix",(function(){o=s})),this._scene.on("tick",(function(){if(s-o>3)for(var t=0,n=e._lodManagerList.length;t=e.minX&&t.maxY>=e.minY&&t.maxZ>=e.minZ},n.boxRayIntersects=function(e,t,n,r,i,a,s){var o=(e.minX-t)*i,l=(e.maxX-t)*i,u=(e.minY-n)*a,c=(e.maxY-n)*a,f=(e.minZ-r)*s,p=(e.maxZ-r)*s,A=Math.min(f,p),d=Math.max(f,p),v=Math.min(u,c),h=Math.max(u,c),I=Math.min(o,l),y=Math.max(o,l),m=Math.max(0,I,v,A);return Math.min(y,h,d)>=m?m:1/0};var g=function(e,t,n,i,a){for(var s,o=[t,n];o.length;)(n=o.pop())-(t=o.pop())<=i||(s=t+Math.ceil((n-t)/i/2)*i,r(e,s,t,n,a),o.push(t,s,s,n))},T=function(e,t){return e.minX-t.minX},E=function(e,t){return e.minY-t.minY},b=function(e,t){return e.minZ-t.minZ},D=function(){function e(e){void 0===e&&(e=16),this.maxEntries=Math.max(e,8),this.minEntries=Math.max(4,Math.ceil(.4*this.maxEntries)),this.clear()}return e.alloc=function(){return this.pool.pop()||new this},e.free=function(e){e.clear(),this.pool.push(e)},e.prototype.searchCustom=function(e,t){var n=this.data,r=[];if(!e(n,f(n)))return r;for(var i=[];n;){for(var a=0,s=n.children.length;a1){for(d=0,v=(c=c[c.length-1]).length;d=t)break;var i=r+1;if(i0;){var r=n-1>>1;if(A[r].dist<=A[n].dist)break;d(n,r),n=r}},I=o;A.length&&A[0].dist=t;o--){l=e.children[o];v(a,l),s+=I(a)}return s},e.prototype.adjustParentBBoxes=function(e,t,n){for(var r=n;r>=0;r--)v(t[r],e)},e.prototype.condense=function(e){for(var t=e.length-1,n=void 0;t>=0;t--)0===e[t].children.length?t>0?((n=e[t-1].children).splice(n.indexOf(e[t]),1),a(e[t])):this.clear():A(e[t])},e.prototype._insert=function(e,t,n){var r=[],i=this.chooseSubtree(e,this.data,t,r);for(i.children.push(e),v(i,e);t>=0&&r[t].children.length>this.maxEntries;)this.split(r,t),t--;this.adjustParentBBoxes(e,r,t)},e.pool=[],e}();n.RBush3D=D},{quickselect:2}],2:[function(e,t,n){!function(e,r){"object"===E(n)&&void 0!==t?t.exports=r():e.quickselect=r()}(this,(function(){function e(n,r,i,a,s){for(;a>i;){if(a-i>600){var o=a-i+1,l=r-i+1,u=Math.log(o),c=.5*Math.exp(2*u/3),f=.5*Math.sqrt(u*c*(o-c)/o)*(l-o/2<0?-1:1);e(n,r,Math.max(i,Math.floor(r-l*c/o+f)),Math.min(a,Math.floor(r+(o-l)*c/o+f)),s)}var p=n[r],A=i,d=a;for(t(n,i,r),s(n[a],p)>0&&t(n,i,a);A0;)d--}0===s(n[i],p)?t(n,i,d):t(n,++d,a),d<=r&&(i=d+1),r<=d&&(a=d-1)}}function t(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function n(e,t){return et?1:0}return function(t,r,i,a,s){e(t,r,i||0,a||t.length-1,s||n)}}))},{}]},{},[1])(1)}));var Qn=Vn.exports.RBush3D,Wn=function(e){function t(e){var t=0;return e.meshes.forEach((function(e){t+=e.numPrimitives})),t}function n(e,t){var n={pos:{x:0,y:0},left:0,right:e,top:0,bottom:t,dir:0};function r(){(0==n.dir&&n.pos.x+1>=n.right||1==n.dir&&n.pos.y+1>=n.bottom||2==n.dir&&n.pos.x-1<=n.left-1||3==n.dir&&n.pos.y-1<=n.top-1)&&(n.dir=(n.dir+1)%4,0==n.dir&&n.left++,1==n.dir&&n.top++,2==n.dir&&n.right--,3==n.dir&&n.bottom--),0==n.dir&&n.pos.x++,1==n.dir&&n.pos.y++,2==n.dir&&n.pos.x--,3==n.dir&&n.pos.y--}for(var i=[],a=e*t;i.lengthp&&(c.push(f),f=[],p=o),f.push(d),p-=v}}while(Ap&&(c.push(A),A=[],p=o),A.push(e),p-=n})),A.length&&c.push(A);var d={};return c.forEach((function(e,t){e.forEach((function(e){d[e.id]=t}))})),{clusters:c,entityIdToClusterIdMapping:d}}(i.cellsX,i.cellsZ,a.maxCellsPerEntity,i.entitiesByCell,i.cellsByEntity,r.maxPolygonsPerCluster),{clusters:{total:s.clusters.length},clusteringResult:s});o+=l.clusters.total,console.log("Total clusters: "+o);var u=[];return l.clusteringResult.clusters.forEach((function(e){e.forEach((function(e){u.push(e.id)}))})),l.orderedEntityIds=u,l}; /** * @author https://github.com/tmarti, with support from https://tribia.com/ * @license MIT